@kubb/plugin-react-query 5.8.0-canary.20261027T202821 → 5.8.0-canary.20261029T082701

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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
2
  import "@kubb/plugin-zod";
3
- import "@kubb/plugin-ts";
3
+ import { ResolverTs } from "@kubb/plugin-ts";
4
4
  import "kubb/jsx";
5
5
  /**
6
6
  * The client selector accepted by a consumer's `client` option. Each calls a registered contract
@@ -16,6 +16,51 @@ type ResolvedContractClient = {
16
16
  kind: 'contract';
17
17
  pluginName: string;
18
18
  };
19
+ /**
20
+ * The two per-operation type names a generated client references: the grouped input and the
21
+ * per-status responses record its `RequestResult` is keyed on.
22
+ */
23
+ type OperationTypeNames = {
24
+ response: {
25
+ /**
26
+ * Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.
27
+ */
28
+ options(node: ast.OperationNode): string;
29
+ /**
30
+ * Resolves the name of the operation's per-status responses record type.
31
+ */
32
+ responses(node: ast.OperationNode): string;
33
+ };
34
+ };
35
+ /**
36
+ * Where a generated client sources its operation types, plus the resolver and output the file
37
+ * declaring them is resolved with.
38
+ */
39
+ type OperationTypeSource = OperationTypeNames & {
40
+ /**
41
+ * `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.
42
+ */
43
+ resolver: ResolverTs;
44
+ /**
45
+ * The supplying plugin's own `output`, when it configured one.
46
+ */
47
+ output: Output | undefined;
48
+ /**
49
+ * The supplying plugin's own `group`, when it configured one.
50
+ */
51
+ group: Group | undefined;
52
+ };
53
+ declare global {
54
+ namespace Kubb {
55
+ interface MemoRegistry {
56
+ operationTypes: OperationTypeSource;
57
+ /**
58
+ * Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.
59
+ */
60
+ zodTypes: unknown;
61
+ }
62
+ }
63
+ }
19
64
  type ParamsCasing = 'camelcase' | undefined;
20
65
  /**
21
66
  * The hook a key is built for. Plain and suspense queries can share a key, but an infinite query
@@ -156,6 +201,10 @@ export declare const mutationKeyTransformer: Transformer;
156
201
  * ```
157
202
  */
158
203
  export declare const queryKeyTransformer: Transformer;
204
+ type ResponseTypes = {
205
+ TData: string;
206
+ TError: string;
207
+ };
159
208
  /**
160
209
  * Helper to define a typed page param function for `infinite.getNextPageParam` or
161
210
  * `infinite.getPreviousPageParam`. Serializes the function to a string for inlining in generated code.
@@ -165,6 +214,13 @@ export declare const queryKeyTransformer: Transformer;
165
214
  * the config file.
166
215
  */
167
216
  export declare function definePageParam<TPage = any, TParam = any>(fn: PageParamFn<TPage, TParam>): string;
217
+ declare global {
218
+ namespace Kubb {
219
+ interface MemoRegistry {
220
+ responseTypes: ResponseTypes;
221
+ }
222
+ }
223
+ }
168
224
  /**
169
225
  * The concrete resolver type for `@kubb/plugin-react-query`.
170
226
  * Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
2
  import "@kubb/plugin-zod";
3
- import "@kubb/plugin-ts";
3
+ import { ResolverTs } from "@kubb/plugin-ts";
4
4
  import "kubb/jsx";
5
5
  /**
6
6
  * The client selector accepted by a consumer's `client` option. Each calls a registered contract
@@ -16,6 +16,51 @@ type ResolvedContractClient = {
16
16
  kind: 'contract';
17
17
  pluginName: string;
18
18
  };
19
+ /**
20
+ * The two per-operation type names a generated client references: the grouped input and the
21
+ * per-status responses record its `RequestResult` is keyed on.
22
+ */
23
+ type OperationTypeNames = {
24
+ response: {
25
+ /**
26
+ * Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.
27
+ */
28
+ options(node: ast.OperationNode): string;
29
+ /**
30
+ * Resolves the name of the operation's per-status responses record type.
31
+ */
32
+ responses(node: ast.OperationNode): string;
33
+ };
34
+ };
35
+ /**
36
+ * Where a generated client sources its operation types, plus the resolver and output the file
37
+ * declaring them is resolved with.
38
+ */
39
+ type OperationTypeSource = OperationTypeNames & {
40
+ /**
41
+ * `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.
42
+ */
43
+ resolver: ResolverTs;
44
+ /**
45
+ * The supplying plugin's own `output`, when it configured one.
46
+ */
47
+ output: Output | undefined;
48
+ /**
49
+ * The supplying plugin's own `group`, when it configured one.
50
+ */
51
+ group: Group | undefined;
52
+ };
53
+ declare global {
54
+ namespace Kubb {
55
+ interface MemoRegistry {
56
+ operationTypes: OperationTypeSource;
57
+ /**
58
+ * Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.
59
+ */
60
+ zodTypes: unknown;
61
+ }
62
+ }
63
+ }
19
64
  type ParamsCasing = 'camelcase' | undefined;
20
65
  /**
21
66
  * The hook a key is built for. Plain and suspense queries can share a key, but an infinite query
@@ -156,6 +201,10 @@ export declare const mutationKeyTransformer: Transformer;
156
201
  * ```
157
202
  */
158
203
  export declare const queryKeyTransformer: Transformer;
204
+ type ResponseTypes = {
205
+ TData: string;
206
+ TError: string;
207
+ };
159
208
  /**
160
209
  * Helper to define a typed page param function for `infinite.getNextPageParam` or
161
210
  * `infinite.getPreviousPageParam`. Serializes the function to a string for inlining in generated code.
@@ -165,6 +214,13 @@ export declare const queryKeyTransformer: Transformer;
165
214
  * the config file.
166
215
  */
167
216
  export declare function definePageParam<TPage = any, TParam = any>(fn: PageParamFn<TPage, TParam>): string;
217
+ declare global {
218
+ namespace Kubb {
219
+ interface MemoRegistry {
220
+ responseTypes: ResponseTypes;
221
+ }
222
+ }
223
+ }
168
224
  /**
169
225
  * The concrete resolver type for `@kubb/plugin-react-query`.
170
226
  * Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
1
+ import { Diagnostics, Resolver, Url, addGenerator, ast, camelCase, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
2
2
  import path from "node:path";
3
3
  import { pluginZodName } from "@kubb/plugin-zod";
4
4
  import { File, Function, Type, jsxRenderer } from "kubb/jsx";
@@ -229,86 +229,37 @@ function resolveSuccessNames(node, resolver) {
229
229
  function resolveStatusCodeNames(node, resolver) {
230
230
  return node.responses.map((response) => resolver.response.status(node, response.statusCode));
231
231
  }
232
- const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
233
- function resolveOperationTypeNames(node, resolver, options = {}) {
234
- const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
235
- let byResolver = typeNamesByResolver.get(resolver);
236
- if (byResolver) {
237
- const cached = byResolver.get(cacheKey);
238
- if (cached) return cached;
239
- } else {
240
- byResolver = /* @__PURE__ */ new Map();
241
- typeNamesByResolver.set(resolver, byResolver);
242
- }
243
- const { path, query, header } = getOperationParameters(node);
244
- const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
245
- const exclude = new Set(options.exclude ?? []);
246
- const paramNames = options.includeParams === false ? [] : [
247
- ...path.map((param) => resolver.param.path(node, param)),
248
- ...query.map((param) => resolver.param.query(node, param)),
249
- ...header.map((param) => resolver.param.headers(node, param))
250
- ];
251
- const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
252
- const result = (options.order === "body-response-first" ? [
253
- ...bodyAndResponseNames,
254
- ...paramNames,
255
- ...responseStatusNames
256
- ] : [
257
- ...paramNames,
258
- ...bodyAndResponseNames,
259
- ...responseStatusNames
260
- ]).filter((name) => Boolean(name) && !exclude.has(name));
261
- byResolver.set(cacheKey, result);
262
- return result;
263
- }
264
- // ../../internals/utils/src/casing.ts
265
- const wordStart = /(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z]{2})(?=[A-Z][a-z]{2})/;
266
232
  /**
267
- * Splits `text` into words on separators (whitespace, hyphens, underscores, dots, slashes, colons)
268
- * and on {@link wordStart}. A segment without lowercase letters, such as `COOL` or `2D`, is one word,
269
- * so snake case leaves a name that is already in it unchanged.
233
+ * Lists the type names an operation's types file declares, computed once per resolver and `options` so every
234
+ * dependent reads the same list.
270
235
  */
271
- function words(text) {
272
- return text.split(/[\s\-_./\\:]+/).filter(Boolean).flatMap((segment) => segment === segment.toUpperCase() ? segment : segment.split(wordStart));
273
- }
274
- /**
275
- * Shared implementation for camelCase and PascalCase conversion.
276
- * Capitalizes each word from {@link words} according to `pascal`.
277
- *
278
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
279
- */
280
- function convert(text, pascal) {
281
- return words(text).flatMap((word) => word.split(/(?<=\d)(?=[a-z])|(?<=[A-Z])(?=[A-Z][a-z])/)).map((word, i) => {
282
- if (word.length > 1 && word === word.toUpperCase()) return word;
283
- return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
284
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
285
- }
286
- const cache = /* @__PURE__ */ new Map();
287
- const cacheLimit = 1e4;
288
- function toCamelOrPascal(text, pascal) {
289
- const key = `${pascal ? "P" : "c"}${text}`;
290
- const cached = cache.get(key);
291
- if (cached !== void 0) return cached;
292
- const result = convert(text, pascal);
293
- if (cache.size >= cacheLimit) cache.clear();
294
- cache.set(key, result);
295
- return result;
296
- }
297
- /**
298
- * Converts `text` to camelCase.
299
- *
300
- * @example Word boundaries
301
- * `camelCase('hello-world') // 'helloWorld'`
302
- *
303
- * @example With a prefix
304
- * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
305
- */
306
- function camelCase(text, { prefix = "", suffix = "" } = {}) {
307
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
236
+ function resolveOperationTypeNames(node, resolver, options = {}) {
237
+ const key = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
238
+ return resolver.memo(`operationTypeNames:${key}`, () => {
239
+ const { path, query, header } = getOperationParameters(node);
240
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
241
+ const exclude = new Set(options.exclude ?? []);
242
+ const paramNames = options.includeParams === false ? [] : [
243
+ ...path.map((param) => resolver.param.path(node, param)),
244
+ ...query.map((param) => resolver.param.query(node, param)),
245
+ ...header.map((param) => resolver.param.headers(node, param))
246
+ ];
247
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
248
+ return (options.order === "body-response-first" ? [
249
+ ...bodyAndResponseNames,
250
+ ...paramNames,
251
+ ...responseStatusNames
252
+ ] : [
253
+ ...paramNames,
254
+ ...bodyAndResponseNames,
255
+ ...responseStatusNames
256
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
257
+ });
308
258
  }
259
+ // ../../internals/utils/src/casing.ts
309
260
  /**
310
261
  * Uppercases only the first character of `text`, leaving the rest untouched.
311
- * Unlike {@link pascalCase} it never re-splits word boundaries or strips characters.
262
+ * Unlike `pascalCase` it never re-splits word boundaries or strips characters.
312
263
  *
313
264
  * @example
314
265
  * `capitalize('getPetById') // 'GetPetById'`
@@ -472,8 +423,11 @@ function getNestedAccessor(param, accessor) {
472
423
  return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
473
424
  }
474
425
  // ../../internals/shared/src/resolver.ts
426
+ /**
427
+ * The shared top-level `name` of the operation plugins, computed once per operation name and build.
428
+ */
475
429
  function resolveOperationName(name) {
476
- return ensureValidVarName(camelCase(name));
430
+ return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)));
477
431
  }
478
432
  /**
479
433
  * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
@@ -529,7 +483,7 @@ var compatibility = {
529
483
  "node": ">=22.22"
530
484
  };
531
485
  // package.json
532
- var version = "5.8.0-canary.20261027T202821";
486
+ var version = "5.8.0-canary.20261029T082701";
533
487
  // ../../internals/client/src/resolveOperationTypes.ts
534
488
  /**
535
489
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
@@ -540,6 +494,7 @@ function toZodTypeResolver(resolver) {
540
494
  return {
541
495
  ...resolver,
542
496
  file: resolver.file.bind(resolver),
497
+ memo: (key, compute) => resolver.memo(`zodTypes:${key}`, compute),
543
498
  param: {
544
499
  name: (node, p) => type(resolver.param.name(node, p)),
545
500
  path: (node, p) => type(resolver.param.path(node, p)),
@@ -569,32 +524,34 @@ function toZodTypeResolver(resolver) {
569
524
  * ```
570
525
  */
571
526
  function resolveOperationTypes(driver, pluginName) {
572
- const pluginTs = driver.getPlugin(pluginTsName);
573
- const pluginZod = driver.getPlugin(pluginZodName);
574
- if (pluginTs && pluginZod?.options?.inferred !== "codec") {
575
- const resolver = driver.getResolver(pluginTsName);
527
+ return driver.memo(`operationTypes:${pluginName}`, () => {
528
+ const pluginTs = driver.getPlugin(pluginTsName);
529
+ const pluginZod = driver.getPlugin(pluginZodName);
530
+ if (pluginTs && pluginZod?.options?.inferred !== "codec") {
531
+ const resolver = driver.getResolver(pluginTsName);
532
+ return {
533
+ response: resolver.response,
534
+ resolver,
535
+ output: pluginTs.options?.output,
536
+ group: pluginTs.options?.group ?? void 0
537
+ };
538
+ }
539
+ if (!pluginZod?.options?.inferred) throw new Diagnostics.Error({
540
+ code: Diagnostics.code.missingDependency,
541
+ severity: "error",
542
+ message: `Plugin "${pluginName}" has no source for operation types.`,
543
+ help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
544
+ location: { kind: "config" },
545
+ plugin: pluginName
546
+ });
547
+ const resolver = toZodTypeResolver(driver.getResolver(pluginZodName));
576
548
  return {
577
549
  response: resolver.response,
578
550
  resolver,
579
- output: pluginTs.options?.output,
580
- group: pluginTs.options?.group ?? void 0
551
+ output: pluginZod.options.output,
552
+ group: pluginZod.options.group ?? void 0
581
553
  };
582
- }
583
- if (!pluginZod?.options?.inferred) throw new Diagnostics.Error({
584
- code: Diagnostics.code.missingDependency,
585
- severity: "error",
586
- message: `Plugin "${pluginName}" has no source for operation types.`,
587
- help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
588
- location: { kind: "config" },
589
- plugin: pluginName
590
554
  });
591
- const resolver = toZodTypeResolver(driver.getResolver(pluginZodName));
592
- return {
593
- response: resolver.response,
594
- resolver,
595
- output: pluginZod.options.output,
596
- group: pluginZod.options.group ?? void 0
597
- };
598
555
  }
599
556
  // ../../internals/client/src/resolveClient.ts
600
557
  /**
@@ -995,13 +952,15 @@ function buildCallResultBody(call, options = {}) {
995
952
  * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
996
953
  */
997
954
  function buildResponseTypes(node, resolver) {
998
- const successNames = resolveSuccessNames(node, resolver);
999
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1000
- const errorNames = resolveErrorNames(node, resolver);
1001
- return {
1002
- TData: responseName,
1003
- TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
1004
- };
955
+ return resolver.memo(`responseTypes:${node.method}\0${node.path}`, () => {
956
+ const successNames = resolveSuccessNames(node, resolver);
957
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
958
+ const errorNames = resolveErrorNames(node, resolver);
959
+ return {
960
+ TData: responseName,
961
+ TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
962
+ };
963
+ });
1005
964
  }
1006
965
  function resolveFallbackPageParamType(initialPageParam) {
1007
966
  if (typeof initialPageParam === "number") return "number";