@kubb/plugin-react-query 5.4.0-canary.20261014T071450 → 5.5.0-canary.20261014T114046
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 +42 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +42 -20
- package/dist/index.js.map +1 -1
- package/docs/guides/calling-operations.md +2 -2
- package/docs/options.md +8 -4
- package/docs/overview.md +1 -1
- package/package.json +6 -6
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.
|
|
360
|
+
var version = "5.5.0-canary.20261014T114046";
|
|
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-
|
|
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
|
|
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 = [
|
|
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
|
|
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-
|
|
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.
|
|
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
|
/**
|
|
@@ -1690,7 +1712,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1690
1712
|
}),
|
|
1691
1713
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1692
1714
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1693
|
-
root: meta.file.path,
|
|
1715
|
+
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
1694
1716
|
path: contractOp.clientPath,
|
|
1695
1717
|
isTypeOnly: true
|
|
1696
1718
|
}),
|
|
@@ -1854,7 +1876,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1854
1876
|
}),
|
|
1855
1877
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1856
1878
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1857
|
-
root: meta.file.path,
|
|
1879
|
+
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
1858
1880
|
path: contractOp.clientPath,
|
|
1859
1881
|
isTypeOnly: true
|
|
1860
1882
|
}),
|
|
@@ -2003,7 +2025,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2003
2025
|
}),
|
|
2004
2026
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2005
2027
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
2006
|
-
root: meta.file.path,
|
|
2028
|
+
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
2007
2029
|
path: contractOp.clientPath,
|
|
2008
2030
|
isTypeOnly: true
|
|
2009
2031
|
}),
|
|
@@ -2170,7 +2192,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2170
2192
|
}),
|
|
2171
2193
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2172
2194
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
2173
|
-
root: meta.file.path,
|
|
2195
|
+
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
2174
2196
|
path: contractOp.clientPath,
|
|
2175
2197
|
isTypeOnly: true
|
|
2176
2198
|
}),
|
|
@@ -2339,7 +2361,7 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2339
2361
|
}),
|
|
2340
2362
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2341
2363
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
2342
|
-
root: meta.file.path,
|
|
2364
|
+
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
2343
2365
|
path: contractOp.clientPath,
|
|
2344
2366
|
isTypeOnly: true
|
|
2345
2367
|
}),
|