@kubb/plugin-swr 5.0.0-alpha.33 → 5.0.0-alpha.35

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 (41) hide show
  1. package/dist/components-BJSzUg7M.cjs +955 -0
  2. package/dist/components-BJSzUg7M.cjs.map +1 -0
  3. package/dist/components-JQ2KRFCa.js +877 -0
  4. package/dist/components-JQ2KRFCa.js.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.ts +77 -37
  7. package/dist/components.js +1 -1
  8. package/dist/generators-17ulS9mu.cjs +537 -0
  9. package/dist/generators-17ulS9mu.cjs.map +1 -0
  10. package/dist/generators-Cl7nr-FB.js +526 -0
  11. package/dist/generators-Cl7nr-FB.js.map +1 -0
  12. package/dist/generators.cjs +1 -1
  13. package/dist/generators.d.ts +4 -4
  14. package/dist/generators.js +1 -1
  15. package/dist/index.cjs +132 -110
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +22 -2
  18. package/dist/index.js +132 -110
  19. package/dist/index.js.map +1 -1
  20. package/dist/{types-BVDtH9S7.d.ts → types-FA5mH9Ch.d.ts} +46 -90
  21. package/package.json +7 -11
  22. package/src/components/Mutation.tsx +165 -170
  23. package/src/components/MutationKey.tsx +50 -1
  24. package/src/components/Query.tsx +122 -126
  25. package/src/components/QueryKey.tsx +65 -1
  26. package/src/components/QueryOptions.tsx +38 -93
  27. package/src/generators/mutationGenerator.tsx +194 -117
  28. package/src/generators/queryGenerator.tsx +205 -139
  29. package/src/plugin.ts +117 -152
  30. package/src/resolvers/resolverSwr.ts +26 -0
  31. package/src/resolvers/resolverSwrLegacy.ts +17 -0
  32. package/src/types.ts +55 -18
  33. package/src/utils.ts +209 -0
  34. package/dist/components-DaCTPplv.js +0 -756
  35. package/dist/components-DaCTPplv.js.map +0 -1
  36. package/dist/components-Qs8_faOt.cjs +0 -834
  37. package/dist/components-Qs8_faOt.cjs.map +0 -1
  38. package/dist/generators-0YayIrse.js +0 -400
  39. package/dist/generators-0YayIrse.js.map +0 -1
  40. package/dist/generators-Bd4rCa3l.cjs +0 -411
  41. package/dist/generators-Bd4rCa3l.cjs.map +0 -1
@@ -0,0 +1,877 @@
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 as Function$1, 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
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * isValidVarName('status') // true
56
+ * isValidVarName('class') // false (reserved word)
57
+ * isValidVarName('42foo') // false (starts with digit)
58
+ * ```
59
+ */
60
+ function isValidVarName(name) {
61
+ try {
62
+ new Function(`var ${name}`);
63
+ } catch {
64
+ return false;
65
+ }
66
+ return true;
67
+ }
68
+ //#endregion
69
+ //#region ../../internals/utils/src/urlPath.ts
70
+ /**
71
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
72
+ *
73
+ * @example
74
+ * const p = new URLPath('/pet/{petId}')
75
+ * p.URL // '/pet/:petId'
76
+ * p.template // '`/pet/${petId}`'
77
+ */
78
+ var URLPath = class {
79
+ /**
80
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
81
+ */
82
+ path;
83
+ #options;
84
+ constructor(path, options = {}) {
85
+ this.path = path;
86
+ this.#options = options;
87
+ }
88
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
93
+ * ```
94
+ */
95
+ get URL() {
96
+ return this.toURLPath();
97
+ }
98
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
103
+ * new URLPath('/pet/{petId}').isURL // false
104
+ * ```
105
+ */
106
+ get isURL() {
107
+ try {
108
+ return !!new URL(this.path).href;
109
+ } catch {
110
+ return false;
111
+ }
112
+ }
113
+ /**
114
+ * Converts the OpenAPI path to a TypeScript template literal string.
115
+ *
116
+ * @example
117
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
118
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
119
+ */
120
+ get template() {
121
+ return this.toTemplateString();
122
+ }
123
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * new URLPath('/pet/{petId}').object
128
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
129
+ * ```
130
+ */
131
+ get object() {
132
+ return this.toObject();
133
+ }
134
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
139
+ * new URLPath('/pet').params // undefined
140
+ * ```
141
+ */
142
+ get params() {
143
+ return this.getParams();
144
+ }
145
+ #transformParam(raw) {
146
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
147
+ return this.#options.casing === "camelcase" ? camelCase(param) : param;
148
+ }
149
+ /**
150
+ * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
151
+ */
152
+ #eachParam(fn) {
153
+ for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
154
+ const raw = match[1];
155
+ fn(raw, this.#transformParam(raw));
156
+ }
157
+ }
158
+ toObject({ type = "path", replacer, stringify } = {}) {
159
+ const object = {
160
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
161
+ params: this.getParams()
162
+ };
163
+ if (stringify) {
164
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
165
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
166
+ return `{ url: '${object.url}' }`;
167
+ }
168
+ return object;
169
+ }
170
+ /**
171
+ * Converts the OpenAPI path to a TypeScript template literal string.
172
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
173
+ *
174
+ * @example
175
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
176
+ */
177
+ toTemplateString({ prefix = "", replacer } = {}) {
178
+ return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
179
+ if (i % 2 === 0) return part;
180
+ const param = this.#transformParam(part);
181
+ return `\${${replacer ? replacer(param) : param}}`;
182
+ }).join("")}\``;
183
+ }
184
+ /**
185
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
186
+ * An optional `replacer` transforms each parameter name in both key and value positions.
187
+ * Returns `undefined` when no path parameters are found.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * new URLPath('/pet/{petId}/tag/{tagId}').getParams()
192
+ * // { petId: 'petId', tagId: 'tagId' }
193
+ * ```
194
+ */
195
+ getParams(replacer) {
196
+ const params = {};
197
+ this.#eachParam((_raw, param) => {
198
+ const key = replacer ? replacer(param) : param;
199
+ params[key] = key;
200
+ });
201
+ return Object.keys(params).length > 0 ? params : void 0;
202
+ }
203
+ /** Converts the OpenAPI path to Express-style colon syntax.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
208
+ * ```
209
+ */
210
+ toURLPath() {
211
+ return this.path.replace(/\{([^}]+)\}/g, ":$1");
212
+ }
213
+ };
214
+ //#endregion
215
+ //#region src/utils.ts
216
+ /**
217
+ * Apply the user-provided `transformers.name` function (if any) to a resolved name.
218
+ * Mirrors the old `createPlugin` `resolveName` lifecycle that applied transformers
219
+ * after resolving the full name (base + suffix).
220
+ */
221
+ function transformName(name, type, transformers) {
222
+ return transformers?.name?.(name, type) || name;
223
+ }
224
+ /**
225
+ * Build JSDoc comment lines from an OperationNode.
226
+ */
227
+ function getComments(node) {
228
+ return [
229
+ node.description && `@description ${node.description}`,
230
+ node.summary && `@summary ${node.summary}`,
231
+ node.deprecated && "@deprecated",
232
+ `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`
233
+ ].filter((x) => Boolean(x));
234
+ }
235
+ /**
236
+ * Resolve error type names from operation responses.
237
+ */
238
+ function resolveErrorNames(node, tsResolver) {
239
+ return node.responses.filter((r) => {
240
+ return Number.parseInt(r.statusCode, 10) >= 400 || r.statusCode === "default";
241
+ }).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
242
+ }
243
+ /**
244
+ * Resolve the type for a single path parameter.
245
+ *
246
+ * - When the resolver's group name differs from the individual param name
247
+ * (e.g. kubbV4) → `GroupName['paramName']` (member access).
248
+ * - When they match (v5 default) → `TypeName` (direct reference).
249
+ */
250
+ function resolvePathParamType(node, param, resolver) {
251
+ const individualName = resolver.resolveParamName(node, param);
252
+ const groupName = resolver.resolvePathParamsName(node, param);
253
+ if (groupName !== individualName) return ast.createParamsType({
254
+ variant: "member",
255
+ base: groupName,
256
+ key: param.name
257
+ });
258
+ return ast.createParamsType({
259
+ variant: "reference",
260
+ name: individualName
261
+ });
262
+ }
263
+ /**
264
+ * Derive a query-params group type from the resolver.
265
+ * Returns `undefined` when no query params exist or when the group name
266
+ * equals the individual param name (no real group).
267
+ */
268
+ function resolveQueryGroupType(node, params, resolver) {
269
+ if (!params.length) return void 0;
270
+ const firstParam = params[0];
271
+ const groupName = resolver.resolveQueryParamsName(node, firstParam);
272
+ if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
273
+ return {
274
+ type: ast.createParamsType({
275
+ variant: "reference",
276
+ name: groupName
277
+ }),
278
+ optional: params.every((p) => !p.required)
279
+ };
280
+ }
281
+ /**
282
+ * Derive a header-params group type from the resolver.
283
+ */
284
+ function resolveHeaderGroupType(node, params, resolver) {
285
+ if (!params.length) return void 0;
286
+ const firstParam = params[0];
287
+ const groupName = resolver.resolveHeaderParamsName(node, firstParam);
288
+ if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
289
+ return {
290
+ type: ast.createParamsType({
291
+ variant: "reference",
292
+ name: groupName
293
+ }),
294
+ optional: params.every((p) => !p.required)
295
+ };
296
+ }
297
+ /**
298
+ * Build a single `FunctionParameterNode` for a query or header group.
299
+ */
300
+ function buildGroupParam(name, node, params, groupType, resolver) {
301
+ if (groupType) return [ast.createFunctionParameter({
302
+ name,
303
+ type: groupType.type,
304
+ optional: groupType.optional
305
+ })];
306
+ if (params.length) {
307
+ const structProps = params.map((p) => ({
308
+ name: p.name,
309
+ type: ast.createParamsType({
310
+ variant: "reference",
311
+ name: resolver.resolveParamName(node, p)
312
+ }),
313
+ optional: !p.required
314
+ }));
315
+ return [ast.createFunctionParameter({
316
+ name,
317
+ type: ast.createParamsType({
318
+ variant: "struct",
319
+ properties: structProps
320
+ }),
321
+ optional: params.every((p) => !p.required)
322
+ })];
323
+ }
324
+ return [];
325
+ }
326
+ /**
327
+ * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
328
+ */
329
+ function buildQueryKeyParams(node, options) {
330
+ const { pathParamsType, paramsCasing, resolver } = options;
331
+ const casedParams = ast.caseParams(node.parameters, paramsCasing);
332
+ const pathParams = casedParams.filter((p) => p.in === "path");
333
+ const queryParams = casedParams.filter((p) => p.in === "query");
334
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
335
+ const bodyType = node.requestBody?.schema ? ast.createParamsType({
336
+ variant: "reference",
337
+ name: resolver.resolveDataName(node)
338
+ }) : void 0;
339
+ const bodyRequired = node.requestBody?.required ?? false;
340
+ const params = [];
341
+ if (pathParams.length) {
342
+ const pathChildren = pathParams.map((p) => ast.createFunctionParameter({
343
+ name: p.name,
344
+ type: resolvePathParamType(node, p, resolver),
345
+ optional: !p.required
346
+ }));
347
+ params.push({
348
+ kind: "ParameterGroup",
349
+ properties: pathChildren,
350
+ inline: pathParamsType === "inline",
351
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
352
+ });
353
+ }
354
+ if (bodyType) params.push(ast.createFunctionParameter({
355
+ name: "data",
356
+ type: bodyType,
357
+ optional: !bodyRequired
358
+ }));
359
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
360
+ return ast.createFunctionParameters({ params });
361
+ }
362
+ /**
363
+ * Build mutation arg params for paramsToTrigger mode.
364
+ * Contains pathParams + data + queryParams + headers (all flattened, for type alias).
365
+ */
366
+ function buildMutationArgParams(node, options) {
367
+ const { paramsCasing, resolver } = options;
368
+ const casedParams = ast.caseParams(node.parameters, paramsCasing);
369
+ const pathParams = casedParams.filter((p) => p.in === "path");
370
+ const queryParams = casedParams.filter((p) => p.in === "query");
371
+ const headerParams = casedParams.filter((p) => p.in === "header");
372
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
373
+ const headerGroupType = resolveHeaderGroupType(node, headerParams, resolver);
374
+ const bodyType = node.requestBody?.schema ? ast.createParamsType({
375
+ variant: "reference",
376
+ name: resolver.resolveDataName(node)
377
+ }) : void 0;
378
+ const bodyRequired = node.requestBody?.required ?? false;
379
+ const params = [];
380
+ for (const p of pathParams) params.push(ast.createFunctionParameter({
381
+ name: p.name,
382
+ type: resolvePathParamType(node, p, resolver),
383
+ optional: !p.required
384
+ }));
385
+ if (bodyType) params.push(ast.createFunctionParameter({
386
+ name: "data",
387
+ type: bodyType,
388
+ optional: !bodyRequired
389
+ }));
390
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
391
+ params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
392
+ return ast.createFunctionParameters({ params });
393
+ }
394
+ //#endregion
395
+ //#region src/components/Mutation.tsx
396
+ const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
397
+ const callPrinter$3 = functionPrinter({ mode: "call" });
398
+ const keysPrinter = functionPrinter({ mode: "keys" });
399
+ /**
400
+ * Default mutation hook params (paramsToTrigger=false):
401
+ * pathParams + queryParams + headers + options (NO data — it comes via useSWRMutation arg)
402
+ */
403
+ function getParams$3(node, options) {
404
+ const { paramsCasing, pathParamsType, dataReturnType, resolver, mutationKeyTypeName } = options;
405
+ const responseName = resolver.resolveResponseName(node);
406
+ const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
407
+ const errorNames = resolveErrorNames(node, resolver);
408
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
409
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
410
+ const TExtraArg = requestName || "never";
411
+ const casedParams = ast.caseParams(node.parameters, paramsCasing);
412
+ const pathParams = casedParams.filter((p) => p.in === "path");
413
+ const queryParams = casedParams.filter((p) => p.in === "query");
414
+ const headerParams = casedParams.filter((p) => p.in === "header");
415
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
416
+ const headerGroupType = resolveHeaderGroupType(node, headerParams, resolver);
417
+ const params = [];
418
+ if (pathParams.length) {
419
+ const pathChildren = pathParams.map((p) => ast.createFunctionParameter({
420
+ name: p.name,
421
+ type: resolvePathParamType(node, p, resolver),
422
+ optional: !p.required
423
+ }));
424
+ params.push({
425
+ kind: "ParameterGroup",
426
+ properties: pathChildren,
427
+ inline: pathParamsType === "inline",
428
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
429
+ });
430
+ }
431
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
432
+ params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
433
+ params.push(ast.createFunctionParameter({
434
+ name: "options",
435
+ type: ast.createParamsType({
436
+ variant: "reference",
437
+ name: `{
438
+ mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${TExtraArg}> & { throwOnError?: boolean },
439
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
440
+ shouldFetch?: boolean,
441
+ }`
442
+ }),
443
+ default: "{}"
444
+ }));
445
+ return ast.createFunctionParameters({ params });
446
+ }
447
+ __name(getParams$3, "getParams");
448
+ /**
449
+ * Trigger-mode params (paramsToTrigger=true): just `options`
450
+ */
451
+ function getTriggerParams(node, options) {
452
+ const { dataReturnType, resolver, mutationKeyTypeName, mutationArgTypeName } = options;
453
+ const responseName = resolver.resolveResponseName(node);
454
+ const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
455
+ const errorNames = resolveErrorNames(node, resolver);
456
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
457
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
458
+ return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
459
+ name: "options",
460
+ type: ast.createParamsType({
461
+ variant: "reference",
462
+ name: `{
463
+ mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
464
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
465
+ shouldFetch?: boolean,
466
+ }`
467
+ }),
468
+ default: "{}"
469
+ })] });
470
+ }
471
+ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, paramsToTrigger = false }) {
472
+ const responseName = tsResolver.resolveResponseName(node);
473
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
474
+ const errorNames = resolveErrorNames(node, tsResolver);
475
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
476
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
477
+ const clientCallParamsNode = ast.createOperationParams(node, {
478
+ paramsType,
479
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
480
+ paramsCasing,
481
+ resolver: tsResolver,
482
+ extraParams: [ast.createFunctionParameter({
483
+ name: "config",
484
+ type: ast.createParamsType({
485
+ variant: "reference",
486
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
487
+ }),
488
+ default: "{}"
489
+ })]
490
+ });
491
+ const clientCallStr = callPrinter$3.print(clientCallParamsNode) ?? "";
492
+ if (paramsToTrigger) {
493
+ const mutationArgTypeName = `${mutationKeyTypeName.replace("MutationKey", "")}MutationArg`;
494
+ const mutationArgParamsNode = buildMutationArgParams(node, {
495
+ paramsCasing,
496
+ resolver: tsResolver
497
+ });
498
+ const hasMutationParams = mutationArgParamsNode.params.length > 0;
499
+ const mutationArgDeclaration = hasMutationParams ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
500
+ const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
501
+ const paramsNode = getTriggerParams(node, {
502
+ dataReturnType,
503
+ resolver: tsResolver,
504
+ mutationKeyTypeName,
505
+ mutationArgTypeName
506
+ });
507
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
508
+ const generics = [
509
+ TData,
510
+ TError,
511
+ `${mutationKeyTypeName} | null`,
512
+ mutationArgTypeName
513
+ ].filter(Boolean);
514
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
515
+ name: mutationArgTypeName,
516
+ isExportable: true,
517
+ isIndexable: true,
518
+ isTypeOnly: true,
519
+ children: /* @__PURE__ */ jsx(Type, {
520
+ name: mutationArgTypeName,
521
+ export: true,
522
+ children: hasMutationParams ? `{${mutationArgDeclaration}}` : "never"
523
+ })
524
+ }), /* @__PURE__ */ jsx(File.Source, {
525
+ name,
526
+ isExportable: true,
527
+ isIndexable: true,
528
+ children: /* @__PURE__ */ jsx(Function$1, {
529
+ name,
530
+ export: true,
531
+ params: paramsSignature,
532
+ JSDoc: { comments: getComments(node) },
533
+ children: `
534
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
535
+ const mutationKey = ${mutationKeyName}()
536
+
537
+ return useSWRMutation<${generics.join(", ")}>(
538
+ shouldFetch ? mutationKey : null,
539
+ async (_url${hasMutationParams ? `, { arg: { ${argKeysStr} } }` : ""}) => {
540
+ return ${clientName}(${clientCallStr})
541
+ },
542
+ mutationOptions
543
+ )
544
+ `
545
+ })
546
+ })] });
547
+ }
548
+ const generics = [
549
+ TData,
550
+ TError,
551
+ `${mutationKeyTypeName} | null`,
552
+ requestName
553
+ ].filter(Boolean);
554
+ const paramsNode = getParams$3(node, {
555
+ paramsCasing,
556
+ pathParamsType,
557
+ dataReturnType,
558
+ resolver: tsResolver,
559
+ mutationKeyTypeName
560
+ });
561
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
562
+ return /* @__PURE__ */ jsx(File.Source, {
563
+ name,
564
+ isExportable: true,
565
+ isIndexable: true,
566
+ children: /* @__PURE__ */ jsx(Function$1, {
567
+ name,
568
+ export: true,
569
+ params: paramsSignature,
570
+ JSDoc: { comments: getComments(node) },
571
+ children: `
572
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
573
+ const mutationKey = ${mutationKeyName}()
574
+
575
+ return useSWRMutation<${generics.join(", ")}>(
576
+ shouldFetch ? mutationKey : null,
577
+ async (_url${requestName ? ", { arg: data }" : ""}) => {
578
+ return ${clientName}(${clientCallStr})
579
+ },
580
+ mutationOptions
581
+ )
582
+ `
583
+ })
584
+ });
585
+ }
586
+ //#endregion
587
+ //#region src/components/MutationKey.tsx
588
+ const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
589
+ function getParams$2() {
590
+ return ast.createFunctionParameters({ params: [] });
591
+ }
592
+ __name(getParams$2, "getParams");
593
+ const getTransformer$1 = /* @__PURE__ */ __name(({ node, casing }) => {
594
+ return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
595
+ }, "getTransformer");
596
+ function MutationKey({ name, paramsCasing, node, typeName, transformer = getTransformer$1 }) {
597
+ const paramsNode = getParams$2();
598
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
599
+ const keys = transformer({
600
+ node,
601
+ casing: paramsCasing
602
+ });
603
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
604
+ name,
605
+ isExportable: true,
606
+ isIndexable: true,
607
+ children: /* @__PURE__ */ jsx(Function$1.Arrow, {
608
+ name,
609
+ export: true,
610
+ params: paramsSignature,
611
+ singleLine: true,
612
+ children: `[${keys.join(", ")}] as const`
613
+ })
614
+ }), /* @__PURE__ */ jsx(File.Source, {
615
+ name: typeName,
616
+ isExportable: true,
617
+ isIndexable: true,
618
+ isTypeOnly: true,
619
+ children: /* @__PURE__ */ jsx(Type, {
620
+ name: typeName,
621
+ export: true,
622
+ children: `ReturnType<typeof ${name}>`
623
+ })
624
+ })] });
625
+ }
626
+ MutationKey.getParams = getParams$2;
627
+ MutationKey.getTransformer = getTransformer$1;
628
+ //#endregion
629
+ //#region src/components/QueryKey.tsx
630
+ const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
631
+ const callPrinter$2 = functionPrinter({ mode: "call" });
632
+ function getParams$1(node, options) {
633
+ return buildQueryKeyParams(node, options);
634
+ }
635
+ __name(getParams$1, "getParams");
636
+ const getTransformer = ({ node, casing }) => {
637
+ const path = new URLPath(node.path, { casing });
638
+ const hasQueryParams = node.parameters.some((p) => p.in === "query");
639
+ const hasRequestBody = !!node.requestBody?.schema;
640
+ return [
641
+ path.toObject({
642
+ type: "path",
643
+ stringify: true
644
+ }),
645
+ hasQueryParams ? "...(params ? [params] : [])" : void 0,
646
+ hasRequestBody ? "...(data ? [data] : [])" : void 0
647
+ ].filter(Boolean);
648
+ };
649
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = getTransformer }) {
650
+ const paramsNode = getParams$1(node, {
651
+ pathParamsType,
652
+ paramsCasing,
653
+ resolver: tsResolver
654
+ });
655
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
656
+ const keys = transformer({
657
+ node,
658
+ casing: paramsCasing
659
+ });
660
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
661
+ name,
662
+ isExportable: true,
663
+ isIndexable: true,
664
+ children: /* @__PURE__ */ jsx(Function$1.Arrow, {
665
+ name,
666
+ export: true,
667
+ params: paramsSignature,
668
+ singleLine: true,
669
+ children: `[${keys.join(", ")}] as const`
670
+ })
671
+ }), /* @__PURE__ */ jsx(File.Source, {
672
+ name: typeName,
673
+ isExportable: true,
674
+ isIndexable: true,
675
+ isTypeOnly: true,
676
+ children: /* @__PURE__ */ jsx(Type, {
677
+ name: typeName,
678
+ export: true,
679
+ children: `ReturnType<typeof ${name}>`
680
+ })
681
+ })] });
682
+ }
683
+ QueryKey.getParams = getParams$1;
684
+ QueryKey.getTransformer = getTransformer;
685
+ QueryKey.callPrinter = callPrinter$2;
686
+ //#endregion
687
+ //#region src/components/QueryOptions.tsx
688
+ const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
689
+ const callPrinter$1 = functionPrinter({ mode: "call" });
690
+ function getQueryOptionsParams(node, options) {
691
+ const { paramsType, paramsCasing, pathParamsType, resolver } = options;
692
+ const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
693
+ return ast.createOperationParams(node, {
694
+ paramsType,
695
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
696
+ paramsCasing,
697
+ resolver,
698
+ extraParams: [ast.createFunctionParameter({
699
+ name: "config",
700
+ type: ast.createParamsType({
701
+ variant: "reference",
702
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
703
+ }),
704
+ default: "{}"
705
+ })]
706
+ });
707
+ }
708
+ function QueryOptions({ name, clientName, node, tsResolver, paramsCasing, paramsType, pathParamsType }) {
709
+ const paramsNode = getQueryOptionsParams(node, {
710
+ paramsType,
711
+ paramsCasing,
712
+ pathParamsType,
713
+ resolver: tsResolver
714
+ });
715
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
716
+ const paramsCall = callPrinter$1.print(paramsNode) ?? "";
717
+ return /* @__PURE__ */ jsx(File.Source, {
718
+ name,
719
+ isExportable: true,
720
+ isIndexable: true,
721
+ children: /* @__PURE__ */ jsx(Function$1, {
722
+ name,
723
+ export: true,
724
+ params: paramsSignature,
725
+ children: `
726
+ return {
727
+ fetcher: async () => {
728
+ return ${clientName}(${paramsCall})
729
+ },
730
+ }
731
+ `
732
+ })
733
+ });
734
+ }
735
+ //#endregion
736
+ //#region src/components/Query.tsx
737
+ const declarationPrinter = functionPrinter({ mode: "declaration" });
738
+ const callPrinter = functionPrinter({ mode: "call" });
739
+ function getParams(node, options) {
740
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
741
+ const responseName = resolver.resolveResponseName(node);
742
+ const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
743
+ const errorNames = resolveErrorNames(node, resolver);
744
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
745
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
746
+ const optionsParam = ast.createFunctionParameter({
747
+ name: "options",
748
+ type: ast.createParamsType({
749
+ variant: "reference",
750
+ name: `{
751
+ query?: Parameters<typeof useSWR<${TData}, ${TError}>>[2],
752
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
753
+ shouldFetch?: boolean,
754
+ immutable?: boolean
755
+ }`
756
+ }),
757
+ default: "{}"
758
+ });
759
+ if (paramsType === "object") {
760
+ const baseParams = ast.createOperationParams(node, {
761
+ paramsType: "object",
762
+ pathParamsType: "object",
763
+ paramsCasing,
764
+ resolver,
765
+ extraParams: []
766
+ });
767
+ return ast.createFunctionParameters({ params: [...baseParams.params, optionsParam] });
768
+ }
769
+ const casedParams = ast.caseParams(node.parameters, paramsCasing);
770
+ const pathParams = casedParams.filter((p) => p.in === "path");
771
+ const queryParams = casedParams.filter((p) => p.in === "query");
772
+ const headerParams = casedParams.filter((p) => p.in === "header");
773
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
774
+ const bodyType = node.requestBody?.schema ? ast.createParamsType({
775
+ variant: "reference",
776
+ name: resolver.resolveDataName(node)
777
+ }) : void 0;
778
+ const bodyRequired = node.requestBody?.required ?? false;
779
+ const params = [];
780
+ if (pathParams.length) {
781
+ const pathChildren = pathParams.map((p) => ast.createFunctionParameter({
782
+ name: p.name,
783
+ type: resolvePathParamType(node, p, resolver),
784
+ optional: !p.required
785
+ }));
786
+ params.push({
787
+ kind: "ParameterGroup",
788
+ properties: pathChildren,
789
+ inline: pathParamsType === "inline",
790
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
791
+ });
792
+ }
793
+ if (bodyType) params.push(ast.createFunctionParameter({
794
+ name: "data",
795
+ type: bodyType,
796
+ optional: !bodyRequired
797
+ }));
798
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
799
+ const headerGroupType = node.parameters.some((p) => p.in === "header") ? (() => {
800
+ const hParams = casedParams.filter((p) => p.in === "header");
801
+ const firstParam = hParams[0];
802
+ const groupName = resolver.resolveHeaderParamsName(node, firstParam);
803
+ if (groupName !== resolver.resolveParamName(node, firstParam)) return {
804
+ type: ast.createParamsType({
805
+ variant: "reference",
806
+ name: groupName
807
+ }),
808
+ optional: hParams.every((p) => !p.required)
809
+ };
810
+ })() : void 0;
811
+ params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
812
+ params.push(optionsParam);
813
+ return ast.createFunctionParameters({ params });
814
+ }
815
+ function Query({ name, node, tsResolver, queryKeyName, queryKeyTypeName, queryOptionsName, dataReturnType, paramsType, paramsCasing, pathParamsType }) {
816
+ const responseName = tsResolver.resolveResponseName(node);
817
+ const errorNames = resolveErrorNames(node, tsResolver);
818
+ const generics = [
819
+ dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`,
820
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
821
+ `${queryKeyTypeName} | null`
822
+ ];
823
+ const queryKeyParamsNode = QueryKey.getParams(node, {
824
+ pathParamsType,
825
+ paramsCasing,
826
+ resolver: tsResolver
827
+ });
828
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
829
+ const paramsNode = getParams(node, {
830
+ paramsType,
831
+ paramsCasing,
832
+ pathParamsType,
833
+ dataReturnType,
834
+ resolver: tsResolver
835
+ });
836
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
837
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
838
+ paramsType,
839
+ paramsCasing,
840
+ pathParamsType,
841
+ resolver: tsResolver
842
+ });
843
+ const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
844
+ return /* @__PURE__ */ jsx(File.Source, {
845
+ name,
846
+ isExportable: true,
847
+ isIndexable: true,
848
+ children: /* @__PURE__ */ jsx(Function$1, {
849
+ name,
850
+ export: true,
851
+ params: paramsSignature,
852
+ JSDoc: { comments: getComments(node) },
853
+ children: `
854
+ const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
855
+
856
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
857
+
858
+ return useSWR<${generics.join(", ")}>(
859
+ shouldFetch ? queryKey : null,
860
+ {
861
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
862
+ ...(immutable ? {
863
+ revalidateIfStale: false,
864
+ revalidateOnFocus: false,
865
+ revalidateOnReconnect: false
866
+ } : { }),
867
+ ...queryOptions
868
+ }
869
+ )
870
+ `
871
+ })
872
+ });
873
+ }
874
+ //#endregion
875
+ export { Mutation as a, MutationKey as i, QueryOptions as n, transformName as o, QueryKey as r, camelCase as s, Query as t };
876
+
877
+ //# sourceMappingURL=components-JQ2KRFCa.js.map