@kubb/plugin-vue-query 5.0.0-beta.64 → 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.
@@ -1,1118 +0,0 @@
1
- import { t as __name } from "./chunk-C0LytTxp.js";
2
- import { ast } from "@kubb/core";
3
- import { buildGroupParam, caseParams, createOperationParams, getNestedAccessor, resolveGroupType, resolveParamType } from "@kubb/ast/utils";
4
- import { functionPrinter, renderType } from "@kubb/plugin-ts";
5
- import { File, Function, Type } from "@kubb/renderer-jsx";
6
- import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
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 = 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$7 = 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.factory.createFunctionParameters({ params: [] });
364
- const paramsSignature = declarationPrinter$7.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
- * Returns the `TypeLiteral` members of a destructured group parameter, or `null`
386
- * for a plain named parameter.
387
- */
388
- function groupMembers(param) {
389
- if (typeof param.name === "string") return null;
390
- return param.type && typeof param.type !== "string" && param.type.kind === "TypeLiteral" ? param.type.members : [];
391
- }
392
- /**
393
- * Builds the shared `(…params, config = {})` parameter list for a TanStack
394
- * query-options function. The trailing `config` parameter is typed as a partial
395
- * `RequestConfig` with an optional `client`. Framework plugins wrap the result
396
- * when needed, for example vue-query applies `MaybeRefOrGetter`.
397
- */
398
- function buildQueryOptionsParams(node, options) {
399
- const { paramsType, paramsCasing, pathParamsType, resolver } = options;
400
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
401
- return createOperationParams(node, {
402
- paramsType,
403
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
404
- paramsCasing,
405
- resolver,
406
- extraParams: [ast.factory.createFunctionParameter({
407
- name: "config",
408
- type: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
409
- default: "{}"
410
- })]
411
- });
412
- }
413
- /**
414
- * Returns `'zod'` when response-direction parsing is enabled.
415
- * The string shorthand `'zod'` also enables response parsing.
416
- */
417
- function resolveResponseParser(parser) {
418
- if (!parser) return null;
419
- if (parser === "zod") return "zod";
420
- return parser.response ?? null;
421
- }
422
- /**
423
- * Returns `'zod'` when request body parsing is enabled.
424
- * The string shorthand `'zod'` also enables request body parsing (existing behavior).
425
- */
426
- function resolveRequestParser(parser) {
427
- if (!parser) return null;
428
- if (parser === "zod") return "zod";
429
- return parser.request ?? null;
430
- }
431
- /**
432
- * Returns `'zod'` when query-params parsing is enabled.
433
- * Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
434
- */
435
- function resolveQueryParamsParser(parser) {
436
- if (!parser || parser === "zod") return null;
437
- return parser.request ?? null;
438
- }
439
- /**
440
- * Collects the Zod schema import names for an operation based on the active parser directions.
441
- *
442
- * - `parser: 'zod'`: response and request body names (backward-compatible behavior).
443
- * - `parser: { request: 'zod' }`: request body and query params names.
444
- * - `parser: { response: 'zod' }`: response name only.
445
- * - `parser: { request: 'zod', response: 'zod' }`: all three.
446
- *
447
- * Returns an empty array when no resolver is provided or `parser` is falsy.
448
- */
449
- function resolveZodSchemaNames(node, zodResolver, parser) {
450
- if (!zodResolver || !parser) return [];
451
- const { query: queryParams } = getOperationParameters(node);
452
- return [
453
- resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
454
- resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
455
- resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
456
- ].filter((n) => Boolean(n));
457
- }
458
- /**
459
- * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
460
- */
461
- function buildQueryKeyParams(node, options) {
462
- const { pathParamsType, paramsCasing, resolver } = options;
463
- const casedParams = caseParams(node.parameters, paramsCasing);
464
- const pathParams = casedParams.filter((p) => p.in === "path");
465
- const queryParams = casedParams.filter((p) => p.in === "query");
466
- const queryGroupType = resolveGroupType({
467
- node,
468
- params: queryParams,
469
- group: "query",
470
- resolver
471
- });
472
- const bodyType = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
473
- const bodyRequired = node.requestBody?.required ?? false;
474
- const params = [];
475
- if (pathParams.length) {
476
- const pathChildren = pathParams.map((p) => ({
477
- name: p.name,
478
- type: resolveParamType({
479
- node,
480
- param: p,
481
- resolver
482
- }),
483
- optional: !p.required
484
- }));
485
- if (pathParamsType === "object") params.push(ast.factory.createFunctionParameter({
486
- properties: pathChildren,
487
- default: pathChildren.every((c) => c.optional) ? "{}" : void 0
488
- }));
489
- else params.push(...pathChildren.map((child) => ast.factory.createFunctionParameter(child)));
490
- }
491
- if (bodyType) params.push(ast.factory.createFunctionParameter({
492
- name: "data",
493
- type: bodyType,
494
- optional: !bodyRequired
495
- }));
496
- params.push(...buildGroupParam({
497
- name: "params",
498
- node,
499
- params: queryParams,
500
- groupType: queryGroupType,
501
- resolver,
502
- wrapType: (type) => type
503
- }));
504
- return ast.factory.createFunctionParameters({ params });
505
- }
506
- /**
507
- * Collect the names of the required params (no default) that drive the `enabled`
508
- * guard. These are exactly the params that should be made optional in the
509
- * generated signatures so callers can pass `undefined` to reach the disabled state.
510
- */
511
- function getEnabledParamNames(paramsNode) {
512
- const required = [];
513
- for (const param of paramsNode.params) {
514
- const members = groupMembers(param);
515
- if (members) {
516
- for (const member of members) if (!member.optional) required.push(member.name);
517
- } else if (typeof param.name === "string" && !param.optional && param.default === void 0) required.push(param.name);
518
- }
519
- return required;
520
- }
521
- /**
522
- * Return a copy of `paramsNode` with the named params marked optional.
523
- *
524
- * Used to align signatures with the `enabled` guard: the guard already disables
525
- * the query while a param is falsy, so the param should accept `undefined`. The
526
- * change is type-only — the `queryFn` keeps calling the client with a non-null
527
- * assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
528
- */
529
- function markParamsOptional(paramsNode, names) {
530
- if (names.length === 0) return paramsNode;
531
- const nameSet = new Set(names);
532
- const params = paramsNode.params.map((param) => {
533
- const members = groupMembers(param);
534
- if (members) {
535
- const next = members.map((member) => nameSet.has(member.name) ? {
536
- ...member,
537
- optional: true
538
- } : member);
539
- return {
540
- ...param,
541
- type: ast.factory.createTypeLiteral({ members: next })
542
- };
543
- }
544
- return typeof param.name === "string" && nameSet.has(param.name) ? ast.factory.createFunctionParameter({
545
- name: param.name,
546
- type: param.type,
547
- rest: param.rest,
548
- optional: true
549
- }) : param;
550
- });
551
- return ast.factory.createFunctionParameters({ params });
552
- }
553
- functionPrinter({ mode: "declaration" });
554
- const queryKeyTransformer = ({ node, casing }) => {
555
- if (!node.path) return [];
556
- const hasQueryParams = getOperationParameters(node).query.length > 0;
557
- const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
558
- return [
559
- Url.toObject(node.path, {
560
- type: "path",
561
- stringify: true,
562
- casing
563
- }),
564
- hasQueryParams ? "...(params ? [params] : [])" : null,
565
- hasRequestBody ? "...(data ? [data] : [])" : null
566
- ].filter(Boolean);
567
- };
568
- //#endregion
569
- //#region src/utils.ts
570
- /**
571
- * Wraps each parameter type in `MaybeRefOrGetter<…>` so a vue-query signature
572
- * accepts refs or getters. Group members are wrapped individually; `skip` opts a
573
- * plain parameter out by name.
574
- */
575
- function wrapWithMaybeRefOrGetter(paramsNode, skip) {
576
- const wrappedParams = paramsNode.params.map((param) => {
577
- if (typeof param.name !== "string") {
578
- const type = param.type;
579
- if (type && typeof type !== "string" && type.kind === "TypeLiteral") return {
580
- ...param,
581
- type: ast.factory.createTypeLiteral({ members: type.members.map((member) => ({
582
- ...member,
583
- type: `MaybeRefOrGetter<${renderType(member.type)}>`
584
- })) })
585
- };
586
- return param;
587
- }
588
- if (skip?.(param.name)) return param;
589
- return {
590
- ...param,
591
- type: param.type ? `MaybeRefOrGetter<${renderType(param.type)}>` : param.type
592
- };
593
- });
594
- return ast.factory.createFunctionParameters({ params: wrappedParams });
595
- }
596
- //#endregion
597
- //#region src/components/QueryKey.tsx
598
- const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
599
- function buildQueryKeyParamsNode(node, options) {
600
- return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
601
- }
602
- function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
603
- const baseParamsNode = buildQueryKeyParamsNode(node, {
604
- pathParamsType,
605
- paramsCasing,
606
- resolver: tsResolver
607
- });
608
- const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
609
- const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
610
- const keys = (transformer ?? queryKeyTransformer)({
611
- node,
612
- casing: paramsCasing
613
- });
614
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
615
- name,
616
- isExportable: true,
617
- isIndexable: true,
618
- children: /* @__PURE__ */ jsx(Function.Arrow, {
619
- name,
620
- export: true,
621
- params: paramsSignature,
622
- singleLine: true,
623
- children: `[${keys.join(", ")}] as const`
624
- })
625
- }), /* @__PURE__ */ jsx(File.Source, {
626
- name: typeName,
627
- isExportable: true,
628
- isIndexable: true,
629
- isTypeOnly: true,
630
- children: /* @__PURE__ */ jsx(Type, {
631
- name: typeName,
632
- export: true,
633
- children: `ReturnType<typeof ${name}>`
634
- })
635
- })] });
636
- }
637
- //#endregion
638
- //#region src/components/QueryOptions.tsx
639
- const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
640
- const callPrinter$4 = functionPrinter({ mode: "call" });
641
- function getQueryOptionsParams(node, options) {
642
- return wrapWithMaybeRefOrGetter(buildQueryOptionsParams(node, options), (name) => name === "config");
643
- }
644
- function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
645
- const successNames = resolveSuccessNames(node, tsResolver);
646
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
647
- const errorNames = resolveErrorNames(node, tsResolver);
648
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
649
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
650
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
651
- pathParamsType,
652
- paramsCasing,
653
- resolver: tsResolver
654
- });
655
- const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
656
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
657
- const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
658
- const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
659
- paramsType,
660
- paramsCasing,
661
- pathParamsType,
662
- resolver: tsResolver
663
- }), enabledNames);
664
- const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
665
- const clientCallStr = (callPrinter$4.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
666
- return /* @__PURE__ */ jsx(File.Source, {
667
- name,
668
- isExportable: true,
669
- isIndexable: true,
670
- children: /* @__PURE__ */ jsx(Function, {
671
- name,
672
- export: true,
673
- params: paramsSignature,
674
- children: `
675
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
676
- return queryOptions<${TData}, ${TError}, ${TData}>({${enabledText ? `\n ${enabledText}` : ""}
677
- queryKey,
678
- queryFn: async ({ signal }) => {
679
- return ${clientName}(${addToValueCalls$1(clientCallStr, enabledNames)})
680
- },
681
- })
682
- `
683
- })
684
- });
685
- }
686
- /**
687
- * Wraps parameter names with `toValue()` in the client call string,
688
- * except for 'config'-related params (which are already plain objects).
689
- *
690
- * Handles both inline params (`petId, config`) and object shorthand
691
- * params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
692
- */
693
- function addToValueCalls$1(callStr, enabledNames = []) {
694
- const optional = new Set(enabledNames);
695
- let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
696
- if (inner.includes(":") || inner.includes("...")) return match;
697
- return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
698
- });
699
- result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
700
- if (name === "config" || name === "signal" || name === "undefined") return match;
701
- if (match.includes("toValue(")) return match;
702
- return `toValue(${optional.has(name) ? `${name}!` : name})`;
703
- });
704
- return result;
705
- }
706
- __name(addToValueCalls$1, "addToValueCalls");
707
- //#endregion
708
- //#region src/components/InfiniteQuery.tsx
709
- const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
710
- const callPrinter$3 = functionPrinter({ mode: "call" });
711
- function buildInfiniteQueryParamsNode(node, options) {
712
- const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
713
- const successNames = resolveSuccessNames(node, resolver);
714
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
715
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
716
- const errorNames = resolveErrorNames(node, resolver);
717
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
718
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
719
- const optionsParam = ast.factory.createFunctionParameter({
720
- name: "options",
721
- type: `{
722
- query?: Partial<UseInfiniteQueryOptions<${[
723
- TData,
724
- TError,
725
- "TQueryData",
726
- "TQueryKey",
727
- "TQueryData"
728
- ].join(", ")}>> & { client?: QueryClient },
729
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
730
- }`,
731
- default: "{}"
732
- });
733
- return wrapWithMaybeRefOrGetter(createOperationParams(node, {
734
- paramsType,
735
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
736
- paramsCasing,
737
- resolver,
738
- extraParams: [optionsParam]
739
- }), (name) => name === "options");
740
- }
741
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
742
- const successNames = resolveSuccessNames(node, tsResolver);
743
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
744
- const errorNames = resolveErrorNames(node, tsResolver);
745
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
746
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
747
- const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
748
- const generics = [
749
- `TData = InfiniteData<${TData}>`,
750
- `TQueryData = ${TData}`,
751
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
752
- ];
753
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
754
- pathParamsType,
755
- paramsCasing,
756
- resolver: tsResolver
757
- });
758
- const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
759
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
760
- const queryOptionsParamsNode = getQueryOptionsParams(node, {
761
- paramsType,
762
- paramsCasing,
763
- pathParamsType,
764
- resolver: tsResolver
765
- });
766
- const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
767
- const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
768
- paramsType,
769
- paramsCasing,
770
- pathParamsType,
771
- dataReturnType,
772
- resolver: tsResolver
773
- }), enabledNames);
774
- const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
775
- return /* @__PURE__ */ jsx(File.Source, {
776
- name,
777
- isExportable: true,
778
- isIndexable: true,
779
- children: /* @__PURE__ */ jsx(Function, {
780
- name,
781
- export: true,
782
- generics: generics.join(", "),
783
- params: paramsSignature,
784
- JSDoc: { comments: buildOperationComments(node) },
785
- children: `
786
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
787
- const { client: queryClient, ...resolvedOptions } = queryConfig
788
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
789
-
790
- const query = useInfiniteQuery({
791
- ...${queryOptionsName}(${queryOptionsParamsCall}),
792
- ...resolvedOptions,
793
- queryKey
794
- } as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
795
-
796
- query.queryKey = queryKey as TQueryKey
797
-
798
- return query
799
- `
800
- })
801
- });
802
- }
803
- //#endregion
804
- //#region src/components/InfiniteQueryOptions.tsx
805
- const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
806
- const callPrinter$2 = functionPrinter({ mode: "call" });
807
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
808
- const successNames = resolveSuccessNames(node, tsResolver);
809
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
810
- const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
811
- const errorNames = resolveErrorNames(node, tsResolver);
812
- const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
813
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
814
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
815
- const parts = initialPageParam.split(" as ");
816
- return parts[parts.length - 1] ?? "unknown";
817
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
818
- const rawQueryParams = getOperationParameters(node).query;
819
- const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
820
- const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
821
- return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
822
- })() : null;
823
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
824
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
825
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
826
- pathParamsType,
827
- paramsCasing,
828
- resolver: tsResolver
829
- });
830
- const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
831
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
832
- const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
833
- const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
834
- paramsType,
835
- paramsCasing,
836
- pathParamsType,
837
- resolver: tsResolver
838
- }), enabledNames);
839
- const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
840
- const clientCallStr = (callPrinter$2.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
841
- const hasNewParams = nextParam != null || previousParam != null;
842
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
843
- if (hasNewParams) {
844
- const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
845
- const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
846
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
847
- }
848
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
849
- 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"];
850
- })();
851
- const queryOptionsArr = [
852
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
853
- getNextPageParamExpr,
854
- getPreviousPageParamExpr
855
- ].filter(Boolean);
856
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
857
- ...(params ?? {}),
858
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
859
- } as ${queryParamsTypeName}` : "";
860
- if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
861
- name,
862
- isExportable: true,
863
- isIndexable: true,
864
- children: /* @__PURE__ */ jsx(Function, {
865
- name,
866
- export: true,
867
- params: paramsSignature,
868
- children: `
869
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
870
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
871
- queryKey,
872
- queryFn: async ({ signal, pageParam }) => {
873
- ${infiniteOverrideParams}
874
- return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
875
- },
876
- ${queryOptionsArr.join(",\n ")}
877
- })
878
- `
879
- })
880
- });
881
- return /* @__PURE__ */ jsx(File.Source, {
882
- name,
883
- isExportable: true,
884
- isIndexable: true,
885
- children: /* @__PURE__ */ jsx(Function, {
886
- name,
887
- export: true,
888
- params: paramsSignature,
889
- children: `
890
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
891
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
892
- queryKey,
893
- queryFn: async ({ signal }) => {
894
- return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
895
- },
896
- ${queryOptionsArr.join(",\n ")}
897
- })
898
- `
899
- })
900
- });
901
- }
902
- function addToValueCalls(callStr, enabledNames = []) {
903
- const optional = new Set(enabledNames);
904
- let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
905
- if (inner.includes(":") || inner.includes("...")) return match;
906
- return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
907
- });
908
- result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
909
- if (name === "config" || name === "signal" || name === "undefined") return match;
910
- if (match.includes("toValue(")) return match;
911
- return `toValue(${optional.has(name) ? `${name}!` : name})`;
912
- });
913
- return result;
914
- }
915
- //#endregion
916
- //#region src/components/Mutation.tsx
917
- const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
918
- const callPrinter$1 = functionPrinter({ mode: "call" });
919
- const keysPrinter = functionPrinter({ mode: "call" });
920
- function createMutationArgParams(node, options) {
921
- return createOperationParams(node, {
922
- paramsType: "inline",
923
- pathParamsType: "inline",
924
- paramsCasing: options.paramsCasing,
925
- resolver: options.resolver
926
- });
927
- }
928
- function buildMutationParamsNode(node, options) {
929
- const { paramsCasing, dataReturnType, resolver } = options;
930
- const successNames = resolveSuccessNames(node, resolver);
931
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
932
- const errorNames = resolveErrorNames(node, resolver);
933
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
934
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
935
- const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
936
- paramsCasing,
937
- resolver
938
- }));
939
- const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
940
- return ast.factory.createFunctionParameters({ params: [ast.factory.createFunctionParameter({
941
- name: "options",
942
- type: `{
943
- mutation?: MutationObserverOptions<${[
944
- TData,
945
- TError,
946
- TRequestWrapped ? `{${TRequestWrapped}}` : "undefined",
947
- "TContext"
948
- ].join(", ")}> & { client?: QueryClient },
949
- client?: ${buildRequestConfigType(node, resolver)},
950
- }`,
951
- default: "{}"
952
- })] });
953
- }
954
- function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
955
- const successNames = resolveSuccessNames(node, tsResolver);
956
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
957
- const errorNames = resolveErrorNames(node, tsResolver);
958
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
959
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
960
- const mutationArgParamsNode = createMutationArgParams(node, {
961
- paramsCasing,
962
- resolver: tsResolver
963
- });
964
- const hasMutationParams = mutationArgParamsNode.params.length > 0;
965
- const TRequest = hasMutationParams ? declarationPrinter$1.print(mutationArgParamsNode) ?? "" : "";
966
- const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
967
- const generics = [
968
- TData,
969
- TError,
970
- TRequest ? `{${TRequest}}` : "undefined",
971
- "TContext"
972
- ].join(", ");
973
- const mutationKeyParamsNode = ast.factory.createFunctionParameters({ params: [] });
974
- const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
975
- const clientCallParamsNode = createOperationParams(node, {
976
- paramsType,
977
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
978
- paramsCasing,
979
- resolver: tsResolver,
980
- extraParams: [ast.factory.createFunctionParameter({
981
- name: "config",
982
- type: buildRequestConfigType(node, tsResolver),
983
- default: "{}"
984
- })]
985
- });
986
- const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
987
- const paramsNode = buildMutationParamsNode(node, {
988
- paramsCasing,
989
- dataReturnType,
990
- resolver: tsResolver
991
- });
992
- const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
993
- return /* @__PURE__ */ jsx(File.Source, {
994
- name,
995
- isExportable: true,
996
- isIndexable: true,
997
- children: /* @__PURE__ */ jsx(Function, {
998
- name,
999
- export: true,
1000
- params: paramsSignature,
1001
- JSDoc: { comments: buildOperationComments(node) },
1002
- generics: ["TContext"],
1003
- children: `
1004
- const { mutation = {}, client: config = {} } = options ?? {}
1005
- const { client: queryClient, ...mutationOptions } = mutation;
1006
- const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParamsCall})
1007
-
1008
- return useMutation<${generics}>({
1009
- mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : ""}) => {
1010
- return ${clientName}(${clientCallStr})
1011
- },
1012
- mutationKey,
1013
- ...mutationOptions
1014
- }, queryClient)
1015
- `
1016
- })
1017
- });
1018
- }
1019
- //#endregion
1020
- //#region src/components/Query.tsx
1021
- const declarationPrinter = functionPrinter({ mode: "declaration" });
1022
- const callPrinter = functionPrinter({ mode: "call" });
1023
- function buildQueryParamsNode(node, options) {
1024
- const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1025
- const successNames = resolveSuccessNames(node, resolver);
1026
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
1027
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
1028
- const errorNames = resolveErrorNames(node, resolver);
1029
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
1030
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1031
- const optionsParam = ast.factory.createFunctionParameter({
1032
- name: "options",
1033
- type: `{
1034
- query?: Partial<UseQueryOptions<${[
1035
- TData,
1036
- TError,
1037
- "TData",
1038
- "TQueryData",
1039
- "TQueryKey"
1040
- ].join(", ")}>> & { client?: QueryClient },
1041
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1042
- }`,
1043
- default: "{}"
1044
- });
1045
- return wrapWithMaybeRefOrGetter(createOperationParams(node, {
1046
- paramsType,
1047
- pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1048
- paramsCasing,
1049
- resolver,
1050
- extraParams: [optionsParam]
1051
- }), (name) => name === "options");
1052
- }
1053
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
1054
- const successNames = resolveSuccessNames(node, tsResolver);
1055
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1056
- const errorNames = resolveErrorNames(node, tsResolver);
1057
- const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1058
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1059
- const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1060
- const generics = [
1061
- `TData = ${TData}`,
1062
- `TQueryData = ${TData}`,
1063
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1064
- ];
1065
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
1066
- pathParamsType,
1067
- paramsCasing,
1068
- resolver: tsResolver
1069
- });
1070
- const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1071
- const enabledNames = getEnabledParamNames(queryKeyParamsNode);
1072
- const queryOptionsParamsNode = getQueryOptionsParams(node, {
1073
- paramsType,
1074
- paramsCasing,
1075
- pathParamsType,
1076
- resolver: tsResolver
1077
- });
1078
- const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1079
- const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
1080
- paramsType,
1081
- paramsCasing,
1082
- pathParamsType,
1083
- dataReturnType,
1084
- resolver: tsResolver
1085
- }), enabledNames);
1086
- const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1087
- return /* @__PURE__ */ jsx(File.Source, {
1088
- name,
1089
- isExportable: true,
1090
- isIndexable: true,
1091
- children: /* @__PURE__ */ jsx(Function, {
1092
- name,
1093
- export: true,
1094
- generics: generics.join(", "),
1095
- params: paramsSignature,
1096
- JSDoc: { comments: buildOperationComments(node) },
1097
- children: `
1098
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1099
- const { client: queryClient, ...resolvedOptions } = queryConfig
1100
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
1101
-
1102
- const query = useQuery({
1103
- ...${queryOptionsName}(${queryOptionsParamsCall}),
1104
- ...resolvedOptions,
1105
- queryKey
1106
- } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
1107
-
1108
- query.queryKey = queryKey as TQueryKey
1109
-
1110
- return query
1111
- `
1112
- })
1113
- });
1114
- }
1115
- //#endregion
1116
- export { QueryOptions as a, resolveZodSchemaNames as c, getOperationParameters as d, operationFileEntry as f, InfiniteQuery as i, MutationKey as l, camelCase as m, Mutation as n, QueryKey as o, resolveOperationTypeNames as p, InfiniteQueryOptions as r, queryKeyTransformer as s, Query as t, mutationKeyTransformer as u };
1117
-
1118
- //# sourceMappingURL=components-CAlEf7Oh.js.map