@kubb/plugin-vue-query 5.0.0-beta.79 → 5.0.0-beta.81
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 +139 -225
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -167
- package/dist/index.js +139 -225
- package/dist/index.js.map +1 -1
- package/package.json +8 -9
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import "./rolldown-runtime-C0LytTxp.js";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core";
|
|
4
4
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
-
import { pluginZodName } from "@kubb/plugin-zod";
|
|
6
5
|
import { File, Function, Type, jsxRenderer } from "@kubb/renderer-jsx";
|
|
7
6
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
8
7
|
import { getNestedAccessor } from "@kubb/ast/utils";
|
|
@@ -529,109 +528,6 @@ function createGroupConfig(group) {
|
|
|
529
528
|
};
|
|
530
529
|
}
|
|
531
530
|
//#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
531
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
636
532
|
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
637
533
|
const mutationKeyTransformer = ({ node }) => {
|
|
@@ -671,6 +567,19 @@ const requestGroupOrder$1 = [
|
|
|
671
567
|
"headers"
|
|
672
568
|
];
|
|
673
569
|
/**
|
|
570
|
+
* Widens a request-group member type so a generated TanStack hook accepts either the value or a
|
|
571
|
+
* deferred value. Both plugins apply this through the `memberTypeWrapper` of `buildGroupedRequestParam`;
|
|
572
|
+
* they only differ in how the deferred form is later resolved.
|
|
573
|
+
*
|
|
574
|
+
* `maybeRefOrGetter` is used by vue-query, which keeps the ref/getter live and unwraps it lazily with
|
|
575
|
+
* `toValue` because vue-query keys are reactive. `maybeValueOrGetter` is used by react-query, which
|
|
576
|
+
* resolves the getter once at the hook boundary and forwards a plain value because React Query hashes
|
|
577
|
+
* keys structurally and cannot hold a function.
|
|
578
|
+
*/
|
|
579
|
+
function maybeRefOrGetter(type) {
|
|
580
|
+
return `MaybeRefOrGetter<${type}>`;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
674
583
|
* Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
|
|
675
584
|
* function signature. Only the groups the operation carries are emitted, typed from the
|
|
676
585
|
* operation's `RequestConfig`. `keys` narrows the emitted groups, used by the query key which
|
|
@@ -733,51 +642,6 @@ function buildQueryOptionsParams(node, options) {
|
|
|
733
642
|
default: "{}"
|
|
734
643
|
})].filter((param) => param !== null) });
|
|
735
644
|
}
|
|
736
|
-
/**
|
|
737
|
-
* Returns `'zod'` when response-direction parsing is enabled.
|
|
738
|
-
* The string shorthand `'zod'` also enables response parsing.
|
|
739
|
-
*/
|
|
740
|
-
function resolveResponseParser(parser) {
|
|
741
|
-
if (!parser) return null;
|
|
742
|
-
if (parser === "zod") return "zod";
|
|
743
|
-
return parser.response ?? null;
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* Returns `'zod'` when request body parsing is enabled.
|
|
747
|
-
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
748
|
-
*/
|
|
749
|
-
function resolveRequestParser(parser) {
|
|
750
|
-
if (!parser) return null;
|
|
751
|
-
if (parser === "zod") return "zod";
|
|
752
|
-
return parser.request ?? null;
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* Returns `'zod'` when query-params parsing is enabled.
|
|
756
|
-
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
757
|
-
*/
|
|
758
|
-
function resolveQueryParamsParser(parser) {
|
|
759
|
-
if (!parser || parser === "zod") return null;
|
|
760
|
-
return parser.request ?? null;
|
|
761
|
-
}
|
|
762
|
-
/**
|
|
763
|
-
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
764
|
-
*
|
|
765
|
-
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
766
|
-
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
767
|
-
* - `parser: { response: 'zod' }`: response name only.
|
|
768
|
-
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
769
|
-
*
|
|
770
|
-
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
771
|
-
*/
|
|
772
|
-
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
773
|
-
if (!zodResolver || !parser) return [];
|
|
774
|
-
const { query: queryParams } = getOperationParameters(node, { paramsCasing: "original" });
|
|
775
|
-
return [
|
|
776
|
-
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
777
|
-
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
778
|
-
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
779
|
-
].filter((n) => Boolean(n));
|
|
780
|
-
}
|
|
781
645
|
functionPrinter({ mode: "declaration" });
|
|
782
646
|
const queryKeyTransformer = ({ node }) => {
|
|
783
647
|
if (!node.path) return [];
|
|
@@ -791,13 +655,100 @@ const queryKeyTransformer = ({ node }) => {
|
|
|
791
655
|
].filter(Boolean);
|
|
792
656
|
};
|
|
793
657
|
//#endregion
|
|
794
|
-
//#region src/
|
|
658
|
+
//#region ../../internals/client/src/resolveClient.ts
|
|
659
|
+
/**
|
|
660
|
+
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
661
|
+
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
662
|
+
*
|
|
663
|
+
* Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
|
|
664
|
+
* contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
|
|
665
|
+
*
|
|
666
|
+
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
667
|
+
* imports and calls them.
|
|
668
|
+
* - `error` — no client plugin is registered, several are registered without a selector, or the
|
|
669
|
+
* requested one is missing.
|
|
670
|
+
*
|
|
671
|
+
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
672
|
+
* contract client plugin is picked up automatically.
|
|
673
|
+
*/
|
|
674
|
+
const pluginFetchName = "plugin-fetch";
|
|
675
|
+
const pluginAxiosName = "plugin-axios";
|
|
676
|
+
const selectorToPlugin = {
|
|
677
|
+
fetch: pluginFetchName,
|
|
678
|
+
axios: pluginAxiosName
|
|
679
|
+
};
|
|
680
|
+
const contractPlugins = [pluginFetchName, pluginAxiosName];
|
|
795
681
|
/**
|
|
796
|
-
*
|
|
682
|
+
* Applies the `client` resolution rules. See the module comment for the strategy shape.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
|
|
687
|
+
* // { kind: 'contract', pluginName: 'plugin-fetch' }
|
|
688
|
+
* ```
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* ```ts
|
|
692
|
+
* resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
|
|
693
|
+
* // { kind: 'error', message: 'No client plugin is registered…' }
|
|
694
|
+
* ```
|
|
797
695
|
*/
|
|
798
|
-
function
|
|
799
|
-
|
|
696
|
+
function resolveClient(options) {
|
|
697
|
+
const { client, pluginNames } = options;
|
|
698
|
+
const has = (name) => pluginNames.includes(name);
|
|
699
|
+
if (client === "fetch" || client === "axios") {
|
|
700
|
+
const pluginName = selectorToPlugin[client];
|
|
701
|
+
if (!has(pluginName)) return {
|
|
702
|
+
kind: "error",
|
|
703
|
+
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.`
|
|
704
|
+
};
|
|
705
|
+
return {
|
|
706
|
+
kind: "contract",
|
|
707
|
+
pluginName
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
const registered = contractPlugins.filter(has);
|
|
711
|
+
if (registered.length === 1) return {
|
|
712
|
+
kind: "contract",
|
|
713
|
+
pluginName: registered[0]
|
|
714
|
+
};
|
|
715
|
+
if (registered.length > 1) return {
|
|
716
|
+
kind: "error",
|
|
717
|
+
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.`
|
|
718
|
+
};
|
|
719
|
+
return {
|
|
720
|
+
kind: "error",
|
|
721
|
+
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."
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
726
|
+
/**
|
|
727
|
+
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
|
|
728
|
+
* the registered contract client plugin's resolver and output. Works for any contract client plugin
|
|
729
|
+
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
730
|
+
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
731
|
+
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
732
|
+
*/
|
|
733
|
+
function resolveClientOperation(options) {
|
|
734
|
+
const { clientPlugin, driver, node, root, output } = options;
|
|
735
|
+
if (!clientPlugin) return null;
|
|
736
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
737
|
+
if (!resolver) return null;
|
|
738
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
739
|
+
const file = resolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
740
|
+
root,
|
|
741
|
+
output: plugin?.options?.output ?? output,
|
|
742
|
+
group: plugin?.options?.group ?? void 0
|
|
743
|
+
});
|
|
744
|
+
return {
|
|
745
|
+
name: resolver.resolveName(node.operationId),
|
|
746
|
+
path: file.path,
|
|
747
|
+
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
748
|
+
};
|
|
800
749
|
}
|
|
750
|
+
//#endregion
|
|
751
|
+
//#region src/utils.ts
|
|
801
752
|
const requestGroupOrder = [
|
|
802
753
|
"path",
|
|
803
754
|
"query",
|
|
@@ -1241,7 +1192,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1241
1192
|
operation(node, ctx) {
|
|
1242
1193
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1243
1194
|
const { config, driver, resolver, root } = ctx;
|
|
1244
|
-
const { output, query, mutation, infinite,
|
|
1195
|
+
const { output, query, mutation, infinite, client, group, hooks } = ctx.options;
|
|
1245
1196
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1246
1197
|
if (!pluginTs) return null;
|
|
1247
1198
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1291,14 +1242,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1291
1242
|
includeParams: false
|
|
1292
1243
|
})
|
|
1293
1244
|
].filter((name) => Boolean(name));
|
|
1294
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1295
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1296
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1297
|
-
root,
|
|
1298
|
-
output: pluginZod?.options?.output ?? output,
|
|
1299
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1300
|
-
}) : null;
|
|
1301
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1302
1245
|
const calledClientName = contractOp.name;
|
|
1303
1246
|
return /* @__PURE__ */ jsxs(File, {
|
|
1304
1247
|
baseName: meta.file.baseName,
|
|
@@ -1321,11 +1264,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1321
1264
|
}
|
|
1322
1265
|
}),
|
|
1323
1266
|
children: [
|
|
1324
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1325
|
-
name: zodSchemaNames,
|
|
1326
|
-
root: meta.file.path,
|
|
1327
|
-
path: fileZod.path
|
|
1328
|
-
}),
|
|
1329
1267
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1330
1268
|
name: [contractOp.name],
|
|
1331
1269
|
root: meta.file.path,
|
|
@@ -1380,30 +1318,32 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1380
1318
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1381
1319
|
queryParam: infiniteOptions.queryParam
|
|
1382
1320
|
}),
|
|
1383
|
-
/* @__PURE__ */
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1321
|
+
hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1322
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
1323
|
+
name: ["useInfiniteQuery"],
|
|
1324
|
+
path: importPath
|
|
1325
|
+
}),
|
|
1326
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
1327
|
+
name: [
|
|
1328
|
+
"QueryKey",
|
|
1329
|
+
"QueryClient",
|
|
1330
|
+
"UseInfiniteQueryOptions",
|
|
1331
|
+
"UseInfiniteQueryReturnType"
|
|
1332
|
+
],
|
|
1333
|
+
path: importPath,
|
|
1334
|
+
isTypeOnly: true
|
|
1335
|
+
}),
|
|
1336
|
+
/* @__PURE__ */ jsx(InfiniteQuery, {
|
|
1337
|
+
name: queryName,
|
|
1338
|
+
queryOptionsName,
|
|
1339
|
+
queryKeyName,
|
|
1340
|
+
queryKeyTypeName,
|
|
1341
|
+
node,
|
|
1342
|
+
tsResolver,
|
|
1343
|
+
initialPageParam: infiniteOptions.initialPageParam,
|
|
1344
|
+
queryParam: infiniteOptions.queryParam
|
|
1345
|
+
})
|
|
1346
|
+
] })
|
|
1407
1347
|
]
|
|
1408
1348
|
});
|
|
1409
1349
|
}
|
|
@@ -1421,7 +1361,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1421
1361
|
operation(node, ctx) {
|
|
1422
1362
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1423
1363
|
const { config, driver, resolver, root } = ctx;
|
|
1424
|
-
const { output, query, mutation,
|
|
1364
|
+
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1425
1365
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1426
1366
|
if (!pluginTs) return null;
|
|
1427
1367
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1456,14 +1396,6 @@ const mutationGenerator = defineGenerator({
|
|
|
1456
1396
|
order: "body-response-first",
|
|
1457
1397
|
includeParams: false
|
|
1458
1398
|
})].filter((name) => Boolean(name));
|
|
1459
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1460
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1461
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1462
|
-
root,
|
|
1463
|
-
output: pluginZod?.options?.output ?? output,
|
|
1464
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1465
|
-
}) : null;
|
|
1466
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1467
1399
|
const calledClientName = contractOp.name;
|
|
1468
1400
|
const groups = getRequestGroups(node);
|
|
1469
1401
|
const hasRequestGroups = groups.path || groups.query || groups.body || groups.headers;
|
|
@@ -1488,11 +1420,6 @@ const mutationGenerator = defineGenerator({
|
|
|
1488
1420
|
}
|
|
1489
1421
|
}),
|
|
1490
1422
|
children: [
|
|
1491
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1492
|
-
name: zodSchemaNames,
|
|
1493
|
-
root: meta.file.path,
|
|
1494
|
-
path: fileZod.path
|
|
1495
|
-
}),
|
|
1496
1423
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1497
1424
|
name: [contractOp.name],
|
|
1498
1425
|
root: meta.file.path,
|
|
@@ -1524,7 +1451,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1524
1451
|
node,
|
|
1525
1452
|
transformer: ctx.options.mutationKey
|
|
1526
1453
|
}),
|
|
1527
|
-
mutation && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1454
|
+
mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1528
1455
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1529
1456
|
name: ["useMutation"],
|
|
1530
1457
|
path: importPath
|
|
@@ -1560,7 +1487,7 @@ const queryGenerator = defineGenerator({
|
|
|
1560
1487
|
operation(node, ctx) {
|
|
1561
1488
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1562
1489
|
const { config, driver, resolver, root } = ctx;
|
|
1563
|
-
const { output, query, mutation,
|
|
1490
|
+
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1564
1491
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1565
1492
|
if (!pluginTs) return null;
|
|
1566
1493
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1598,14 +1525,6 @@ const queryGenerator = defineGenerator({
|
|
|
1598
1525
|
order: "body-response-first",
|
|
1599
1526
|
includeParams: false
|
|
1600
1527
|
})].filter((name) => Boolean(name));
|
|
1601
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1602
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1603
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1604
|
-
root,
|
|
1605
|
-
output: pluginZod?.options?.output ?? output,
|
|
1606
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1607
|
-
}) : null;
|
|
1608
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1609
1528
|
const calledClientName = contractOp.name;
|
|
1610
1529
|
return /* @__PURE__ */ jsxs(File, {
|
|
1611
1530
|
baseName: meta.file.baseName,
|
|
@@ -1628,11 +1547,6 @@ const queryGenerator = defineGenerator({
|
|
|
1628
1547
|
}
|
|
1629
1548
|
}),
|
|
1630
1549
|
children: [
|
|
1631
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1632
|
-
name: zodSchemaNames,
|
|
1633
|
-
root: meta.file.path,
|
|
1634
|
-
path: fileZod.path
|
|
1635
|
-
}),
|
|
1636
1550
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1637
1551
|
name: [contractOp.name],
|
|
1638
1552
|
root: meta.file.path,
|
|
@@ -1677,7 +1591,7 @@ const queryGenerator = defineGenerator({
|
|
|
1677
1591
|
node,
|
|
1678
1592
|
tsResolver
|
|
1679
1593
|
}),
|
|
1680
|
-
query && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1594
|
+
query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1681
1595
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1682
1596
|
name: ["useQuery"],
|
|
1683
1597
|
path: importPath
|
|
@@ -1788,7 +1702,7 @@ const pluginVueQueryName = "plugin-vue-query";
|
|
|
1788
1702
|
/**
|
|
1789
1703
|
* Generates one TanStack Query composable per OpenAPI operation for Vue's
|
|
1790
1704
|
* Composition API. Queries become `useFooQuery` (and optionally
|
|
1791
|
-
* `useFooInfiniteQuery`)
|
|
1705
|
+
* `useFooInfiniteQuery`). Mutations become `useFooMutation`. Each composable
|
|
1792
1706
|
* is fully typed end to end.
|
|
1793
1707
|
*
|
|
1794
1708
|
* @example
|
|
@@ -1813,7 +1727,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1813
1727
|
const { output = {
|
|
1814
1728
|
path: "hooks",
|
|
1815
1729
|
barrel: { type: "named" }
|
|
1816
|
-
}, group, exclude = [], include, override = [],
|
|
1730
|
+
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
1817
1731
|
const selectedGenerators = [
|
|
1818
1732
|
queryGenerator,
|
|
1819
1733
|
infiniteQueryGenerator,
|
|
@@ -1823,7 +1737,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1823
1737
|
return {
|
|
1824
1738
|
name: pluginVueQueryName,
|
|
1825
1739
|
options,
|
|
1826
|
-
dependencies: [pluginTsName
|
|
1740
|
+
dependencies: [pluginTsName],
|
|
1827
1741
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1828
1742
|
const resolver = userResolver ? {
|
|
1829
1743
|
...resolverVueQuery,
|
|
@@ -1866,7 +1780,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1866
1780
|
previousParam: null,
|
|
1867
1781
|
...infinite
|
|
1868
1782
|
} : false,
|
|
1869
|
-
|
|
1783
|
+
hooks,
|
|
1870
1784
|
group: groupConfig,
|
|
1871
1785
|
exclude,
|
|
1872
1786
|
include,
|