@kubb/plugin-react-query 5.0.0-beta.56 → 5.0.0-beta.73

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