@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.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { pluginZodName } from "@kubb/plugin-zod";
|
|
3
4
|
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
4
5
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
@@ -331,7 +332,74 @@ var compatibility = {
|
|
|
331
332
|
};
|
|
332
333
|
//#endregion
|
|
333
334
|
//#region package.json
|
|
334
|
-
var version = "5.6.
|
|
335
|
+
var version = "5.6.2";
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
338
|
+
/**
|
|
339
|
+
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
340
|
+
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
341
|
+
*/
|
|
342
|
+
function toZodTypeResolver(resolver) {
|
|
343
|
+
const type = (name) => resolver.schema.type(name);
|
|
344
|
+
return {
|
|
345
|
+
...resolver,
|
|
346
|
+
file: resolver.file.bind(resolver),
|
|
347
|
+
param: {
|
|
348
|
+
name: (node, p) => type(resolver.param.name(node, p)),
|
|
349
|
+
path: (node, p) => type(resolver.param.path(node, p)),
|
|
350
|
+
query: (node, p) => type(resolver.param.query(node, p)),
|
|
351
|
+
headers: (node, p) => type(resolver.param.headers(node, p))
|
|
352
|
+
},
|
|
353
|
+
response: {
|
|
354
|
+
body: (node) => type(resolver.response.body(node)),
|
|
355
|
+
status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
|
|
356
|
+
response: (node) => type(resolver.response.response(node)),
|
|
357
|
+
responses: (node) => type(resolver.response.responses(node)),
|
|
358
|
+
options: (node) => resolver.response.options(node)
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.
|
|
364
|
+
*
|
|
365
|
+
* `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`
|
|
366
|
+
* wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws
|
|
367
|
+
* `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)
|
|
372
|
+
* types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
function resolveOperationTypes(driver, pluginName) {
|
|
376
|
+
const pluginTs = driver.getPlugin(pluginTsName);
|
|
377
|
+
const pluginZod = driver.getPlugin(pluginZodName);
|
|
378
|
+
if (pluginTs && pluginZod?.options?.inferred !== "codec") {
|
|
379
|
+
const resolver = driver.getResolver(pluginTsName);
|
|
380
|
+
return {
|
|
381
|
+
response: resolver.response,
|
|
382
|
+
resolver,
|
|
383
|
+
output: pluginTs.options?.output,
|
|
384
|
+
group: pluginTs.options?.group ?? void 0
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
if (!pluginZod?.options?.inferred) throw new Diagnostics.Error({
|
|
388
|
+
code: Diagnostics.code.missingDependency,
|
|
389
|
+
severity: "error",
|
|
390
|
+
message: `Plugin "${pluginName}" has no source for operation types.`,
|
|
391
|
+
help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
|
|
392
|
+
location: { kind: "config" },
|
|
393
|
+
plugin: pluginName
|
|
394
|
+
});
|
|
395
|
+
const resolver = toZodTypeResolver(driver.getResolver(pluginZodName));
|
|
396
|
+
return {
|
|
397
|
+
response: resolver.response,
|
|
398
|
+
resolver,
|
|
399
|
+
output: pluginZod.options.output,
|
|
400
|
+
group: pluginZod.options.group ?? void 0
|
|
401
|
+
};
|
|
402
|
+
}
|
|
335
403
|
//#endregion
|
|
336
404
|
//#region ../../internals/client/src/resolveClient.ts
|
|
337
405
|
/**
|
|
@@ -506,13 +574,14 @@ function resolveClientOperation(options) {
|
|
|
506
574
|
//#endregion
|
|
507
575
|
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
508
576
|
/**
|
|
509
|
-
* Resolves what every TanStack hook file shares: its file, the
|
|
577
|
+
* Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
|
|
578
|
+
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
510
579
|
*/
|
|
511
580
|
function resolveHookFile(node, ctx, options) {
|
|
512
581
|
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
513
582
|
const { config, root, resolver } = ctx;
|
|
514
|
-
const
|
|
515
|
-
const tsResolver =
|
|
583
|
+
const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
|
|
584
|
+
const tsResolver = types.resolver;
|
|
516
585
|
const file = resolver.file({
|
|
517
586
|
...operationFileEntry(node, name),
|
|
518
587
|
root,
|
|
@@ -524,8 +593,8 @@ function resolveHookFile(node, ctx, options) {
|
|
|
524
593
|
node,
|
|
525
594
|
resolver: tsResolver,
|
|
526
595
|
root,
|
|
527
|
-
output:
|
|
528
|
-
group:
|
|
596
|
+
output: types.output ?? output,
|
|
597
|
+
group: types.group
|
|
529
598
|
});
|
|
530
599
|
const importedTypeNames = [
|
|
531
600
|
tsResolver.response.options(node),
|
|
@@ -1647,7 +1716,7 @@ function createQueryGenerator({ name, variant }) {
|
|
|
1647
1716
|
const queryOptionsName = variantResolver.optionsName(node);
|
|
1648
1717
|
const queryKeyName = variantResolver.keyName(node);
|
|
1649
1718
|
const queryKeyTypeName = variantResolver.keyTypeName(node);
|
|
1650
|
-
const tsResolver = driver.
|
|
1719
|
+
const tsResolver = resolveOperationTypes(driver, resolver.pluginName).resolver;
|
|
1651
1720
|
const hook = resolveHookFile(node, ctx, {
|
|
1652
1721
|
name: queryName,
|
|
1653
1722
|
output,
|
|
@@ -2078,7 +2147,7 @@ const pluginReactQuery = defineExtension({
|
|
|
2078
2147
|
version,
|
|
2079
2148
|
compatibility
|
|
2080
2149
|
},
|
|
2081
|
-
dependencies: { [pluginTsName]: {} },
|
|
2150
|
+
dependencies: { [pluginTsName]: { optional: true } },
|
|
2082
2151
|
setup(options) {
|
|
2083
2152
|
const { output = {
|
|
2084
2153
|
path: "hooks",
|