@kubb/plugin-vue-query 5.6.0 → 5.6.1

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 CHANGED
@@ -28,6 +28,7 @@ let kubb_kit = require("kubb/kit");
28
28
  let node_path = require("node:path");
29
29
  node_path = __toESM(node_path, 1);
30
30
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
31
+ let _kubb_plugin_zod = require("@kubb/plugin-zod");
31
32
  let kubb_jsx = require("kubb/jsx");
32
33
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
33
34
  //#region ../../internals/shared/src/operation.ts
@@ -356,17 +357,256 @@ var compatibility = {
356
357
  };
357
358
  //#endregion
358
359
  //#region package.json
359
- var version = "5.6.0";
360
+ var version = "5.6.1";
361
+ //#endregion
362
+ //#region ../../internals/client/src/resolveOperationTypes.ts
363
+ /**
364
+ * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
365
+ * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
366
+ */
367
+ function toZodTypeResolver(resolver) {
368
+ const type = (name) => resolver.schema.type(name);
369
+ return {
370
+ ...resolver,
371
+ file: resolver.file.bind(resolver),
372
+ param: {
373
+ name: (node, p) => type(resolver.param.name(node, p)),
374
+ path: (node, p) => type(resolver.param.path(node, p)),
375
+ query: (node, p) => type(resolver.param.query(node, p)),
376
+ headers: (node, p) => type(resolver.param.headers(node, p))
377
+ },
378
+ response: {
379
+ body: (node) => type(resolver.response.body(node)),
380
+ status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
381
+ response: (node) => type(resolver.response.response(node)),
382
+ responses: (node) => type(resolver.response.responses(node)),
383
+ options: (node) => resolver.response.options(node)
384
+ }
385
+ };
386
+ }
387
+ /**
388
+ * Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.
389
+ *
390
+ * `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`
391
+ * wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws
392
+ * `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)
397
+ * types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod
398
+ * ```
399
+ */
400
+ function resolveOperationTypes(driver, pluginName) {
401
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
402
+ const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
403
+ if (pluginTs && pluginZod?.options?.inferred !== "codec") {
404
+ const resolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
405
+ return {
406
+ response: resolver.response,
407
+ resolver,
408
+ output: pluginTs.options?.output,
409
+ group: pluginTs.options?.group ?? void 0
410
+ };
411
+ }
412
+ if (!pluginZod?.options?.inferred) throw new kubb_kit.Diagnostics.Error({
413
+ code: kubb_kit.Diagnostics.code.missingDependency,
414
+ severity: "error",
415
+ message: `Plugin "${pluginName}" has no source for operation types.`,
416
+ help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
417
+ location: { kind: "config" },
418
+ plugin: pluginName
419
+ });
420
+ const resolver = toZodTypeResolver(driver.getResolver(_kubb_plugin_zod.pluginZodName));
421
+ return {
422
+ response: resolver.response,
423
+ resolver,
424
+ output: pluginZod.options.output,
425
+ group: pluginZod.options.group ?? void 0
426
+ };
427
+ }
428
+ //#endregion
429
+ //#region ../../internals/client/src/resolveClient.ts
430
+ /**
431
+ * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
432
+ * operation, shared so the selection rules and diagnostics stay in one place.
433
+ *
434
+ * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
435
+ * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
436
+ * inline client:
437
+ *
438
+ * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
439
+ * imports and calls them.
440
+ * - `error` — no client plugin is registered, several are registered without a selector, the
441
+ * requested one is missing, or `client` is not a known selector.
442
+ *
443
+ * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
444
+ * lone registered contract client plugin is picked up automatically.
445
+ */
446
+ const pluginFetchName = "plugin-fetch";
447
+ const pluginAxiosName = "plugin-axios";
448
+ const pluginClientName = "plugin-client";
449
+ const selectorToPlugin = {
450
+ fetch: pluginFetchName,
451
+ axios: pluginAxiosName,
452
+ client: pluginClientName
453
+ };
454
+ const contractPlugins = [
455
+ pluginFetchName,
456
+ pluginAxiosName,
457
+ pluginClientName
458
+ ];
459
+ /**
460
+ * Applies the `client` resolution rules. See the module comment for the strategy shape.
461
+ *
462
+ * @example
463
+ * ```ts
464
+ * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
465
+ * // { kind: 'contract', pluginName: 'plugin-fetch' }
466
+ * ```
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
471
+ * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }
472
+ * ```
473
+ */
474
+ function resolveClient(options) {
475
+ const { client, pluginNames } = options;
476
+ const has = (name) => pluginNames.includes(name);
477
+ if (client === "fetch" || client === "axios" || client === "client") {
478
+ const pluginName = selectorToPlugin[client];
479
+ if (!has(pluginName)) return {
480
+ kind: "error",
481
+ code: kubb_kit.Diagnostics.code.missingDependency,
482
+ message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
483
+ help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
484
+ };
485
+ return {
486
+ kind: "contract",
487
+ pluginName
488
+ };
489
+ }
490
+ if (client !== void 0) return {
491
+ kind: "error",
492
+ code: kubb_kit.Diagnostics.code.invalidPluginOptions,
493
+ message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
494
+ help: "Set `client` to one of those values, or drop it to use the registered client plugin."
495
+ };
496
+ const registered = contractPlugins.filter(has);
497
+ if (registered.length === 1) return {
498
+ kind: "contract",
499
+ pluginName: registered[0]
500
+ };
501
+ if (registered.length > 1) return {
502
+ kind: "error",
503
+ code: kubb_kit.Diagnostics.code.invalidPluginOptions,
504
+ message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
505
+ help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
506
+ };
507
+ return {
508
+ kind: "error",
509
+ code: kubb_kit.Diagnostics.code.missingDependency,
510
+ message: "No client plugin is registered.",
511
+ help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
512
+ };
513
+ }
514
+ /**
515
+ * Resolves the contract client during a consumer plugin's setup hook.
516
+ * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.
517
+ * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer
518
+ * fails fast with the same message.
519
+ */
520
+ function resolveContractClient(options) {
521
+ const { plugin, client, plugins = [] } = options;
522
+ const resolved = resolveClient({
523
+ client,
524
+ pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
525
+ });
526
+ if (resolved.kind === "error") {
527
+ const { code, message, help } = resolved;
528
+ throw new kubb_kit.Diagnostics.Error({
529
+ code,
530
+ severity: "error",
531
+ message,
532
+ help,
533
+ location: { kind: "config" },
534
+ plugin
535
+ });
536
+ }
537
+ return resolved;
538
+ }
539
+ //#endregion
540
+ //#region ../../internals/client/src/resolveClientOperation.ts
541
+ function isRelativeImport(importPath) {
542
+ return importPath.startsWith(".");
543
+ }
544
+ function resolveImportPath(options) {
545
+ const { importPath, operationFile } = options;
546
+ return isRelativeImport(importPath) ? node_path.default.resolve(node_path.default.dirname(operationFile), importPath) : importPath;
547
+ }
548
+ /**
549
+ * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
550
+ * the registered contract client plugin's resolver and output. Works for any contract client plugin
551
+ * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline
552
+ * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
553
+ * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
554
+ * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
555
+ * With plugin-client they come from the user's `importPath` module instead.
556
+ *
557
+ * The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
558
+ * so several dependents reading the same client plugin for one operation in a single pass
559
+ * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
560
+ * one computed result instead of each re-deriving the name and path.
561
+ *
562
+ * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
563
+ * `override` entries, the same resolution its own generator sees. A dependent's generated call body
564
+ * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
565
+ */
566
+ function resolveClientOperation(options) {
567
+ const { clientPlugin, driver, node, root, output, cache } = options;
568
+ if (!clientPlugin) return null;
569
+ return cache.ensureItem(`${clientPlugin.pluginName}:clientOperation`, () => {
570
+ const resolver = driver.getResolver(clientPlugin.pluginName);
571
+ const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
572
+ const { exclude, include, override } = pluginOptions;
573
+ const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
574
+ options: pluginOptions,
575
+ exclude,
576
+ include,
577
+ override
578
+ }) : pluginOptions;
579
+ if (!operationOptions) return null;
580
+ const file = resolver.file({
581
+ ...operationFileEntry(node, node.operationId),
582
+ root,
583
+ output: operationOptions.output ?? output,
584
+ group: operationOptions.group ?? void 0
585
+ });
586
+ const { importPath } = operationOptions;
587
+ return {
588
+ name: resolver.name(node.operationId),
589
+ path: file.path,
590
+ clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
591
+ importPath,
592
+ operationFile: file.path
593
+ }),
594
+ clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
595
+ returnType: operationOptions.returnType ?? "full"
596
+ };
597
+ });
598
+ }
360
599
  //#endregion
361
600
  //#region ../../internals/tanstack-query/src/components/HookFile.tsx
362
601
  /**
363
- * Resolves what every TanStack hook file shares: its file, the `@kubb/plugin-ts` file and type names, banner and footer.
602
+ * Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
603
+ * `pluginZod({ inferred: 'codec' })`), banner and footer.
364
604
  */
365
605
  function resolveHookFile(node, ctx, options) {
366
606
  const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
367
607
  const { config, root, resolver } = ctx;
368
- const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
369
- const tsResolver = ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName);
608
+ const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
609
+ const tsResolver = types.resolver;
370
610
  const file = resolver.file({
371
611
  ...operationFileEntry(node, name),
372
612
  root,
@@ -378,8 +618,8 @@ function resolveHookFile(node, ctx, options) {
378
618
  node,
379
619
  resolver: tsResolver,
380
620
  root,
381
- output: pluginTs.options?.output ?? output,
382
- group: pluginTs.options?.group
621
+ output: types.output ?? output,
622
+ group: types.group
383
623
  });
384
624
  const importedTypeNames = [
385
625
  tsResolver.response.options(node),
@@ -1004,177 +1244,6 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
1004
1244
  })] });
1005
1245
  }
1006
1246
  //#endregion
1007
- //#region ../../internals/client/src/resolveClient.ts
1008
- /**
1009
- * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
1010
- * operation, shared so the selection rules and diagnostics stay in one place.
1011
- *
1012
- * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
1013
- * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
1014
- * inline client:
1015
- *
1016
- * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
1017
- * imports and calls them.
1018
- * - `error` — no client plugin is registered, several are registered without a selector, the
1019
- * requested one is missing, or `client` is not a known selector.
1020
- *
1021
- * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
1022
- * lone registered contract client plugin is picked up automatically.
1023
- */
1024
- const pluginFetchName = "plugin-fetch";
1025
- const pluginAxiosName = "plugin-axios";
1026
- const pluginClientName = "plugin-client";
1027
- const selectorToPlugin = {
1028
- fetch: pluginFetchName,
1029
- axios: pluginAxiosName,
1030
- client: pluginClientName
1031
- };
1032
- const contractPlugins = [
1033
- pluginFetchName,
1034
- pluginAxiosName,
1035
- pluginClientName
1036
- ];
1037
- /**
1038
- * Applies the `client` resolution rules. See the module comment for the strategy shape.
1039
- *
1040
- * @example
1041
- * ```ts
1042
- * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
1043
- * // { kind: 'contract', pluginName: 'plugin-fetch' }
1044
- * ```
1045
- *
1046
- * @example
1047
- * ```ts
1048
- * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
1049
- * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }
1050
- * ```
1051
- */
1052
- function resolveClient(options) {
1053
- const { client, pluginNames } = options;
1054
- const has = (name) => pluginNames.includes(name);
1055
- if (client === "fetch" || client === "axios" || client === "client") {
1056
- const pluginName = selectorToPlugin[client];
1057
- if (!has(pluginName)) return {
1058
- kind: "error",
1059
- code: kubb_kit.Diagnostics.code.missingDependency,
1060
- message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
1061
- help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
1062
- };
1063
- return {
1064
- kind: "contract",
1065
- pluginName
1066
- };
1067
- }
1068
- if (client !== void 0) return {
1069
- kind: "error",
1070
- code: kubb_kit.Diagnostics.code.invalidPluginOptions,
1071
- message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
1072
- help: "Set `client` to one of those values, or drop it to use the registered client plugin."
1073
- };
1074
- const registered = contractPlugins.filter(has);
1075
- if (registered.length === 1) return {
1076
- kind: "contract",
1077
- pluginName: registered[0]
1078
- };
1079
- if (registered.length > 1) return {
1080
- kind: "error",
1081
- code: kubb_kit.Diagnostics.code.invalidPluginOptions,
1082
- message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
1083
- help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
1084
- };
1085
- return {
1086
- kind: "error",
1087
- code: kubb_kit.Diagnostics.code.missingDependency,
1088
- message: "No client plugin is registered.",
1089
- help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
1090
- };
1091
- }
1092
- /**
1093
- * Resolves the contract client during a consumer plugin's setup hook.
1094
- * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.
1095
- * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer
1096
- * fails fast with the same message.
1097
- */
1098
- function resolveContractClient(options) {
1099
- const { plugin, client, plugins = [] } = options;
1100
- const resolved = resolveClient({
1101
- client,
1102
- pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
1103
- });
1104
- if (resolved.kind === "error") {
1105
- const { code, message, help } = resolved;
1106
- throw new kubb_kit.Diagnostics.Error({
1107
- code,
1108
- severity: "error",
1109
- message,
1110
- help,
1111
- location: { kind: "config" },
1112
- plugin
1113
- });
1114
- }
1115
- return resolved;
1116
- }
1117
- //#endregion
1118
- //#region ../../internals/client/src/resolveClientOperation.ts
1119
- function isRelativeImport(importPath) {
1120
- return importPath.startsWith(".");
1121
- }
1122
- function resolveImportPath(options) {
1123
- const { importPath, operationFile } = options;
1124
- return isRelativeImport(importPath) ? node_path.default.resolve(node_path.default.dirname(operationFile), importPath) : importPath;
1125
- }
1126
- /**
1127
- * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
1128
- * the registered contract client plugin's resolver and output. Works for any contract client plugin
1129
- * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline
1130
- * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
1131
- * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
1132
- * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
1133
- * With plugin-client they come from the user's `importPath` module instead.
1134
- *
1135
- * The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
1136
- * so several dependents reading the same client plugin for one operation in a single pass
1137
- * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
1138
- * one computed result instead of each re-deriving the name and path.
1139
- *
1140
- * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
1141
- * `override` entries, the same resolution its own generator sees. A dependent's generated call body
1142
- * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
1143
- */
1144
- function resolveClientOperation(options) {
1145
- const { clientPlugin, driver, node, root, output, cache } = options;
1146
- if (!clientPlugin) return null;
1147
- return cache.ensureItem(`${clientPlugin.pluginName}:clientOperation`, () => {
1148
- const resolver = driver.getResolver(clientPlugin.pluginName);
1149
- const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
1150
- const { exclude, include, override } = pluginOptions;
1151
- const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
1152
- options: pluginOptions,
1153
- exclude,
1154
- include,
1155
- override
1156
- }) : pluginOptions;
1157
- if (!operationOptions) return null;
1158
- const file = resolver.file({
1159
- ...operationFileEntry(node, node.operationId),
1160
- root,
1161
- output: operationOptions.output ?? output,
1162
- group: operationOptions.group ?? void 0
1163
- });
1164
- const { importPath } = operationOptions;
1165
- return {
1166
- name: resolver.name(node.operationId),
1167
- path: file.path,
1168
- clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
1169
- importPath,
1170
- operationFile: file.path
1171
- }),
1172
- clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
1173
- returnType: operationOptions.returnType ?? "full"
1174
- };
1175
- });
1176
- }
1177
- //#endregion
1178
1247
  //#region src/components/QueryOptions.tsx
1179
1248
  const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1180
1249
  const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
@@ -1354,7 +1423,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1354
1423
  contractOp,
1355
1424
  keyTypeName: queryKeyTypeName,
1356
1425
  extraTypeNames: [resolvePageParamType(node, {
1357
- resolver: ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName),
1426
+ resolver: resolveOperationTypes(ctx.driver, ctx.resolver.pluginName).resolver,
1358
1427
  initialPageParam: infiniteOptions.initialPageParam,
1359
1428
  queryParam: infiniteOptions.queryParam
1360
1429
  }).queryParamsTypeName]
@@ -1749,7 +1818,7 @@ const pluginVueQuery = (0, kubb_kit.defineExtension)({
1749
1818
  version,
1750
1819
  compatibility
1751
1820
  },
1752
- dependencies: { [_kubb_plugin_ts.pluginTsName]: {} },
1821
+ dependencies: { [_kubb_plugin_ts.pluginTsName]: { optional: true } },
1753
1822
  setup(options) {
1754
1823
  const { output = {
1755
1824
  path: "hooks",