@kubb/plugin-react-query 5.0.0-beta.80 → 5.0.0-beta.81
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 +10 -132
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -170
- package/dist/index.js +10 -132
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,6 @@ let node_path = require("node:path");
|
|
|
28
28
|
node_path = __toESM(node_path, 1);
|
|
29
29
|
let _kubb_core = require("@kubb/core");
|
|
30
30
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
31
|
-
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
32
31
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
33
32
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
34
33
|
let node_fs = require("node:fs");
|
|
@@ -557,16 +556,6 @@ function createGroupConfig(group) {
|
|
|
557
556
|
};
|
|
558
557
|
}
|
|
559
558
|
//#endregion
|
|
560
|
-
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
561
|
-
/**
|
|
562
|
-
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
563
|
-
*/
|
|
564
|
-
function isValidatorEnabled(validator) {
|
|
565
|
-
if (!validator) return false;
|
|
566
|
-
if (validator === "zod") return true;
|
|
567
|
-
return Boolean(validator.request || validator.response);
|
|
568
|
-
}
|
|
569
|
-
//#endregion
|
|
570
559
|
//#region ../../internals/client/src/resolveClient.ts
|
|
571
560
|
/**
|
|
572
561
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -809,51 +798,6 @@ function resolveOperationOverrides(node, override) {
|
|
|
809
798
|
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
810
799
|
}
|
|
811
800
|
/**
|
|
812
|
-
* Returns `'zod'` when response-direction parsing is enabled.
|
|
813
|
-
* The string shorthand `'zod'` also enables response parsing.
|
|
814
|
-
*/
|
|
815
|
-
function resolveResponseParser(parser) {
|
|
816
|
-
if (!parser) return null;
|
|
817
|
-
if (parser === "zod") return "zod";
|
|
818
|
-
return parser.response ?? null;
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Returns `'zod'` when request body parsing is enabled.
|
|
822
|
-
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
823
|
-
*/
|
|
824
|
-
function resolveRequestParser(parser) {
|
|
825
|
-
if (!parser) return null;
|
|
826
|
-
if (parser === "zod") return "zod";
|
|
827
|
-
return parser.request ?? null;
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Returns `'zod'` when query-params parsing is enabled.
|
|
831
|
-
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
832
|
-
*/
|
|
833
|
-
function resolveQueryParamsParser(parser) {
|
|
834
|
-
if (!parser || parser === "zod") return null;
|
|
835
|
-
return parser.request ?? null;
|
|
836
|
-
}
|
|
837
|
-
/**
|
|
838
|
-
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
839
|
-
*
|
|
840
|
-
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
841
|
-
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
842
|
-
* - `parser: { response: 'zod' }`: response name only.
|
|
843
|
-
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
844
|
-
*
|
|
845
|
-
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
846
|
-
*/
|
|
847
|
-
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
848
|
-
if (!zodResolver || !parser) return [];
|
|
849
|
-
const { query: queryParams } = getOperationParameters(node, { paramsCasing: "original" });
|
|
850
|
-
return [
|
|
851
|
-
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
852
|
-
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
853
|
-
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
854
|
-
].filter((n) => Boolean(n));
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
801
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
858
802
|
* typed from the operation's `RequestConfig` minus `url`. The query key transformer reads the
|
|
859
803
|
* grouped `path`/`query`/`body` bindings.
|
|
@@ -1843,7 +1787,7 @@ const infiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1843
1787
|
operation(node, ctx) {
|
|
1844
1788
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
1845
1789
|
const { config, driver, resolver, root } = ctx;
|
|
1846
|
-
const { output, query, mutation, infinite,
|
|
1790
|
+
const { output, query, mutation, infinite, client, group, customOptions, hooks } = ctx.options;
|
|
1847
1791
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1848
1792
|
if (!pluginTs) return null;
|
|
1849
1793
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1893,14 +1837,6 @@ const infiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1893
1837
|
includeParams: false
|
|
1894
1838
|
})
|
|
1895
1839
|
].filter((name) => Boolean(name));
|
|
1896
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
1897
|
-
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
1898
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1899
|
-
root,
|
|
1900
|
-
output: pluginZod?.options?.output ?? output,
|
|
1901
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1902
|
-
}) : null;
|
|
1903
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1904
1840
|
const calledClientName = contractOp.name;
|
|
1905
1841
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1906
1842
|
baseName: meta.file.baseName,
|
|
@@ -1923,11 +1859,6 @@ const infiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1923
1859
|
}
|
|
1924
1860
|
}),
|
|
1925
1861
|
children: [
|
|
1926
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1927
|
-
name: zodSchemaNames,
|
|
1928
|
-
root: meta.file.path,
|
|
1929
|
-
path: fileZod.path
|
|
1930
|
-
}),
|
|
1931
1862
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1932
1863
|
name: [contractOp.name],
|
|
1933
1864
|
root: meta.file.path,
|
|
@@ -2021,7 +1952,7 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2021
1952
|
operation(node, ctx) {
|
|
2022
1953
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
2023
1954
|
const { config, driver, resolver, root } = ctx;
|
|
2024
|
-
const { output, query, mutation,
|
|
1955
|
+
const { output, query, mutation, client, group, customOptions, hooks } = ctx.options;
|
|
2025
1956
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2026
1957
|
if (!pluginTs) return null;
|
|
2027
1958
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -2057,14 +1988,6 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2057
1988
|
order: "body-response-first",
|
|
2058
1989
|
includeParams: false
|
|
2059
1990
|
})].filter((name) => Boolean(name));
|
|
2060
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
2061
|
-
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
2062
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2063
|
-
root,
|
|
2064
|
-
output: pluginZod?.options?.output ?? output,
|
|
2065
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2066
|
-
}) : null;
|
|
2067
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2068
1991
|
const calledClientName = contractOp.name;
|
|
2069
1992
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2070
1993
|
baseName: meta.file.baseName,
|
|
@@ -2087,11 +2010,6 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2087
2010
|
}
|
|
2088
2011
|
}),
|
|
2089
2012
|
children: [
|
|
2090
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2091
|
-
name: zodSchemaNames,
|
|
2092
|
-
root: meta.file.path,
|
|
2093
|
-
path: fileZod.path
|
|
2094
|
-
}),
|
|
2095
2013
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2096
2014
|
name: [contractOp.name],
|
|
2097
2015
|
root: meta.file.path,
|
|
@@ -2170,7 +2088,7 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2170
2088
|
operation(node, ctx) {
|
|
2171
2089
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
2172
2090
|
const { config, driver, resolver, root } = ctx;
|
|
2173
|
-
const { output, query, mutation,
|
|
2091
|
+
const { output, query, mutation, client, group, customOptions, hooks } = ctx.options;
|
|
2174
2092
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2175
2093
|
if (!pluginTs) return null;
|
|
2176
2094
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -2208,14 +2126,6 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2208
2126
|
order: "body-response-first",
|
|
2209
2127
|
includeParams: false
|
|
2210
2128
|
})].filter((name) => Boolean(name));
|
|
2211
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
2212
|
-
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
2213
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2214
|
-
root,
|
|
2215
|
-
output: pluginZod?.options?.output ?? output,
|
|
2216
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2217
|
-
}) : null;
|
|
2218
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2219
2129
|
const calledClientName = contractOp.name;
|
|
2220
2130
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2221
2131
|
baseName: meta.file.baseName,
|
|
@@ -2238,11 +2148,6 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2238
2148
|
}
|
|
2239
2149
|
}),
|
|
2240
2150
|
children: [
|
|
2241
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2242
|
-
name: zodSchemaNames,
|
|
2243
|
-
root: meta.file.path,
|
|
2244
|
-
path: fileZod.path
|
|
2245
|
-
}),
|
|
2246
2151
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2247
2152
|
name: [contractOp.name],
|
|
2248
2153
|
root: meta.file.path,
|
|
@@ -2316,7 +2221,7 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2316
2221
|
/**
|
|
2317
2222
|
* Built-in generator for `useSuspenseInfiniteQuery` hooks. Enabled when both
|
|
2318
2223
|
* `suspense` and `infinite` are configured. Combines suspense semantics with
|
|
2319
|
-
* cursor-based pagination
|
|
2224
|
+
* cursor-based pagination. Handlers throw promises while loading and pull
|
|
2320
2225
|
* additional pages on demand.
|
|
2321
2226
|
*/
|
|
2322
2227
|
const suspenseInfiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
@@ -2325,7 +2230,7 @@ const suspenseInfiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2325
2230
|
operation(node, ctx) {
|
|
2326
2231
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
2327
2232
|
const { config, driver, resolver, root } = ctx;
|
|
2328
|
-
const { output, query, mutation, infinite, suspense,
|
|
2233
|
+
const { output, query, mutation, infinite, suspense, client, group, customOptions, hooks } = ctx.options;
|
|
2329
2234
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2330
2235
|
if (!pluginTs) return null;
|
|
2331
2236
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -2375,14 +2280,6 @@ const suspenseInfiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2375
2280
|
includeParams: false
|
|
2376
2281
|
})
|
|
2377
2282
|
].filter((name) => Boolean(name));
|
|
2378
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
2379
|
-
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
2380
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2381
|
-
root,
|
|
2382
|
-
output: pluginZod?.options?.output ?? output,
|
|
2383
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2384
|
-
}) : null;
|
|
2385
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2386
2283
|
const calledClientName = contractOp.name;
|
|
2387
2284
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2388
2285
|
baseName: meta.file.baseName,
|
|
@@ -2405,11 +2302,6 @@ const suspenseInfiniteQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2405
2302
|
}
|
|
2406
2303
|
}),
|
|
2407
2304
|
children: [
|
|
2408
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2409
|
-
name: zodSchemaNames,
|
|
2410
|
-
root: meta.file.path,
|
|
2411
|
-
path: fileZod.path
|
|
2412
|
-
}),
|
|
2413
2305
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2414
2306
|
name: [contractOp.name],
|
|
2415
2307
|
root: meta.file.path,
|
|
@@ -2504,7 +2396,7 @@ const suspenseQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2504
2396
|
operation(node, ctx) {
|
|
2505
2397
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
2506
2398
|
const { config, driver, resolver, root } = ctx;
|
|
2507
|
-
const { output, query, mutation, suspense,
|
|
2399
|
+
const { output, query, mutation, suspense, client, group, customOptions, hooks } = ctx.options;
|
|
2508
2400
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2509
2401
|
if (!pluginTs) return null;
|
|
2510
2402
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -2542,14 +2434,6 @@ const suspenseQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2542
2434
|
order: "body-response-first",
|
|
2543
2435
|
includeParams: false
|
|
2544
2436
|
})].filter((name) => Boolean(name));
|
|
2545
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
|
|
2546
|
-
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
|
|
2547
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2548
|
-
root,
|
|
2549
|
-
output: pluginZod?.options?.output ?? output,
|
|
2550
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2551
|
-
}) : null;
|
|
2552
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2553
2437
|
const calledClientName = contractOp.name;
|
|
2554
2438
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2555
2439
|
baseName: meta.file.baseName,
|
|
@@ -2572,11 +2456,6 @@ const suspenseQueryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
2572
2456
|
}
|
|
2573
2457
|
}),
|
|
2574
2458
|
children: [
|
|
2575
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2576
|
-
name: zodSchemaNames,
|
|
2577
|
-
root: meta.file.path,
|
|
2578
|
-
path: fileZod.path
|
|
2579
|
-
}),
|
|
2580
2459
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2581
2460
|
name: [contractOp.name],
|
|
2582
2461
|
root: meta.file.path,
|
|
@@ -2769,8 +2648,8 @@ const resolverReactQuery = (0, _kubb_core.defineResolver)(() => ({
|
|
|
2769
2648
|
const pluginReactQueryName = "plugin-react-query";
|
|
2770
2649
|
/**
|
|
2771
2650
|
* Generates one TanStack Query hook per OpenAPI operation for React. Queries
|
|
2772
|
-
* become `
|
|
2773
|
-
* become `
|
|
2651
|
+
* become `useFoo`, with `useFooSuspense` and `useFooInfinite` variants.
|
|
2652
|
+
* Mutations become `useFoo`. Each hook is fully typed: query keys, input
|
|
2774
2653
|
* variables, response data, and error shape all come from the spec.
|
|
2775
2654
|
*
|
|
2776
2655
|
* @example
|
|
@@ -2796,7 +2675,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2796
2675
|
const { output = {
|
|
2797
2676
|
path: "hooks",
|
|
2798
2677
|
barrel: { type: "named" }
|
|
2799
|
-
}, group, exclude = [], include, override = [],
|
|
2678
|
+
}, group, exclude = [], include, override = [], suspense = {}, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
2800
2679
|
const selectedGenerators = [
|
|
2801
2680
|
queryGenerator,
|
|
2802
2681
|
suspenseQueryGenerator,
|
|
@@ -2810,7 +2689,7 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2810
2689
|
return {
|
|
2811
2690
|
name: pluginReactQueryName,
|
|
2812
2691
|
options,
|
|
2813
|
-
dependencies: [_kubb_plugin_ts.pluginTsName
|
|
2692
|
+
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
2814
2693
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
2815
2694
|
const resolver = userResolver ? {
|
|
2816
2695
|
...resolverReactQuery,
|
|
@@ -2859,7 +2738,6 @@ const pluginReactQuery = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2859
2738
|
...customOptions
|
|
2860
2739
|
} : null,
|
|
2861
2740
|
hooks,
|
|
2862
|
-
validator,
|
|
2863
2741
|
group: groupConfig,
|
|
2864
2742
|
exclude,
|
|
2865
2743
|
include,
|