@orval/query 6.20.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 +47 -26
- 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
|
@@ -190,6 +190,7 @@ var require_color_name = __commonJS({
|
|
|
190
190
|
// ../../node_modules/color-convert/conversions.js
|
|
191
191
|
var require_conversions = __commonJS({
|
|
192
192
|
"../../node_modules/color-convert/conversions.js"(exports, module2) {
|
|
193
|
+
"use strict";
|
|
193
194
|
var cssKeywords = require_color_name();
|
|
194
195
|
var reverseKeywords = {};
|
|
195
196
|
for (const key of Object.keys(cssKeywords)) {
|
|
@@ -861,6 +862,7 @@ var require_conversions = __commonJS({
|
|
|
861
862
|
// ../../node_modules/color-convert/route.js
|
|
862
863
|
var require_route = __commonJS({
|
|
863
864
|
"../../node_modules/color-convert/route.js"(exports, module2) {
|
|
865
|
+
"use strict";
|
|
864
866
|
var conversions = require_conversions();
|
|
865
867
|
function buildGraph() {
|
|
866
868
|
const graph = {};
|
|
@@ -931,6 +933,7 @@ var require_route = __commonJS({
|
|
|
931
933
|
// ../../node_modules/color-convert/index.js
|
|
932
934
|
var require_color_convert = __commonJS({
|
|
933
935
|
"../../node_modules/color-convert/index.js"(exports, module2) {
|
|
936
|
+
"use strict";
|
|
934
937
|
var conversions = require_conversions();
|
|
935
938
|
var route = require_route();
|
|
936
939
|
var convert = {};
|
|
@@ -1662,6 +1665,8 @@ var vueUnRefParams = (props) => {
|
|
|
1662
1665
|
return `${prop.name} = unref(${prop.name});`;
|
|
1663
1666
|
}).join("\n");
|
|
1664
1667
|
};
|
|
1668
|
+
var wrapRouteParameters = (route, prepend, append) => route.replaceAll(/\${(.+?)}/g, `\${${prepend}$1${append}}`);
|
|
1669
|
+
var makeRouteSafe = (route) => wrapRouteParameters(route, "encodeURIComponent(String(", "))");
|
|
1665
1670
|
var isVue = (client) => import_core.OutputClient.VUE_QUERY === client;
|
|
1666
1671
|
|
|
1667
1672
|
// src/index.ts
|
|
@@ -1826,7 +1831,10 @@ var VUE_QUERY_DEPENDENCIES_V3 = [
|
|
|
1826
1831
|
dependency: "vue-query/types"
|
|
1827
1832
|
},
|
|
1828
1833
|
{
|
|
1829
|
-
exports: [
|
|
1834
|
+
exports: [
|
|
1835
|
+
{ name: "unref", values: true },
|
|
1836
|
+
{ name: "computed", values: true }
|
|
1837
|
+
],
|
|
1830
1838
|
dependency: "vue"
|
|
1831
1839
|
},
|
|
1832
1840
|
{
|
|
@@ -1852,12 +1860,12 @@ var VUE_QUERY_DEPENDENCIES = [
|
|
|
1852
1860
|
dependency: "@tanstack/vue-query"
|
|
1853
1861
|
},
|
|
1854
1862
|
{
|
|
1855
|
-
exports: [
|
|
1863
|
+
exports: [
|
|
1864
|
+
{ name: "unref", values: true },
|
|
1865
|
+
{ name: "MaybeRef" },
|
|
1866
|
+
{ name: "computed", values: true }
|
|
1867
|
+
],
|
|
1856
1868
|
dependency: "vue"
|
|
1857
|
-
},
|
|
1858
|
-
{
|
|
1859
|
-
exports: [{ name: "MaybeRef" }],
|
|
1860
|
-
dependency: "@tanstack/vue-query/build/lib/types"
|
|
1861
1869
|
}
|
|
1862
1870
|
];
|
|
1863
1871
|
var isVueQueryV3 = (packageJson) => {
|
|
@@ -1918,12 +1926,16 @@ var generateQueryRequestFunction = ({
|
|
|
1918
1926
|
formUrlEncoded,
|
|
1919
1927
|
paramsSerializer,
|
|
1920
1928
|
override
|
|
1921
|
-
}, { route, context }, outputClient) => {
|
|
1929
|
+
}, { route: _route, context }, outputClient, output) => {
|
|
1922
1930
|
var _a, _b;
|
|
1923
1931
|
let props = _props;
|
|
1932
|
+
let route = _route;
|
|
1924
1933
|
if (isVue(outputClient)) {
|
|
1925
1934
|
props = vueWrapTypeWithMaybeRef(_props);
|
|
1926
1935
|
}
|
|
1936
|
+
if (output == null ? void 0 : output.urlEncodeParameters) {
|
|
1937
|
+
route = makeRouteSafe(route);
|
|
1938
|
+
}
|
|
1927
1939
|
const isRequestOptions = override.requestOptions !== false;
|
|
1928
1940
|
const isFormData = override.formData !== false;
|
|
1929
1941
|
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
@@ -1952,10 +1964,12 @@ var generateQueryRequestFunction = ({
|
|
|
1952
1964
|
isFormUrlEncoded,
|
|
1953
1965
|
isBodyVerb,
|
|
1954
1966
|
hasSignal,
|
|
1955
|
-
isExactOptionalPropertyTypes
|
|
1967
|
+
isExactOptionalPropertyTypes,
|
|
1968
|
+
isVue: isVue(outputClient)
|
|
1956
1969
|
});
|
|
1970
|
+
let bodyDefinition = body.definition.replace("[]", "\\[\\]");
|
|
1957
1971
|
let propsImplementation = (mutator == null ? void 0 : mutator.bodyTypeName) && body.definition ? (0, import_core2.toObjectString)(props, "implementation").replace(
|
|
1958
|
-
new RegExp(`(\\w*):\\s?${
|
|
1972
|
+
new RegExp(`(\\w*):\\s?${bodyDefinition}`),
|
|
1959
1973
|
`$1: ${mutator.bodyTypeName}<${body.definition}>`
|
|
1960
1974
|
) : (0, import_core2.toObjectString)(props, "implementation");
|
|
1961
1975
|
const requestOptions = isRequestOptions ? (0, import_core2.generateMutatorRequestOptions)(
|
|
@@ -2000,7 +2014,8 @@ var generateQueryRequestFunction = ({
|
|
|
2000
2014
|
paramsSerializer,
|
|
2001
2015
|
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
2002
2016
|
isExactOptionalPropertyTypes,
|
|
2003
|
-
hasSignal
|
|
2017
|
+
hasSignal,
|
|
2018
|
+
isVue: isVue(outputClient)
|
|
2004
2019
|
});
|
|
2005
2020
|
const optionsArgs = generateRequestOptionsArguments({
|
|
2006
2021
|
isRequestOptions,
|
|
@@ -2024,7 +2039,8 @@ var INFINITE_QUERY_PROPERTIES = ["getNextPageParam", "getPreviousPageParam"];
|
|
|
2024
2039
|
var generateQueryOptions = ({
|
|
2025
2040
|
params,
|
|
2026
2041
|
options,
|
|
2027
|
-
type
|
|
2042
|
+
type,
|
|
2043
|
+
outputClient
|
|
2028
2044
|
}) => {
|
|
2029
2045
|
var _a;
|
|
2030
2046
|
if (options === false) {
|
|
@@ -2042,7 +2058,7 @@ var generateQueryOptions = ({
|
|
|
2042
2058
|
}
|
|
2043
2059
|
return "...queryOptions";
|
|
2044
2060
|
}
|
|
2045
|
-
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`;
|
|
2046
2062
|
};
|
|
2047
2063
|
var getQueryArgumentsRequestType = (mutator) => {
|
|
2048
2064
|
if (!mutator) {
|
|
@@ -2076,7 +2092,7 @@ var getQueryOptionsDefinition = ({
|
|
|
2076
2092
|
type
|
|
2077
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 ? ">" : ""}`;
|
|
2078
2094
|
}
|
|
2079
|
-
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>`;
|
|
2080
2096
|
};
|
|
2081
2097
|
var generateQueryArguments = ({
|
|
2082
2098
|
operationName,
|
|
@@ -2227,7 +2243,7 @@ var generateQueryImplementation = ({
|
|
|
2227
2243
|
const httpFunctionProps = queryParam ? props.map((param) => {
|
|
2228
2244
|
if (param.type === import_core2.GetterPropType.NAMED_PATH_PARAMS && !isVue(outputClient))
|
|
2229
2245
|
return param.destructured;
|
|
2230
|
-
return param.name === "params" ? `{ ${queryParam}: pageParam
|
|
2246
|
+
return param.name === "params" ? `{...params, ${queryParam}: pageParam || ${isVue(outputClient) ? `unref(params)?.['${queryParam}']` : `params?.['${queryParam}']`}}` : param.name;
|
|
2231
2247
|
}).join(",") : queryProperties;
|
|
2232
2248
|
const returnType = generateQueryReturnType({
|
|
2233
2249
|
outputClient,
|
|
@@ -2281,7 +2297,8 @@ var generateQueryImplementation = ({
|
|
|
2281
2297
|
const queryOptionsImp = generateQueryOptions({
|
|
2282
2298
|
params,
|
|
2283
2299
|
options,
|
|
2284
|
-
type
|
|
2300
|
+
type,
|
|
2301
|
+
outputClient
|
|
2285
2302
|
});
|
|
2286
2303
|
const queryOptionsFnName = (0, import_core2.camel)(
|
|
2287
2304
|
queryKeyMutator || queryOptionsMutator || (mutator == null ? void 0 : mutator.isHook) ? `use-${name}-queryOptions` : `get-${name}-queryOptions`
|
|
@@ -2382,7 +2399,7 @@ var generateQueryHook = async ({
|
|
|
2382
2399
|
const doc = (0, import_core2.jsDoc)({ summary, deprecated });
|
|
2383
2400
|
let implementation = "";
|
|
2384
2401
|
let mutators = void 0;
|
|
2385
|
-
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);
|
|
2386
2403
|
if (isQuery) {
|
|
2387
2404
|
const queryKeyMutator = query.queryKey ? await (0, import_core2.generateMutator)({
|
|
2388
2405
|
output,
|
|
@@ -2417,7 +2434,7 @@ var generateQueryHook = async ({
|
|
|
2417
2434
|
queryParam: query == null ? void 0 : query.useInfiniteQueryParam
|
|
2418
2435
|
}
|
|
2419
2436
|
] : [],
|
|
2420
|
-
|
|
2437
|
+
...(query == null ? void 0 : query.useQuery) ? [
|
|
2421
2438
|
{
|
|
2422
2439
|
name: operationName,
|
|
2423
2440
|
options: query == null ? void 0 : query.options,
|
|
@@ -2445,9 +2462,8 @@ var generateQueryHook = async ({
|
|
|
2445
2462
|
props.filter((prop) => prop.type !== import_core2.GetterPropType.HEADER),
|
|
2446
2463
|
"implementation"
|
|
2447
2464
|
);
|
|
2448
|
-
const routeString = `\`${route}\``;
|
|
2465
|
+
const routeString = isVue(outputClient) ? (0, import_core2.getRouteAsArray)(route) : `\`${route}\``;
|
|
2449
2466
|
const queryKeyFn = `export const ${queryKeyFnName} = (${queryKeyProps}) => {
|
|
2450
|
-
${isVue(outputClient) ? vueUnRefParams(props) : ""}
|
|
2451
2467
|
return [${routeString}${queryParams ? ", ...(params ? [params]: [])" : ""}${body.implementation ? `, ${body.implementation}` : ""}] as const;
|
|
2452
2468
|
}`;
|
|
2453
2469
|
implementation += `${!queryKeyMutator ? queryKeyFn : ""}
|
|
@@ -2524,14 +2540,13 @@ var generateQueryHook = async ({
|
|
|
2524
2540
|
);
|
|
2525
2541
|
const mutationOptionsVarName = isRequestOptions ? "mutationOptions" : "options";
|
|
2526
2542
|
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
|
|
2527
|
-
${!definitions ? `TVariables = void,` : ""}
|
|
2528
2543
|
TContext = unknown>(${mutationArguments}): ${mutationOptionFnReturnType} => {
|
|
2529
2544
|
${isRequestOptions ? `const {mutation: mutationOptions${!mutator ? `, axios: axiosOptions` : (mutator == null ? void 0 : mutator.hasSecondArg) ? ", request: requestOptions" : ""}} = options ?? {};` : ""}
|
|
2530
2545
|
|
|
2531
2546
|
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0, import_core2.pascal)(operationName)}Hook()` : ""}
|
|
2532
2547
|
|
|
2533
2548
|
|
|
2534
|
-
const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "
|
|
2549
|
+
const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "{}"}> = (${properties ? "props" : ""}) => {
|
|
2535
2550
|
${properties ? `const {${properties}} = props ?? {};` : ""}
|
|
2536
2551
|
|
|
2537
2552
|
return ${operationName}(${properties}${properties ? "," : ""}${isRequestOptions ? !mutator ? `axiosOptions` : (mutator == null ? void 0 : mutator.hasSecondArg) ? "requestOptions" : "" : ""})
|
|
@@ -2554,7 +2569,6 @@ ${mutationOptionsFn}
|
|
|
2554
2569
|
${doc}export const ${(0, import_core2.camel)(
|
|
2555
2570
|
`${operationPrefix}-${operationName}`
|
|
2556
2571
|
)} = <TError = ${errorType},
|
|
2557
|
-
${!definitions ? `TVariables = void,` : ""}
|
|
2558
2572
|
TContext = unknown>(${mutationArguments}) => {
|
|
2559
2573
|
|
|
2560
2574
|
const ${mutationOptionsVarName} = ${mutationOptionsFnName}(${isRequestOptions ? "options" : "mutationOptions"});
|
|
@@ -2590,12 +2604,13 @@ ${isRequestOptions && isMutator ? `// eslint-disable-next-line
|
|
|
2590
2604
|
` : ""}
|
|
2591
2605
|
`;
|
|
2592
2606
|
};
|
|
2593
|
-
var generateQuery = async (verbOptions, options, outputClient) => {
|
|
2607
|
+
var generateQuery = async (verbOptions, options, outputClient, output) => {
|
|
2594
2608
|
const imports = (0, import_core2.generateVerbImports)(verbOptions);
|
|
2595
2609
|
const functionImplementation = generateQueryRequestFunction(
|
|
2596
2610
|
verbOptions,
|
|
2597
2611
|
options,
|
|
2598
|
-
outputClient
|
|
2612
|
+
outputClient,
|
|
2613
|
+
output
|
|
2599
2614
|
);
|
|
2600
2615
|
const { implementation: hookImplementation, mutators } = await generateQueryHook(verbOptions, options, outputClient);
|
|
2601
2616
|
return {
|
|
@@ -2613,9 +2628,15 @@ var dependenciesBuilder = {
|
|
|
2613
2628
|
};
|
|
2614
2629
|
var builder = ({
|
|
2615
2630
|
type = "react-query",
|
|
2616
|
-
options: queryOptions
|
|
2631
|
+
options: queryOptions,
|
|
2632
|
+
output
|
|
2617
2633
|
} = {}) => () => {
|
|
2618
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
|
+
}
|
|
2619
2640
|
if (queryOptions) {
|
|
2620
2641
|
const normalizedQueryOptions = normalizeQueryOptions(
|
|
2621
2642
|
queryOptions,
|
|
@@ -2630,7 +2651,7 @@ var builder = ({
|
|
|
2630
2651
|
verbOptions.override.query
|
|
2631
2652
|
);
|
|
2632
2653
|
}
|
|
2633
|
-
return generateQuery(verbOptions, options, outputClient);
|
|
2654
|
+
return generateQuery(verbOptions, options, outputClient, output);
|
|
2634
2655
|
};
|
|
2635
2656
|
return {
|
|
2636
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"
|