@kubb/plugin-swr 5.0.0-alpha.9 → 5.0.0-beta.33

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 (44) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +33 -26
  3. package/dist/components-ByADeLZO.cjs +1029 -0
  4. package/dist/components-ByADeLZO.cjs.map +1 -0
  5. package/dist/components-CBdpiiay.js +933 -0
  6. package/dist/components-CBdpiiay.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +45 -51
  9. package/dist/components.js +1 -1
  10. package/dist/generators-Bb5wNYig.cjs +445 -0
  11. package/dist/generators-Bb5wNYig.cjs.map +1 -0
  12. package/dist/generators-D5kJZsB1.js +434 -0
  13. package/dist/generators-D5kJZsB1.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +4 -500
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +134 -113
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +130 -113
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-D9jeG3fE.d.ts +220 -0
  23. package/extension.yaml +199 -0
  24. package/package.json +57 -67
  25. package/src/components/Mutation.tsx +106 -227
  26. package/src/components/MutationKey.tsx +25 -1
  27. package/src/components/Query.tsx +75 -140
  28. package/src/components/QueryOptions.tsx +46 -95
  29. package/src/generators/mutationGenerator.tsx +113 -128
  30. package/src/generators/queryGenerator.tsx +125 -137
  31. package/src/index.ts +2 -2
  32. package/src/plugin.ts +117 -170
  33. package/src/resolvers/resolverSwr.ts +56 -0
  34. package/src/types.ts +115 -59
  35. package/src/utils.ts +10 -0
  36. package/dist/components-DRDGvgXG.js +0 -702
  37. package/dist/components-DRDGvgXG.js.map +0 -1
  38. package/dist/components-jd0l9XKn.cjs +0 -780
  39. package/dist/components-jd0l9XKn.cjs.map +0 -1
  40. package/dist/generators-CRSl6u2M.js +0 -399
  41. package/dist/generators-CRSl6u2M.js.map +0 -1
  42. package/dist/generators-D062obA7.cjs +0 -410
  43. package/dist/generators-D062obA7.cjs.map +0 -1
  44. package/dist/types-BIaGRPjD.d.ts +0 -210
@@ -0,0 +1,933 @@
1
+ import { t as __name } from "./chunk--u3MIqq1.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
+ //#region ../../internals/utils/src/casing.ts
7
+ /**
8
+ * Shared implementation for camelCase and PascalCase conversion.
9
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
10
+ * and capitalizes each word according to `pascal`.
11
+ *
12
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
13
+ */
14
+ function toCamelOrPascal(text, pascal) {
15
+ 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) => {
16
+ if (word.length > 1 && word === word.toUpperCase()) return word;
17
+ if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
18
+ return word.charAt(0).toUpperCase() + word.slice(1);
19
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
20
+ }
21
+ /**
22
+ * Splits `text` on `.` and applies `transformPart` to each segment.
23
+ * The last segment receives `isLast = true`, all earlier segments receive `false`.
24
+ * Segments are joined with `/` to form a file path.
25
+ *
26
+ * Only splits on dots followed by a letter so that version numbers
27
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
28
+ */
29
+ function applyToFileParts(text, transformPart) {
30
+ const parts = text.split(/\.(?=[a-zA-Z])/);
31
+ return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
32
+ }
33
+ /**
34
+ * Converts `text` to camelCase.
35
+ * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
36
+ *
37
+ * @example
38
+ * camelCase('hello-world') // 'helloWorld'
39
+ * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
40
+ */
41
+ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
42
+ if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
43
+ prefix,
44
+ suffix
45
+ } : {}));
46
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
47
+ }
48
+ //#endregion
49
+ //#region ../../internals/utils/src/reserved.ts
50
+ /**
51
+ * JavaScript and Java reserved words.
52
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
53
+ */
54
+ const reservedWords = new Set([
55
+ "abstract",
56
+ "arguments",
57
+ "boolean",
58
+ "break",
59
+ "byte",
60
+ "case",
61
+ "catch",
62
+ "char",
63
+ "class",
64
+ "const",
65
+ "continue",
66
+ "debugger",
67
+ "default",
68
+ "delete",
69
+ "do",
70
+ "double",
71
+ "else",
72
+ "enum",
73
+ "eval",
74
+ "export",
75
+ "extends",
76
+ "false",
77
+ "final",
78
+ "finally",
79
+ "float",
80
+ "for",
81
+ "function",
82
+ "goto",
83
+ "if",
84
+ "implements",
85
+ "import",
86
+ "in",
87
+ "instanceof",
88
+ "int",
89
+ "interface",
90
+ "let",
91
+ "long",
92
+ "native",
93
+ "new",
94
+ "null",
95
+ "package",
96
+ "private",
97
+ "protected",
98
+ "public",
99
+ "return",
100
+ "short",
101
+ "static",
102
+ "super",
103
+ "switch",
104
+ "synchronized",
105
+ "this",
106
+ "throw",
107
+ "throws",
108
+ "transient",
109
+ "true",
110
+ "try",
111
+ "typeof",
112
+ "var",
113
+ "void",
114
+ "volatile",
115
+ "while",
116
+ "with",
117
+ "yield",
118
+ "Array",
119
+ "Date",
120
+ "hasOwnProperty",
121
+ "Infinity",
122
+ "isFinite",
123
+ "isNaN",
124
+ "isPrototypeOf",
125
+ "length",
126
+ "Math",
127
+ "name",
128
+ "NaN",
129
+ "Number",
130
+ "Object",
131
+ "prototype",
132
+ "String",
133
+ "toString",
134
+ "undefined",
135
+ "valueOf"
136
+ ]);
137
+ /**
138
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * isValidVarName('status') // true
143
+ * isValidVarName('class') // false (reserved word)
144
+ * isValidVarName('42foo') // false (starts with digit)
145
+ * ```
146
+ */
147
+ function isValidVarName(name) {
148
+ if (!name || reservedWords.has(name)) return false;
149
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
150
+ }
151
+ //#endregion
152
+ //#region ../../internals/utils/src/urlPath.ts
153
+ /**
154
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
155
+ *
156
+ * @example
157
+ * const p = new URLPath('/pet/{petId}')
158
+ * p.URL // '/pet/:petId'
159
+ * p.template // '`/pet/${petId}`'
160
+ */
161
+ var URLPath = class {
162
+ /**
163
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
164
+ */
165
+ path;
166
+ #options;
167
+ constructor(path, options = {}) {
168
+ this.path = path;
169
+ this.#options = options;
170
+ }
171
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
176
+ * ```
177
+ */
178
+ get URL() {
179
+ return this.toURLPath();
180
+ }
181
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
186
+ * new URLPath('/pet/{petId}').isURL // false
187
+ * ```
188
+ */
189
+ get isURL() {
190
+ try {
191
+ return !!new URL(this.path).href;
192
+ } catch {
193
+ return false;
194
+ }
195
+ }
196
+ /**
197
+ * Converts the OpenAPI path to a TypeScript template literal string.
198
+ *
199
+ * @example
200
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
201
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
202
+ */
203
+ get template() {
204
+ return this.toTemplateString();
205
+ }
206
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * new URLPath('/pet/{petId}').object
211
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
212
+ * ```
213
+ */
214
+ get object() {
215
+ return this.toObject();
216
+ }
217
+ /** Returns a map of path parameter names, or `null` when the path has no parameters.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
222
+ * new URLPath('/pet').params // null
223
+ * ```
224
+ */
225
+ get params() {
226
+ return this.toParamsObject();
227
+ }
228
+ #transformParam(raw) {
229
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
230
+ return this.#options.casing === "camelcase" ? camelCase(param) : param;
231
+ }
232
+ /**
233
+ * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
234
+ */
235
+ #eachParam(fn) {
236
+ for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
237
+ const raw = match[1];
238
+ fn(raw, this.#transformParam(raw));
239
+ }
240
+ }
241
+ toObject({ type = "path", replacer, stringify } = {}) {
242
+ const object = {
243
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
244
+ params: this.toParamsObject()
245
+ };
246
+ if (stringify) {
247
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
248
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
249
+ return `{ url: '${object.url}' }`;
250
+ }
251
+ return object;
252
+ }
253
+ /**
254
+ * Converts the OpenAPI path to a TypeScript template literal string.
255
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
256
+ *
257
+ * @example
258
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
259
+ */
260
+ toTemplateString({ prefix, replacer } = {}) {
261
+ const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
262
+ if (i % 2 === 0) return part;
263
+ const param = this.#transformParam(part);
264
+ return `\${${replacer ? replacer(param) : param}}`;
265
+ }).join("");
266
+ return `\`${prefix ?? ""}${result}\``;
267
+ }
268
+ /**
269
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
270
+ * An optional `replacer` transforms each parameter name in both key and value positions.
271
+ * Returns `undefined` when no path parameters are found.
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
276
+ * // { petId: 'petId', tagId: 'tagId' }
277
+ * ```
278
+ */
279
+ toParamsObject(replacer) {
280
+ const params = {};
281
+ this.#eachParam((_raw, param) => {
282
+ const key = replacer ? replacer(param) : param;
283
+ params[key] = key;
284
+ });
285
+ return Object.keys(params).length > 0 ? params : null;
286
+ }
287
+ /** Converts the OpenAPI path to Express-style colon syntax.
288
+ *
289
+ * @example
290
+ * ```ts
291
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
292
+ * ```
293
+ */
294
+ toURLPath() {
295
+ return this.path.replace(/\{([^}]+)\}/g, ":$1");
296
+ }
297
+ };
298
+ //#endregion
299
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
300
+ const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
301
+ const mutationKeyTransformer = ({ node, casing }) => {
302
+ if (!node.path) return [];
303
+ return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
304
+ };
305
+ function MutationKey$1({ name, paramsCasing, node, transformer }) {
306
+ const paramsNode = ast.createFunctionParameters({ params: [] });
307
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
308
+ const keys = (transformer ?? mutationKeyTransformer)({
309
+ node,
310
+ casing: paramsCasing
311
+ });
312
+ return /* @__PURE__ */ jsx(File.Source, {
313
+ name,
314
+ isExportable: true,
315
+ isIndexable: true,
316
+ children: /* @__PURE__ */ jsx(Function.Arrow, {
317
+ name,
318
+ export: true,
319
+ params: paramsSignature,
320
+ singleLine: true,
321
+ children: `[${keys.join(", ")}] as const`
322
+ })
323
+ });
324
+ }
325
+ __name(MutationKey$1, "MutationKey");
326
+ //#endregion
327
+ //#region ../../internals/shared/src/operation.ts
328
+ function getOperationLink(node, link) {
329
+ if (!link) return null;
330
+ if (typeof link === "function") return link(node) ?? null;
331
+ if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
332
+ return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
333
+ }
334
+ function getContentTypeInfo(node) {
335
+ const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
336
+ const isMultipleContentTypes = contentTypes.length > 1;
337
+ return {
338
+ contentTypes,
339
+ isMultipleContentTypes,
340
+ contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
341
+ defaultContentType: contentTypes[0] ?? "application/json",
342
+ hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
343
+ };
344
+ }
345
+ function buildRequestConfigType(node, resolver) {
346
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
347
+ const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
348
+ return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
349
+ }
350
+ function buildOperationComments(node, options = {}) {
351
+ const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
352
+ const linkComment = getOperationLink(node, link);
353
+ const filteredComments = (linkPosition === "beforeDeprecated" ? [
354
+ node.description && `@description ${node.description}`,
355
+ node.summary && `@summary ${node.summary}`,
356
+ linkComment,
357
+ node.deprecated && "@deprecated"
358
+ ] : [
359
+ node.description && `@description ${node.description}`,
360
+ node.summary && `@summary ${node.summary}`,
361
+ node.deprecated && "@deprecated",
362
+ linkComment
363
+ ]).filter((comment) => Boolean(comment));
364
+ if (!splitLines) return filteredComments;
365
+ return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
366
+ }
367
+ function getOperationParameters(node, options = {}) {
368
+ const params = ast.caseParams(node.parameters, options.paramsCasing);
369
+ return {
370
+ path: params.filter((param) => param.in === "path"),
371
+ query: params.filter((param) => param.in === "query"),
372
+ header: params.filter((param) => param.in === "header"),
373
+ cookie: params.filter((param) => param.in === "cookie")
374
+ };
375
+ }
376
+ function getStatusCodeNumber(statusCode) {
377
+ const code = Number(statusCode);
378
+ return Number.isNaN(code) ? null : code;
379
+ }
380
+ function isErrorStatusCode(statusCode) {
381
+ const code = getStatusCodeNumber(statusCode);
382
+ return code !== null && code >= 400;
383
+ }
384
+ function resolveErrorNames(node, resolver) {
385
+ return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
386
+ }
387
+ function resolveStatusCodeNames(node, resolver) {
388
+ return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
389
+ }
390
+ const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
391
+ function resolveOperationTypeNames(node, resolver, options = {}) {
392
+ const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
393
+ let byResolver = typeNamesByResolver.get(resolver);
394
+ if (byResolver) {
395
+ const cached = byResolver.get(cacheKey);
396
+ if (cached) return cached;
397
+ } else {
398
+ byResolver = /* @__PURE__ */ new Map();
399
+ typeNamesByResolver.set(resolver, byResolver);
400
+ }
401
+ const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
402
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
403
+ const exclude = new Set(options.exclude ?? []);
404
+ const paramNames = [
405
+ ...path.map((param) => resolver.resolvePathParamsName(node, param)),
406
+ ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
407
+ ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
408
+ ];
409
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
410
+ const result = (options.order === "body-response-first" ? [
411
+ ...bodyAndResponseNames,
412
+ ...paramNames,
413
+ ...responseStatusNames
414
+ ] : [
415
+ ...paramNames,
416
+ ...bodyAndResponseNames,
417
+ ...responseStatusNames
418
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
419
+ byResolver.set(cacheKey, result);
420
+ return result;
421
+ }
422
+ //#endregion
423
+ //#region ../../internals/tanstack-query/src/utils.ts
424
+ /**
425
+ * Collects the Zod schema import names for an operation (response + request body).
426
+ *
427
+ * Returns an empty array when no resolver is provided or the operation has no request body schema.
428
+ */
429
+ function resolveZodSchemaNames(node, zodResolver) {
430
+ if (!zodResolver) return [];
431
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
432
+ }
433
+ /**
434
+ * Resolve the type for a single path parameter.
435
+ *
436
+ * - When the resolver's group name differs from the individual param name
437
+ * (e.g. kubbV4) → `GroupName['paramName']` (member access).
438
+ * - When they match (v5 default) → `TypeName` (direct reference).
439
+ */
440
+ function resolvePathParamType(node, param, resolver) {
441
+ const individualName = resolver.resolveParamName(node, param);
442
+ const groupName = resolver.resolvePathParamsName(node, param);
443
+ if (groupName !== individualName) return ast.createParamsType({
444
+ variant: "member",
445
+ base: groupName,
446
+ key: param.name
447
+ });
448
+ return ast.createParamsType({
449
+ variant: "reference",
450
+ name: individualName
451
+ });
452
+ }
453
+ /**
454
+ * Derive a query-params group type from the resolver.
455
+ * Returns `null` when no query params exist or when the group name
456
+ * equals the individual param name (no real group).
457
+ */
458
+ function resolveQueryGroupType(node, params, resolver) {
459
+ if (!params.length) return null;
460
+ const firstParam = params[0];
461
+ const groupName = resolver.resolveQueryParamsName(node, firstParam);
462
+ if (groupName === resolver.resolveParamName(node, firstParam)) return null;
463
+ return {
464
+ type: ast.createParamsType({
465
+ variant: "reference",
466
+ name: groupName
467
+ }),
468
+ optional: params.every((p) => !p.required)
469
+ };
470
+ }
471
+ /**
472
+ * Build a single `FunctionParameterNode` for a query or header group.
473
+ */
474
+ function buildGroupParam(name, node, params, groupType, resolver) {
475
+ if (groupType) return [ast.createFunctionParameter({
476
+ name,
477
+ type: groupType.type,
478
+ optional: groupType.optional
479
+ })];
480
+ if (params.length) {
481
+ const structProps = params.map((p) => ({
482
+ name: p.name,
483
+ type: ast.createParamsType({
484
+ variant: "reference",
485
+ name: resolver.resolveParamName(node, p)
486
+ }),
487
+ optional: !p.required
488
+ }));
489
+ return [ast.createFunctionParameter({
490
+ name,
491
+ type: ast.createParamsType({
492
+ variant: "struct",
493
+ properties: structProps
494
+ }),
495
+ optional: params.every((p) => !p.required)
496
+ })];
497
+ }
498
+ return [];
499
+ }
500
+ /**
501
+ * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
502
+ */
503
+ function buildQueryKeyParams(node, options) {
504
+ const { pathParamsType, paramsCasing, resolver } = options;
505
+ const casedParams = ast.caseParams(node.parameters, paramsCasing);
506
+ const pathParams = casedParams.filter((p) => p.in === "path");
507
+ const queryParams = casedParams.filter((p) => p.in === "query");
508
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
509
+ const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
510
+ variant: "reference",
511
+ name: resolver.resolveDataName(node)
512
+ }) : null;
513
+ const bodyRequired = node.requestBody?.required ?? false;
514
+ const params = [];
515
+ if (pathParams.length) {
516
+ const pathChildren = pathParams.map((p) => ast.createFunctionParameter({
517
+ name: p.name,
518
+ type: resolvePathParamType(node, p, resolver),
519
+ optional: !p.required
520
+ }));
521
+ params.push({
522
+ kind: "ParameterGroup",
523
+ properties: pathChildren,
524
+ inline: pathParamsType === "inline",
525
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
526
+ });
527
+ }
528
+ if (bodyType) params.push(ast.createFunctionParameter({
529
+ name: "data",
530
+ type: bodyType,
531
+ optional: !bodyRequired
532
+ }));
533
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
534
+ return ast.createFunctionParameters({ params });
535
+ }
536
+ /**
537
+ * Collect the names of the required params (no default) that drive the `enabled`
538
+ * guard. These are exactly the params that should be made optional in the
539
+ * generated signatures so callers can pass `undefined` to reach the disabled state.
540
+ */
541
+ function getEnabledParamNames(paramsNode) {
542
+ const required = [];
543
+ for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
544
+ const group = param;
545
+ for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
546
+ } else {
547
+ const fp = param;
548
+ if (!fp.optional && fp.default === void 0) required.push(fp.name);
549
+ }
550
+ return required;
551
+ }
552
+ /**
553
+ * Return a copy of `paramsNode` with the named params marked optional.
554
+ *
555
+ * Used to align signatures with the `enabled` guard: the guard already disables
556
+ * the query while a param is falsy, so the param should accept `undefined`. The
557
+ * change is type-only — the `queryFn` keeps calling the client with a non-null
558
+ * assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
559
+ */
560
+ function markParamsOptional(paramsNode, names) {
561
+ if (names.length === 0) return paramsNode;
562
+ const nameSet = new Set(names);
563
+ const params = paramsNode.params.map((param) => {
564
+ if ("kind" in param && param.kind === "ParameterGroup") {
565
+ const group = param;
566
+ return {
567
+ ...group,
568
+ properties: group.properties.map((child) => nameSet.has(child.name) ? ast.createFunctionParameter({
569
+ name: child.name,
570
+ type: child.type,
571
+ rest: child.rest,
572
+ optional: true
573
+ }) : child)
574
+ };
575
+ }
576
+ const fp = param;
577
+ return nameSet.has(fp.name) ? ast.createFunctionParameter({
578
+ name: fp.name,
579
+ type: fp.type,
580
+ rest: fp.rest,
581
+ optional: true
582
+ }) : fp;
583
+ });
584
+ return ast.createFunctionParameters({ params });
585
+ }
586
+ /**
587
+ * Add a non-null assertion (`!`) to the named params inside a printed client-call
588
+ * string. Bridges the type gap created by `markParamsOptional` while keeping the
589
+ * runtime identical (the `!` is erased at compile time).
590
+ *
591
+ * Handles destructured shorthand groups (`{ petId }` → `{ petId: petId! }`) and
592
+ * standalone identifiers (`params` → `params!`).
593
+ */
594
+ function injectNonNullAssertions(callStr, names) {
595
+ if (names.length === 0) return callStr;
596
+ const nameSet = new Set(names);
597
+ let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
598
+ if (inner.includes(":") || inner.includes("...")) return match;
599
+ const keys = inner.split(",").map((k) => k.trim()).filter(Boolean);
600
+ if (!keys.some((k) => nameSet.has(k))) return match;
601
+ return `{ ${keys.map((k) => nameSet.has(k) ? `${k}: ${k}!` : k).join(", ")} }`;
602
+ });
603
+ result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => nameSet.has(name) ? `${name}!` : match);
604
+ return result;
605
+ }
606
+ //#endregion
607
+ //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
608
+ const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
609
+ const queryKeyTransformer = ({ node, casing }) => {
610
+ if (!node.path) return [];
611
+ const path = new URLPath(node.path, { casing });
612
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
613
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
614
+ return [
615
+ path.toObject({
616
+ type: "path",
617
+ stringify: true
618
+ }),
619
+ hasQueryParams ? "...(params ? [params] : [])" : null,
620
+ hasRequestBody ? "...(data ? [data] : [])" : null
621
+ ].filter(Boolean);
622
+ };
623
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
624
+ const baseParamsNode = buildQueryKeyParams(node, {
625
+ pathParamsType,
626
+ paramsCasing,
627
+ resolver: tsResolver
628
+ });
629
+ const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
630
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
631
+ const keys = (transformer ?? queryKeyTransformer)({
632
+ node,
633
+ casing: paramsCasing
634
+ });
635
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
636
+ name,
637
+ isExportable: true,
638
+ isIndexable: true,
639
+ children: /* @__PURE__ */ jsx(Function.Arrow, {
640
+ name,
641
+ export: true,
642
+ params: paramsSignature,
643
+ singleLine: true,
644
+ children: `[${keys.join(", ")}] as const`
645
+ })
646
+ }), /* @__PURE__ */ jsx(File.Source, {
647
+ name: typeName,
648
+ isTypeOnly: true,
649
+ children: /* @__PURE__ */ jsx(Type, {
650
+ name: typeName,
651
+ children: `ReturnType<typeof ${name}>`
652
+ })
653
+ })] });
654
+ }
655
+ //#endregion
656
+ //#region src/components/Mutation.tsx
657
+ const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
658
+ const callPrinter$2 = functionPrinter({ mode: "call" });
659
+ const keysPrinter = functionPrinter({ mode: "keys" });
660
+ function createMutationArgParams(node, options) {
661
+ return ast.createOperationParams(node, {
662
+ paramsType: "inline",
663
+ pathParamsType: "inline",
664
+ paramsCasing: options.paramsCasing,
665
+ resolver: options.resolver
666
+ });
667
+ }
668
+ function buildMutationParamsNode(node, options) {
669
+ const { dataReturnType, mutationKeyTypeName, mutationArgTypeName, resolver } = options;
670
+ const responseName = resolver.resolveResponseName(node);
671
+ const errorNames = resolveErrorNames(node, resolver);
672
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
673
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
674
+ return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
675
+ name: "options",
676
+ type: ast.createParamsType({
677
+ variant: "reference",
678
+ name: `{
679
+ mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
680
+ client?: ${buildRequestConfigType(node, resolver)},
681
+ shouldFetch?: boolean,
682
+ }`
683
+ }),
684
+ default: "{}"
685
+ })] });
686
+ }
687
+ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver }) {
688
+ const responseName = tsResolver.resolveResponseName(node);
689
+ const errorNames = resolveErrorNames(node, tsResolver);
690
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
691
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
692
+ const mutationArgParamsNode = createMutationArgParams(node, {
693
+ paramsCasing,
694
+ resolver: tsResolver
695
+ });
696
+ const hasMutationParams = mutationArgParamsNode.params.length > 0;
697
+ const argTypeBody = hasMutationParams ? declarationPrinter$2.print(mutationArgParamsNode) ?? "" : "";
698
+ const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
699
+ const generics = [
700
+ TData,
701
+ TError,
702
+ `${mutationKeyTypeName} | null`,
703
+ mutationArgTypeName
704
+ ];
705
+ const paramsNode = buildMutationParamsNode(node, {
706
+ paramsCasing,
707
+ dataReturnType,
708
+ mutationKeyTypeName,
709
+ mutationArgTypeName,
710
+ resolver: tsResolver
711
+ });
712
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
713
+ const clientCallParamsNode = ast.createOperationParams(node, {
714
+ paramsType,
715
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
716
+ paramsCasing,
717
+ resolver: tsResolver,
718
+ extraParams: [ast.createFunctionParameter({
719
+ name: "config",
720
+ type: ast.createParamsType({
721
+ variant: "reference",
722
+ name: buildRequestConfigType(node, tsResolver)
723
+ }),
724
+ default: "{}"
725
+ })]
726
+ });
727
+ const clientCallStr = callPrinter$2.print(clientCallParamsNode) ?? "";
728
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
729
+ name: mutationArgTypeName,
730
+ isExportable: true,
731
+ isIndexable: true,
732
+ isTypeOnly: true,
733
+ children: /* @__PURE__ */ jsx(Type, {
734
+ name: mutationArgTypeName,
735
+ export: true,
736
+ children: hasMutationParams ? `{ ${argTypeBody} }` : "never"
737
+ })
738
+ }), /* @__PURE__ */ jsx(File.Source, {
739
+ name,
740
+ isExportable: true,
741
+ isIndexable: true,
742
+ children: /* @__PURE__ */ jsx(Function, {
743
+ name,
744
+ export: true,
745
+ params: paramsSignature,
746
+ JSDoc: { comments: buildOperationComments(node) },
747
+ children: `
748
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
749
+ const mutationKey = ${mutationKeyName}()
750
+
751
+ return useSWRMutation<${generics.join(", ")}>(
752
+ shouldFetch ? mutationKey : null,
753
+ async (_url${hasMutationParams ? `, { arg: { ${argKeysStr} } }` : ""}) => {
754
+ return ${clientName}(${clientCallStr})
755
+ },
756
+ mutationOptions
757
+ )
758
+ `
759
+ })
760
+ })] });
761
+ }
762
+ //#endregion
763
+ //#region src/components/MutationKey.tsx
764
+ function MutationKey({ name, typeName, node, paramsCasing, pathParamsType, transformer }) {
765
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MutationKey$1, {
766
+ name,
767
+ node,
768
+ paramsCasing,
769
+ pathParamsType,
770
+ transformer
771
+ }), /* @__PURE__ */ jsx(File.Source, {
772
+ name: typeName,
773
+ isExportable: true,
774
+ isIndexable: true,
775
+ isTypeOnly: true,
776
+ children: /* @__PURE__ */ jsx(Type, {
777
+ export: true,
778
+ name: typeName,
779
+ children: `ReturnType<typeof ${name}>`
780
+ })
781
+ })] });
782
+ }
783
+ //#endregion
784
+ //#region src/components/QueryOptions.tsx
785
+ const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
786
+ const callPrinter$1 = functionPrinter({ mode: "call" });
787
+ function getQueryOptionsParams(node, options) {
788
+ const { paramsType, paramsCasing, pathParamsType, resolver } = options;
789
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
790
+ return ast.createOperationParams(node, {
791
+ paramsType,
792
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
793
+ paramsCasing,
794
+ resolver,
795
+ extraParams: [ast.createFunctionParameter({
796
+ name: "config",
797
+ type: ast.createParamsType({
798
+ variant: "reference",
799
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
800
+ }),
801
+ default: "{}"
802
+ })]
803
+ });
804
+ }
805
+ function QueryOptions({ name, clientName, node, tsResolver, paramsCasing, paramsType, pathParamsType }) {
806
+ const enabledNames = getEnabledParamNames(buildQueryKeyParams(node, {
807
+ pathParamsType,
808
+ paramsCasing,
809
+ resolver: tsResolver
810
+ }));
811
+ const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
812
+ paramsType,
813
+ paramsCasing,
814
+ pathParamsType,
815
+ resolver: tsResolver
816
+ }), enabledNames);
817
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
818
+ const clientCallStr = injectNonNullAssertions(callPrinter$1.print(paramsNode) ?? "", enabledNames);
819
+ return /* @__PURE__ */ jsx(File.Source, {
820
+ name,
821
+ isExportable: true,
822
+ isIndexable: true,
823
+ children: /* @__PURE__ */ jsx(Function, {
824
+ name,
825
+ export: true,
826
+ params: paramsSignature,
827
+ children: `
828
+ return {
829
+ fetcher: async () => {
830
+ return ${clientName}(${clientCallStr})
831
+ },
832
+ }
833
+ `
834
+ })
835
+ });
836
+ }
837
+ //#endregion
838
+ //#region src/components/Query.tsx
839
+ const declarationPrinter = functionPrinter({ mode: "declaration" });
840
+ const callPrinter = functionPrinter({ mode: "call" });
841
+ function buildQueryParamsNode(node, options) {
842
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
843
+ const responseName = resolver.resolveResponseName(node);
844
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
845
+ const errorNames = resolveErrorNames(node, resolver);
846
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
847
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
848
+ const optionsParam = ast.createFunctionParameter({
849
+ name: "options",
850
+ type: ast.createParamsType({
851
+ variant: "reference",
852
+ name: `{
853
+ query?: SWRConfiguration<${[TData, TError].join(", ")}>,
854
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
855
+ shouldFetch?: boolean,
856
+ immutable?: boolean
857
+ }`
858
+ }),
859
+ default: "{}"
860
+ });
861
+ return ast.createOperationParams(node, {
862
+ paramsType,
863
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
864
+ paramsCasing,
865
+ resolver,
866
+ extraParams: [optionsParam]
867
+ });
868
+ }
869
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
870
+ const responseName = tsResolver.resolveResponseName(node);
871
+ const errorNames = resolveErrorNames(node, tsResolver);
872
+ const generics = [
873
+ dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`,
874
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
875
+ `${queryKeyTypeName} | null`
876
+ ];
877
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
878
+ pathParamsType,
879
+ paramsCasing,
880
+ resolver: tsResolver
881
+ });
882
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
883
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
884
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
885
+ paramsType,
886
+ paramsCasing,
887
+ pathParamsType,
888
+ resolver: tsResolver
889
+ });
890
+ const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
891
+ const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
892
+ paramsType,
893
+ paramsCasing,
894
+ pathParamsType,
895
+ dataReturnType,
896
+ resolver: tsResolver
897
+ }), enabledNames);
898
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
899
+ const shouldFetchExpr = enabledNames.length ? `shouldFetch && !!(${enabledNames.join(" && ")})` : "shouldFetch";
900
+ return /* @__PURE__ */ jsx(File.Source, {
901
+ name,
902
+ isExportable: true,
903
+ isIndexable: true,
904
+ children: /* @__PURE__ */ jsx(Function, {
905
+ name,
906
+ export: true,
907
+ params: paramsSignature,
908
+ JSDoc: { comments: buildOperationComments(node) },
909
+ children: `
910
+ const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
911
+
912
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
913
+
914
+ return useSWR<${generics.join(", ")}>(
915
+ ${shouldFetchExpr} ? queryKey : null,
916
+ {
917
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
918
+ ...(immutable ? {
919
+ revalidateIfStale: false,
920
+ revalidateOnFocus: false,
921
+ revalidateOnReconnect: false
922
+ } : { }),
923
+ ...queryOptions,
924
+ }
925
+ )
926
+ `
927
+ })
928
+ });
929
+ }
930
+ //#endregion
931
+ export { QueryKey as a, resolveOperationTypeNames as c, Mutation as i, mutationKeyTransformer as l, QueryOptions as n, queryKeyTransformer as o, MutationKey as r, resolveZodSchemaNames as s, Query as t, camelCase as u };
932
+
933
+ //# sourceMappingURL=components-CBdpiiay.js.map