@orval/query 8.19.0 → 8.20.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.mjs +49 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -48,24 +48,6 @@ const normalizeMutator = (workspace, mutator) => {
|
|
|
48
48
|
default: true
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
|
-
function vueWrapTypeWithMaybeRef(props) {
|
|
52
|
-
return props.map((prop) => {
|
|
53
|
-
const [paramName, paramType] = prop.implementation.split(":");
|
|
54
|
-
if (!paramType) return prop;
|
|
55
|
-
const name = prop.type === GetterPropType.NAMED_PATH_PARAMS ? prop.name : paramName;
|
|
56
|
-
const [type, defaultValue] = paramType.split("=");
|
|
57
|
-
return {
|
|
58
|
-
...prop,
|
|
59
|
-
implementation: `${name}: MaybeRef<${type.trim()}>${defaultValue ? ` = ${defaultValue}` : ""}`
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
const vueUnRefParams = (props) => {
|
|
64
|
-
return props.map((prop) => {
|
|
65
|
-
if (prop.type === GetterPropType.NAMED_PATH_PARAMS) return `const ${prop.destructured} = unref(${prop.name});`;
|
|
66
|
-
return `${prop.name} = unref(${prop.name});`;
|
|
67
|
-
}).join("\n");
|
|
68
|
-
};
|
|
69
51
|
const getQueryTypeForFramework = (type) => {
|
|
70
52
|
switch (type) {
|
|
71
53
|
case "suspenseQuery": return "query";
|
|
@@ -688,15 +670,20 @@ const VUE_QUERY_DEPENDENCIES = [{
|
|
|
688
670
|
dependency: "@tanstack/vue-query"
|
|
689
671
|
}, {
|
|
690
672
|
exports: [
|
|
673
|
+
{
|
|
674
|
+
name: "computed",
|
|
675
|
+
values: true
|
|
676
|
+
},
|
|
691
677
|
{
|
|
692
678
|
name: "unref",
|
|
693
679
|
values: true
|
|
694
680
|
},
|
|
695
|
-
{ name: "MaybeRef" },
|
|
696
681
|
{
|
|
697
|
-
name: "
|
|
682
|
+
name: "toValue",
|
|
698
683
|
values: true
|
|
699
|
-
}
|
|
684
|
+
},
|
|
685
|
+
{ name: "MaybeRef" },
|
|
686
|
+
{ name: "MaybeRefOrGetter" }
|
|
700
687
|
],
|
|
701
688
|
dependency: "vue"
|
|
702
689
|
}];
|
|
@@ -1294,6 +1281,33 @@ const createSvelteAdapter = ({ hasSvelteQueryV4, hasSvelteQueryV6, hasQueryV5, h
|
|
|
1294
1281
|
};
|
|
1295
1282
|
//#endregion
|
|
1296
1283
|
//#region src/frameworks/vue.ts
|
|
1284
|
+
const getVueReactivity = (hasQueryV5) => hasQueryV5 ? {
|
|
1285
|
+
wrapper: "MaybeRefOrGetter",
|
|
1286
|
+
resolve: "toValue"
|
|
1287
|
+
} : {
|
|
1288
|
+
wrapper: "MaybeRef",
|
|
1289
|
+
resolve: "unref"
|
|
1290
|
+
};
|
|
1291
|
+
function vueWrapTypeWithMaybeRef(props, hasQueryV5) {
|
|
1292
|
+
const { wrapper } = getVueReactivity(hasQueryV5);
|
|
1293
|
+
return props.map((prop) => {
|
|
1294
|
+
const [paramName, paramType] = prop.implementation.split(":");
|
|
1295
|
+
if (!paramType) return prop;
|
|
1296
|
+
const name = prop.type === GetterPropType.NAMED_PATH_PARAMS ? prop.name : paramName;
|
|
1297
|
+
const [type, defaultValue] = paramType.split("=");
|
|
1298
|
+
return {
|
|
1299
|
+
...prop,
|
|
1300
|
+
implementation: `${name}: ${wrapper}<${type.trim()}>${defaultValue ? ` = ${defaultValue}` : ""}`
|
|
1301
|
+
};
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
const vueUnRefParams = (props, hasQueryV5) => {
|
|
1305
|
+
const { resolve } = getVueReactivity(hasQueryV5);
|
|
1306
|
+
return props.map((prop) => {
|
|
1307
|
+
if (prop.type === GetterPropType.NAMED_PATH_PARAMS) return `const ${prop.destructured} = ${resolve}(${prop.name});`;
|
|
1308
|
+
return `${prop.name} = ${resolve}(${prop.name});`;
|
|
1309
|
+
}).join("\n");
|
|
1310
|
+
};
|
|
1297
1311
|
const createVueAdapter = ({ hasVueQueryV4, hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, hasQueryV5WithMutationContextOnSuccess, hasQueryV5WithRequiredContextOnSuccess }) => ({
|
|
1298
1312
|
outputClient: OutputClient.VUE_QUERY,
|
|
1299
1313
|
hookPrefix: "use",
|
|
@@ -1303,19 +1317,23 @@ const createVueAdapter = ({ hasVueQueryV4, hasQueryV5, hasQueryV5WithDataTagErro
|
|
|
1303
1317
|
hasQueryV5WithMutationContextOnSuccess,
|
|
1304
1318
|
hasQueryV5WithRequiredContextOnSuccess,
|
|
1305
1319
|
transformProps(props) {
|
|
1306
|
-
return vueWrapTypeWithMaybeRef(props);
|
|
1320
|
+
return vueWrapTypeWithMaybeRef(props, hasQueryV5);
|
|
1307
1321
|
},
|
|
1308
1322
|
shouldDestructureNamedPathParams() {
|
|
1309
1323
|
return false;
|
|
1310
1324
|
},
|
|
1311
1325
|
getHttpFunctionQueryProps(queryProperties, httpClient) {
|
|
1312
|
-
if (httpClient === OutputHttpClient.FETCH && queryProperties)
|
|
1326
|
+
if (httpClient === OutputHttpClient.FETCH && queryProperties) {
|
|
1327
|
+
const { resolve } = getVueReactivity(hasQueryV5);
|
|
1328
|
+
return queryProperties.split(",").map((prop) => `${resolve}(${prop})`).join(",");
|
|
1329
|
+
}
|
|
1313
1330
|
return queryProperties;
|
|
1314
1331
|
},
|
|
1315
1332
|
getInfiniteQueryHttpProps(props, queryParam, httpClient) {
|
|
1333
|
+
const { resolve } = getVueReactivity(hasQueryV5);
|
|
1316
1334
|
return props.map((param) => {
|
|
1317
|
-
if (param.name === "params") return `{
|
|
1318
|
-
return httpClient === OutputHttpClient.FETCH ?
|
|
1335
|
+
if (param.name === "params") return `{...${resolve}(params), '${queryParam}': pageParam ?? ${resolve}(params)?.['${queryParam}']}`;
|
|
1336
|
+
return httpClient === OutputHttpClient.FETCH ? `${resolve}(${param.name})` : param.name;
|
|
1319
1337
|
}).join(",");
|
|
1320
1338
|
},
|
|
1321
1339
|
getQueryReturnType({ type }) {
|
|
@@ -1343,17 +1361,20 @@ const createVueAdapter = ({ hasVueQueryV4, hasQueryV5, hasQueryV5WithDataTagErro
|
|
|
1343
1361
|
return false;
|
|
1344
1362
|
},
|
|
1345
1363
|
getRequestUnrefStatements(props) {
|
|
1346
|
-
return vueUnRefParams(props);
|
|
1364
|
+
return vueUnRefParams(props, hasQueryV5);
|
|
1347
1365
|
},
|
|
1348
1366
|
getQueryOptionsUnrefStatements(props) {
|
|
1349
|
-
return vueUnRefParams(props.filter((prop) => prop.type === GetterPropType.NAMED_PATH_PARAMS));
|
|
1367
|
+
return vueUnRefParams(props.filter((prop) => prop.type === GetterPropType.NAMED_PATH_PARAMS), hasQueryV5);
|
|
1350
1368
|
},
|
|
1351
1369
|
wrapHookMutatorCallback(callback) {
|
|
1352
1370
|
return callback;
|
|
1353
1371
|
},
|
|
1354
1372
|
generateEnabledOption(params, options) {
|
|
1355
1373
|
if (params.length === 0) return "";
|
|
1356
|
-
if (!isObject(options) || !Object.hasOwn(options, "enabled"))
|
|
1374
|
+
if (!isObject(options) || !Object.hasOwn(options, "enabled")) {
|
|
1375
|
+
const { resolve } = getVueReactivity(hasQueryV5);
|
|
1376
|
+
return `enabled: computed(() => ${params.map(({ name }) => `${resolve}(${name}) !== null && ${resolve}(${name}) !== undefined`).join(" && ")}),`;
|
|
1377
|
+
}
|
|
1357
1378
|
return "";
|
|
1358
1379
|
},
|
|
1359
1380
|
getQueryKeyPrefix() {
|