@kubb/plugin-react-query 5.6.0 → 5.6.2
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 +77 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +77 -8
- package/dist/index.js.map +1 -1
- package/docs/overview.md +1 -1
- package/kubb-extension.json +1 -0
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
let kubb_kit = require("kubb/kit");
|
|
28
28
|
let node_path = require("node:path");
|
|
29
29
|
node_path = __toESM(node_path, 1);
|
|
30
|
+
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
30
31
|
let kubb_jsx = require("kubb/jsx");
|
|
31
32
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
32
33
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
@@ -358,7 +359,74 @@ var compatibility = {
|
|
|
358
359
|
};
|
|
359
360
|
//#endregion
|
|
360
361
|
//#region package.json
|
|
361
|
-
var version = "5.6.
|
|
362
|
+
var version = "5.6.2";
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
365
|
+
/**
|
|
366
|
+
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
367
|
+
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
368
|
+
*/
|
|
369
|
+
function toZodTypeResolver(resolver) {
|
|
370
|
+
const type = (name) => resolver.schema.type(name);
|
|
371
|
+
return {
|
|
372
|
+
...resolver,
|
|
373
|
+
file: resolver.file.bind(resolver),
|
|
374
|
+
param: {
|
|
375
|
+
name: (node, p) => type(resolver.param.name(node, p)),
|
|
376
|
+
path: (node, p) => type(resolver.param.path(node, p)),
|
|
377
|
+
query: (node, p) => type(resolver.param.query(node, p)),
|
|
378
|
+
headers: (node, p) => type(resolver.param.headers(node, p))
|
|
379
|
+
},
|
|
380
|
+
response: {
|
|
381
|
+
body: (node) => type(resolver.response.body(node)),
|
|
382
|
+
status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
|
|
383
|
+
response: (node) => type(resolver.response.response(node)),
|
|
384
|
+
responses: (node) => type(resolver.response.responses(node)),
|
|
385
|
+
options: (node) => resolver.response.options(node)
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.
|
|
391
|
+
*
|
|
392
|
+
* `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`
|
|
393
|
+
* wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws
|
|
394
|
+
* `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)
|
|
399
|
+
* types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
function resolveOperationTypes(driver, pluginName) {
|
|
403
|
+
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
404
|
+
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
405
|
+
if (pluginTs && pluginZod?.options?.inferred !== "codec") {
|
|
406
|
+
const resolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
407
|
+
return {
|
|
408
|
+
response: resolver.response,
|
|
409
|
+
resolver,
|
|
410
|
+
output: pluginTs.options?.output,
|
|
411
|
+
group: pluginTs.options?.group ?? void 0
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
if (!pluginZod?.options?.inferred) throw new kubb_kit.Diagnostics.Error({
|
|
415
|
+
code: kubb_kit.Diagnostics.code.missingDependency,
|
|
416
|
+
severity: "error",
|
|
417
|
+
message: `Plugin "${pluginName}" has no source for operation types.`,
|
|
418
|
+
help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
|
|
419
|
+
location: { kind: "config" },
|
|
420
|
+
plugin: pluginName
|
|
421
|
+
});
|
|
422
|
+
const resolver = toZodTypeResolver(driver.getResolver(_kubb_plugin_zod.pluginZodName));
|
|
423
|
+
return {
|
|
424
|
+
response: resolver.response,
|
|
425
|
+
resolver,
|
|
426
|
+
output: pluginZod.options.output,
|
|
427
|
+
group: pluginZod.options.group ?? void 0
|
|
428
|
+
};
|
|
429
|
+
}
|
|
362
430
|
//#endregion
|
|
363
431
|
//#region ../../internals/client/src/resolveClient.ts
|
|
364
432
|
/**
|
|
@@ -533,13 +601,14 @@ function resolveClientOperation(options) {
|
|
|
533
601
|
//#endregion
|
|
534
602
|
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
535
603
|
/**
|
|
536
|
-
* Resolves what every TanStack hook file shares: its file, the
|
|
604
|
+
* Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
|
|
605
|
+
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
537
606
|
*/
|
|
538
607
|
function resolveHookFile(node, ctx, options) {
|
|
539
608
|
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
540
609
|
const { config, root, resolver } = ctx;
|
|
541
|
-
const
|
|
542
|
-
const tsResolver =
|
|
610
|
+
const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
|
|
611
|
+
const tsResolver = types.resolver;
|
|
543
612
|
const file = resolver.file({
|
|
544
613
|
...operationFileEntry(node, name),
|
|
545
614
|
root,
|
|
@@ -551,8 +620,8 @@ function resolveHookFile(node, ctx, options) {
|
|
|
551
620
|
node,
|
|
552
621
|
resolver: tsResolver,
|
|
553
622
|
root,
|
|
554
|
-
output:
|
|
555
|
-
group:
|
|
623
|
+
output: types.output ?? output,
|
|
624
|
+
group: types.group
|
|
556
625
|
});
|
|
557
626
|
const importedTypeNames = [
|
|
558
627
|
tsResolver.response.options(node),
|
|
@@ -1674,7 +1743,7 @@ function createQueryGenerator({ name, variant }) {
|
|
|
1674
1743
|
const queryOptionsName = variantResolver.optionsName(node);
|
|
1675
1744
|
const queryKeyName = variantResolver.keyName(node);
|
|
1676
1745
|
const queryKeyTypeName = variantResolver.keyTypeName(node);
|
|
1677
|
-
const tsResolver = driver.
|
|
1746
|
+
const tsResolver = resolveOperationTypes(driver, resolver.pluginName).resolver;
|
|
1678
1747
|
const hook = resolveHookFile(node, ctx, {
|
|
1679
1748
|
name: queryName,
|
|
1680
1749
|
output,
|
|
@@ -2105,7 +2174,7 @@ const pluginReactQuery = (0, kubb_kit.defineExtension)({
|
|
|
2105
2174
|
version,
|
|
2106
2175
|
compatibility
|
|
2107
2176
|
},
|
|
2108
|
-
dependencies: { [_kubb_plugin_ts.pluginTsName]: {} },
|
|
2177
|
+
dependencies: { [_kubb_plugin_ts.pluginTsName]: { optional: true } },
|
|
2109
2178
|
setup(options) {
|
|
2110
2179
|
const { output = {
|
|
2111
2180
|
path: "hooks",
|