@kubb/plugin-react-query 5.8.0-canary.20261027T072349 → 5.8.0-canary.20261027T172409

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
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- //#region \0rolldown/runtime.js
5
+ // \0rolldown/runtime.js
6
6
  var __create = Object.create;
7
7
  var __defProp = Object.defineProperty;
8
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  value: mod,
24
24
  enumerable: true
25
25
  }) : target, mod));
26
- //#endregion
27
26
  let kubb_kit = require("kubb/kit");
28
27
  let node_path = require("node:path");
29
28
  node_path = __toESM(node_path, 1);
@@ -33,7 +32,7 @@ let _kubb_plugin_ts = require("@kubb/plugin-ts");
33
32
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
34
33
  let node_fs = require("node:fs");
35
34
  node_fs = __toESM(node_fs, 1);
36
- //#region ../../internals/shared/src/operation.ts
35
+ // ../../internals/shared/src/operation.ts
37
36
  /**
38
37
  * Builds the `ResolverFileParams` every operation generator passes to
39
38
  * `resolver.file`: a file named `name`, tagged by the operation's first
@@ -289,8 +288,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
289
288
  byResolver.set(cacheKey, result);
290
289
  return result;
291
290
  }
292
- //#endregion
293
- //#region ../../internals/utils/src/casing.ts
291
+ // ../../internals/utils/src/casing.ts
294
292
  /**
295
293
  * Shared implementation for camelCase and PascalCase conversion.
296
294
  * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
@@ -337,8 +335,7 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
337
335
  function capitalize(text) {
338
336
  return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
339
337
  }
340
- //#endregion
341
- //#region ../../internals/utils/src/reserved.ts
338
+ // ../../internals/utils/src/reserved.ts
342
339
  /**
343
340
  * JavaScript and Java reserved words.
344
341
  * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
@@ -477,8 +474,7 @@ function ensureValidVarName(name) {
477
474
  function isIdentifier(name) {
478
475
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
479
476
  }
480
- //#endregion
481
- //#region ../../internals/utils/src/strings.ts
477
+ // ../../internals/utils/src/strings.ts
482
478
  /**
483
479
  * Renders a dotted path or string array as an optional-chaining accessor expression rooted at
484
480
  * `accessor`. Returns `null` for an empty path.
@@ -494,13 +490,29 @@ function getNestedAccessor(param, accessor) {
494
490
  if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
495
491
  return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
496
492
  }
497
- //#endregion
498
- //#region ../../internals/shared/src/resolver.ts
493
+ // ../../internals/shared/src/resolver.ts
499
494
  function resolveOperationName(name) {
500
495
  return ensureValidVarName(camelCase(name));
501
496
  }
502
- //#endregion
503
- //#region ../../internals/shared/src/group.ts
497
+ /**
498
+ * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
499
+ * it is, so two of them never share an allocation even when a custom resolver gives both the same
500
+ * name. Leave `scope` empty for the operation's own declaration.
501
+ *
502
+ * @example
503
+ * ```ts
504
+ * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
505
+ * ```
506
+ */
507
+ function operationKey(node, ...scope) {
508
+ return [
509
+ "operation",
510
+ node.method,
511
+ node.path,
512
+ ...scope.map(String)
513
+ ];
514
+ }
515
+ // ../../internals/shared/src/group.ts
504
516
  /**
505
517
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
506
518
  * shared default naming so every plugin groups output consistently:
@@ -530,17 +542,14 @@ function createGroupConfig(group) {
530
542
  name: group.name ? group.name : defaultName
531
543
  };
532
544
  }
533
- //#endregion
534
- //#region kubb-extension.json
545
+ // kubb-extension.json
535
546
  var compatibility = {
536
- "kubb": ">=5.8.3",
547
+ "kubb": ">=5.14.6",
537
548
  "node": ">=22.22"
538
549
  };
539
- //#endregion
540
- //#region package.json
541
- var version = "5.8.0-canary.20261027T072349";
542
- //#endregion
543
- //#region ../../internals/client/src/resolveOperationTypes.ts
550
+ // package.json
551
+ var version = "5.8.0-canary.20261027T172409";
552
+ // ../../internals/client/src/resolveOperationTypes.ts
544
553
  /**
545
554
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
546
555
  * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
@@ -606,8 +615,7 @@ function resolveOperationTypes(driver, pluginName) {
606
615
  group: pluginZod.options.group ?? void 0
607
616
  };
608
617
  }
609
- //#endregion
610
- //#region ../../internals/client/src/resolveClient.ts
618
+ // ../../internals/client/src/resolveClient.ts
611
619
  /**
612
620
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
613
621
  * operation, shared so the selection rules and diagnostics stay in one place.
@@ -717,8 +725,7 @@ function resolveContractClient(options) {
717
725
  }
718
726
  return resolved;
719
727
  }
720
- //#endregion
721
- //#region ../../internals/client/src/resolveClientOperation.ts
728
+ // ../../internals/client/src/resolveClientOperation.ts
722
729
  function isRelativeImport(importPath) {
723
730
  return importPath.startsWith(".");
724
731
  }
@@ -765,8 +772,12 @@ function resolveClientOperation(options) {
765
772
  group: operationOptions.group ?? void 0
766
773
  });
767
774
  const { importPath } = operationOptions;
775
+ const name = resolver.name(node.operationId);
768
776
  return {
769
- name: resolver.name(node.operationId),
777
+ name: resolver.resolveName({
778
+ key: operationKey(node),
779
+ name
780
+ }),
770
781
  path: file.path,
771
782
  clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
772
783
  importPath,
@@ -777,8 +788,7 @@ function resolveClientOperation(options) {
777
788
  };
778
789
  });
779
790
  }
780
- //#endregion
781
- //#region ../../internals/tanstack-query/src/components/HookFile.tsx
791
+ // ../../internals/tanstack-query/src/components/HookFile.tsx
782
792
  /**
783
793
  * Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
784
794
  * `pluginZod({ inferred: 'codec' })`), banner and footer.
@@ -867,8 +877,7 @@ function HookFile({ hook, imports, children }) {
867
877
  ]
868
878
  });
869
879
  }
870
- //#endregion
871
- //#region ../../internals/tanstack-query/src/utils.ts
880
+ // ../../internals/tanstack-query/src/utils.ts
872
881
  /**
873
882
  * The grouped request options, ordered for both the destructured signature and the
874
883
  * call passed to the underlying client.
@@ -1234,8 +1243,7 @@ function buildResolvedRequestParams(node) {
1234
1243
  if (names.length === 0) return null;
1235
1244
  return `{ ${names.map((name) => `${name}: typeof ${name} === 'function' ? ${name}() : ${name}`).join(", ")} }`;
1236
1245
  }
1237
- //#endregion
1238
- //#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
1246
+ // ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
1239
1247
  const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1240
1248
  const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1241
1249
  function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
@@ -1311,8 +1319,7 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
1311
1319
  })
1312
1320
  });
1313
1321
  }
1314
- //#endregion
1315
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
1322
+ // ../../internals/tanstack-query/src/components/MutationKey.tsx
1316
1323
  const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1317
1324
  /**
1318
1325
  * Default `mutationKey` builder. Call it from a custom builder to extend the default key.
@@ -1359,8 +1366,7 @@ function MutationKey({ name, node, transformer, typeName }) {
1359
1366
  })
1360
1367
  })] });
1361
1368
  }
1362
- //#endregion
1363
- //#region ../../internals/tanstack-query/src/resolver.ts
1369
+ // ../../internals/tanstack-query/src/resolver.ts
1364
1370
  /**
1365
1371
  * Builds the shared query namespace for a variant. Spread the result into
1366
1372
  * `createResolver` once per variant the plugin supports.
@@ -1376,19 +1382,39 @@ function MutationKey({ name, node, transformer, typeName }) {
1376
1382
  function createQueryResolver(variant = "") {
1377
1383
  return {
1378
1384
  name(node) {
1379
- return `use${capitalize(this.name(node.operationId))}${variant}`;
1385
+ const name = `use${capitalize(this.name(node.operationId))}${variant}`;
1386
+ return this.resolveName({
1387
+ key: operationKey(node, "query", variant, "name"),
1388
+ name
1389
+ });
1380
1390
  },
1381
1391
  optionsName(node) {
1382
- return `${this.name(node.operationId)}${variant}QueryOptions`;
1392
+ const name = `${this.name(node.operationId)}${variant}QueryOptions`;
1393
+ return this.resolveName({
1394
+ key: operationKey(node, "query", variant, "optionsName"),
1395
+ name
1396
+ });
1383
1397
  },
1384
1398
  keyName(node) {
1385
- return `${this.name(node.operationId)}${variant}QueryKey`;
1399
+ const name = `${this.name(node.operationId)}${variant}QueryKey`;
1400
+ return this.resolveName({
1401
+ key: operationKey(node, "query", variant, "keyName"),
1402
+ name
1403
+ });
1386
1404
  },
1387
1405
  keyTypeName(node) {
1388
- return `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1406
+ const name = `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1407
+ return this.resolveName({
1408
+ key: operationKey(node, "query", variant, "keyTypeName"),
1409
+ name
1410
+ });
1389
1411
  },
1390
1412
  clientName(node) {
1391
- return `${this.name(node.operationId)}${variant}`;
1413
+ const name = `${this.name(node.operationId)}${variant}`;
1414
+ return this.resolveName({
1415
+ key: operationKey(node, "query", variant, "clientName"),
1416
+ name
1417
+ });
1392
1418
  }
1393
1419
  };
1394
1420
  }
@@ -1405,15 +1431,22 @@ function createQueryResolver(variant = "") {
1405
1431
  function createMutationResolver() {
1406
1432
  return {
1407
1433
  name(node) {
1408
- return `use${capitalize(this.name(node.operationId))}`;
1434
+ const name = `use${capitalize(this.name(node.operationId))}`;
1435
+ return this.resolveName({
1436
+ key: operationKey(node, "mutation", "name"),
1437
+ name
1438
+ });
1409
1439
  },
1410
1440
  keyName(node) {
1411
- return `${this.name(node.operationId)}MutationKey`;
1441
+ const name = `${this.name(node.operationId)}MutationKey`;
1442
+ return this.resolveName({
1443
+ key: operationKey(node, "mutation", "keyName"),
1444
+ name
1445
+ });
1412
1446
  }
1413
1447
  };
1414
1448
  }
1415
- //#endregion
1416
- //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
1449
+ // ../../internals/tanstack-query/src/components/QueryKey.tsx
1417
1450
  const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1418
1451
  /**
1419
1452
  * Default `queryKey` builder. Call it from a custom builder to extend the default key.
@@ -1471,8 +1504,7 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
1471
1504
  })
1472
1505
  })] });
1473
1506
  }
1474
- //#endregion
1475
- //#region src/generators/customHookOptionsFileGenerator.tsx
1507
+ // src/generators/customHookOptionsFileGenerator.tsx
1476
1508
  /**
1477
1509
  * Scaffolds the user-editable `useCustomHookOptions` file when
1478
1510
  * `pluginReactQuery({ customOptions: { ... }, hooks: true })` is configured. The file is
@@ -1569,8 +1601,7 @@ const customHookOptionsFileGenerator = (0, kubb_kit.defineGenerator)({
1569
1601
  });
1570
1602
  }
1571
1603
  });
1572
- //#endregion
1573
- //#region src/generators/hookOptionsGenerator.tsx
1604
+ // src/generators/hookOptionsGenerator.tsx
1574
1605
  /**
1575
1606
  * Emits the `HookOptions` type used by `customOptions`. Enabled when
1576
1607
  * `pluginReactQuery({ customOptions: { ... } })`. The generated type lists
@@ -1729,8 +1760,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
1729
1760
  });
1730
1761
  }
1731
1762
  });
1732
- //#endregion
1733
- //#region src/components/Query.tsx
1763
+ // src/components/Query.tsx
1734
1764
  const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1735
1765
  const OBSERVER_OPTIONS_NAMES = {
1736
1766
  infinite: {
@@ -1840,8 +1870,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1840
1870
  })
1841
1871
  });
1842
1872
  }
1843
- //#endregion
1844
- //#region src/components/QueryOptions.tsx
1873
+ // src/components/QueryOptions.tsx
1845
1874
  const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1846
1875
  const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1847
1876
  function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
@@ -1874,8 +1903,7 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
1874
1903
  })
1875
1904
  });
1876
1905
  }
1877
- //#endregion
1878
- //#region src/generators/createQueryGenerator.tsx
1906
+ // src/generators/createQueryGenerator.tsx
1879
1907
  const OBSERVER_IMPORTS = {
1880
1908
  query: ["QueryObserverOptions", "UseQueryResult"],
1881
1909
  suspenseQuery: ["UseSuspenseQueryOptions", "UseSuspenseQueryResult"],
@@ -2034,8 +2062,7 @@ function createQueryGenerator({ name, variant }) {
2034
2062
  }
2035
2063
  });
2036
2064
  }
2037
- //#endregion
2038
- //#region src/generators/infiniteQueryGenerator.tsx
2065
+ // src/generators/infiniteQueryGenerator.tsx
2039
2066
  /**
2040
2067
  * Built-in generator for `useInfiniteQuery` hooks. Enabled when
2041
2068
  * `pluginReactQuery({ infinite: { ... }, hooks: true })`. Emits one
@@ -2047,8 +2074,7 @@ const infiniteQueryGenerator = createQueryGenerator({
2047
2074
  name: "react-infinite-query",
2048
2075
  variant: "infiniteQuery"
2049
2076
  });
2050
- //#endregion
2051
- //#region src/components/MutationOptions.tsx
2077
+ // src/components/MutationOptions.tsx
2052
2078
  const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
2053
2079
  const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
2054
2080
  function buildMutationConfigParamsNode(node) {
@@ -2097,8 +2123,7 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
2097
2123
  })
2098
2124
  });
2099
2125
  }
2100
- //#endregion
2101
- //#region src/components/Mutation.tsx
2126
+ // src/components/Mutation.tsx
2102
2127
  const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
2103
2128
  const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
2104
2129
  function buildMutationParamsNode(node, options) {
@@ -2157,8 +2182,7 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
2157
2182
  })
2158
2183
  });
2159
2184
  }
2160
- //#endregion
2161
- //#region src/generators/mutationGenerator.tsx
2185
+ // src/generators/mutationGenerator.tsx
2162
2186
  /**
2163
2187
  * Built-in generator for `useMutation` hooks. Emits one `useFooMutation` hook
2164
2188
  * per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
@@ -2251,8 +2275,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
2251
2275
  });
2252
2276
  }
2253
2277
  });
2254
- //#endregion
2255
- //#region src/generators/queryGenerator.tsx
2278
+ // src/generators/queryGenerator.tsx
2256
2279
  /**
2257
2280
  * Built-in generator for `useQuery` hooks. Emits one `useFooQuery` hook per
2258
2281
  * GET and QUERY operation (configurable via `query.methods`) plus the matching
@@ -2262,8 +2285,7 @@ const queryGenerator = createQueryGenerator({
2262
2285
  name: "react-query",
2263
2286
  variant: "query"
2264
2287
  });
2265
- //#endregion
2266
- //#region src/generators/suspenseInfiniteQueryGenerator.tsx
2288
+ // src/generators/suspenseInfiniteQueryGenerator.tsx
2267
2289
  /**
2268
2290
  * Built-in generator for `useSuspenseInfiniteQuery` hooks. Enabled when
2269
2291
  * `suspense`, `infinite`, and `hooks` are all configured. Combines suspense
@@ -2274,8 +2296,7 @@ const suspenseInfiniteQueryGenerator = createQueryGenerator({
2274
2296
  name: "react-suspense-infinite-query",
2275
2297
  variant: "suspenseInfiniteQuery"
2276
2298
  });
2277
- //#endregion
2278
- //#region src/generators/suspenseQueryGenerator.tsx
2299
+ // src/generators/suspenseQueryGenerator.tsx
2279
2300
  /**
2280
2301
  * Built-in generator for `useSuspenseQuery` hooks. Enabled when
2281
2302
  * `pluginReactQuery({ suspense: {}, hooks: true })`. Emits one
@@ -2287,8 +2308,7 @@ const suspenseQueryGenerator = createQueryGenerator({
2287
2308
  name: "react-suspense-query",
2288
2309
  variant: "suspenseQuery"
2289
2310
  });
2290
- //#endregion
2291
- //#region src/resolvers/resolverReactQuery.ts
2311
+ // src/resolvers/resolverReactQuery.ts
2292
2312
  /**
2293
2313
  * Default resolver used by `@kubb/plugin-react-query`. Decides the names and
2294
2314
  * file paths for every generated TanStack Query hook (`useFoo`,
@@ -2318,23 +2338,36 @@ const resolverReactQuery = (0, kubb_kit.createResolver)({
2318
2338
  mutation: {
2319
2339
  ...createMutationResolver(),
2320
2340
  optionsName(node) {
2321
- return `${this.name(node.operationId)}MutationOptions`;
2341
+ const name = `${this.name(node.operationId)}MutationOptions`;
2342
+ return this.resolveName({
2343
+ key: operationKey(node, "mutation", "optionsName"),
2344
+ name
2345
+ });
2322
2346
  },
2323
2347
  typeName(node) {
2324
- return capitalize(this.name(node.operationId));
2348
+ const name = capitalize(this.name(node.operationId));
2349
+ return this.resolveName({
2350
+ key: operationKey(node, "mutation", "typeName"),
2351
+ name
2352
+ });
2325
2353
  }
2326
2354
  },
2327
2355
  hook: {
2328
2356
  optionsName() {
2329
- return "HookOptions";
2357
+ return this.resolveName({
2358
+ key: ["hook", "options"],
2359
+ name: "HookOptions"
2360
+ });
2330
2361
  },
2331
2362
  customOptionsName() {
2332
- return "getCustomHookOptions";
2363
+ return this.resolveName({
2364
+ key: ["hook", "custom-options"],
2365
+ name: "getCustomHookOptions"
2366
+ });
2333
2367
  }
2334
2368
  }
2335
2369
  });
2336
- //#endregion
2337
- //#region src/plugin.ts
2370
+ // src/plugin.ts
2338
2371
  /**
2339
2372
  * Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups
2340
2373
  * and cross-plugin dependency references.
@@ -2408,7 +2441,6 @@ const pluginReactQuery = (0, kubb_kit.defineExtension)({
2408
2441
  };
2409
2442
  }
2410
2443
  });
2411
- //#endregion
2412
2444
  exports.default = pluginReactQuery;
2413
2445
  exports.definePageParam = definePageParam;
2414
2446
  exports.mutationKeyTransformer = mutationKeyTransformer;