@kubb/plugin-react-query 5.4.0-canary.20261014T071450 → 5.5.0-canary.20261014T114558

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
@@ -357,7 +357,7 @@ var compatibility = {
357
357
  };
358
358
  //#endregion
359
359
  //#region package.json
360
- var version = "5.4.0-canary.20261014T071450";
360
+ var version = "5.5.0-canary.20261014T114558";
361
361
  //#endregion
362
362
  //#region ../../internals/client/src/resolveClient.ts
363
363
  /**
@@ -365,23 +365,30 @@ var version = "5.4.0-canary.20261014T071450";
365
365
  * operation, shared so the selection rules and diagnostics stay in one place.
366
366
  *
367
367
  * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
368
- * contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
368
+ * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
369
+ * inline client:
369
370
  *
370
371
  * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
371
372
  * imports and calls them.
372
373
  * - `error` — no client plugin is registered, several are registered without a selector, the
373
374
  * requested one is missing, or `client` is not a known selector.
374
375
  *
375
- * The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
376
- * contract client plugin is picked up automatically.
376
+ * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
377
+ * lone registered contract client plugin is picked up automatically.
377
378
  */
378
379
  const pluginFetchName = "plugin-fetch";
379
380
  const pluginAxiosName = "plugin-axios";
381
+ const pluginClientName = "plugin-client";
380
382
  const selectorToPlugin = {
381
383
  fetch: pluginFetchName,
382
- axios: pluginAxiosName
384
+ axios: pluginAxiosName,
385
+ client: pluginClientName
383
386
  };
384
- const contractPlugins = [pluginFetchName, pluginAxiosName];
387
+ const contractPlugins = [
388
+ pluginFetchName,
389
+ pluginAxiosName,
390
+ pluginClientName
391
+ ];
385
392
  /**
386
393
  * Applies the `client` resolution rules. See the module comment for the strategy shape.
387
394
  *
@@ -400,7 +407,7 @@ const contractPlugins = [pluginFetchName, pluginAxiosName];
400
407
  function resolveClient(options) {
401
408
  const { client, pluginNames } = options;
402
409
  const has = (name) => pluginNames.includes(name);
403
- if (client === "fetch" || client === "axios") {
410
+ if (client === "fetch" || client === "axios" || client === "client") {
404
411
  const pluginName = selectorToPlugin[client];
405
412
  if (!has(pluginName)) return {
406
413
  kind: "error",
@@ -413,7 +420,7 @@ function resolveClient(options) {
413
420
  }
414
421
  if (client !== void 0) return {
415
422
  kind: "error",
416
- message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios'. Drop \`client\` to use the registered client plugin.`
423
+ message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'. Drop \`client\` to use the registered client plugin.`
417
424
  };
418
425
  const registered = contractPlugins.filter(has);
419
426
  if (registered.length === 1) return {
@@ -422,11 +429,11 @@ function resolveClient(options) {
422
429
  };
423
430
  if (registered.length > 1) return {
424
431
  kind: "error",
425
- 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.`
432
+ message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}). Set \`client: 'fetch' | 'axios' | 'client'\` to choose which client the hooks call, or register a single client plugin.`
426
433
  };
427
434
  return {
428
435
  kind: "error",
429
- 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."
436
+ message: "No client plugin is registered. Add `@kubb/plugin-axios`, `@kubb/plugin-fetch`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
430
437
  };
431
438
  }
432
439
  /**
@@ -445,13 +452,21 @@ function resolveContractClient(options) {
445
452
  }
446
453
  //#endregion
447
454
  //#region ../../internals/client/src/resolveClientOperation.ts
455
+ function isRelativeImport(importPath) {
456
+ return importPath.startsWith(".");
457
+ }
458
+ function resolveImportPath(options) {
459
+ const { importPath, operationFile } = options;
460
+ return isRelativeImport(importPath) ? node_path.default.resolve(node_path.default.dirname(operationFile), importPath) : importPath;
461
+ }
448
462
  /**
449
463
  * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
450
464
  * the registered contract client plugin's resolver and output. Works for any contract client plugin
451
- * (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
465
+ * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline
452
466
  * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
453
- * emits no `<op>` to import. The plugin injects `.kubb/client.ts` at the global output root, the
454
- * same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
467
+ * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
468
+ * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
469
+ * With plugin-client they come from the user's `importPath` module instead.
455
470
  *
456
471
  * The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
457
472
  * so several dependents reading the same client plugin for one operation in a single pass
@@ -482,10 +497,15 @@ function resolveClientOperation(options) {
482
497
  output: operationOptions.output ?? output,
483
498
  group: operationOptions.group ?? void 0
484
499
  });
500
+ const { importPath } = operationOptions;
485
501
  return {
486
502
  name: resolver.name(node.operationId),
487
503
  path: file.path,
488
- clientPath: node_path.default.resolve(root, ".kubb/client.ts"),
504
+ clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
505
+ importPath,
506
+ operationFile: file.path
507
+ }),
508
+ clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
489
509
  returnType: operationOptions.returnType ?? "full"
490
510
  };
491
511
  });
@@ -600,7 +620,8 @@ function buildClientCall(node, options) {
600
620
  * success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
601
621
  * `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
602
622
  * (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
603
- * off the full result by hand.
623
+ * off the full result by hand. With `'plain'` (plugin-client) the call resolves to the user's
624
+ * `RequestResult`, so the body awaits it and reads `data`.
604
625
  *
605
626
  * @example
606
627
  * ```ts
@@ -611,6 +632,7 @@ function buildClientCall(node, options) {
611
632
  function buildCallResultBody(call, options = {}) {
612
633
  const { returnType = "full" } = options;
613
634
  if (returnType === "data") return `return await ${call}`;
635
+ if (returnType === "plain") return `return (await ${call}).data`;
614
636
  return `return ${call}.unwrap()`;
615
637
  }
616
638
  /**
@@ -655,13 +677,14 @@ function resolvePageParamType(node, { resolver, initialPageParam, queryParam })
655
677
  }
656
678
  /**
657
679
  * Applies the shared query defaults during plugin setup: `false` disables query generation, and an
658
- * object merges over `methods: ['GET']` and the plugin's runtime `importPath`.
680
+ * object merges over `methods: ['GET', 'QUERY']` and the plugin's runtime `importPath`. QUERY
681
+ * (RFC 10008) is a safe, idempotent read that carries its input in the body, so it is a query too.
659
682
  */
660
683
  function resolveQueryConfig(query, options) {
661
684
  if (query === false) return false;
662
685
  return {
663
686
  importPath: options.importPath,
664
- methods: ["GET"],
687
+ methods: ["GET", "QUERY"],
665
688
  ...query
666
689
  };
667
690
  }
@@ -974,7 +997,7 @@ const queryKeyTransformer = ({ node, variant }) => {
974
997
  if (isInfinite) urlFields.push("infinite: true");
975
998
  const result = [`{ ${urlFields.join(", ")} }`];
976
999
  if (query.length > 0) result.push("...(query ? [query] : [])");
977
- if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
1000
+ if (node.requestBody?.content?.[0]?.schema) result.push("...(body !== undefined ? [body] : [])");
978
1001
  return result;
979
1002
  };
980
1003
  function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
@@ -1690,7 +1713,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1690
1713
  }),
1691
1714
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1692
1715
  name: ["RequestConfig", "ResponseErrorConfig"],
1693
- root: meta.file.path,
1716
+ root: contractOp.clientPathIsFile ? meta.file.path : void 0,
1694
1717
  path: contractOp.clientPath,
1695
1718
  isTypeOnly: true
1696
1719
  }),
@@ -1854,7 +1877,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
1854
1877
  }),
1855
1878
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1856
1879
  name: ["RequestConfig", "ResponseErrorConfig"],
1857
- root: meta.file.path,
1880
+ root: contractOp.clientPathIsFile ? meta.file.path : void 0,
1858
1881
  path: contractOp.clientPath,
1859
1882
  isTypeOnly: true
1860
1883
  }),
@@ -1917,7 +1940,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
1917
1940
  //#region src/generators/queryGenerator.tsx
1918
1941
  /**
1919
1942
  * Built-in generator for `useQuery` hooks. Emits one `useFooQuery` hook per
1920
- * GET operation (configurable via `query.methods`) plus the matching
1943
+ * GET and QUERY operation (configurable via `query.methods`) plus the matching
1921
1944
  * `fooQueryKey` / `fooQueryOptions` helpers.
1922
1945
  */
1923
1946
  const queryGenerator = (0, kubb_kit.defineGenerator)({
@@ -2003,7 +2026,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
2003
2026
  }),
2004
2027
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
2005
2028
  name: ["RequestConfig", "ResponseErrorConfig"],
2006
- root: meta.file.path,
2029
+ root: contractOp.clientPathIsFile ? meta.file.path : void 0,
2007
2030
  path: contractOp.clientPath,
2008
2031
  isTypeOnly: true
2009
2032
  }),
@@ -2170,7 +2193,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2170
2193
  }),
2171
2194
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
2172
2195
  name: ["RequestConfig", "ResponseErrorConfig"],
2173
- root: meta.file.path,
2196
+ root: contractOp.clientPathIsFile ? meta.file.path : void 0,
2174
2197
  path: contractOp.clientPath,
2175
2198
  isTypeOnly: true
2176
2199
  }),
@@ -2339,7 +2362,7 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
2339
2362
  }),
2340
2363
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
2341
2364
  name: ["RequestConfig", "ResponseErrorConfig"],
2342
- root: meta.file.path,
2365
+ root: contractOp.clientPathIsFile ? meta.file.path : void 0,
2343
2366
  path: contractOp.clientPath,
2344
2367
  isTypeOnly: true
2345
2368
  }),