@kubb/plugin-react-query 5.0.0-beta.64 → 5.0.0-beta.74

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.
@@ -1,1583 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", {
5
- value,
6
- configurable: true
7
- });
8
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
- var __getOwnPropNames = Object.getOwnPropertyNames;
10
- var __getProtoOf = Object.getPrototypeOf;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
- key = keys[i];
15
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: ((k) => from[k]).bind(null, key),
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
- //#endregion
27
- let _kubb_core = require("@kubb/core");
28
- let _kubb_ast_utils = require("@kubb/ast/utils");
29
- let _kubb_plugin_ts = require("@kubb/plugin-ts");
30
- let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
31
- let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
32
- //#region ../../internals/utils/src/casing.ts
33
- /**
34
- * Shared implementation for camelCase and PascalCase conversion.
35
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
36
- * and capitalizes each word according to `pascal`.
37
- *
38
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
39
- */
40
- function toCamelOrPascal(text, pascal) {
41
- return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
42
- if (word.length > 1 && word === word.toUpperCase()) return word;
43
- return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
44
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
45
- }
46
- /**
47
- * Converts `text` to camelCase.
48
- *
49
- * @example Word boundaries
50
- * `camelCase('hello-world') // 'helloWorld'`
51
- *
52
- * @example With a prefix
53
- * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
54
- */
55
- function camelCase(text, { prefix = "", suffix = "" } = {}) {
56
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
57
- }
58
- //#endregion
59
- //#region ../../internals/utils/src/reserved.ts
60
- /**
61
- * JavaScript and Java reserved words.
62
- * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
63
- */
64
- const reservedWords = new Set([
65
- "abstract",
66
- "arguments",
67
- "boolean",
68
- "break",
69
- "byte",
70
- "case",
71
- "catch",
72
- "char",
73
- "class",
74
- "const",
75
- "continue",
76
- "debugger",
77
- "default",
78
- "delete",
79
- "do",
80
- "double",
81
- "else",
82
- "enum",
83
- "eval",
84
- "export",
85
- "extends",
86
- "false",
87
- "final",
88
- "finally",
89
- "float",
90
- "for",
91
- "function",
92
- "goto",
93
- "if",
94
- "implements",
95
- "import",
96
- "in",
97
- "instanceof",
98
- "int",
99
- "interface",
100
- "let",
101
- "long",
102
- "native",
103
- "new",
104
- "null",
105
- "package",
106
- "private",
107
- "protected",
108
- "public",
109
- "return",
110
- "short",
111
- "static",
112
- "super",
113
- "switch",
114
- "synchronized",
115
- "this",
116
- "throw",
117
- "throws",
118
- "transient",
119
- "true",
120
- "try",
121
- "typeof",
122
- "var",
123
- "void",
124
- "volatile",
125
- "while",
126
- "with",
127
- "yield",
128
- "Array",
129
- "Date",
130
- "hasOwnProperty",
131
- "Infinity",
132
- "isFinite",
133
- "isNaN",
134
- "isPrototypeOf",
135
- "length",
136
- "Math",
137
- "name",
138
- "NaN",
139
- "Number",
140
- "Object",
141
- "prototype",
142
- "String",
143
- "toString",
144
- "undefined",
145
- "valueOf"
146
- ]);
147
- /**
148
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
149
- *
150
- * @example
151
- * ```ts
152
- * isValidVarName('status') // true
153
- * isValidVarName('class') // false (reserved word)
154
- * isValidVarName('42foo') // false (starts with digit)
155
- * ```
156
- */
157
- function isValidVarName(name) {
158
- if (!name || reservedWords.has(name)) return false;
159
- return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
160
- }
161
- //#endregion
162
- //#region ../../internals/utils/src/url.ts
163
- function transformParam(raw, casing) {
164
- const param = isValidVarName(raw) ? raw : camelCase(raw);
165
- return casing === "camelcase" ? camelCase(param) : param;
166
- }
167
- function toParamsObject(path, { replacer, casing } = {}) {
168
- const params = {};
169
- for (const match of path.matchAll(/\{([^}]+)\}/g)) {
170
- const param = transformParam(match[1], casing);
171
- const key = replacer ? replacer(param) : param;
172
- params[key] = key;
173
- }
174
- return Object.keys(params).length > 0 ? params : null;
175
- }
176
- /**
177
- * Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
178
- */
179
- var Url = class Url {
180
- /**
181
- * Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
182
- *
183
- * @example
184
- * Url.canParse('https://petstore.swagger.io/v2') // true
185
- * Url.canParse('/pet/{petId}') // false
186
- */
187
- static canParse(url, base) {
188
- return URL.canParse(url, base);
189
- }
190
- /**
191
- * Converts an OpenAPI/Swagger path to Express-style colon syntax.
192
- *
193
- * @example
194
- * Url.toPath('/pet/{petId}') // '/pet/:petId'
195
- */
196
- static toPath(path) {
197
- return path.replace(/\{([^}]+)\}/g, ":$1");
198
- }
199
- /**
200
- * Converts an OpenAPI/Swagger path to a TypeScript template literal string.
201
- * `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
202
- * and `casing` controls parameter identifier casing.
203
- *
204
- * @example
205
- * Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
206
- *
207
- * @example
208
- * Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
209
- */
210
- static toTemplateString(path, { prefix, replacer, casing } = {}) {
211
- const result = path.split(/\{([^}]+)\}/).map((part, i) => {
212
- if (i % 2 === 0) return part;
213
- const param = transformParam(part, casing);
214
- return `\${${replacer ? replacer(param) : param}}`;
215
- }).join("");
216
- return `\`${prefix ?? ""}${result}\``;
217
- }
218
- /**
219
- * Returns the path and its extracted params as a structured `URLObject`, or as a stringified
220
- * expression when `stringify` is set.
221
- *
222
- * @example
223
- * Url.toObject('/pet/{petId}')
224
- * // { url: '/pet/:petId', params: { petId: 'petId' } }
225
- */
226
- static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
227
- const object = {
228
- url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
229
- replacer,
230
- casing
231
- }),
232
- params: toParamsObject(path, {
233
- replacer,
234
- casing
235
- })
236
- };
237
- if (stringify) {
238
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
239
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
240
- return `{ url: '${object.url}' }`;
241
- }
242
- return object;
243
- }
244
- };
245
- //#endregion
246
- //#region ../../internals/shared/src/operation.ts
247
- /**
248
- * Builds the `ResolverFileParams` every operation generator passes to
249
- * `resolver.resolveFile`: a file named `name`, tagged by the operation's first
250
- * tag (or `'default'`), at the operation's path. Centralizes the entry object
251
- * that was repeated at dozens of call sites across the client and query plugins.
252
- *
253
- * @example
254
- * ```ts
255
- * resolver.resolveFile(operationFileEntry(node, node.operationId), { root, output, group })
256
- * ```
257
- */
258
- function operationFileEntry(node, name, extname = ".ts") {
259
- return {
260
- name,
261
- extname,
262
- tag: node.tags[0] ?? "default",
263
- path: node.path
264
- };
265
- }
266
- function getOperationLink(node, link) {
267
- if (!link) return null;
268
- if (typeof link === "function") return link(node) ?? null;
269
- if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
270
- return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
271
- }
272
- function getContentTypeInfo(node) {
273
- const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
274
- const isMultipleContentTypes = contentTypes.length > 1;
275
- return {
276
- contentTypes,
277
- isMultipleContentTypes,
278
- contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
279
- defaultContentType: contentTypes[0] ?? "application/json",
280
- hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
281
- };
282
- }
283
- function buildRequestConfigType(node, resolver) {
284
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
285
- const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
286
- return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
287
- }
288
- function buildOperationComments(node, options = {}) {
289
- const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
290
- const linkComment = getOperationLink(node, link);
291
- const filteredComments = (linkPosition === "beforeDeprecated" ? [
292
- node.description && `@description ${node.description}`,
293
- node.summary && `@summary ${node.summary}`,
294
- linkComment,
295
- node.deprecated && "@deprecated"
296
- ] : [
297
- node.description && `@description ${node.description}`,
298
- node.summary && `@summary ${node.summary}`,
299
- node.deprecated && "@deprecated",
300
- linkComment
301
- ]).filter((comment) => Boolean(comment));
302
- if (!splitLines) return filteredComments;
303
- return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
304
- }
305
- function getOperationParameters(node, options = {}) {
306
- const params = (0, _kubb_ast_utils.caseParams)(node.parameters, options.paramsCasing);
307
- return {
308
- path: params.filter((param) => param.in === "path"),
309
- query: params.filter((param) => param.in === "query"),
310
- header: params.filter((param) => param.in === "header"),
311
- cookie: params.filter((param) => param.in === "cookie")
312
- };
313
- }
314
- function getStatusCodeNumber(statusCode) {
315
- const code = Number(statusCode);
316
- return Number.isNaN(code) ? null : code;
317
- }
318
- function isSuccessStatusCode(statusCode) {
319
- const code = getStatusCodeNumber(statusCode);
320
- return code !== null && code >= 200 && code < 300;
321
- }
322
- function isErrorStatusCode(statusCode) {
323
- const code = getStatusCodeNumber(statusCode);
324
- return code !== null && code >= 400;
325
- }
326
- function resolveErrorNames(node, resolver) {
327
- return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
328
- }
329
- function resolveSuccessNames(node, resolver) {
330
- return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
331
- }
332
- function resolveStatusCodeNames(node, resolver) {
333
- return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
334
- }
335
- /**
336
- * Builds the discriminated union type string for `dataReturnType: 'full'` return shapes.
337
- * Each member is `{ status: N; data: StatusNType; statusText: string }`.
338
- */
339
- function buildStatusUnionType(node, resolver) {
340
- const members = node.responses.map((r) => {
341
- const typeName = resolver.resolveResponseStatusName(node, r.statusCode);
342
- const statusCode = Number.parseInt(r.statusCode, 10);
343
- return `{ status: ${Number.isNaN(statusCode) ? "number" : String(statusCode)}; data: ${typeName}; statusText: string }`;
344
- });
345
- if (members.length === 1) return members[0];
346
- return `(${members.join(" | ")})`;
347
- }
348
- const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
349
- function resolveOperationTypeNames(node, resolver, options = {}) {
350
- const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
351
- let byResolver = typeNamesByResolver.get(resolver);
352
- if (byResolver) {
353
- const cached = byResolver.get(cacheKey);
354
- if (cached) return cached;
355
- } else {
356
- byResolver = /* @__PURE__ */ new Map();
357
- typeNamesByResolver.set(resolver, byResolver);
358
- }
359
- const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
360
- const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
361
- const exclude = new Set(options.exclude ?? []);
362
- const paramNames = [
363
- ...path.map((param) => resolver.resolvePathParamsName(node, param)),
364
- ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
365
- ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
366
- ];
367
- const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
368
- const result = (options.order === "body-response-first" ? [
369
- ...bodyAndResponseNames,
370
- ...paramNames,
371
- ...responseStatusNames
372
- ] : [
373
- ...paramNames,
374
- ...bodyAndResponseNames,
375
- ...responseStatusNames
376
- ]).filter((name) => Boolean(name) && !exclude.has(name));
377
- byResolver.set(cacheKey, result);
378
- return result;
379
- }
380
- //#endregion
381
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
382
- const declarationPrinter$10 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
383
- const mutationKeyTransformer = ({ node }) => {
384
- if (!node.path) return [];
385
- return [`{ url: '${Url.toPath(node.path)}' }`];
386
- };
387
- function MutationKey({ name, paramsCasing, node, transformer }) {
388
- const paramsNode = _kubb_core.ast.factory.createFunctionParameters({ params: [] });
389
- const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
390
- const keys = (transformer ?? mutationKeyTransformer)({
391
- node,
392
- casing: paramsCasing
393
- });
394
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
395
- name,
396
- isExportable: true,
397
- isIndexable: true,
398
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
399
- name,
400
- export: true,
401
- params: paramsSignature,
402
- singleLine: true,
403
- children: `[${keys.join(", ")}] as const`
404
- })
405
- });
406
- }
407
- //#endregion
408
- //#region ../../internals/tanstack-query/src/utils.ts
409
- /**
410
- * Returns the `TypeLiteral` members of a destructured group parameter, or `null`
411
- * for a plain named parameter.
412
- */
413
- function groupMembers(param) {
414
- if (typeof param.name === "string") return null;
415
- return param.type && typeof param.type !== "string" && param.type.kind === "TypeLiteral" ? param.type.members : [];
416
- }
417
- /**
418
- * Builds the shared `(…params, config = {})` parameter list for a TanStack
419
- * query-options function. The trailing `config` parameter is typed as a partial
420
- * `RequestConfig` with an optional `client`. Framework plugins wrap the result
421
- * when needed, for example vue-query applies `MaybeRefOrGetter`.
422
- */
423
- function buildQueryOptionsParams(node, options) {
424
- const { paramsType, paramsCasing, pathParamsType, resolver } = options;
425
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
426
- return (0, _kubb_ast_utils.createOperationParams)(node, {
427
- paramsType,
428
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
429
- paramsCasing,
430
- resolver,
431
- extraParams: [_kubb_core.ast.factory.createFunctionParameter({
432
- name: "config",
433
- type: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
434
- default: "{}"
435
- })]
436
- });
437
- }
438
- function matchesPattern(node, ov) {
439
- const { type, pattern } = ov;
440
- const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
441
- if (type === "operationId") return matches(node.operationId);
442
- if (type === "tag") return node.tags.some((t) => matches(t));
443
- if (type === "path") return node.path !== void 0 && matches(node.path);
444
- if (type === "method") return node.method !== void 0 && matches(node.method);
445
- return false;
446
- }
447
- /**
448
- * Resolves per-operation overrides (first matching override wins).
449
- *
450
- * @example
451
- * ```ts
452
- * const opts = resolveOperationOverrides(node, override)
453
- * const queryOpts = 'query' in opts ? opts.query : defaultQuery
454
- * ```
455
- */
456
- function resolveOperationOverrides(node, override) {
457
- if (!override) return {};
458
- return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
459
- }
460
- /**
461
- * Returns `'zod'` when response-direction parsing is enabled.
462
- * The string shorthand `'zod'` also enables response parsing.
463
- */
464
- function resolveResponseParser(parser) {
465
- if (!parser) return null;
466
- if (parser === "zod") return "zod";
467
- return parser.response ?? null;
468
- }
469
- /**
470
- * Returns `'zod'` when request body parsing is enabled.
471
- * The string shorthand `'zod'` also enables request body parsing (existing behavior).
472
- */
473
- function resolveRequestParser(parser) {
474
- if (!parser) return null;
475
- if (parser === "zod") return "zod";
476
- return parser.request ?? null;
477
- }
478
- /**
479
- * Returns `'zod'` when query-params parsing is enabled.
480
- * Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
481
- */
482
- function resolveQueryParamsParser(parser) {
483
- if (!parser || parser === "zod") return null;
484
- return parser.request ?? null;
485
- }
486
- /**
487
- * Collects the Zod schema import names for an operation based on the active parser directions.
488
- *
489
- * - `parser: 'zod'`: response and request body names (backward-compatible behavior).
490
- * - `parser: { request: 'zod' }`: request body and query params names.
491
- * - `parser: { response: 'zod' }`: response name only.
492
- * - `parser: { request: 'zod', response: 'zod' }`: all three.
493
- *
494
- * Returns an empty array when no resolver is provided or `parser` is falsy.
495
- */
496
- function resolveZodSchemaNames(node, zodResolver, parser) {
497
- if (!zodResolver || !parser) return [];
498
- const { query: queryParams } = getOperationParameters(node);
499
- return [
500
- resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
501
- resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
502
- resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
503
- ].filter((n) => Boolean(n));
504
- }
505
- /**
506
- * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
507
- */
508
- function buildQueryKeyParams(node, options) {
509
- const { pathParamsType, paramsCasing, resolver } = options;
510
- const casedParams = (0, _kubb_ast_utils.caseParams)(node.parameters, paramsCasing);
511
- const pathParams = casedParams.filter((p) => p.in === "path");
512
- const queryParams = casedParams.filter((p) => p.in === "query");
513
- const queryGroupType = (0, _kubb_ast_utils.resolveGroupType)({
514
- node,
515
- params: queryParams,
516
- group: "query",
517
- resolver
518
- });
519
- const bodyType = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
520
- const bodyRequired = node.requestBody?.required ?? false;
521
- const params = [];
522
- if (pathParams.length) {
523
- const pathChildren = pathParams.map((p) => ({
524
- name: p.name,
525
- type: (0, _kubb_ast_utils.resolveParamType)({
526
- node,
527
- param: p,
528
- resolver
529
- }),
530
- optional: !p.required
531
- }));
532
- if (pathParamsType === "object") params.push(_kubb_core.ast.factory.createFunctionParameter({
533
- properties: pathChildren,
534
- default: pathChildren.every((c) => c.optional) ? "{}" : void 0
535
- }));
536
- else params.push(...pathChildren.map((child) => _kubb_core.ast.factory.createFunctionParameter(child)));
537
- }
538
- if (bodyType) params.push(_kubb_core.ast.factory.createFunctionParameter({
539
- name: "data",
540
- type: bodyType,
541
- optional: !bodyRequired
542
- }));
543
- params.push(...(0, _kubb_ast_utils.buildGroupParam)({
544
- name: "params",
545
- node,
546
- params: queryParams,
547
- groupType: queryGroupType,
548
- resolver,
549
- wrapType: (type) => type
550
- }));
551
- return _kubb_core.ast.factory.createFunctionParameters({ params });
552
- }
553
- /**
554
- * Collect the names of the required params (no default) that drive the `enabled`
555
- * guard. These are exactly the params that should be made optional in the
556
- * generated signatures so callers can pass `undefined` to reach the disabled state.
557
- */
558
- function getEnabledParamNames(paramsNode) {
559
- const required = [];
560
- for (const param of paramsNode.params) {
561
- const members = groupMembers(param);
562
- if (members) {
563
- for (const member of members) if (!member.optional) required.push(member.name);
564
- } else if (typeof param.name === "string" && !param.optional && param.default === void 0) required.push(param.name);
565
- }
566
- return required;
567
- }
568
- /**
569
- * Return a copy of `paramsNode` with the named params marked optional.
570
- *
571
- * Used to align signatures with the `enabled` guard: the guard already disables
572
- * the query while a param is falsy, so the param should accept `undefined`. The
573
- * change is type-only — the `queryFn` keeps calling the client with a non-null
574
- * assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
575
- */
576
- function markParamsOptional(paramsNode, names) {
577
- if (names.length === 0) return paramsNode;
578
- const nameSet = new Set(names);
579
- const params = paramsNode.params.map((param) => {
580
- const members = groupMembers(param);
581
- if (members) {
582
- const next = members.map((member) => nameSet.has(member.name) ? {
583
- ...member,
584
- optional: true
585
- } : member);
586
- return {
587
- ...param,
588
- type: _kubb_core.ast.factory.createTypeLiteral({ members: next })
589
- };
590
- }
591
- return typeof param.name === "string" && nameSet.has(param.name) ? _kubb_core.ast.factory.createFunctionParameter({
592
- name: param.name,
593
- type: param.type,
594
- rest: param.rest,
595
- optional: true
596
- }) : param;
597
- });
598
- return _kubb_core.ast.factory.createFunctionParameters({ params });
599
- }
600
- /**
601
- * Add a non-null assertion (`!`) to the named params inside a printed client-call
602
- * string. Bridges the type gap created by `markParamsOptional` while keeping the
603
- * runtime identical (the `!` is erased at compile time).
604
- *
605
- * Handles destructured shorthand groups (`{ petId }` → `{ petId: petId! }`) and
606
- * standalone identifiers (`params` → `params!`).
607
- */
608
- function injectNonNullAssertions(callStr, names) {
609
- if (names.length === 0) return callStr;
610
- const nameSet = new Set(names);
611
- let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
612
- if (inner.includes(":") || inner.includes("...")) return match;
613
- const keys = inner.split(",").map((k) => k.trim()).filter(Boolean);
614
- if (!keys.some((k) => nameSet.has(k))) return match;
615
- return `{ ${keys.map((k) => nameSet.has(k) ? `${k}: ${k}!` : k).join(", ")} }`;
616
- });
617
- result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => nameSet.has(name) ? `${name}!` : match);
618
- return result;
619
- }
620
- //#endregion
621
- //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
622
- const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
623
- const queryKeyTransformer = ({ node, casing }) => {
624
- if (!node.path) return [];
625
- const hasQueryParams = getOperationParameters(node).query.length > 0;
626
- const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
627
- return [
628
- Url.toObject(node.path, {
629
- type: "path",
630
- stringify: true,
631
- casing
632
- }),
633
- hasQueryParams ? "...(params ? [params] : [])" : null,
634
- hasRequestBody ? "...(data ? [data] : [])" : null
635
- ].filter(Boolean);
636
- };
637
- function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
638
- const baseParamsNode = buildQueryKeyParams(node, {
639
- pathParamsType,
640
- paramsCasing,
641
- resolver: tsResolver
642
- });
643
- const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
644
- const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
645
- const keys = (transformer ?? queryKeyTransformer)({
646
- node,
647
- casing: paramsCasing
648
- });
649
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
650
- name,
651
- isExportable: true,
652
- isIndexable: true,
653
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
654
- name,
655
- export: true,
656
- params: paramsSignature,
657
- singleLine: true,
658
- children: `[${keys.join(", ")}] as const`
659
- })
660
- }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
661
- name: typeName,
662
- isTypeOnly: true,
663
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
664
- name: typeName,
665
- children: `ReturnType<typeof ${name}>`
666
- })
667
- })] });
668
- }
669
- //#endregion
670
- //#region src/components/QueryOptions.tsx
671
- const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
672
- const callPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
673
- function getQueryOptionsParams(node, options) {
674
- return buildQueryOptionsParams(node, options);
675
- }
676
- function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
677
- const successNames = resolveSuccessNames(node, tsResolver);
678
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
679
- const errorNames = resolveErrorNames(node, tsResolver);
680
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
681
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
682
- const queryKeyParamsNode = buildQueryKeyParams(node, {
683
- pathParamsType,
684
- paramsCasing,
685
- resolver: tsResolver
686
- });
687
- const queryKeyParamsCall = callPrinter$8.print(queryKeyParamsNode) ?? "";
688
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
689
- const optionalNames = suspense ? [] : enabledNames;
690
- const enabledText = suspense ? "" : enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
691
- const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
692
- paramsType,
693
- paramsCasing,
694
- pathParamsType,
695
- resolver: tsResolver
696
- }), optionalNames);
697
- const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
698
- const clientCallStr = injectNonNullAssertions((callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), optionalNames);
699
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
700
- name,
701
- isExportable: true,
702
- isIndexable: true,
703
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
704
- name,
705
- export: true,
706
- params: paramsSignature,
707
- children: `
708
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
709
- return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({${enabledText ? `\n ${enabledText}` : ""}
710
- queryKey,
711
- queryFn: async ({ signal }) => {
712
- return ${clientName}(${clientCallStr})
713
- },
714
- })
715
- `
716
- })
717
- });
718
- }
719
- //#endregion
720
- //#region src/components/InfiniteQuery.tsx
721
- const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
722
- const callPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
723
- function buildInfiniteQueryParamsNode(node, options) {
724
- const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
725
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
726
- const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
727
- name: "options",
728
- type: `{
729
- query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
730
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
731
- }`,
732
- default: "{}"
733
- });
734
- return (0, _kubb_ast_utils.createOperationParams)(node, {
735
- paramsType,
736
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
737
- paramsCasing,
738
- resolver,
739
- extraParams: [optionsParam]
740
- });
741
- }
742
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, initialPageParam, queryParam, customOptions }) {
743
- const successNames = resolveSuccessNames(node, tsResolver);
744
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
745
- const errorNames = resolveErrorNames(node, tsResolver);
746
- const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
747
- const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
748
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
749
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
750
- const parts = initialPageParam.split(" as ");
751
- return parts[parts.length - 1] ?? "unknown";
752
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
753
- const rawQueryParams = getOperationParameters(node).query;
754
- const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
755
- const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
756
- return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
757
- })() : null;
758
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
759
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
760
- const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
761
- const generics = [
762
- `TQueryFnData = ${responseType}`,
763
- `TError = ${errorType}`,
764
- "TData = InfiniteData<TQueryFnData>",
765
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
766
- `TPageParam = ${pageParamType}`
767
- ];
768
- const queryKeyParamsNode = buildQueryKeyParams(node, {
769
- pathParamsType,
770
- paramsCasing,
771
- resolver: tsResolver
772
- });
773
- const queryKeyParamsCall = callPrinter$7.print(queryKeyParamsNode) ?? "";
774
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
775
- const queryOptionsParamsNode = getQueryOptionsParams(node, {
776
- paramsType,
777
- paramsCasing,
778
- pathParamsType,
779
- resolver: tsResolver
780
- });
781
- const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
782
- const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
783
- paramsType,
784
- paramsCasing,
785
- pathParamsType,
786
- dataReturnType,
787
- resolver: tsResolver,
788
- pageParamGeneric: "TPageParam"
789
- }), enabledNames);
790
- const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
791
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
792
- name,
793
- isExportable: true,
794
- isIndexable: true,
795
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
796
- name,
797
- export: true,
798
- generics: generics.join(", "),
799
- params: paramsSignature,
800
- returnType: void 0,
801
- JSDoc: { comments: buildOperationComments(node) },
802
- children: `
803
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
804
- const { client: queryClient, ...resolvedOptions } = queryConfig
805
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
806
-
807
- const query = useInfiniteQuery({
808
- ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
809
- ...resolvedOptions,
810
- queryKey,
811
- } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
812
-
813
- query.queryKey = queryKey as TQueryKey
814
-
815
- return query
816
- `
817
- })
818
- });
819
- }
820
- //#endregion
821
- //#region src/components/InfiniteQueryOptions.tsx
822
- const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
823
- const callPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
824
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
825
- const successNames = resolveSuccessNames(node, tsResolver);
826
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
827
- const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
828
- const errorNames = resolveErrorNames(node, tsResolver);
829
- const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
830
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
831
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
832
- const parts = initialPageParam.split(" as ");
833
- return parts[parts.length - 1] ?? "unknown";
834
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
835
- const rawQueryParams = getOperationParameters(node).query;
836
- const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
837
- const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
838
- return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
839
- })() : null;
840
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
841
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
842
- const queryKeyParamsNode = buildQueryKeyParams(node, {
843
- pathParamsType,
844
- paramsCasing,
845
- resolver: tsResolver
846
- });
847
- const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
848
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
849
- const enabledText = enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
850
- const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
851
- paramsType,
852
- paramsCasing,
853
- pathParamsType,
854
- resolver: tsResolver
855
- }), enabledNames);
856
- const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
857
- const clientCallStr = injectNonNullAssertions((callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), enabledNames);
858
- const hasNewParams = nextParam != null || previousParam != null;
859
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
860
- if (hasNewParams) {
861
- const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
862
- const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
863
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
864
- }
865
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
866
- return [dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
867
- })();
868
- const queryOptionsArr = [
869
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
870
- getNextPageParamExpr,
871
- getPreviousPageParamExpr
872
- ].filter(Boolean);
873
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
874
- ...(params ?? {}),
875
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
876
- } as ${queryParamsTypeName}` : "";
877
- if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
878
- name,
879
- isExportable: true,
880
- isIndexable: true,
881
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
882
- name,
883
- export: true,
884
- params: paramsSignature,
885
- children: `
886
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
887
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
888
- queryKey,
889
- queryFn: async ({ signal, pageParam }) => {
890
- ${infiniteOverrideParams}
891
- return ${clientName}(${clientCallStr})
892
- },
893
- ${queryOptionsArr.join(",\n ")}
894
- })
895
- `
896
- })
897
- });
898
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
899
- name,
900
- isExportable: true,
901
- isIndexable: true,
902
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
903
- name,
904
- export: true,
905
- params: paramsSignature,
906
- children: `
907
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
908
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
909
- queryKey,
910
- queryFn: async ({ signal }) => {
911
- return ${clientName}(${clientCallStr})
912
- },
913
- ${queryOptionsArr.join(",\n ")}
914
- })
915
- `
916
- })
917
- });
918
- }
919
- //#endregion
920
- //#region src/components/MutationOptions.tsx
921
- const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
922
- const callPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
923
- const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
924
- function buildMutationConfigParamsNode(node, resolver) {
925
- return _kubb_core.ast.factory.createFunctionParameters({ params: [_kubb_core.ast.factory.createFunctionParameter({
926
- name: "config",
927
- type: buildRequestConfigType(node, resolver),
928
- default: "{}"
929
- })] });
930
- }
931
- function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
932
- const successNames = resolveSuccessNames(node, tsResolver);
933
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
934
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
935
- const errorNames = resolveErrorNames(node, tsResolver);
936
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
937
- const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
938
- const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
939
- const mutationArgParamsNode = (0, _kubb_ast_utils.createOperationParams)(node, {
940
- paramsType: "inline",
941
- pathParamsType: "inline",
942
- paramsCasing,
943
- resolver: tsResolver
944
- });
945
- const hasMutationParams = mutationArgParamsNode.params.length > 0;
946
- const TRequest = hasMutationParams ? declarationPrinter$5.print(mutationArgParamsNode) ?? "" : "";
947
- const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
948
- const clientCallParamsNode = (0, _kubb_ast_utils.createOperationParams)(node, {
949
- paramsType,
950
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
951
- paramsCasing,
952
- resolver: tsResolver,
953
- extraParams: [_kubb_core.ast.factory.createFunctionParameter({
954
- name: "config",
955
- type: buildRequestConfigType(node, tsResolver),
956
- default: "{}"
957
- })]
958
- });
959
- const clientCallStr = callPrinter$5.print(clientCallParamsNode) ?? "";
960
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
961
- name,
962
- isExportable: true,
963
- isIndexable: true,
964
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
965
- name,
966
- export: true,
967
- params: paramsSignature,
968
- generics: ["TContext = unknown"],
969
- children: `
970
- const mutationKey = ${mutationKeyName}()
971
- return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "undefined"}, TContext>({
972
- mutationKey,
973
- mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : "_"}) => {
974
- return ${clientName}(${clientCallStr})
975
- },
976
- })
977
- `
978
- })
979
- });
980
- }
981
- //#endregion
982
- //#region src/components/Mutation.tsx
983
- const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
984
- const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
985
- function createMutationArgParams(node, options) {
986
- return (0, _kubb_ast_utils.createOperationParams)(node, {
987
- paramsType: "inline",
988
- pathParamsType: "inline",
989
- paramsCasing: options.paramsCasing,
990
- resolver: options.resolver
991
- });
992
- }
993
- function buildMutationParamsNode(node, options) {
994
- const { paramsCasing, dataReturnType, resolver } = options;
995
- const successNames = resolveSuccessNames(node, resolver);
996
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
997
- const errorNames = resolveErrorNames(node, resolver);
998
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
999
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1000
- const mutationArgParamsNode = createMutationArgParams(node, {
1001
- paramsCasing,
1002
- resolver
1003
- });
1004
- const TRequest = mutationArgParamsNode.params.length > 0 ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
1005
- const generics = [
1006
- TData,
1007
- TError,
1008
- TRequest ? `{${TRequest}}` : "undefined",
1009
- "TContext"
1010
- ].join(", ");
1011
- return _kubb_core.ast.factory.createFunctionParameters({ params: [_kubb_core.ast.factory.createFunctionParameter({
1012
- name: "options",
1013
- type: `{
1014
- mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
1015
- client?: ${buildRequestConfigType(node, resolver)},
1016
- }`,
1017
- default: "{}"
1018
- })] });
1019
- }
1020
- function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, node, tsResolver, mutationKeyName, customOptions }) {
1021
- const successNames = resolveSuccessNames(node, tsResolver);
1022
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1023
- const errorNames = resolveErrorNames(node, tsResolver);
1024
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1025
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1026
- const mutationArgParamsNode = createMutationArgParams(node, {
1027
- paramsCasing,
1028
- resolver: tsResolver
1029
- });
1030
- const TRequest = mutationArgParamsNode.params.length > 0 ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
1031
- const generics = [
1032
- TData,
1033
- TError,
1034
- TRequest ? `{${TRequest}}` : "undefined",
1035
- "TContext"
1036
- ].join(", ");
1037
- const returnType = `UseMutationResult<${generics}>`;
1038
- const mutationOptionsConfigNode = buildMutationConfigParamsNode(node, tsResolver);
1039
- const mutationOptionsParamsCall = callPrinter$4.print(mutationOptionsConfigNode) ?? "";
1040
- const paramsNode = buildMutationParamsNode(node, {
1041
- paramsCasing,
1042
- dataReturnType,
1043
- resolver: tsResolver
1044
- });
1045
- const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1046
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1047
- name,
1048
- isExportable: true,
1049
- isIndexable: true,
1050
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1051
- name,
1052
- export: true,
1053
- params: paramsSignature,
1054
- JSDoc: { comments: buildOperationComments(node) },
1055
- generics: ["TContext"],
1056
- children: `
1057
- const { mutation = {}, client: config = {} } = options ?? {}
1058
- const { client: queryClient, ...mutationOptions } = mutation;
1059
- const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
1060
-
1061
- const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}>${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
1062
-
1063
- return useMutation<${generics}>({
1064
- ...baseOptions,${customOptions ? "\n ...customOptions," : ""}
1065
- mutationKey,
1066
- ...mutationOptions,
1067
- }, queryClient) as ${returnType}
1068
- `
1069
- })
1070
- });
1071
- }
1072
- //#endregion
1073
- //#region src/components/Query.tsx
1074
- const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1075
- const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1076
- function buildQueryParamsNode(node, options) {
1077
- const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1078
- const successNames = resolveSuccessNames(node, resolver);
1079
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
1080
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
1081
- const errorNames = resolveErrorNames(node, resolver);
1082
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
1083
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1084
- const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
1085
- name: "options",
1086
- type: `{
1087
- query?: Partial<QueryObserverOptions<${[
1088
- TData,
1089
- TError,
1090
- "TData",
1091
- "TQueryData",
1092
- "TQueryKey"
1093
- ].join(", ")}>> & { client?: QueryClient },
1094
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1095
- }`,
1096
- default: "{}"
1097
- });
1098
- return (0, _kubb_ast_utils.createOperationParams)(node, {
1099
- paramsType,
1100
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1101
- paramsCasing,
1102
- resolver,
1103
- extraParams: [optionsParam]
1104
- });
1105
- }
1106
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
1107
- const successNames = resolveSuccessNames(node, tsResolver);
1108
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1109
- const errorNames = resolveErrorNames(node, tsResolver);
1110
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1111
- const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
1112
- const generics = [
1113
- `TData = ${TData}`,
1114
- `TQueryData = ${TData}`,
1115
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1116
- ];
1117
- const queryKeyParamsNode = buildQueryKeyParams(node, {
1118
- pathParamsType,
1119
- paramsCasing,
1120
- resolver: tsResolver
1121
- });
1122
- const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1123
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
1124
- const queryOptionsParamsNode = getQueryOptionsParams(node, {
1125
- paramsType,
1126
- paramsCasing,
1127
- pathParamsType,
1128
- resolver: tsResolver
1129
- });
1130
- const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
1131
- const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
1132
- paramsType,
1133
- paramsCasing,
1134
- pathParamsType,
1135
- dataReturnType,
1136
- resolver: tsResolver
1137
- }), enabledNames);
1138
- const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1139
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1140
- name,
1141
- isExportable: true,
1142
- isIndexable: true,
1143
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1144
- name,
1145
- export: true,
1146
- generics: generics.join(", "),
1147
- params: paramsSignature,
1148
- returnType: void 0,
1149
- JSDoc: { comments: buildOperationComments(node) },
1150
- children: `
1151
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1152
- const { client: queryClient, ...resolvedOptions } = queryConfig
1153
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1154
-
1155
- const query = useQuery({
1156
- ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
1157
- ...resolvedOptions,
1158
- queryKey,
1159
- } as unknown as QueryObserverOptions, queryClient) as ${returnType}
1160
-
1161
- query.queryKey = queryKey as TQueryKey
1162
-
1163
- return query
1164
- `
1165
- })
1166
- });
1167
- }
1168
- //#endregion
1169
- //#region src/components/SuspenseInfiniteQuery.tsx
1170
- const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1171
- const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1172
- function buildSuspenseInfiniteQueryParamsNode(node, options) {
1173
- const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
1174
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
1175
- const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
1176
- name: "options",
1177
- type: `{
1178
- query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1179
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1180
- }`,
1181
- default: "{}"
1182
- });
1183
- return (0, _kubb_ast_utils.createOperationParams)(node, {
1184
- paramsType,
1185
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1186
- paramsCasing,
1187
- resolver,
1188
- extraParams: [optionsParam]
1189
- });
1190
- }
1191
- function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions, initialPageParam, queryParam }) {
1192
- const successNames = resolveSuccessNames(node, tsResolver);
1193
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1194
- const errorNames = resolveErrorNames(node, tsResolver);
1195
- const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1196
- const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1197
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1198
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1199
- const parts = initialPageParam.split(" as ");
1200
- return parts[parts.length - 1] ?? "unknown";
1201
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1202
- const rawQueryParams = getOperationParameters(node).query;
1203
- const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
1204
- const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
1205
- return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
1206
- })() : null;
1207
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
1208
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1209
- const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1210
- const generics = [
1211
- `TQueryFnData = ${responseType}`,
1212
- `TError = ${errorType}`,
1213
- "TData = InfiniteData<TQueryFnData>",
1214
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
1215
- `TPageParam = ${pageParamType}`
1216
- ];
1217
- const queryKeyParamsNode = buildQueryKeyParams(node, {
1218
- pathParamsType,
1219
- paramsCasing,
1220
- resolver: tsResolver
1221
- });
1222
- const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
1223
- const queryOptionsParamsNode = getQueryOptionsParams(node, {
1224
- paramsType,
1225
- paramsCasing,
1226
- pathParamsType,
1227
- resolver: tsResolver
1228
- });
1229
- const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
1230
- const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
1231
- paramsType,
1232
- paramsCasing,
1233
- pathParamsType,
1234
- dataReturnType,
1235
- resolver: tsResolver,
1236
- pageParamGeneric: "TPageParam"
1237
- });
1238
- const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1239
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1240
- name,
1241
- isExportable: true,
1242
- isIndexable: true,
1243
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1244
- name,
1245
- export: true,
1246
- generics: generics.join(", "),
1247
- params: paramsSignature,
1248
- returnType: void 0,
1249
- JSDoc: { comments: buildOperationComments(node) },
1250
- children: `
1251
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1252
- const { client: queryClient, ...resolvedOptions } = queryConfig
1253
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1254
-
1255
- const query = useSuspenseInfiniteQuery({
1256
- ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
1257
- ...resolvedOptions,
1258
- queryKey,
1259
- } as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1260
-
1261
- query.queryKey = queryKey as TQueryKey
1262
-
1263
- return query
1264
- `
1265
- })
1266
- });
1267
- }
1268
- //#endregion
1269
- //#region src/components/SuspenseInfiniteQueryOptions.tsx
1270
- const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1271
- const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1272
- function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
1273
- const successNames = resolveSuccessNames(node, tsResolver);
1274
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1275
- const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1276
- const errorNames = resolveErrorNames(node, tsResolver);
1277
- const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1278
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1279
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1280
- const parts = initialPageParam.split(" as ");
1281
- return parts[parts.length - 1] ?? "unknown";
1282
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1283
- const rawQueryParams = getOperationParameters(node).query;
1284
- const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
1285
- const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
1286
- return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
1287
- })() : null;
1288
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
1289
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1290
- const paramsNode = getQueryOptionsParams(node, {
1291
- paramsType,
1292
- paramsCasing,
1293
- pathParamsType,
1294
- resolver: tsResolver
1295
- });
1296
- const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1297
- const clientCallStr = (callPrinter$1.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
1298
- const queryKeyParamsNode = buildQueryKeyParams(node, {
1299
- pathParamsType,
1300
- paramsCasing,
1301
- resolver: tsResolver
1302
- });
1303
- const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
1304
- const hasNewParams = nextParam != null || previousParam != null;
1305
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
1306
- if (hasNewParams) {
1307
- const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
1308
- const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
1309
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
1310
- }
1311
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
1312
- return [dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
1313
- })();
1314
- const queryOptionsArr = [
1315
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1316
- getNextPageParamExpr,
1317
- getPreviousPageParamExpr
1318
- ].filter(Boolean);
1319
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
1320
- ...(params ?? {}),
1321
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1322
- } as ${queryParamsTypeName}` : "";
1323
- if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1324
- name,
1325
- isExportable: true,
1326
- isIndexable: true,
1327
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1328
- name,
1329
- export: true,
1330
- params: paramsSignature,
1331
- children: `
1332
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1333
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1334
- queryKey,
1335
- queryFn: async ({ signal, pageParam }) => {
1336
- ${infiniteOverrideParams}
1337
- return ${clientName}(${clientCallStr})
1338
- },
1339
- ${queryOptionsArr.join(",\n ")}
1340
- })
1341
- `
1342
- })
1343
- });
1344
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1345
- name,
1346
- isExportable: true,
1347
- isIndexable: true,
1348
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1349
- name,
1350
- export: true,
1351
- params: paramsSignature,
1352
- children: `
1353
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1354
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1355
- queryKey,
1356
- queryFn: async ({ signal }) => {
1357
- return ${clientName}(${clientCallStr})
1358
- },
1359
- ${queryOptionsArr.join(",\n ")}
1360
- })
1361
- `
1362
- })
1363
- });
1364
- }
1365
- //#endregion
1366
- //#region src/components/SuspenseQuery.tsx
1367
- const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1368
- const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1369
- function buildSuspenseQueryParamsNode(node, options) {
1370
- const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1371
- const successNames = resolveSuccessNames(node, resolver);
1372
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
1373
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
1374
- const errorNames = resolveErrorNames(node, resolver);
1375
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
1376
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1377
- const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
1378
- name: "options",
1379
- type: `{
1380
- query?: Partial<UseSuspenseQueryOptions<${[
1381
- TData,
1382
- TError,
1383
- "TData",
1384
- "TQueryKey"
1385
- ].join(", ")}>> & { client?: QueryClient },
1386
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1387
- }`,
1388
- default: "{}"
1389
- });
1390
- return (0, _kubb_ast_utils.createOperationParams)(node, {
1391
- paramsType,
1392
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1393
- paramsCasing,
1394
- resolver,
1395
- extraParams: [optionsParam]
1396
- });
1397
- }
1398
- function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
1399
- const successNames = resolveSuccessNames(node, tsResolver);
1400
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1401
- const errorNames = resolveErrorNames(node, tsResolver);
1402
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1403
- const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
1404
- const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
1405
- const queryKeyParamsNode = buildQueryKeyParams(node, {
1406
- pathParamsType,
1407
- paramsCasing,
1408
- resolver: tsResolver
1409
- });
1410
- const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1411
- const queryOptionsParamsNode = getQueryOptionsParams(node, {
1412
- paramsType,
1413
- paramsCasing,
1414
- pathParamsType,
1415
- resolver: tsResolver
1416
- });
1417
- const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1418
- const paramsNode = buildSuspenseQueryParamsNode(node, {
1419
- paramsType,
1420
- paramsCasing,
1421
- pathParamsType,
1422
- dataReturnType,
1423
- resolver: tsResolver
1424
- });
1425
- const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1426
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1427
- name,
1428
- isExportable: true,
1429
- isIndexable: true,
1430
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1431
- name,
1432
- export: true,
1433
- generics: generics.join(", "),
1434
- params: paramsSignature,
1435
- returnType: void 0,
1436
- JSDoc: { comments: buildOperationComments(node) },
1437
- children: `
1438
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1439
- const { client: queryClient, ...resolvedOptions } = queryConfig
1440
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1441
-
1442
- const query = useSuspenseQuery({
1443
- ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
1444
- ...resolvedOptions,
1445
- queryKey,
1446
- } as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
1447
-
1448
- query.queryKey = queryKey as TQueryKey
1449
-
1450
- return query
1451
- `
1452
- })
1453
- });
1454
- }
1455
- //#endregion
1456
- Object.defineProperty(exports, "InfiniteQuery", {
1457
- enumerable: true,
1458
- get: function() {
1459
- return InfiniteQuery;
1460
- }
1461
- });
1462
- Object.defineProperty(exports, "InfiniteQueryOptions", {
1463
- enumerable: true,
1464
- get: function() {
1465
- return InfiniteQueryOptions;
1466
- }
1467
- });
1468
- Object.defineProperty(exports, "Mutation", {
1469
- enumerable: true,
1470
- get: function() {
1471
- return Mutation;
1472
- }
1473
- });
1474
- Object.defineProperty(exports, "MutationKey", {
1475
- enumerable: true,
1476
- get: function() {
1477
- return MutationKey;
1478
- }
1479
- });
1480
- Object.defineProperty(exports, "MutationOptions", {
1481
- enumerable: true,
1482
- get: function() {
1483
- return MutationOptions;
1484
- }
1485
- });
1486
- Object.defineProperty(exports, "Query", {
1487
- enumerable: true,
1488
- get: function() {
1489
- return Query;
1490
- }
1491
- });
1492
- Object.defineProperty(exports, "QueryKey", {
1493
- enumerable: true,
1494
- get: function() {
1495
- return QueryKey;
1496
- }
1497
- });
1498
- Object.defineProperty(exports, "QueryOptions", {
1499
- enumerable: true,
1500
- get: function() {
1501
- return QueryOptions;
1502
- }
1503
- });
1504
- Object.defineProperty(exports, "SuspenseInfiniteQuery", {
1505
- enumerable: true,
1506
- get: function() {
1507
- return SuspenseInfiniteQuery;
1508
- }
1509
- });
1510
- Object.defineProperty(exports, "SuspenseInfiniteQueryOptions", {
1511
- enumerable: true,
1512
- get: function() {
1513
- return SuspenseInfiniteQueryOptions;
1514
- }
1515
- });
1516
- Object.defineProperty(exports, "SuspenseQuery", {
1517
- enumerable: true,
1518
- get: function() {
1519
- return SuspenseQuery;
1520
- }
1521
- });
1522
- Object.defineProperty(exports, "__name", {
1523
- enumerable: true,
1524
- get: function() {
1525
- return __name;
1526
- }
1527
- });
1528
- Object.defineProperty(exports, "__toESM", {
1529
- enumerable: true,
1530
- get: function() {
1531
- return __toESM;
1532
- }
1533
- });
1534
- Object.defineProperty(exports, "camelCase", {
1535
- enumerable: true,
1536
- get: function() {
1537
- return camelCase;
1538
- }
1539
- });
1540
- Object.defineProperty(exports, "getOperationParameters", {
1541
- enumerable: true,
1542
- get: function() {
1543
- return getOperationParameters;
1544
- }
1545
- });
1546
- Object.defineProperty(exports, "mutationKeyTransformer", {
1547
- enumerable: true,
1548
- get: function() {
1549
- return mutationKeyTransformer;
1550
- }
1551
- });
1552
- Object.defineProperty(exports, "operationFileEntry", {
1553
- enumerable: true,
1554
- get: function() {
1555
- return operationFileEntry;
1556
- }
1557
- });
1558
- Object.defineProperty(exports, "queryKeyTransformer", {
1559
- enumerable: true,
1560
- get: function() {
1561
- return queryKeyTransformer;
1562
- }
1563
- });
1564
- Object.defineProperty(exports, "resolveOperationOverrides", {
1565
- enumerable: true,
1566
- get: function() {
1567
- return resolveOperationOverrides;
1568
- }
1569
- });
1570
- Object.defineProperty(exports, "resolveOperationTypeNames", {
1571
- enumerable: true,
1572
- get: function() {
1573
- return resolveOperationTypeNames;
1574
- }
1575
- });
1576
- Object.defineProperty(exports, "resolveZodSchemaNames", {
1577
- enumerable: true,
1578
- get: function() {
1579
- return resolveZodSchemaNames;
1580
- }
1581
- });
1582
-
1583
- //# sourceMappingURL=components-B0j2b6y8.cjs.map