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