@kubb/plugin-swr 5.0.0-alpha.8 → 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 -471
  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
@@ -1,780 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", {
5
- value,
6
- configurable: true
7
- });
8
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
- var __getOwnPropNames = Object.getOwnPropertyNames;
10
- var __getProtoOf = Object.getPrototypeOf;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
- key = keys[i];
15
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: ((k) => from[k]).bind(null, key),
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
- //#endregion
27
- let _kubb_oas = require("@kubb/oas");
28
- let _kubb_plugin_client_components = require("@kubb/plugin-client/components");
29
- let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
30
- let _kubb_react_fabric = require("@kubb/react-fabric");
31
- let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
32
- //#region ../../internals/utils/src/casing.ts
33
- /**
34
- * Shared implementation for camelCase and PascalCase conversion.
35
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
36
- * and capitalizes each word according to `pascal`.
37
- *
38
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
39
- */
40
- function toCamelOrPascal(text, pascal) {
41
- return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
42
- if (word.length > 1 && word === word.toUpperCase()) return word;
43
- if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
44
- return word.charAt(0).toUpperCase() + word.slice(1);
45
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
46
- }
47
- /**
48
- * Splits `text` on `.` and applies `transformPart` to each segment.
49
- * The last segment receives `isLast = true`, all earlier segments receive `false`.
50
- * Segments are joined with `/` to form a file path.
51
- */
52
- function applyToFileParts(text, transformPart) {
53
- const parts = text.split(".");
54
- return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
55
- }
56
- /**
57
- * Converts `text` to camelCase.
58
- * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
59
- *
60
- * @example
61
- * camelCase('hello-world') // 'helloWorld'
62
- * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
63
- */
64
- function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
65
- if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
66
- prefix,
67
- suffix
68
- } : {}));
69
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
70
- }
71
- /**
72
- * Converts `text` to PascalCase.
73
- * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
74
- *
75
- * @example
76
- * pascalCase('hello-world') // 'HelloWorld'
77
- * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
78
- */
79
- function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
80
- if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
81
- prefix,
82
- suffix
83
- }) : camelCase(part));
84
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
85
- }
86
- //#endregion
87
- //#region ../../internals/utils/src/reserved.ts
88
- /**
89
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
90
- */
91
- function isValidVarName(name) {
92
- try {
93
- new Function(`var ${name}`);
94
- } catch {
95
- return false;
96
- }
97
- return true;
98
- }
99
- //#endregion
100
- //#region ../../internals/utils/src/urlPath.ts
101
- /**
102
- * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
103
- *
104
- * @example
105
- * const p = new URLPath('/pet/{petId}')
106
- * p.URL // '/pet/:petId'
107
- * p.template // '`/pet/${petId}`'
108
- */
109
- var URLPath = class {
110
- /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
111
- path;
112
- #options;
113
- constructor(path, options = {}) {
114
- this.path = path;
115
- this.#options = options;
116
- }
117
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
118
- get URL() {
119
- return this.toURLPath();
120
- }
121
- /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
122
- get isURL() {
123
- try {
124
- return !!new URL(this.path).href;
125
- } catch {
126
- return false;
127
- }
128
- }
129
- /**
130
- * Converts the OpenAPI path to a TypeScript template literal string.
131
- *
132
- * @example
133
- * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
134
- * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
135
- */
136
- get template() {
137
- return this.toTemplateString();
138
- }
139
- /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
140
- get object() {
141
- return this.toObject();
142
- }
143
- /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
144
- get params() {
145
- return this.getParams();
146
- }
147
- #transformParam(raw) {
148
- const param = isValidVarName(raw) ? raw : camelCase(raw);
149
- return this.#options.casing === "camelcase" ? camelCase(param) : param;
150
- }
151
- /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
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
- getParams(replacer) {
190
- const params = {};
191
- this.#eachParam((_raw, param) => {
192
- const key = replacer ? replacer(param) : param;
193
- params[key] = key;
194
- });
195
- return Object.keys(params).length > 0 ? params : void 0;
196
- }
197
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
198
- toURLPath() {
199
- return this.path.replace(/\{([^}]+)\}/g, ":$1");
200
- }
201
- };
202
- //#endregion
203
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
204
- function getParams$4({}) {
205
- return _kubb_react_fabric.FunctionParams.factory({});
206
- }
207
- __name(getParams$4, "getParams");
208
- const getTransformer$1 = /* @__PURE__ */ __name(({ operation, casing }) => {
209
- return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
210
- }, "getTransformer");
211
- function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer$1 }) {
212
- const params = getParams$4({
213
- pathParamsType,
214
- typeSchemas
215
- });
216
- const keys = transformer({
217
- operation,
218
- schemas: typeSchemas,
219
- casing: paramsCasing
220
- });
221
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
222
- name,
223
- isExportable: true,
224
- isIndexable: true,
225
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function.Arrow, {
226
- name,
227
- export: true,
228
- params: params.toConstructor(),
229
- singleLine: true,
230
- children: `[${keys.join(", ")}] as const`
231
- })
232
- }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
233
- name: typeName,
234
- isExportable: true,
235
- isIndexable: true,
236
- isTypeOnly: true,
237
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
238
- name: typeName,
239
- export: true,
240
- children: `ReturnType<typeof ${name}>`
241
- })
242
- })] });
243
- }
244
- MutationKey.getParams = getParams$4;
245
- MutationKey.getTransformer = getTransformer$1;
246
- //#endregion
247
- //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
248
- function getParams$3({ pathParamsType, paramsCasing, typeSchemas }) {
249
- return _kubb_react_fabric.FunctionParams.factory({
250
- pathParams: typeSchemas.pathParams?.name ? {
251
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
252
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
253
- typed: true,
254
- casing: paramsCasing
255
- })
256
- } : void 0,
257
- data: typeSchemas.request?.name ? {
258
- type: typeSchemas.request?.name,
259
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
260
- } : void 0,
261
- params: typeSchemas.queryParams?.name ? {
262
- type: typeSchemas.queryParams?.name,
263
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
264
- } : void 0
265
- });
266
- }
267
- __name(getParams$3, "getParams");
268
- const getTransformer = ({ operation, schemas, casing }) => {
269
- return [
270
- new URLPath(operation.path, { casing }).toObject({
271
- type: "path",
272
- stringify: true
273
- }),
274
- schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
275
- schemas.request?.name ? "...(data ? [data] : [])" : void 0
276
- ].filter(Boolean);
277
- };
278
- function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }) {
279
- const params = getParams$3({
280
- pathParamsType,
281
- typeSchemas,
282
- paramsCasing
283
- });
284
- const keys = transformer({
285
- operation,
286
- schemas: typeSchemas,
287
- casing: paramsCasing
288
- });
289
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
290
- name,
291
- isExportable: true,
292
- isIndexable: true,
293
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function.Arrow, {
294
- name,
295
- export: true,
296
- params: params.toConstructor(),
297
- singleLine: true,
298
- children: `[${keys.join(", ")}] as const`
299
- })
300
- }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
301
- name: typeName,
302
- isExportable: true,
303
- isIndexable: true,
304
- isTypeOnly: true,
305
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
306
- name: typeName,
307
- export: true,
308
- children: `ReturnType<typeof ${name}>`
309
- })
310
- })] });
311
- }
312
- QueryKey.getParams = getParams$3;
313
- QueryKey.getTransformer = getTransformer;
314
- //#endregion
315
- //#region src/components/Mutation.tsx
316
- function getParams$2({ pathParamsType, paramsCasing, dataReturnType, typeSchemas, mutationKeyTypeName }) {
317
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
318
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
319
- const TExtraArg = typeSchemas.request?.name || "never";
320
- return _kubb_react_fabric.FunctionParams.factory({
321
- pathParams: {
322
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
323
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
324
- typed: true,
325
- casing: paramsCasing
326
- })
327
- },
328
- params: typeSchemas.queryParams?.name ? {
329
- type: typeSchemas.queryParams?.name,
330
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
331
- } : void 0,
332
- headers: typeSchemas.headerParams?.name ? {
333
- type: typeSchemas.headerParams?.name,
334
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
335
- } : void 0,
336
- options: {
337
- type: `
338
- {
339
- mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${TExtraArg}> & { throwOnError?: boolean },
340
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
341
- shouldFetch?: boolean,
342
- }
343
- `,
344
- default: "{}"
345
- }
346
- });
347
- }
348
- __name(getParams$2, "getParams");
349
- function getTriggerParams({ dataReturnType, typeSchemas, mutationKeyTypeName, mutationArgTypeName }) {
350
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
351
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
352
- return _kubb_react_fabric.FunctionParams.factory({ options: {
353
- type: `
354
- {
355
- mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
356
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
357
- shouldFetch?: boolean,
358
- }
359
- `,
360
- default: "{}"
361
- } });
362
- }
363
- function getMutationParams({ paramsCasing, typeSchemas }) {
364
- return _kubb_react_fabric.FunctionParams.factory({
365
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
366
- typed: true,
367
- casing: paramsCasing
368
- }),
369
- data: typeSchemas.request?.name ? {
370
- type: typeSchemas.request?.name,
371
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
372
- } : void 0,
373
- params: typeSchemas.queryParams?.name ? {
374
- type: typeSchemas.queryParams?.name,
375
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
376
- } : void 0,
377
- headers: typeSchemas.headerParams?.name ? {
378
- type: typeSchemas.headerParams?.name,
379
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
380
- } : void 0
381
- });
382
- }
383
- function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, paramsToTrigger = false }) {
384
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
385
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
386
- const mutationKeyParams = MutationKey.getParams({
387
- pathParamsType,
388
- typeSchemas
389
- });
390
- const clientParams = _kubb_plugin_client_components.Client.getParams({
391
- paramsCasing,
392
- paramsType,
393
- typeSchemas,
394
- pathParamsType,
395
- isConfigurable: true
396
- });
397
- if (paramsToTrigger) {
398
- const mutationParams = getMutationParams({
399
- paramsCasing,
400
- typeSchemas
401
- });
402
- const mutationArgTypeName = `${mutationKeyTypeName.replace("MutationKey", "")}MutationArg`;
403
- const hasMutationParams = Object.keys(mutationParams.params).length > 0;
404
- const argParams = _kubb_react_fabric.FunctionParams.factory({ data: {
405
- mode: "object",
406
- children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
407
- if (value) acc[key] = {
408
- ...value,
409
- type: void 0
410
- };
411
- return acc;
412
- }, {})
413
- } });
414
- const params = getTriggerParams({
415
- dataReturnType,
416
- typeSchemas,
417
- mutationKeyTypeName,
418
- mutationArgTypeName
419
- });
420
- const generics = [
421
- TData,
422
- TError,
423
- `${mutationKeyTypeName} | null`,
424
- mutationArgTypeName
425
- ].filter(Boolean);
426
- const mutationArg = mutationParams.toConstructor();
427
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
428
- name: mutationArgTypeName,
429
- isExportable: true,
430
- isIndexable: true,
431
- isTypeOnly: true,
432
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
433
- name: mutationArgTypeName,
434
- export: true,
435
- children: hasMutationParams ? `{${mutationArg}}` : "never"
436
- })
437
- }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
438
- name,
439
- isExportable: true,
440
- isIndexable: true,
441
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
442
- name,
443
- export: true,
444
- params: params.toConstructor(),
445
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
446
- children: `
447
- const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
448
- const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
449
-
450
- return useSWRMutation<${generics.join(", ")}>(
451
- shouldFetch ? mutationKey : null,
452
- async (_url${hasMutationParams ? `, { arg: ${argParams.toCall()} }` : ""}) => {
453
- return ${clientName}(${clientParams.toCall()})
454
- },
455
- mutationOptions
456
- )
457
- `
458
- })
459
- })] });
460
- }
461
- const generics = [
462
- TData,
463
- TError,
464
- `${mutationKeyTypeName} | null`,
465
- typeSchemas.request?.name
466
- ].filter(Boolean);
467
- const params = getParams$2({
468
- paramsCasing,
469
- pathParamsType,
470
- dataReturnType,
471
- typeSchemas,
472
- mutationKeyTypeName
473
- });
474
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
475
- name,
476
- isExportable: true,
477
- isIndexable: true,
478
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
479
- name,
480
- export: true,
481
- params: params.toConstructor(),
482
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
483
- children: `
484
- const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
485
- const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
486
-
487
- return useSWRMutation<${generics.join(", ")}>(
488
- shouldFetch ? mutationKey : null,
489
- async (_url${typeSchemas.request?.name ? ", { arg: data }" : ""}) => {
490
- return ${clientName}(${clientParams.toCall()})
491
- },
492
- mutationOptions
493
- )
494
- `
495
- })
496
- });
497
- }
498
- //#endregion
499
- //#region src/components/QueryOptions.tsx
500
- function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
501
- if (paramsType === "object") {
502
- const pathParams = (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
503
- typed: true,
504
- casing: paramsCasing
505
- });
506
- return _kubb_react_fabric.FunctionParams.factory({
507
- data: {
508
- mode: "object",
509
- children: {
510
- ...pathParams,
511
- data: typeSchemas.request?.name ? {
512
- type: typeSchemas.request?.name,
513
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
514
- } : void 0,
515
- params: typeSchemas.queryParams?.name ? {
516
- type: typeSchemas.queryParams?.name,
517
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
518
- } : void 0,
519
- headers: typeSchemas.headerParams?.name ? {
520
- type: typeSchemas.headerParams?.name,
521
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
522
- } : void 0
523
- }
524
- },
525
- config: {
526
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
527
- default: "{}"
528
- }
529
- });
530
- }
531
- return _kubb_react_fabric.FunctionParams.factory({
532
- pathParams: typeSchemas.pathParams?.name ? {
533
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
534
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
535
- typed: true,
536
- casing: paramsCasing
537
- }),
538
- default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
539
- } : void 0,
540
- data: typeSchemas.request?.name ? {
541
- type: typeSchemas.request?.name,
542
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
543
- } : void 0,
544
- params: typeSchemas.queryParams?.name ? {
545
- type: typeSchemas.queryParams?.name,
546
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
547
- } : void 0,
548
- headers: typeSchemas.headerParams?.name ? {
549
- type: typeSchemas.headerParams?.name,
550
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
551
- } : void 0,
552
- config: {
553
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
554
- default: "{}"
555
- }
556
- });
557
- }
558
- __name(getParams$1, "getParams");
559
- function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, pathParamsType }) {
560
- const params = getParams$1({
561
- paramsType,
562
- paramsCasing,
563
- pathParamsType,
564
- typeSchemas
565
- });
566
- const clientParams = _kubb_plugin_client_components.Client.getParams({
567
- paramsCasing,
568
- paramsType,
569
- typeSchemas,
570
- pathParamsType,
571
- isConfigurable: true
572
- });
573
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
574
- name,
575
- isExportable: true,
576
- isIndexable: true,
577
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
578
- name,
579
- export: true,
580
- params: params.toConstructor(),
581
- children: `
582
- return {
583
- fetcher: async () => {
584
- return ${clientName}(${clientParams.toCall()})
585
- },
586
- }
587
- `
588
- })
589
- });
590
- }
591
- QueryOptions.getParams = getParams$1;
592
- //#endregion
593
- //#region src/components/Query.tsx
594
- function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
595
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
596
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
597
- if (paramsType === "object") {
598
- const children = {
599
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
600
- typed: true,
601
- casing: paramsCasing
602
- }),
603
- data: typeSchemas.request?.name ? {
604
- type: typeSchemas.request?.name,
605
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
606
- } : void 0,
607
- params: typeSchemas.queryParams?.name ? {
608
- type: typeSchemas.queryParams?.name,
609
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
610
- } : void 0,
611
- headers: typeSchemas.headerParams?.name ? {
612
- type: typeSchemas.headerParams?.name,
613
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
614
- } : void 0
615
- };
616
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
617
- return _kubb_react_fabric.FunctionParams.factory({
618
- data: {
619
- mode: "object",
620
- children,
621
- default: allChildrenAreOptional ? "{}" : void 0
622
- },
623
- options: {
624
- type: `
625
- {
626
- query?: Parameters<typeof useSWR<${[TData, TError].join(", ")}>>[2],
627
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
628
- shouldFetch?: boolean,
629
- immutable?: boolean
630
- }
631
- `,
632
- default: "{}"
633
- }
634
- });
635
- }
636
- return _kubb_react_fabric.FunctionParams.factory({
637
- pathParams: typeSchemas.pathParams?.name ? {
638
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
639
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
640
- typed: true,
641
- casing: paramsCasing
642
- }),
643
- default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
644
- } : void 0,
645
- data: typeSchemas.request?.name ? {
646
- type: typeSchemas.request?.name,
647
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
648
- } : void 0,
649
- params: typeSchemas.queryParams?.name ? {
650
- type: typeSchemas.queryParams?.name,
651
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
652
- } : void 0,
653
- headers: typeSchemas.headerParams?.name ? {
654
- type: typeSchemas.headerParams?.name,
655
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
656
- } : void 0,
657
- options: {
658
- type: `
659
- {
660
- query?: Parameters<typeof useSWR<${[TData, TError].join(", ")}>>[2],
661
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
662
- shouldFetch?: boolean,
663
- immutable?: boolean
664
- }
665
- `,
666
- default: "{}"
667
- }
668
- });
669
- }
670
- function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, paramsType, paramsCasing, pathParamsType }) {
671
- const generics = [
672
- dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`,
673
- `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`,
674
- `${queryKeyTypeName} | null`
675
- ];
676
- const queryKeyParams = QueryKey.getParams({
677
- pathParamsType,
678
- typeSchemas,
679
- paramsCasing
680
- });
681
- const params = getParams({
682
- paramsCasing,
683
- paramsType,
684
- pathParamsType,
685
- dataReturnType,
686
- typeSchemas
687
- });
688
- const queryOptionsParams = QueryOptions.getParams({
689
- paramsCasing,
690
- paramsType,
691
- pathParamsType,
692
- typeSchemas
693
- });
694
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
695
- name,
696
- isExportable: true,
697
- isIndexable: true,
698
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
699
- name,
700
- export: true,
701
- params: params.toConstructor(),
702
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
703
- children: `
704
- const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
705
-
706
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
707
-
708
- return useSWR<${generics.join(", ")}>(
709
- shouldFetch ? queryKey : null,
710
- {
711
- ...${queryOptionsName}(${queryOptionsParams.toCall()}),
712
- ...(immutable ? {
713
- revalidateIfStale: false,
714
- revalidateOnFocus: false,
715
- revalidateOnReconnect: false
716
- } : { }),
717
- ...queryOptions
718
- }
719
- )
720
- `
721
- })
722
- });
723
- }
724
- //#endregion
725
- Object.defineProperty(exports, "Mutation", {
726
- enumerable: true,
727
- get: function() {
728
- return Mutation;
729
- }
730
- });
731
- Object.defineProperty(exports, "MutationKey", {
732
- enumerable: true,
733
- get: function() {
734
- return MutationKey;
735
- }
736
- });
737
- Object.defineProperty(exports, "Query", {
738
- enumerable: true,
739
- get: function() {
740
- return Query;
741
- }
742
- });
743
- Object.defineProperty(exports, "QueryKey", {
744
- enumerable: true,
745
- get: function() {
746
- return QueryKey;
747
- }
748
- });
749
- Object.defineProperty(exports, "QueryOptions", {
750
- enumerable: true,
751
- get: function() {
752
- return QueryOptions;
753
- }
754
- });
755
- Object.defineProperty(exports, "__name", {
756
- enumerable: true,
757
- get: function() {
758
- return __name;
759
- }
760
- });
761
- Object.defineProperty(exports, "__toESM", {
762
- enumerable: true,
763
- get: function() {
764
- return __toESM;
765
- }
766
- });
767
- Object.defineProperty(exports, "camelCase", {
768
- enumerable: true,
769
- get: function() {
770
- return camelCase;
771
- }
772
- });
773
- Object.defineProperty(exports, "pascalCase", {
774
- enumerable: true,
775
- get: function() {
776
- return pascalCase;
777
- }
778
- });
779
-
780
- //# sourceMappingURL=components-jd0l9XKn.cjs.map