@kubb/plugin-vue-query 5.0.0-beta.80 → 5.0.0-beta.84
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.cjs +180 -277
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -173
- package/dist/index.js +113 -210
- package/dist/index.js.map +1 -1
- package/package.json +4 -7
package/dist/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { ast, defineGenerator, definePlugin, defineResolver } from "
|
|
3
|
+
import { ast, defineGenerator, definePlugin, defineResolver } from "kubb/kit";
|
|
4
4
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
8
|
-
import { getNestedAccessor } from "@kubb/ast/utils";
|
|
5
|
+
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
9
7
|
//#region ../../internals/utils/src/casing.ts
|
|
10
8
|
/**
|
|
11
9
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -529,109 +527,6 @@ function createGroupConfig(group) {
|
|
|
529
527
|
};
|
|
530
528
|
}
|
|
531
529
|
//#endregion
|
|
532
|
-
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
533
|
-
/**
|
|
534
|
-
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
535
|
-
*/
|
|
536
|
-
function isValidatorEnabled(validator) {
|
|
537
|
-
if (!validator) return false;
|
|
538
|
-
if (validator === "zod") return true;
|
|
539
|
-
return Boolean(validator.request || validator.response);
|
|
540
|
-
}
|
|
541
|
-
//#endregion
|
|
542
|
-
//#region ../../internals/client/src/resolveClient.ts
|
|
543
|
-
/**
|
|
544
|
-
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
545
|
-
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
546
|
-
*
|
|
547
|
-
* Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
|
|
548
|
-
* contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
|
|
549
|
-
*
|
|
550
|
-
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
551
|
-
* imports and calls them.
|
|
552
|
-
* - `error` — no client plugin is registered, several are registered without a selector, or the
|
|
553
|
-
* requested one is missing.
|
|
554
|
-
*
|
|
555
|
-
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
556
|
-
* contract client plugin is picked up automatically.
|
|
557
|
-
*/
|
|
558
|
-
const pluginFetchName = "plugin-fetch";
|
|
559
|
-
const pluginAxiosName = "plugin-axios";
|
|
560
|
-
const selectorToPlugin = {
|
|
561
|
-
fetch: pluginFetchName,
|
|
562
|
-
axios: pluginAxiosName
|
|
563
|
-
};
|
|
564
|
-
const contractPlugins = [pluginFetchName, pluginAxiosName];
|
|
565
|
-
/**
|
|
566
|
-
* Applies the `client` resolution rules. See the module comment for the strategy shape.
|
|
567
|
-
*
|
|
568
|
-
* @example
|
|
569
|
-
* ```ts
|
|
570
|
-
* resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
|
|
571
|
-
* // { kind: 'contract', pluginName: 'plugin-fetch' }
|
|
572
|
-
* ```
|
|
573
|
-
*
|
|
574
|
-
* @example
|
|
575
|
-
* ```ts
|
|
576
|
-
* resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
|
|
577
|
-
* // { kind: 'error', message: 'No client plugin is registered…' }
|
|
578
|
-
* ```
|
|
579
|
-
*/
|
|
580
|
-
function resolveClient(options) {
|
|
581
|
-
const { client, pluginNames } = options;
|
|
582
|
-
const has = (name) => pluginNames.includes(name);
|
|
583
|
-
if (client === "fetch" || client === "axios") {
|
|
584
|
-
const pluginName = selectorToPlugin[client];
|
|
585
|
-
if (!has(pluginName)) return {
|
|
586
|
-
kind: "error",
|
|
587
|
-
message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`. Add it, or drop \`client\` to use a different client plugin.`
|
|
588
|
-
};
|
|
589
|
-
return {
|
|
590
|
-
kind: "contract",
|
|
591
|
-
pluginName
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
const registered = contractPlugins.filter(has);
|
|
595
|
-
if (registered.length === 1) return {
|
|
596
|
-
kind: "contract",
|
|
597
|
-
pluginName: registered[0]
|
|
598
|
-
};
|
|
599
|
-
if (registered.length > 1) return {
|
|
600
|
-
kind: "error",
|
|
601
|
-
message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}). Set \`client: 'fetch' | 'axios'\` to choose which client the hooks call, or register a single client plugin.`
|
|
602
|
-
};
|
|
603
|
-
return {
|
|
604
|
-
kind: "error",
|
|
605
|
-
message: "No client plugin is registered. Add `@kubb/plugin-axios` or `@kubb/plugin-fetch` to `plugins` so the generated code has an HTTP client to call."
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
//#endregion
|
|
609
|
-
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
610
|
-
/**
|
|
611
|
-
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
|
|
612
|
-
* the registered contract client plugin's resolver and output. Works for any contract client plugin
|
|
613
|
-
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
614
|
-
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
615
|
-
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
616
|
-
*/
|
|
617
|
-
function resolveClientOperation(options) {
|
|
618
|
-
const { clientPlugin, driver, node, root, output } = options;
|
|
619
|
-
if (!clientPlugin) return null;
|
|
620
|
-
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
621
|
-
if (!resolver) return null;
|
|
622
|
-
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
623
|
-
const file = resolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
624
|
-
root,
|
|
625
|
-
output: plugin?.options?.output ?? output,
|
|
626
|
-
group: plugin?.options?.group ?? void 0
|
|
627
|
-
});
|
|
628
|
-
return {
|
|
629
|
-
name: resolver.resolveName(node.operationId),
|
|
630
|
-
path: file.path,
|
|
631
|
-
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
//#endregion
|
|
635
530
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
636
531
|
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
637
532
|
const mutationKeyTransformer = ({ node }) => {
|
|
@@ -746,51 +641,6 @@ function buildQueryOptionsParams(node, options) {
|
|
|
746
641
|
default: "{}"
|
|
747
642
|
})].filter((param) => param !== null) });
|
|
748
643
|
}
|
|
749
|
-
/**
|
|
750
|
-
* Returns `'zod'` when response-direction parsing is enabled.
|
|
751
|
-
* The string shorthand `'zod'` also enables response parsing.
|
|
752
|
-
*/
|
|
753
|
-
function resolveResponseParser(parser) {
|
|
754
|
-
if (!parser) return null;
|
|
755
|
-
if (parser === "zod") return "zod";
|
|
756
|
-
return parser.response ?? null;
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Returns `'zod'` when request body parsing is enabled.
|
|
760
|
-
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
761
|
-
*/
|
|
762
|
-
function resolveRequestParser(parser) {
|
|
763
|
-
if (!parser) return null;
|
|
764
|
-
if (parser === "zod") return "zod";
|
|
765
|
-
return parser.request ?? null;
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Returns `'zod'` when query-params parsing is enabled.
|
|
769
|
-
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
770
|
-
*/
|
|
771
|
-
function resolveQueryParamsParser(parser) {
|
|
772
|
-
if (!parser || parser === "zod") return null;
|
|
773
|
-
return parser.request ?? null;
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
777
|
-
*
|
|
778
|
-
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
779
|
-
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
780
|
-
* - `parser: { response: 'zod' }`: response name only.
|
|
781
|
-
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
782
|
-
*
|
|
783
|
-
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
784
|
-
*/
|
|
785
|
-
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
786
|
-
if (!zodResolver || !parser) return [];
|
|
787
|
-
const { query: queryParams } = getOperationParameters(node, { paramsCasing: "original" });
|
|
788
|
-
return [
|
|
789
|
-
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
790
|
-
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
791
|
-
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
792
|
-
].filter((n) => Boolean(n));
|
|
793
|
-
}
|
|
794
644
|
functionPrinter({ mode: "declaration" });
|
|
795
645
|
const queryKeyTransformer = ({ node }) => {
|
|
796
646
|
if (!node.path) return [];
|
|
@@ -804,6 +654,99 @@ const queryKeyTransformer = ({ node }) => {
|
|
|
804
654
|
].filter(Boolean);
|
|
805
655
|
};
|
|
806
656
|
//#endregion
|
|
657
|
+
//#region ../../internals/client/src/resolveClient.ts
|
|
658
|
+
/**
|
|
659
|
+
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
660
|
+
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
661
|
+
*
|
|
662
|
+
* Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
|
|
663
|
+
* contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
|
|
664
|
+
*
|
|
665
|
+
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
666
|
+
* imports and calls them.
|
|
667
|
+
* - `error` — no client plugin is registered, several are registered without a selector, or the
|
|
668
|
+
* requested one is missing.
|
|
669
|
+
*
|
|
670
|
+
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
671
|
+
* contract client plugin is picked up automatically.
|
|
672
|
+
*/
|
|
673
|
+
const pluginFetchName = "plugin-fetch";
|
|
674
|
+
const pluginAxiosName = "plugin-axios";
|
|
675
|
+
const selectorToPlugin = {
|
|
676
|
+
fetch: pluginFetchName,
|
|
677
|
+
axios: pluginAxiosName
|
|
678
|
+
};
|
|
679
|
+
const contractPlugins = [pluginFetchName, pluginAxiosName];
|
|
680
|
+
/**
|
|
681
|
+
* Applies the `client` resolution rules. See the module comment for the strategy shape.
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
|
|
686
|
+
* // { kind: 'contract', pluginName: 'plugin-fetch' }
|
|
687
|
+
* ```
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* ```ts
|
|
691
|
+
* resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
|
|
692
|
+
* // { kind: 'error', message: 'No client plugin is registered…' }
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
function resolveClient(options) {
|
|
696
|
+
const { client, pluginNames } = options;
|
|
697
|
+
const has = (name) => pluginNames.includes(name);
|
|
698
|
+
if (client === "fetch" || client === "axios") {
|
|
699
|
+
const pluginName = selectorToPlugin[client];
|
|
700
|
+
if (!has(pluginName)) return {
|
|
701
|
+
kind: "error",
|
|
702
|
+
message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`. Add it, or drop \`client\` to use a different client plugin.`
|
|
703
|
+
};
|
|
704
|
+
return {
|
|
705
|
+
kind: "contract",
|
|
706
|
+
pluginName
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
const registered = contractPlugins.filter(has);
|
|
710
|
+
if (registered.length === 1) return {
|
|
711
|
+
kind: "contract",
|
|
712
|
+
pluginName: registered[0]
|
|
713
|
+
};
|
|
714
|
+
if (registered.length > 1) return {
|
|
715
|
+
kind: "error",
|
|
716
|
+
message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}). Set \`client: 'fetch' | 'axios'\` to choose which client the hooks call, or register a single client plugin.`
|
|
717
|
+
};
|
|
718
|
+
return {
|
|
719
|
+
kind: "error",
|
|
720
|
+
message: "No client plugin is registered. Add `@kubb/plugin-axios` or `@kubb/plugin-fetch` to `plugins` so the generated code has an HTTP client to call."
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
//#endregion
|
|
724
|
+
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
725
|
+
/**
|
|
726
|
+
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
|
|
727
|
+
* the registered contract client plugin's resolver and output. Works for any contract client plugin
|
|
728
|
+
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
729
|
+
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
730
|
+
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
731
|
+
*/
|
|
732
|
+
function resolveClientOperation(options) {
|
|
733
|
+
const { clientPlugin, driver, node, root, output } = options;
|
|
734
|
+
if (!clientPlugin) return null;
|
|
735
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
736
|
+
if (!resolver) return null;
|
|
737
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
738
|
+
const file = resolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
739
|
+
root,
|
|
740
|
+
output: plugin?.options?.output ?? output,
|
|
741
|
+
group: plugin?.options?.group ?? void 0
|
|
742
|
+
});
|
|
743
|
+
return {
|
|
744
|
+
name: resolver.resolveName(node.operationId),
|
|
745
|
+
path: file.path,
|
|
746
|
+
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
//#endregion
|
|
807
750
|
//#region src/utils.ts
|
|
808
751
|
const requestGroupOrder = [
|
|
809
752
|
"path",
|
|
@@ -1025,8 +968,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1025
968
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1026
969
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1027
970
|
if (hasNewParams) {
|
|
1028
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1029
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
971
|
+
const nextAccessor = nextParam ? ast.getNestedAccessor(nextParam, "lastPage") : null;
|
|
972
|
+
const prevAccessor = previousParam ? ast.getNestedAccessor(previousParam, "firstPage") : null;
|
|
1030
973
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1031
974
|
}
|
|
1032
975
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1248,7 +1191,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1248
1191
|
operation(node, ctx) {
|
|
1249
1192
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1250
1193
|
const { config, driver, resolver, root } = ctx;
|
|
1251
|
-
const { output, query, mutation, infinite,
|
|
1194
|
+
const { output, query, mutation, infinite, client, group, hooks } = ctx.options;
|
|
1252
1195
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1253
1196
|
if (!pluginTs) return null;
|
|
1254
1197
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1298,14 +1241,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1298
1241
|
includeParams: false
|
|
1299
1242
|
})
|
|
1300
1243
|
].filter((name) => Boolean(name));
|
|
1301
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1302
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1303
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1304
|
-
root,
|
|
1305
|
-
output: pluginZod?.options?.output ?? output,
|
|
1306
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1307
|
-
}) : null;
|
|
1308
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1309
1244
|
const calledClientName = contractOp.name;
|
|
1310
1245
|
return /* @__PURE__ */ jsxs(File, {
|
|
1311
1246
|
baseName: meta.file.baseName,
|
|
@@ -1328,11 +1263,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1328
1263
|
}
|
|
1329
1264
|
}),
|
|
1330
1265
|
children: [
|
|
1331
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1332
|
-
name: zodSchemaNames,
|
|
1333
|
-
root: meta.file.path,
|
|
1334
|
-
path: fileZod.path
|
|
1335
|
-
}),
|
|
1336
1266
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1337
1267
|
name: [contractOp.name],
|
|
1338
1268
|
root: meta.file.path,
|
|
@@ -1430,7 +1360,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1430
1360
|
operation(node, ctx) {
|
|
1431
1361
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1432
1362
|
const { config, driver, resolver, root } = ctx;
|
|
1433
|
-
const { output, query, mutation,
|
|
1363
|
+
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1434
1364
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1435
1365
|
if (!pluginTs) return null;
|
|
1436
1366
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1465,14 +1395,6 @@ const mutationGenerator = defineGenerator({
|
|
|
1465
1395
|
order: "body-response-first",
|
|
1466
1396
|
includeParams: false
|
|
1467
1397
|
})].filter((name) => Boolean(name));
|
|
1468
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1469
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1470
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1471
|
-
root,
|
|
1472
|
-
output: pluginZod?.options?.output ?? output,
|
|
1473
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1474
|
-
}) : null;
|
|
1475
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1476
1398
|
const calledClientName = contractOp.name;
|
|
1477
1399
|
const groups = getRequestGroups(node);
|
|
1478
1400
|
const hasRequestGroups = groups.path || groups.query || groups.body || groups.headers;
|
|
@@ -1497,11 +1419,6 @@ const mutationGenerator = defineGenerator({
|
|
|
1497
1419
|
}
|
|
1498
1420
|
}),
|
|
1499
1421
|
children: [
|
|
1500
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1501
|
-
name: zodSchemaNames,
|
|
1502
|
-
root: meta.file.path,
|
|
1503
|
-
path: fileZod.path
|
|
1504
|
-
}),
|
|
1505
1422
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1506
1423
|
name: [contractOp.name],
|
|
1507
1424
|
root: meta.file.path,
|
|
@@ -1569,7 +1486,7 @@ const queryGenerator = defineGenerator({
|
|
|
1569
1486
|
operation(node, ctx) {
|
|
1570
1487
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1571
1488
|
const { config, driver, resolver, root } = ctx;
|
|
1572
|
-
const { output, query, mutation,
|
|
1489
|
+
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1573
1490
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1574
1491
|
if (!pluginTs) return null;
|
|
1575
1492
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1607,14 +1524,6 @@ const queryGenerator = defineGenerator({
|
|
|
1607
1524
|
order: "body-response-first",
|
|
1608
1525
|
includeParams: false
|
|
1609
1526
|
})].filter((name) => Boolean(name));
|
|
1610
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1611
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1612
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1613
|
-
root,
|
|
1614
|
-
output: pluginZod?.options?.output ?? output,
|
|
1615
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1616
|
-
}) : null;
|
|
1617
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1618
1527
|
const calledClientName = contractOp.name;
|
|
1619
1528
|
return /* @__PURE__ */ jsxs(File, {
|
|
1620
1529
|
baseName: meta.file.baseName,
|
|
@@ -1637,11 +1546,6 @@ const queryGenerator = defineGenerator({
|
|
|
1637
1546
|
}
|
|
1638
1547
|
}),
|
|
1639
1548
|
children: [
|
|
1640
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1641
|
-
name: zodSchemaNames,
|
|
1642
|
-
root: meta.file.path,
|
|
1643
|
-
path: fileZod.path
|
|
1644
|
-
}),
|
|
1645
1549
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1646
1550
|
name: [contractOp.name],
|
|
1647
1551
|
root: meta.file.path,
|
|
@@ -1721,8 +1625,8 @@ function capitalize(name) {
|
|
|
1721
1625
|
}
|
|
1722
1626
|
/**
|
|
1723
1627
|
* Default resolver used by `@kubb/plugin-vue-query`. Decides the names and
|
|
1724
|
-
* file paths for every generated TanStack Query composable (`
|
|
1725
|
-
* `
|
|
1628
|
+
* file paths for every generated TanStack Query composable (`useFoo`,
|
|
1629
|
+
* `useFooInfinite`) and its companion helpers.
|
|
1726
1630
|
*
|
|
1727
1631
|
* Functions and files use camelCase; composables get the `use` prefix.
|
|
1728
1632
|
*
|
|
@@ -1796,13 +1700,13 @@ const resolverVueQuery = defineResolver(() => ({
|
|
|
1796
1700
|
const pluginVueQueryName = "plugin-vue-query";
|
|
1797
1701
|
/**
|
|
1798
1702
|
* Generates one TanStack Query composable per OpenAPI operation for Vue's
|
|
1799
|
-
* Composition API. Queries become `
|
|
1800
|
-
* `
|
|
1703
|
+
* Composition API. Queries become `useFoo` (and optionally
|
|
1704
|
+
* `useFooInfinite`). Mutations become `useFoo` as well. Each composable
|
|
1801
1705
|
* is fully typed end to end.
|
|
1802
1706
|
*
|
|
1803
1707
|
* @example
|
|
1804
1708
|
* ```ts
|
|
1805
|
-
* import { defineConfig } from 'kubb'
|
|
1709
|
+
* import { defineConfig } from 'kubb/config'
|
|
1806
1710
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1807
1711
|
* import { pluginVueQuery } from '@kubb/plugin-vue-query'
|
|
1808
1712
|
*
|
|
@@ -1822,7 +1726,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1822
1726
|
const { output = {
|
|
1823
1727
|
path: "hooks",
|
|
1824
1728
|
barrel: { type: "named" }
|
|
1825
|
-
}, group, exclude = [], include, override = [],
|
|
1729
|
+
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
1826
1730
|
const selectedGenerators = [
|
|
1827
1731
|
queryGenerator,
|
|
1828
1732
|
infiniteQueryGenerator,
|
|
@@ -1832,7 +1736,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1832
1736
|
return {
|
|
1833
1737
|
name: pluginVueQueryName,
|
|
1834
1738
|
options,
|
|
1835
|
-
dependencies: [pluginTsName
|
|
1739
|
+
dependencies: [pluginTsName],
|
|
1836
1740
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1837
1741
|
const resolver = userResolver ? {
|
|
1838
1742
|
...resolverVueQuery,
|
|
@@ -1853,17 +1757,17 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1853
1757
|
queryKey,
|
|
1854
1758
|
query: query === false ? false : {
|
|
1855
1759
|
importPath: "@tanstack/vue-query",
|
|
1856
|
-
methods: ["
|
|
1760
|
+
methods: ["GET"],
|
|
1857
1761
|
...query
|
|
1858
1762
|
},
|
|
1859
1763
|
mutationKey,
|
|
1860
1764
|
mutation: mutation === false ? false : {
|
|
1861
1765
|
importPath: "@tanstack/vue-query",
|
|
1862
1766
|
methods: [
|
|
1863
|
-
"
|
|
1864
|
-
"
|
|
1865
|
-
"
|
|
1866
|
-
"
|
|
1767
|
+
"POST",
|
|
1768
|
+
"PUT",
|
|
1769
|
+
"PATCH",
|
|
1770
|
+
"DELETE"
|
|
1867
1771
|
],
|
|
1868
1772
|
...mutation
|
|
1869
1773
|
},
|
|
@@ -1876,7 +1780,6 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1876
1780
|
...infinite
|
|
1877
1781
|
} : false,
|
|
1878
1782
|
hooks,
|
|
1879
|
-
validator,
|
|
1880
1783
|
group: groupConfig,
|
|
1881
1784
|
exclude,
|
|
1882
1785
|
include,
|