@orval/query 6.21.0 → 6.22.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/dist/index.d.ts +3 -2
- package/dist/index.js +46 -27
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { ClientDependenciesBuilder, ClientHeaderBuilder, ClientBuilder, QueryOptions } from '@orval/core';
|
|
1
|
+
import { ClientDependenciesBuilder, ClientHeaderBuilder, ClientBuilder, QueryOptions, NormalizedOutputOptions } from '@orval/core';
|
|
2
2
|
|
|
3
3
|
declare const getSvelteQueryDependencies: ClientDependenciesBuilder;
|
|
4
4
|
declare const getReactQueryDependencies: ClientDependenciesBuilder;
|
|
5
5
|
declare const getVueQueryDependencies: ClientDependenciesBuilder;
|
|
6
6
|
declare const generateQueryHeader: ClientHeaderBuilder;
|
|
7
7
|
declare const generateQuery: ClientBuilder;
|
|
8
|
-
declare const builder: ({ type, options: queryOptions, }?: {
|
|
8
|
+
declare const builder: ({ type, options: queryOptions, output, }?: {
|
|
9
9
|
type?: "react-query" | "vue-query" | "svelte-query" | undefined;
|
|
10
10
|
options?: QueryOptions | undefined;
|
|
11
|
+
output?: NormalizedOutputOptions | undefined;
|
|
11
12
|
}) => () => {
|
|
12
13
|
client: ClientBuilder;
|
|
13
14
|
header: ClientHeaderBuilder;
|
package/dist/index.js
CHANGED
|
@@ -1665,6 +1665,8 @@ var vueUnRefParams = (props) => {
|
|
|
1665
1665
|
return `${prop.name} = unref(${prop.name});`;
|
|
1666
1666
|
}).join("\n");
|
|
1667
1667
|
};
|
|
1668
|
+
var wrapRouteParameters = (route, prepend, append) => route.replaceAll(/\${(.+?)}/g, `\${${prepend}$1${append}}`);
|
|
1669
|
+
var makeRouteSafe = (route) => wrapRouteParameters(route, "encodeURIComponent(String(", "))");
|
|
1668
1670
|
var isVue = (client) => import_core.OutputClient.VUE_QUERY === client;
|
|
1669
1671
|
|
|
1670
1672
|
// src/index.ts
|
|
@@ -1732,7 +1734,8 @@ var SVELTE_QUERY_DEPENDENCIES = [
|
|
|
1732
1734
|
{ name: "MutationFunction" },
|
|
1733
1735
|
{ name: "CreateQueryResult" },
|
|
1734
1736
|
{ name: "CreateInfiniteQueryResult" },
|
|
1735
|
-
{ name: "QueryKey" }
|
|
1737
|
+
{ name: "QueryKey" },
|
|
1738
|
+
{ name: "InfiniteData" }
|
|
1736
1739
|
],
|
|
1737
1740
|
dependency: "@tanstack/svelte-query"
|
|
1738
1741
|
}
|
|
@@ -1829,7 +1832,10 @@ var VUE_QUERY_DEPENDENCIES_V3 = [
|
|
|
1829
1832
|
dependency: "vue-query/types"
|
|
1830
1833
|
},
|
|
1831
1834
|
{
|
|
1832
|
-
exports: [
|
|
1835
|
+
exports: [
|
|
1836
|
+
{ name: "unref", values: true },
|
|
1837
|
+
{ name: "computed", values: true }
|
|
1838
|
+
],
|
|
1833
1839
|
dependency: "vue"
|
|
1834
1840
|
},
|
|
1835
1841
|
{
|
|
@@ -1850,17 +1856,18 @@ var VUE_QUERY_DEPENDENCIES = [
|
|
|
1850
1856
|
{ name: "MutationFunction" },
|
|
1851
1857
|
{ name: "QueryKey" },
|
|
1852
1858
|
{ name: "UseQueryReturnType" },
|
|
1853
|
-
{ name: "UseInfiniteQueryReturnType" }
|
|
1859
|
+
{ name: "UseInfiniteQueryReturnType" },
|
|
1860
|
+
{ name: "InfiniteData" }
|
|
1854
1861
|
],
|
|
1855
1862
|
dependency: "@tanstack/vue-query"
|
|
1856
1863
|
},
|
|
1857
1864
|
{
|
|
1858
|
-
exports: [
|
|
1865
|
+
exports: [
|
|
1866
|
+
{ name: "unref", values: true },
|
|
1867
|
+
{ name: "MaybeRef" },
|
|
1868
|
+
{ name: "computed", values: true }
|
|
1869
|
+
],
|
|
1859
1870
|
dependency: "vue"
|
|
1860
|
-
},
|
|
1861
|
-
{
|
|
1862
|
-
exports: [{ name: "MaybeRef" }],
|
|
1863
|
-
dependency: "@tanstack/vue-query/build/lib/types"
|
|
1864
1871
|
}
|
|
1865
1872
|
];
|
|
1866
1873
|
var isVueQueryV3 = (packageJson) => {
|
|
@@ -1892,7 +1899,7 @@ var getPackageByQueryClient = (packageJson, queryClient) => {
|
|
|
1892
1899
|
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"];
|
|
1893
1900
|
}
|
|
1894
1901
|
case "svelte-query": {
|
|
1895
|
-
return (_f = (_d = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _d["@
|
|
1902
|
+
return (_f = (_d = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _d["@tanstack/svelte-query"]) != null ? _f : (_e = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _e["@tanstack/svelte-query"];
|
|
1896
1903
|
}
|
|
1897
1904
|
case "vue-query": {
|
|
1898
1905
|
return (_i = (_g = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _g["@tanstack/vue-query"]) != null ? _i : (_h = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _h["@tanstack/vue-query"];
|
|
@@ -1921,12 +1928,16 @@ var generateQueryRequestFunction = ({
|
|
|
1921
1928
|
formUrlEncoded,
|
|
1922
1929
|
paramsSerializer,
|
|
1923
1930
|
override
|
|
1924
|
-
}, { route, context }, outputClient) => {
|
|
1931
|
+
}, { route: _route, context }, outputClient, output) => {
|
|
1925
1932
|
var _a, _b;
|
|
1926
1933
|
let props = _props;
|
|
1934
|
+
let route = _route;
|
|
1927
1935
|
if (isVue(outputClient)) {
|
|
1928
1936
|
props = vueWrapTypeWithMaybeRef(_props);
|
|
1929
1937
|
}
|
|
1938
|
+
if (output == null ? void 0 : output.urlEncodeParameters) {
|
|
1939
|
+
route = makeRouteSafe(route);
|
|
1940
|
+
}
|
|
1930
1941
|
const isRequestOptions = override.requestOptions !== false;
|
|
1931
1942
|
const isFormData = override.formData !== false;
|
|
1932
1943
|
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
@@ -1955,7 +1966,8 @@ var generateQueryRequestFunction = ({
|
|
|
1955
1966
|
isFormUrlEncoded,
|
|
1956
1967
|
isBodyVerb,
|
|
1957
1968
|
hasSignal,
|
|
1958
|
-
isExactOptionalPropertyTypes
|
|
1969
|
+
isExactOptionalPropertyTypes,
|
|
1970
|
+
isVue: isVue(outputClient)
|
|
1959
1971
|
});
|
|
1960
1972
|
let bodyDefinition = body.definition.replace("[]", "\\[\\]");
|
|
1961
1973
|
let propsImplementation = (mutator == null ? void 0 : mutator.bodyTypeName) && body.definition ? (0, import_core2.toObjectString)(props, "implementation").replace(
|
|
@@ -2004,7 +2016,8 @@ var generateQueryRequestFunction = ({
|
|
|
2004
2016
|
paramsSerializer,
|
|
2005
2017
|
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
2006
2018
|
isExactOptionalPropertyTypes,
|
|
2007
|
-
hasSignal
|
|
2019
|
+
hasSignal,
|
|
2020
|
+
isVue: isVue(outputClient)
|
|
2008
2021
|
});
|
|
2009
2022
|
const optionsArgs = generateRequestOptionsArguments({
|
|
2010
2023
|
isRequestOptions,
|
|
@@ -2028,7 +2041,8 @@ var INFINITE_QUERY_PROPERTIES = ["getNextPageParam", "getPreviousPageParam"];
|
|
|
2028
2041
|
var generateQueryOptions = ({
|
|
2029
2042
|
params,
|
|
2030
2043
|
options,
|
|
2031
|
-
type
|
|
2044
|
+
type,
|
|
2045
|
+
outputClient
|
|
2032
2046
|
}) => {
|
|
2033
2047
|
var _a;
|
|
2034
2048
|
if (options === false) {
|
|
@@ -2046,7 +2060,7 @@ var generateQueryOptions = ({
|
|
|
2046
2060
|
}
|
|
2047
2061
|
return "...queryOptions";
|
|
2048
2062
|
}
|
|
2049
|
-
return `${!(0, import_core2.isObject)(options) || !options.hasOwnProperty("enabled") ? `enabled: !!(${params.map(({ name }) => name).join(" && ")}),` : ""}${queryConfig} ...queryOptions`;
|
|
2063
|
+
return `${!(0, import_core2.isObject)(options) || !options.hasOwnProperty("enabled") ? isVue(outputClient) ? `enabled: computed(() => !!(${params.map(({ name }) => `unref(${name})`).join(" && ")})),` : `enabled: !!(${params.map(({ name }) => name).join(" && ")}),` : ""}${queryConfig} ...queryOptions`;
|
|
2050
2064
|
};
|
|
2051
2065
|
var getQueryArgumentsRequestType = (mutator) => {
|
|
2052
2066
|
if (!mutator) {
|
|
@@ -2080,7 +2094,7 @@ var getQueryOptionsDefinition = ({
|
|
|
2080
2094
|
type
|
|
2081
2095
|
)}Options<${funcReturnType}, TError, TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, ${funcReturnType}, QueryKey, ${queryParams == null ? void 0 : queryParams.schema.name}['${queryParam}']` : ""}>${partialOptions ? ">" : ""}`;
|
|
2082
2096
|
}
|
|
2083
|
-
return `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core2.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "
|
|
2097
|
+
return `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core2.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "void"}, TContext>`;
|
|
2084
2098
|
};
|
|
2085
2099
|
var generateQueryArguments = ({
|
|
2086
2100
|
operationName,
|
|
@@ -2285,7 +2299,8 @@ var generateQueryImplementation = ({
|
|
|
2285
2299
|
const queryOptionsImp = generateQueryOptions({
|
|
2286
2300
|
params,
|
|
2287
2301
|
options,
|
|
2288
|
-
type
|
|
2302
|
+
type,
|
|
2303
|
+
outputClient
|
|
2289
2304
|
});
|
|
2290
2305
|
const queryOptionsFnName = (0, import_core2.camel)(
|
|
2291
2306
|
queryKeyMutator || queryOptionsMutator || (mutator == null ? void 0 : mutator.isHook) ? `use-${name}-queryOptions` : `get-${name}-queryOptions`
|
|
@@ -2386,7 +2401,7 @@ var generateQueryHook = async ({
|
|
|
2386
2401
|
const doc = (0, import_core2.jsDoc)({ summary, deprecated });
|
|
2387
2402
|
let implementation = "";
|
|
2388
2403
|
let mutators = void 0;
|
|
2389
|
-
const isQuery = import_core2.Verbs.GET === verb && (override.query.useQuery || override.query.useInfinite) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useInfinite) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useQuery);
|
|
2404
|
+
const isQuery = import_core2.Verbs.GET === verb && (override.query.useQuery || override.query.useSuspenseQuery || override.query.useInfinite || override.query.useSuspenseInfiniteQuery) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useInfinite) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useSuspenseInfiniteQuery) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useQuery) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useSuspenseQuery);
|
|
2390
2405
|
if (isQuery) {
|
|
2391
2406
|
const queryKeyMutator = query.queryKey ? await (0, import_core2.generateMutator)({
|
|
2392
2407
|
output,
|
|
@@ -2421,7 +2436,7 @@ var generateQueryHook = async ({
|
|
|
2421
2436
|
queryParam: query == null ? void 0 : query.useInfiniteQueryParam
|
|
2422
2437
|
}
|
|
2423
2438
|
] : [],
|
|
2424
|
-
|
|
2439
|
+
...(query == null ? void 0 : query.useQuery) ? [
|
|
2425
2440
|
{
|
|
2426
2441
|
name: operationName,
|
|
2427
2442
|
options: query == null ? void 0 : query.options,
|
|
@@ -2449,9 +2464,8 @@ var generateQueryHook = async ({
|
|
|
2449
2464
|
props.filter((prop) => prop.type !== import_core2.GetterPropType.HEADER),
|
|
2450
2465
|
"implementation"
|
|
2451
2466
|
);
|
|
2452
|
-
const routeString = `\`${route}\``;
|
|
2467
|
+
const routeString = isVue(outputClient) ? (0, import_core2.getRouteAsArray)(route) : `\`${route}\``;
|
|
2453
2468
|
const queryKeyFn = `export const ${queryKeyFnName} = (${queryKeyProps}) => {
|
|
2454
|
-
${isVue(outputClient) ? vueUnRefParams(props) : ""}
|
|
2455
2469
|
return [${routeString}${queryParams ? ", ...(params ? [params]: [])" : ""}${body.implementation ? `, ${body.implementation}` : ""}] as const;
|
|
2456
2470
|
}`;
|
|
2457
2471
|
implementation += `${!queryKeyMutator ? queryKeyFn : ""}
|
|
@@ -2528,14 +2542,13 @@ var generateQueryHook = async ({
|
|
|
2528
2542
|
);
|
|
2529
2543
|
const mutationOptionsVarName = isRequestOptions ? "mutationOptions" : "options";
|
|
2530
2544
|
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
|
|
2531
|
-
${!definitions ? `TVariables = void,` : ""}
|
|
2532
2545
|
TContext = unknown>(${mutationArguments}): ${mutationOptionFnReturnType} => {
|
|
2533
2546
|
${isRequestOptions ? `const {mutation: mutationOptions${!mutator ? `, axios: axiosOptions` : (mutator == null ? void 0 : mutator.hasSecondArg) ? ", request: requestOptions" : ""}} = options ?? {};` : ""}
|
|
2534
2547
|
|
|
2535
2548
|
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0, import_core2.pascal)(operationName)}Hook()` : ""}
|
|
2536
2549
|
|
|
2537
2550
|
|
|
2538
|
-
const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "
|
|
2551
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "void"}> = (${properties ? "props" : ""}) => {
|
|
2539
2552
|
${properties ? `const {${properties}} = props ?? {};` : ""}
|
|
2540
2553
|
|
|
2541
2554
|
return ${operationName}(${properties}${properties ? "," : ""}${isRequestOptions ? !mutator ? `axiosOptions` : (mutator == null ? void 0 : mutator.hasSecondArg) ? "requestOptions" : "" : ""})
|
|
@@ -2558,7 +2571,6 @@ ${mutationOptionsFn}
|
|
|
2558
2571
|
${doc}export const ${(0, import_core2.camel)(
|
|
2559
2572
|
`${operationPrefix}-${operationName}`
|
|
2560
2573
|
)} = <TError = ${errorType},
|
|
2561
|
-
${!definitions ? `TVariables = void,` : ""}
|
|
2562
2574
|
TContext = unknown>(${mutationArguments}) => {
|
|
2563
2575
|
|
|
2564
2576
|
const ${mutationOptionsVarName} = ${mutationOptionsFnName}(${isRequestOptions ? "options" : "mutationOptions"});
|
|
@@ -2594,12 +2606,13 @@ ${isRequestOptions && isMutator ? `// eslint-disable-next-line
|
|
|
2594
2606
|
` : ""}
|
|
2595
2607
|
`;
|
|
2596
2608
|
};
|
|
2597
|
-
var generateQuery = async (verbOptions, options, outputClient) => {
|
|
2609
|
+
var generateQuery = async (verbOptions, options, outputClient, output) => {
|
|
2598
2610
|
const imports = (0, import_core2.generateVerbImports)(verbOptions);
|
|
2599
2611
|
const functionImplementation = generateQueryRequestFunction(
|
|
2600
2612
|
verbOptions,
|
|
2601
2613
|
options,
|
|
2602
|
-
outputClient
|
|
2614
|
+
outputClient,
|
|
2615
|
+
output
|
|
2603
2616
|
);
|
|
2604
2617
|
const { implementation: hookImplementation, mutators } = await generateQueryHook(verbOptions, options, outputClient);
|
|
2605
2618
|
return {
|
|
@@ -2617,9 +2630,15 @@ var dependenciesBuilder = {
|
|
|
2617
2630
|
};
|
|
2618
2631
|
var builder = ({
|
|
2619
2632
|
type = "react-query",
|
|
2620
|
-
options: queryOptions
|
|
2633
|
+
options: queryOptions,
|
|
2634
|
+
output
|
|
2621
2635
|
} = {}) => () => {
|
|
2622
2636
|
const client = (verbOptions, options, outputClient) => {
|
|
2637
|
+
if (options.override.useNamedParameters && (type === "vue-query" || outputClient === "vue-query")) {
|
|
2638
|
+
throw new Error(
|
|
2639
|
+
`vue-query client does not support named parameters, and had broken reactivity previously, please set useNamedParameters to false; See for context: https://github.com/anymaniax/orval/pull/931#issuecomment-1752355686`
|
|
2640
|
+
);
|
|
2641
|
+
}
|
|
2623
2642
|
if (queryOptions) {
|
|
2624
2643
|
const normalizedQueryOptions = normalizeQueryOptions(
|
|
2625
2644
|
queryOptions,
|
|
@@ -2634,7 +2653,7 @@ var builder = ({
|
|
|
2634
2653
|
verbOptions.override.query
|
|
2635
2654
|
);
|
|
2636
2655
|
}
|
|
2637
|
-
return generateQuery(verbOptions, options, outputClient);
|
|
2656
|
+
return generateQuery(verbOptions, options, outputClient, output);
|
|
2638
2657
|
};
|
|
2639
2658
|
return {
|
|
2640
2659
|
client,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/query",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.22.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsup ./src/index.ts --target node12 --clean --dts",
|
|
12
12
|
"dev": "tsup ./src/index.ts --target node12 --clean --watch src",
|
|
13
|
-
"lint": "eslint src/**/*.ts"
|
|
13
|
+
"lint": "eslint src/**/*.ts",
|
|
14
|
+
"test": "vitest"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"@orval/core": "6.
|
|
17
|
-
"lodash.omitby": "^4.6.0"
|
|
17
|
+
"@orval/core": "6.22.1",
|
|
18
|
+
"lodash.omitby": "^4.6.0",
|
|
19
|
+
"vitest": "^0.34.6"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
22
|
"@types/lodash.omitby": "^4.6.7"
|