@orval/query 6.21.0 → 6.22.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.d.ts +3 -2
- package/dist/index.js +41 -24
- 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
|
|
@@ -1829,7 +1831,10 @@ var VUE_QUERY_DEPENDENCIES_V3 = [
|
|
|
1829
1831
|
dependency: "vue-query/types"
|
|
1830
1832
|
},
|
|
1831
1833
|
{
|
|
1832
|
-
exports: [
|
|
1834
|
+
exports: [
|
|
1835
|
+
{ name: "unref", values: true },
|
|
1836
|
+
{ name: "computed", values: true }
|
|
1837
|
+
],
|
|
1833
1838
|
dependency: "vue"
|
|
1834
1839
|
},
|
|
1835
1840
|
{
|
|
@@ -1855,12 +1860,12 @@ var VUE_QUERY_DEPENDENCIES = [
|
|
|
1855
1860
|
dependency: "@tanstack/vue-query"
|
|
1856
1861
|
},
|
|
1857
1862
|
{
|
|
1858
|
-
exports: [
|
|
1863
|
+
exports: [
|
|
1864
|
+
{ name: "unref", values: true },
|
|
1865
|
+
{ name: "MaybeRef" },
|
|
1866
|
+
{ name: "computed", values: true }
|
|
1867
|
+
],
|
|
1859
1868
|
dependency: "vue"
|
|
1860
|
-
},
|
|
1861
|
-
{
|
|
1862
|
-
exports: [{ name: "MaybeRef" }],
|
|
1863
|
-
dependency: "@tanstack/vue-query/build/lib/types"
|
|
1864
1869
|
}
|
|
1865
1870
|
];
|
|
1866
1871
|
var isVueQueryV3 = (packageJson) => {
|
|
@@ -1921,12 +1926,16 @@ var generateQueryRequestFunction = ({
|
|
|
1921
1926
|
formUrlEncoded,
|
|
1922
1927
|
paramsSerializer,
|
|
1923
1928
|
override
|
|
1924
|
-
}, { route, context }, outputClient) => {
|
|
1929
|
+
}, { route: _route, context }, outputClient, output) => {
|
|
1925
1930
|
var _a, _b;
|
|
1926
1931
|
let props = _props;
|
|
1932
|
+
let route = _route;
|
|
1927
1933
|
if (isVue(outputClient)) {
|
|
1928
1934
|
props = vueWrapTypeWithMaybeRef(_props);
|
|
1929
1935
|
}
|
|
1936
|
+
if (output == null ? void 0 : output.urlEncodeParameters) {
|
|
1937
|
+
route = makeRouteSafe(route);
|
|
1938
|
+
}
|
|
1930
1939
|
const isRequestOptions = override.requestOptions !== false;
|
|
1931
1940
|
const isFormData = override.formData !== false;
|
|
1932
1941
|
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
@@ -1955,7 +1964,8 @@ var generateQueryRequestFunction = ({
|
|
|
1955
1964
|
isFormUrlEncoded,
|
|
1956
1965
|
isBodyVerb,
|
|
1957
1966
|
hasSignal,
|
|
1958
|
-
isExactOptionalPropertyTypes
|
|
1967
|
+
isExactOptionalPropertyTypes,
|
|
1968
|
+
isVue: isVue(outputClient)
|
|
1959
1969
|
});
|
|
1960
1970
|
let bodyDefinition = body.definition.replace("[]", "\\[\\]");
|
|
1961
1971
|
let propsImplementation = (mutator == null ? void 0 : mutator.bodyTypeName) && body.definition ? (0, import_core2.toObjectString)(props, "implementation").replace(
|
|
@@ -2004,7 +2014,8 @@ var generateQueryRequestFunction = ({
|
|
|
2004
2014
|
paramsSerializer,
|
|
2005
2015
|
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
2006
2016
|
isExactOptionalPropertyTypes,
|
|
2007
|
-
hasSignal
|
|
2017
|
+
hasSignal,
|
|
2018
|
+
isVue: isVue(outputClient)
|
|
2008
2019
|
});
|
|
2009
2020
|
const optionsArgs = generateRequestOptionsArguments({
|
|
2010
2021
|
isRequestOptions,
|
|
@@ -2028,7 +2039,8 @@ var INFINITE_QUERY_PROPERTIES = ["getNextPageParam", "getPreviousPageParam"];
|
|
|
2028
2039
|
var generateQueryOptions = ({
|
|
2029
2040
|
params,
|
|
2030
2041
|
options,
|
|
2031
|
-
type
|
|
2042
|
+
type,
|
|
2043
|
+
outputClient
|
|
2032
2044
|
}) => {
|
|
2033
2045
|
var _a;
|
|
2034
2046
|
if (options === false) {
|
|
@@ -2046,7 +2058,7 @@ var generateQueryOptions = ({
|
|
|
2046
2058
|
}
|
|
2047
2059
|
return "...queryOptions";
|
|
2048
2060
|
}
|
|
2049
|
-
return `${!(0, import_core2.isObject)(options) || !options.hasOwnProperty("enabled") ? `enabled: !!(${params.map(({ name }) => name).join(" && ")}),` : ""}${queryConfig} ...queryOptions`;
|
|
2061
|
+
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
2062
|
};
|
|
2051
2063
|
var getQueryArgumentsRequestType = (mutator) => {
|
|
2052
2064
|
if (!mutator) {
|
|
@@ -2080,7 +2092,7 @@ var getQueryOptionsDefinition = ({
|
|
|
2080
2092
|
type
|
|
2081
2093
|
)}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
2094
|
}
|
|
2083
|
-
return `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core2.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "
|
|
2095
|
+
return `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core2.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "{}"}, TContext>`;
|
|
2084
2096
|
};
|
|
2085
2097
|
var generateQueryArguments = ({
|
|
2086
2098
|
operationName,
|
|
@@ -2285,7 +2297,8 @@ var generateQueryImplementation = ({
|
|
|
2285
2297
|
const queryOptionsImp = generateQueryOptions({
|
|
2286
2298
|
params,
|
|
2287
2299
|
options,
|
|
2288
|
-
type
|
|
2300
|
+
type,
|
|
2301
|
+
outputClient
|
|
2289
2302
|
});
|
|
2290
2303
|
const queryOptionsFnName = (0, import_core2.camel)(
|
|
2291
2304
|
queryKeyMutator || queryOptionsMutator || (mutator == null ? void 0 : mutator.isHook) ? `use-${name}-queryOptions` : `get-${name}-queryOptions`
|
|
@@ -2386,7 +2399,7 @@ var generateQueryHook = async ({
|
|
|
2386
2399
|
const doc = (0, import_core2.jsDoc)({ summary, deprecated });
|
|
2387
2400
|
let implementation = "";
|
|
2388
2401
|
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);
|
|
2402
|
+
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
2403
|
if (isQuery) {
|
|
2391
2404
|
const queryKeyMutator = query.queryKey ? await (0, import_core2.generateMutator)({
|
|
2392
2405
|
output,
|
|
@@ -2421,7 +2434,7 @@ var generateQueryHook = async ({
|
|
|
2421
2434
|
queryParam: query == null ? void 0 : query.useInfiniteQueryParam
|
|
2422
2435
|
}
|
|
2423
2436
|
] : [],
|
|
2424
|
-
|
|
2437
|
+
...(query == null ? void 0 : query.useQuery) ? [
|
|
2425
2438
|
{
|
|
2426
2439
|
name: operationName,
|
|
2427
2440
|
options: query == null ? void 0 : query.options,
|
|
@@ -2449,9 +2462,8 @@ var generateQueryHook = async ({
|
|
|
2449
2462
|
props.filter((prop) => prop.type !== import_core2.GetterPropType.HEADER),
|
|
2450
2463
|
"implementation"
|
|
2451
2464
|
);
|
|
2452
|
-
const routeString = `\`${route}\``;
|
|
2465
|
+
const routeString = isVue(outputClient) ? (0, import_core2.getRouteAsArray)(route) : `\`${route}\``;
|
|
2453
2466
|
const queryKeyFn = `export const ${queryKeyFnName} = (${queryKeyProps}) => {
|
|
2454
|
-
${isVue(outputClient) ? vueUnRefParams(props) : ""}
|
|
2455
2467
|
return [${routeString}${queryParams ? ", ...(params ? [params]: [])" : ""}${body.implementation ? `, ${body.implementation}` : ""}] as const;
|
|
2456
2468
|
}`;
|
|
2457
2469
|
implementation += `${!queryKeyMutator ? queryKeyFn : ""}
|
|
@@ -2528,14 +2540,13 @@ var generateQueryHook = async ({
|
|
|
2528
2540
|
);
|
|
2529
2541
|
const mutationOptionsVarName = isRequestOptions ? "mutationOptions" : "options";
|
|
2530
2542
|
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
|
|
2531
|
-
${!definitions ? `TVariables = void,` : ""}
|
|
2532
2543
|
TContext = unknown>(${mutationArguments}): ${mutationOptionFnReturnType} => {
|
|
2533
2544
|
${isRequestOptions ? `const {mutation: mutationOptions${!mutator ? `, axios: axiosOptions` : (mutator == null ? void 0 : mutator.hasSecondArg) ? ", request: requestOptions" : ""}} = options ?? {};` : ""}
|
|
2534
2545
|
|
|
2535
2546
|
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0, import_core2.pascal)(operationName)}Hook()` : ""}
|
|
2536
2547
|
|
|
2537
2548
|
|
|
2538
|
-
const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "
|
|
2549
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "{}"}> = (${properties ? "props" : ""}) => {
|
|
2539
2550
|
${properties ? `const {${properties}} = props ?? {};` : ""}
|
|
2540
2551
|
|
|
2541
2552
|
return ${operationName}(${properties}${properties ? "," : ""}${isRequestOptions ? !mutator ? `axiosOptions` : (mutator == null ? void 0 : mutator.hasSecondArg) ? "requestOptions" : "" : ""})
|
|
@@ -2558,7 +2569,6 @@ ${mutationOptionsFn}
|
|
|
2558
2569
|
${doc}export const ${(0, import_core2.camel)(
|
|
2559
2570
|
`${operationPrefix}-${operationName}`
|
|
2560
2571
|
)} = <TError = ${errorType},
|
|
2561
|
-
${!definitions ? `TVariables = void,` : ""}
|
|
2562
2572
|
TContext = unknown>(${mutationArguments}) => {
|
|
2563
2573
|
|
|
2564
2574
|
const ${mutationOptionsVarName} = ${mutationOptionsFnName}(${isRequestOptions ? "options" : "mutationOptions"});
|
|
@@ -2594,12 +2604,13 @@ ${isRequestOptions && isMutator ? `// eslint-disable-next-line
|
|
|
2594
2604
|
` : ""}
|
|
2595
2605
|
`;
|
|
2596
2606
|
};
|
|
2597
|
-
var generateQuery = async (verbOptions, options, outputClient) => {
|
|
2607
|
+
var generateQuery = async (verbOptions, options, outputClient, output) => {
|
|
2598
2608
|
const imports = (0, import_core2.generateVerbImports)(verbOptions);
|
|
2599
2609
|
const functionImplementation = generateQueryRequestFunction(
|
|
2600
2610
|
verbOptions,
|
|
2601
2611
|
options,
|
|
2602
|
-
outputClient
|
|
2612
|
+
outputClient,
|
|
2613
|
+
output
|
|
2603
2614
|
);
|
|
2604
2615
|
const { implementation: hookImplementation, mutators } = await generateQueryHook(verbOptions, options, outputClient);
|
|
2605
2616
|
return {
|
|
@@ -2617,9 +2628,15 @@ var dependenciesBuilder = {
|
|
|
2617
2628
|
};
|
|
2618
2629
|
var builder = ({
|
|
2619
2630
|
type = "react-query",
|
|
2620
|
-
options: queryOptions
|
|
2631
|
+
options: queryOptions,
|
|
2632
|
+
output
|
|
2621
2633
|
} = {}) => () => {
|
|
2622
2634
|
const client = (verbOptions, options, outputClient) => {
|
|
2635
|
+
if (options.override.useNamedParameters && (type === "vue-query" || outputClient === "vue-query")) {
|
|
2636
|
+
throw new Error(
|
|
2637
|
+
`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`
|
|
2638
|
+
);
|
|
2639
|
+
}
|
|
2623
2640
|
if (queryOptions) {
|
|
2624
2641
|
const normalizedQueryOptions = normalizeQueryOptions(
|
|
2625
2642
|
queryOptions,
|
|
@@ -2634,7 +2651,7 @@ var builder = ({
|
|
|
2634
2651
|
verbOptions.override.query
|
|
2635
2652
|
);
|
|
2636
2653
|
}
|
|
2637
|
-
return generateQuery(verbOptions, options, outputClient);
|
|
2654
|
+
return generateQuery(verbOptions, options, outputClient, output);
|
|
2638
2655
|
};
|
|
2639
2656
|
return {
|
|
2640
2657
|
client,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/query",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.22.0",
|
|
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.0",
|
|
18
|
+
"lodash.omitby": "^4.6.0",
|
|
19
|
+
"vitest": "^0.34.6"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
22
|
"@types/lodash.omitby": "^4.6.7"
|