@kubb/plugin-react-query 5.0.0-alpha.9 → 5.0.0-beta.3

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 (52) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-DTGLu4UV.js +1451 -0
  4. package/dist/components-DTGLu4UV.js.map +1 -0
  5. package/dist/components-dAKJEn9b.cjs +1571 -0
  6. package/dist/components-dAKJEn9b.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +105 -161
  9. package/dist/components.js +1 -1
  10. package/dist/generators-CWEQsdO9.cjs +1502 -0
  11. package/dist/generators-CWEQsdO9.cjs.map +1 -0
  12. package/dist/generators-C_fbcjpG.js +1460 -0
  13. package/dist/generators-C_fbcjpG.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +9 -505
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +114 -126
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +110 -126
  21. package/dist/index.js.map +1 -1
  22. package/dist/{types-D5S7Ny9r.d.ts → types-DfaFRSBf.d.ts} +100 -86
  23. package/package.json +59 -62
  24. package/src/components/InfiniteQuery.tsx +75 -139
  25. package/src/components/InfiniteQueryOptions.tsx +62 -164
  26. package/src/components/Mutation.tsx +58 -113
  27. package/src/components/MutationOptions.tsx +61 -80
  28. package/src/components/Query.tsx +67 -140
  29. package/src/components/QueryOptions.tsx +75 -135
  30. package/src/components/SuspenseInfiniteQuery.tsx +75 -139
  31. package/src/components/SuspenseInfiniteQueryOptions.tsx +62 -164
  32. package/src/components/SuspenseQuery.tsx +67 -150
  33. package/src/generators/customHookOptionsFileGenerator.tsx +33 -45
  34. package/src/generators/hookOptionsGenerator.tsx +115 -175
  35. package/src/generators/infiniteQueryGenerator.tsx +183 -176
  36. package/src/generators/mutationGenerator.tsx +127 -138
  37. package/src/generators/queryGenerator.tsx +141 -141
  38. package/src/generators/suspenseInfiniteQueryGenerator.tsx +175 -155
  39. package/src/generators/suspenseQueryGenerator.tsx +149 -148
  40. package/src/index.ts +1 -1
  41. package/src/plugin.ts +133 -183
  42. package/src/resolvers/resolverReactQuery.ts +22 -0
  43. package/src/types.ts +67 -45
  44. package/src/utils.ts +40 -0
  45. package/dist/components-BHQT9ZLc.cjs +0 -1634
  46. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  47. package/dist/components-CpyHYGOw.js +0 -1520
  48. package/dist/components-CpyHYGOw.js.map +0 -1
  49. package/dist/generators-DP07m3rH.cjs +0 -1469
  50. package/dist/generators-DP07m3rH.cjs.map +0 -1
  51. package/dist/generators-DkQwKTc2.js +0 -1427
  52. package/dist/generators-DkQwKTc2.js.map +0 -1
@@ -1,1634 +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_oas_utils = require("@kubb/plugin-oas/utils");
29
- let _kubb_react_fabric = require("@kubb/react-fabric");
30
- let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
31
- let _kubb_plugin_client_components = require("@kubb/plugin-client/components");
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/object.ts
88
- /**
89
- * Converts a dot-notation path or string array into an optional-chaining accessor expression.
90
- *
91
- * @example
92
- * getNestedAccessor('pagination.next.id', 'lastPage')
93
- * // → "lastPage?.['pagination']?.['next']?.['id']"
94
- */
95
- function getNestedAccessor(param, accessor) {
96
- const parts = Array.isArray(param) ? param : param.split(".");
97
- if (parts.length === 0 || parts.length === 1 && parts[0] === "") return void 0;
98
- return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
99
- }
100
- //#endregion
101
- //#region ../../internals/utils/src/reserved.ts
102
- /**
103
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
104
- */
105
- function isValidVarName(name) {
106
- try {
107
- new Function(`var ${name}`);
108
- } catch {
109
- return false;
110
- }
111
- return true;
112
- }
113
- //#endregion
114
- //#region ../../internals/utils/src/urlPath.ts
115
- /**
116
- * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
117
- *
118
- * @example
119
- * const p = new URLPath('/pet/{petId}')
120
- * p.URL // '/pet/:petId'
121
- * p.template // '`/pet/${petId}`'
122
- */
123
- var URLPath = class {
124
- /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
125
- path;
126
- #options;
127
- constructor(path, options = {}) {
128
- this.path = path;
129
- this.#options = options;
130
- }
131
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
132
- get URL() {
133
- return this.toURLPath();
134
- }
135
- /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
136
- get isURL() {
137
- try {
138
- return !!new URL(this.path).href;
139
- } catch {
140
- return false;
141
- }
142
- }
143
- /**
144
- * Converts the OpenAPI path to a TypeScript template literal string.
145
- *
146
- * @example
147
- * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
148
- * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
149
- */
150
- get template() {
151
- return this.toTemplateString();
152
- }
153
- /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
154
- get object() {
155
- return this.toObject();
156
- }
157
- /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
158
- get params() {
159
- return this.getParams();
160
- }
161
- #transformParam(raw) {
162
- const param = isValidVarName(raw) ? raw : camelCase(raw);
163
- return this.#options.casing === "camelcase" ? camelCase(param) : param;
164
- }
165
- /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
166
- #eachParam(fn) {
167
- for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
168
- const raw = match[1];
169
- fn(raw, this.#transformParam(raw));
170
- }
171
- }
172
- toObject({ type = "path", replacer, stringify } = {}) {
173
- const object = {
174
- url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
175
- params: this.getParams()
176
- };
177
- if (stringify) {
178
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
179
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
180
- return `{ url: '${object.url}' }`;
181
- }
182
- return object;
183
- }
184
- /**
185
- * Converts the OpenAPI path to a TypeScript template literal string.
186
- * An optional `replacer` can transform each extracted parameter name before interpolation.
187
- *
188
- * @example
189
- * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
190
- */
191
- toTemplateString({ prefix = "", replacer } = {}) {
192
- return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
193
- if (i % 2 === 0) return part;
194
- const param = this.#transformParam(part);
195
- return `\${${replacer ? replacer(param) : param}}`;
196
- }).join("")}\``;
197
- }
198
- /**
199
- * Extracts all `{param}` segments from the path and returns them as a key-value map.
200
- * An optional `replacer` transforms each parameter name in both key and value positions.
201
- * Returns `undefined` when no path parameters are found.
202
- */
203
- getParams(replacer) {
204
- const params = {};
205
- this.#eachParam((_raw, param) => {
206
- const key = replacer ? replacer(param) : param;
207
- params[key] = key;
208
- });
209
- return Object.keys(params).length > 0 ? params : void 0;
210
- }
211
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
212
- toURLPath() {
213
- return this.path.replace(/\{([^}]+)\}/g, ":$1");
214
- }
215
- };
216
- //#endregion
217
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
218
- function getParams$10({}) {
219
- return _kubb_react_fabric.FunctionParams.factory({});
220
- }
221
- __name(getParams$10, "getParams");
222
- const getTransformer$1 = /* @__PURE__ */ __name(({ operation, casing }) => {
223
- return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
224
- }, "getTransformer");
225
- function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer$1 }) {
226
- const params = getParams$10({
227
- pathParamsType,
228
- typeSchemas
229
- });
230
- const keys = transformer({
231
- operation,
232
- schemas: typeSchemas,
233
- casing: paramsCasing
234
- });
235
- 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, {
236
- name,
237
- isExportable: true,
238
- isIndexable: true,
239
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function.Arrow, {
240
- name,
241
- export: true,
242
- params: params.toConstructor(),
243
- singleLine: true,
244
- children: `[${keys.join(", ")}] as const`
245
- })
246
- }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
247
- name: typeName,
248
- isExportable: true,
249
- isIndexable: true,
250
- isTypeOnly: true,
251
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
252
- name: typeName,
253
- export: true,
254
- children: `ReturnType<typeof ${name}>`
255
- })
256
- })] });
257
- }
258
- MutationKey.getParams = getParams$10;
259
- MutationKey.getTransformer = getTransformer$1;
260
- //#endregion
261
- //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
262
- function getParams$9({ pathParamsType, paramsCasing, typeSchemas }) {
263
- return _kubb_react_fabric.FunctionParams.factory({
264
- pathParams: typeSchemas.pathParams?.name ? {
265
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
266
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
267
- typed: true,
268
- casing: paramsCasing
269
- })
270
- } : void 0,
271
- data: typeSchemas.request?.name ? {
272
- type: typeSchemas.request?.name,
273
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
274
- } : void 0,
275
- params: typeSchemas.queryParams?.name ? {
276
- type: typeSchemas.queryParams?.name,
277
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
278
- } : void 0
279
- });
280
- }
281
- __name(getParams$9, "getParams");
282
- const getTransformer = ({ operation, schemas, casing }) => {
283
- return [
284
- new URLPath(operation.path, { casing }).toObject({
285
- type: "path",
286
- stringify: true
287
- }),
288
- schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
289
- schemas.request?.name ? "...(data ? [data] : [])" : void 0
290
- ].filter(Boolean);
291
- };
292
- function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }) {
293
- const params = getParams$9({
294
- pathParamsType,
295
- typeSchemas,
296
- paramsCasing
297
- });
298
- const keys = transformer({
299
- operation,
300
- schemas: typeSchemas,
301
- casing: paramsCasing
302
- });
303
- 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, {
304
- name,
305
- isExportable: true,
306
- isIndexable: true,
307
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function.Arrow, {
308
- name,
309
- export: true,
310
- params: params.toConstructor(),
311
- singleLine: true,
312
- children: `[${keys.join(", ")}] as const`
313
- })
314
- }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
315
- name: typeName,
316
- isExportable: true,
317
- isIndexable: true,
318
- isTypeOnly: true,
319
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
320
- name: typeName,
321
- export: true,
322
- children: `ReturnType<typeof ${name}>`
323
- })
324
- })] });
325
- }
326
- QueryKey.getParams = getParams$9;
327
- QueryKey.getTransformer = getTransformer;
328
- //#endregion
329
- //#region src/components/QueryOptions.tsx
330
- function getParams$8({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
331
- if (paramsType === "object") {
332
- const children = {
333
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
334
- typed: true,
335
- casing: paramsCasing
336
- }),
337
- data: typeSchemas.request?.name ? {
338
- type: typeSchemas.request?.name,
339
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
340
- } : void 0,
341
- params: typeSchemas.queryParams?.name ? {
342
- type: typeSchemas.queryParams?.name,
343
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
344
- } : void 0,
345
- headers: typeSchemas.headerParams?.name ? {
346
- type: typeSchemas.headerParams?.name,
347
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
348
- } : void 0
349
- };
350
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
351
- return _kubb_react_fabric.FunctionParams.factory({
352
- data: {
353
- mode: "object",
354
- children,
355
- default: allChildrenAreOptional ? "{}" : void 0
356
- },
357
- config: {
358
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
359
- default: "{}"
360
- }
361
- });
362
- }
363
- return _kubb_react_fabric.FunctionParams.factory({
364
- pathParams: typeSchemas.pathParams?.name ? {
365
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
366
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
367
- typed: true,
368
- casing: paramsCasing
369
- }),
370
- default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
371
- } : void 0,
372
- data: typeSchemas.request?.name ? {
373
- type: typeSchemas.request?.name,
374
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
375
- } : void 0,
376
- params: typeSchemas.queryParams?.name ? {
377
- type: typeSchemas.queryParams?.name,
378
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
379
- } : void 0,
380
- headers: typeSchemas.headerParams?.name ? {
381
- type: typeSchemas.headerParams?.name,
382
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
383
- } : void 0,
384
- config: {
385
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
386
- default: "{}"
387
- }
388
- });
389
- }
390
- __name(getParams$8, "getParams");
391
- function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
392
- const params = getParams$8({
393
- paramsType,
394
- paramsCasing,
395
- pathParamsType,
396
- typeSchemas
397
- });
398
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
399
- const TError = typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error";
400
- const clientParams = _kubb_plugin_client_components.Client.getParams({
401
- typeSchemas,
402
- paramsCasing,
403
- paramsType,
404
- pathParamsType,
405
- isConfigurable: true
406
- });
407
- const queryKeyParams = QueryKey.getParams({
408
- pathParamsType,
409
- typeSchemas,
410
- paramsCasing
411
- });
412
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => {
413
- return item && !item.optional && !item.default ? key : void 0;
414
- }).filter(Boolean).join("&& ");
415
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
416
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
417
- name,
418
- isExportable: true,
419
- isIndexable: true,
420
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
421
- name,
422
- export: true,
423
- params: params.toConstructor(),
424
- children: `
425
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
426
- return queryOptions<${TData}, ResponseErrorConfig<${TError}>, ${TData}, typeof queryKey>({
427
- ${enabledText}
428
- queryKey,
429
- queryFn: async ({ signal }) => {
430
- return ${clientName}(${clientParams.toCall({ transformName(name) {
431
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
432
- return name;
433
- } })})
434
- },
435
- })
436
- `
437
- })
438
- });
439
- }
440
- QueryOptions.getParams = getParams$8;
441
- //#endregion
442
- //#region src/components/InfiniteQuery.tsx
443
- function getParams$7({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }) {
444
- if (paramsType === "object") {
445
- const children = {
446
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
447
- typed: true,
448
- casing: paramsCasing
449
- }),
450
- data: typeSchemas.request?.name ? {
451
- type: typeSchemas.request?.name,
452
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
453
- } : void 0,
454
- params: typeSchemas.queryParams?.name ? {
455
- type: typeSchemas.queryParams?.name,
456
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
457
- } : void 0,
458
- headers: typeSchemas.headerParams?.name ? {
459
- type: typeSchemas.headerParams?.name,
460
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
461
- } : void 0
462
- };
463
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
464
- return _kubb_react_fabric.FunctionParams.factory({
465
- data: {
466
- mode: "object",
467
- children,
468
- default: allChildrenAreOptional ? "{}" : void 0
469
- },
470
- options: {
471
- type: `
472
- {
473
- query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
474
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
475
- }
476
- `,
477
- default: "{}"
478
- }
479
- });
480
- }
481
- return _kubb_react_fabric.FunctionParams.factory({
482
- pathParams: typeSchemas.pathParams?.name ? {
483
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
484
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
485
- typed: true,
486
- casing: paramsCasing
487
- }),
488
- default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
489
- } : void 0,
490
- data: typeSchemas.request?.name ? {
491
- type: typeSchemas.request?.name,
492
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
493
- } : void 0,
494
- params: typeSchemas.queryParams?.name ? {
495
- type: typeSchemas.queryParams?.name,
496
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
497
- } : void 0,
498
- headers: typeSchemas.headerParams?.name ? {
499
- type: typeSchemas.headerParams?.name,
500
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
501
- } : void 0,
502
- options: {
503
- type: `
504
- {
505
- query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
506
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
507
- }
508
- `,
509
- default: "{}"
510
- }
511
- });
512
- }
513
- __name(getParams$7, "getParams");
514
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, initialPageParam, queryParam, customOptions }) {
515
- const responseType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
516
- const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
517
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
518
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
519
- const parts = initialPageParam.split(" as ");
520
- return parts[parts.length - 1] ?? "unknown";
521
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
522
- const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : void 0;
523
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
524
- const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
525
- const generics = [
526
- `TQueryFnData = ${responseType}`,
527
- `TError = ${errorType}`,
528
- "TData = InfiniteData<TQueryFnData>",
529
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
530
- `TPageParam = ${pageParamType}`
531
- ];
532
- const queryKeyParams = QueryKey.getParams({
533
- pathParamsType,
534
- typeSchemas,
535
- paramsCasing
536
- });
537
- const queryOptionsParams = QueryOptions.getParams({
538
- paramsType,
539
- pathParamsType,
540
- typeSchemas,
541
- paramsCasing
542
- });
543
- const params = getParams$7({
544
- paramsCasing,
545
- paramsType,
546
- pathParamsType,
547
- typeSchemas,
548
- pageParamGeneric: "TPageParam"
549
- });
550
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
551
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
552
- name,
553
- isExportable: true,
554
- isIndexable: true,
555
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
556
- name,
557
- export: true,
558
- generics: generics.join(", "),
559
- params: params.toConstructor(),
560
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
561
- children: `
562
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
563
- const { client: queryClient, ...resolvedOptions } = queryConfig
564
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
565
- ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ""}
566
-
567
- const query = useInfiniteQuery({
568
- ...${queryOptions},${customOptions ? "\n...customOptions," : ""}
569
- ...resolvedOptions,
570
- queryKey,
571
- } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
572
-
573
- query.queryKey = queryKey as TQueryKey
574
-
575
- return query
576
- `
577
- })
578
- });
579
- }
580
- InfiniteQuery.getParams = getParams$7;
581
- //#endregion
582
- //#region src/components/InfiniteQueryOptions.tsx
583
- function getParams$6({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
584
- if (paramsType === "object") {
585
- const children = {
586
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
587
- typed: true,
588
- casing: paramsCasing
589
- }),
590
- data: typeSchemas.request?.name ? {
591
- type: typeSchemas.request?.name,
592
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
593
- } : void 0,
594
- params: typeSchemas.queryParams?.name ? {
595
- type: typeSchemas.queryParams?.name,
596
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
597
- } : void 0,
598
- headers: typeSchemas.headerParams?.name ? {
599
- type: typeSchemas.headerParams?.name,
600
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
601
- } : void 0
602
- };
603
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
604
- return _kubb_react_fabric.FunctionParams.factory({
605
- data: {
606
- mode: "object",
607
- children,
608
- default: allChildrenAreOptional ? "{}" : void 0
609
- },
610
- config: {
611
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
612
- default: "{}"
613
- }
614
- });
615
- }
616
- return _kubb_react_fabric.FunctionParams.factory({
617
- pathParams: typeSchemas.pathParams?.name ? {
618
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
619
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
620
- typed: true,
621
- casing: paramsCasing
622
- }),
623
- default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
624
- } : void 0,
625
- data: typeSchemas.request?.name ? {
626
- type: typeSchemas.request?.name,
627
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
628
- } : void 0,
629
- params: typeSchemas.queryParams?.name ? {
630
- type: typeSchemas.queryParams?.name,
631
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
632
- } : void 0,
633
- headers: typeSchemas.headerParams?.name ? {
634
- type: typeSchemas.headerParams?.name,
635
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
636
- } : void 0,
637
- config: {
638
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
639
- default: "{}"
640
- }
641
- });
642
- }
643
- __name(getParams$6, "getParams");
644
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, typeSchemas, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
645
- const queryFnDataType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
646
- const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
647
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
648
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
649
- const parts = initialPageParam.split(" as ");
650
- return parts[parts.length - 1] ?? "unknown";
651
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
652
- const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : void 0;
653
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
654
- const params = getParams$6({
655
- paramsType,
656
- paramsCasing,
657
- pathParamsType,
658
- typeSchemas
659
- });
660
- const clientParams = _kubb_plugin_client_components.Client.getParams({
661
- paramsCasing,
662
- typeSchemas,
663
- paramsType,
664
- pathParamsType,
665
- isConfigurable: true
666
- });
667
- const queryKeyParams = QueryKey.getParams({
668
- pathParamsType,
669
- typeSchemas,
670
- paramsCasing
671
- });
672
- const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
673
- let getNextPageParamExpr;
674
- let getPreviousPageParamExpr;
675
- if (hasNewParams) {
676
- if (nextParam) {
677
- const accessor = getNestedAccessor(nextParam, "lastPage");
678
- if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
679
- }
680
- if (previousParam) {
681
- const accessor = getNestedAccessor(previousParam, "firstPage");
682
- if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
683
- }
684
- } else if (cursorParam) {
685
- getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
686
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
687
- } else {
688
- if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
689
- else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
690
- getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
691
- }
692
- const queryOptions = [
693
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
694
- getNextPageParamExpr,
695
- getPreviousPageParamExpr
696
- ].filter(Boolean);
697
- const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
698
- params = {
699
- ...(params ?? {}),
700
- ['${queryParam}']: pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}'],
701
- } as ${typeSchemas.queryParams?.name}` : "";
702
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => {
703
- return item && !item.optional && !item.default ? key : void 0;
704
- }).filter(Boolean).join("&& ");
705
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
706
- if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
707
- name,
708
- isExportable: true,
709
- isIndexable: true,
710
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
711
- name,
712
- export: true,
713
- params: params.toConstructor(),
714
- children: `
715
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
716
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
717
- ${enabledText}
718
- queryKey,
719
- queryFn: async ({ signal, pageParam }) => {
720
- ${infiniteOverrideParams}
721
- return ${clientName}(${clientParams.toCall({ transformName(name) {
722
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
723
- return name;
724
- } })})
725
- },
726
- ${queryOptions.join(",\n")}
727
- })
728
- `
729
- })
730
- });
731
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
732
- name,
733
- isExportable: true,
734
- isIndexable: true,
735
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
736
- name,
737
- export: true,
738
- params: params.toConstructor(),
739
- children: `
740
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
741
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
742
- ${enabledText}
743
- queryKey,
744
- queryFn: async ({ signal }) => {
745
- return ${clientName}(${clientParams.toCall({ transformName(name) {
746
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
747
- return name;
748
- } })})
749
- },
750
- ${queryOptions.join(",\n")}
751
- })
752
- `
753
- })
754
- });
755
- }
756
- InfiniteQueryOptions.getParams = getParams$6;
757
- //#endregion
758
- //#region src/components/MutationOptions.tsx
759
- function getParams$5({ typeSchemas }) {
760
- return _kubb_react_fabric.FunctionParams.factory({ config: {
761
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
762
- default: "{}"
763
- } });
764
- }
765
- __name(getParams$5, "getParams");
766
- function MutationOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
767
- const params = getParams$5({ typeSchemas });
768
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
769
- const TError = typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error";
770
- const clientParams = _kubb_plugin_client_components.Client.getParams({
771
- typeSchemas,
772
- paramsCasing,
773
- paramsType,
774
- pathParamsType,
775
- isConfigurable: true
776
- });
777
- const mutationKeyParams = MutationKey.getParams({
778
- pathParamsType,
779
- typeSchemas
780
- });
781
- const mutationParams = _kubb_react_fabric.FunctionParams.factory({
782
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
783
- typed: true,
784
- casing: paramsCasing
785
- }),
786
- data: typeSchemas.request?.name ? {
787
- type: typeSchemas.request?.name,
788
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
789
- } : void 0,
790
- params: typeSchemas.queryParams?.name ? {
791
- type: typeSchemas.queryParams?.name,
792
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
793
- } : void 0,
794
- headers: typeSchemas.headerParams?.name ? {
795
- type: typeSchemas.headerParams?.name,
796
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
797
- } : void 0
798
- });
799
- const dataParams = _kubb_react_fabric.FunctionParams.factory({ data: {
800
- mode: "object",
801
- children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
802
- if (value) acc[key] = {
803
- ...value,
804
- type: void 0
805
- };
806
- return acc;
807
- }, {})
808
- } });
809
- const TRequest = mutationParams.toConstructor();
810
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
811
- name,
812
- isExportable: true,
813
- isIndexable: true,
814
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
815
- name,
816
- export: true,
817
- params: params.toConstructor(),
818
- generics: ["TContext = unknown"],
819
- children: `
820
- const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
821
- return mutationOptions<${TData}, ResponseErrorConfig<${TError}>, ${TRequest ? `{${TRequest}}` : "void"}, TContext>({
822
- mutationKey,
823
- mutationFn: async(${dataParams.toConstructor()}) => {
824
- return ${clientName}(${clientParams.toCall()})
825
- },
826
- })
827
- `
828
- })
829
- });
830
- }
831
- MutationOptions.getParams = getParams$5;
832
- //#endregion
833
- //#region src/components/Mutation.tsx
834
- function getParams$4({ paramsCasing, dataReturnType, typeSchemas }) {
835
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
836
- const pathParams = (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
837
- typed: true,
838
- casing: paramsCasing
839
- });
840
- const TRequest = _kubb_react_fabric.FunctionParams.factory({
841
- ...pathParams,
842
- data: typeSchemas.request?.name ? {
843
- type: typeSchemas.request?.name,
844
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
845
- } : void 0,
846
- params: typeSchemas.queryParams?.name ? {
847
- type: typeSchemas.queryParams?.name,
848
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
849
- } : void 0,
850
- headers: typeSchemas.headerParams?.name ? {
851
- type: typeSchemas.headerParams?.name,
852
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
853
- } : void 0
854
- }).toConstructor();
855
- const generics = [
856
- TData,
857
- `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`,
858
- TRequest ? `{${TRequest}}` : "void",
859
- "TContext"
860
- ].join(", ");
861
- return _kubb_react_fabric.FunctionParams.factory({ options: {
862
- type: `
863
- {
864
- mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
865
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
866
- }
867
- `,
868
- default: "{}"
869
- } });
870
- }
871
- __name(getParams$4, "getParams");
872
- function Mutation({ name, mutationOptionsName, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName, customOptions }) {
873
- const mutationKeyParams = MutationKey.getParams({
874
- pathParamsType,
875
- typeSchemas
876
- });
877
- const params = getParams$4({
878
- paramsCasing,
879
- pathParamsType,
880
- dataReturnType,
881
- typeSchemas
882
- });
883
- const mutationParams = _kubb_react_fabric.FunctionParams.factory({
884
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
885
- typed: true,
886
- casing: paramsCasing
887
- }),
888
- data: typeSchemas.request?.name ? {
889
- type: typeSchemas.request?.name,
890
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
891
- } : void 0,
892
- params: typeSchemas.queryParams?.name ? {
893
- type: typeSchemas.queryParams?.name,
894
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
895
- } : void 0,
896
- headers: typeSchemas.headerParams?.name ? {
897
- type: typeSchemas.headerParams?.name,
898
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
899
- } : void 0
900
- });
901
- const mutationOptionsParams = MutationOptions.getParams({ typeSchemas });
902
- const TRequest = mutationParams.toConstructor();
903
- const generics = [
904
- dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`,
905
- `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`,
906
- TRequest ? `{${TRequest}}` : "void",
907
- "TContext"
908
- ].join(", ");
909
- const returnType = `UseMutationResult<${generics}>`;
910
- const mutationOptions = `${mutationOptionsName}(${mutationOptionsParams.toCall()})`;
911
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
912
- name,
913
- isExportable: true,
914
- isIndexable: true,
915
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
916
- name,
917
- export: true,
918
- params: params.toConstructor(),
919
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
920
- generics: ["TContext"],
921
- children: `
922
- const { mutation = {}, client: config = {} } = options ?? {}
923
- const { client: queryClient, ...mutationOptions } = mutation;
924
- const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
925
-
926
- const baseOptions = ${mutationOptions} as UseMutationOptions<${generics}>
927
- ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' }) as UseMutationOptions<${generics}>` : ""}
928
-
929
- return useMutation<${generics}>({
930
- ...baseOptions,${customOptions ? "\n...customOptions," : ""}
931
- mutationKey,
932
- ...mutationOptions,
933
- }, queryClient) as ${returnType}
934
- `
935
- })
936
- });
937
- }
938
- //#endregion
939
- //#region src/components/Query.tsx
940
- function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
941
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
942
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
943
- if (paramsType === "object") {
944
- const children = {
945
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
946
- typed: true,
947
- casing: paramsCasing
948
- }),
949
- data: typeSchemas.request?.name ? {
950
- type: typeSchemas.request?.name,
951
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
952
- } : void 0,
953
- params: typeSchemas.queryParams?.name ? {
954
- type: typeSchemas.queryParams?.name,
955
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
956
- } : void 0,
957
- headers: typeSchemas.headerParams?.name ? {
958
- type: typeSchemas.headerParams?.name,
959
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
960
- } : void 0
961
- };
962
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
963
- return _kubb_react_fabric.FunctionParams.factory({
964
- data: {
965
- mode: "object",
966
- children,
967
- default: allChildrenAreOptional ? "{}" : void 0
968
- },
969
- options: {
970
- type: `
971
- {
972
- query?: Partial<QueryObserverOptions<${[
973
- TData,
974
- TError,
975
- "TData",
976
- "TQueryData",
977
- "TQueryKey"
978
- ].join(", ")}>> & { client?: QueryClient },
979
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
980
- }
981
- `,
982
- default: "{}"
983
- }
984
- });
985
- }
986
- return _kubb_react_fabric.FunctionParams.factory({
987
- pathParams: typeSchemas.pathParams?.name ? {
988
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
989
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
990
- typed: true,
991
- casing: paramsCasing
992
- }),
993
- default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
994
- } : void 0,
995
- data: typeSchemas.request?.name ? {
996
- type: typeSchemas.request?.name,
997
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
998
- } : void 0,
999
- params: typeSchemas.queryParams?.name ? {
1000
- type: typeSchemas.queryParams?.name,
1001
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
1002
- } : void 0,
1003
- headers: typeSchemas.headerParams?.name ? {
1004
- type: typeSchemas.headerParams?.name,
1005
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
1006
- } : void 0,
1007
- options: {
1008
- type: `
1009
- {
1010
- query?: Partial<QueryObserverOptions<${[
1011
- TData,
1012
- TError,
1013
- "TData",
1014
- "TQueryData",
1015
- "TQueryKey"
1016
- ].join(", ")}>> & { client?: QueryClient },
1017
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1018
- }
1019
- `,
1020
- default: "{}"
1021
- }
1022
- });
1023
- }
1024
- __name(getParams$3, "getParams");
1025
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, customOptions }) {
1026
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
1027
- const returnType = `UseQueryResult<${["TData", `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`].join(", ")}> & { queryKey: TQueryKey }`;
1028
- const generics = [
1029
- `TData = ${TData}`,
1030
- `TQueryData = ${TData}`,
1031
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1032
- ];
1033
- const queryKeyParams = QueryKey.getParams({
1034
- pathParamsType,
1035
- typeSchemas,
1036
- paramsCasing
1037
- });
1038
- const queryOptionsParams = QueryOptions.getParams({
1039
- paramsType,
1040
- pathParamsType,
1041
- typeSchemas,
1042
- paramsCasing
1043
- });
1044
- const params = getParams$3({
1045
- paramsCasing,
1046
- paramsType,
1047
- pathParamsType,
1048
- dataReturnType,
1049
- typeSchemas
1050
- });
1051
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
1052
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1053
- name,
1054
- isExportable: true,
1055
- isIndexable: true,
1056
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1057
- name,
1058
- export: true,
1059
- generics: generics.join(", "),
1060
- params: params.toConstructor(),
1061
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
1062
- children: `
1063
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1064
- const { client: queryClient, ...resolvedOptions } = queryConfig
1065
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
1066
- ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ""}
1067
-
1068
- const query = useQuery({
1069
- ...${queryOptions},${customOptions ? "\n...customOptions," : ""}
1070
- ...resolvedOptions,
1071
- queryKey,
1072
- } as unknown as QueryObserverOptions, queryClient) as ${returnType}
1073
-
1074
- query.queryKey = queryKey as TQueryKey
1075
-
1076
- return query
1077
- `
1078
- })
1079
- });
1080
- }
1081
- Query.getParams = getParams$3;
1082
- //#endregion
1083
- //#region src/components/SuspenseInfiniteQuery.tsx
1084
- function getParams$2({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }) {
1085
- if (paramsType === "object") {
1086
- const children = {
1087
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
1088
- typed: true,
1089
- casing: paramsCasing
1090
- }),
1091
- data: typeSchemas.request?.name ? {
1092
- type: typeSchemas.request?.name,
1093
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
1094
- } : void 0,
1095
- params: typeSchemas.queryParams?.name ? {
1096
- type: typeSchemas.queryParams?.name,
1097
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
1098
- } : void 0,
1099
- headers: typeSchemas.headerParams?.name ? {
1100
- type: typeSchemas.headerParams?.name,
1101
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
1102
- } : void 0
1103
- };
1104
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
1105
- return _kubb_react_fabric.FunctionParams.factory({
1106
- data: {
1107
- mode: "object",
1108
- children,
1109
- default: allChildrenAreOptional ? "{}" : void 0
1110
- },
1111
- options: {
1112
- type: `
1113
- {
1114
- query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1115
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1116
- }
1117
- `,
1118
- default: "{}"
1119
- }
1120
- });
1121
- }
1122
- return _kubb_react_fabric.FunctionParams.factory({
1123
- pathParams: typeSchemas.pathParams?.name ? {
1124
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
1125
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
1126
- typed: true,
1127
- casing: paramsCasing
1128
- }),
1129
- default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
1130
- } : void 0,
1131
- data: typeSchemas.request?.name ? {
1132
- type: typeSchemas.request?.name,
1133
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
1134
- } : void 0,
1135
- params: typeSchemas.queryParams?.name ? {
1136
- type: typeSchemas.queryParams?.name,
1137
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
1138
- } : void 0,
1139
- headers: typeSchemas.headerParams?.name ? {
1140
- type: typeSchemas.headerParams?.name,
1141
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
1142
- } : void 0,
1143
- options: {
1144
- type: `
1145
- {
1146
- query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1147
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1148
- }
1149
- `,
1150
- default: "{}"
1151
- }
1152
- });
1153
- }
1154
- __name(getParams$2, "getParams");
1155
- function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, customOptions, initialPageParam, queryParam }) {
1156
- const responseType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
1157
- const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
1158
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1159
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1160
- const parts = initialPageParam.split(" as ");
1161
- return parts[parts.length - 1] ?? "unknown";
1162
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1163
- const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : void 0;
1164
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1165
- const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1166
- const generics = [
1167
- `TQueryFnData = ${responseType}`,
1168
- `TError = ${errorType}`,
1169
- "TData = InfiniteData<TQueryFnData>",
1170
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
1171
- `TPageParam = ${pageParamType}`
1172
- ];
1173
- const queryKeyParams = QueryKey.getParams({
1174
- pathParamsType,
1175
- typeSchemas,
1176
- paramsCasing
1177
- });
1178
- const queryOptionsParams = QueryOptions.getParams({
1179
- paramsType,
1180
- pathParamsType,
1181
- typeSchemas,
1182
- paramsCasing
1183
- });
1184
- const params = getParams$2({
1185
- paramsCasing,
1186
- paramsType,
1187
- pathParamsType,
1188
- typeSchemas,
1189
- pageParamGeneric: "TPageParam"
1190
- });
1191
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
1192
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1193
- name,
1194
- isExportable: true,
1195
- isIndexable: true,
1196
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1197
- name,
1198
- export: true,
1199
- generics: generics.join(", "),
1200
- params: params.toConstructor(),
1201
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
1202
- children: `
1203
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1204
- const { client: queryClient, ...resolvedOptions } = queryConfig
1205
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
1206
- ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ""}
1207
-
1208
- const query = useSuspenseInfiniteQuery({
1209
- ...${queryOptions},${customOptions ? "\n...customOptions," : ""}
1210
- ...resolvedOptions,
1211
- queryKey,
1212
- } as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1213
-
1214
- query.queryKey = queryKey as TQueryKey
1215
-
1216
- return query
1217
- `
1218
- })
1219
- });
1220
- }
1221
- SuspenseInfiniteQuery.getParams = getParams$2;
1222
- //#endregion
1223
- //#region src/components/SuspenseInfiniteQueryOptions.tsx
1224
- function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
1225
- if (paramsType === "object") {
1226
- const children = {
1227
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
1228
- typed: true,
1229
- casing: paramsCasing
1230
- }),
1231
- data: typeSchemas.request?.name ? {
1232
- type: typeSchemas.request?.name,
1233
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
1234
- } : void 0,
1235
- params: typeSchemas.queryParams?.name ? {
1236
- type: typeSchemas.queryParams?.name,
1237
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
1238
- } : void 0,
1239
- headers: typeSchemas.headerParams?.name ? {
1240
- type: typeSchemas.headerParams?.name,
1241
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
1242
- } : void 0
1243
- };
1244
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
1245
- return _kubb_react_fabric.FunctionParams.factory({
1246
- data: {
1247
- mode: "object",
1248
- children,
1249
- default: allChildrenAreOptional ? "{}" : void 0
1250
- },
1251
- config: {
1252
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
1253
- default: "{}"
1254
- }
1255
- });
1256
- }
1257
- return _kubb_react_fabric.FunctionParams.factory({
1258
- pathParams: typeSchemas.pathParams?.name ? {
1259
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
1260
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
1261
- typed: true,
1262
- casing: paramsCasing
1263
- }),
1264
- default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
1265
- } : void 0,
1266
- data: typeSchemas.request?.name ? {
1267
- type: typeSchemas.request?.name,
1268
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
1269
- } : void 0,
1270
- params: typeSchemas.queryParams?.name ? {
1271
- type: typeSchemas.queryParams?.name,
1272
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
1273
- } : void 0,
1274
- headers: typeSchemas.headerParams?.name ? {
1275
- type: typeSchemas.headerParams?.name,
1276
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
1277
- } : void 0,
1278
- config: {
1279
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
1280
- default: "{}"
1281
- }
1282
- });
1283
- }
1284
- __name(getParams$1, "getParams");
1285
- function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, typeSchemas, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
1286
- const queryFnDataType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
1287
- const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
1288
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1289
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1290
- const parts = initialPageParam.split(" as ");
1291
- return parts[parts.length - 1] ?? "unknown";
1292
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1293
- const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : void 0;
1294
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1295
- const params = getParams$1({
1296
- paramsType,
1297
- paramsCasing,
1298
- pathParamsType,
1299
- typeSchemas
1300
- });
1301
- const clientParams = _kubb_plugin_client_components.Client.getParams({
1302
- paramsCasing,
1303
- typeSchemas,
1304
- paramsType,
1305
- pathParamsType,
1306
- isConfigurable: true
1307
- });
1308
- const queryKeyParams = QueryKey.getParams({
1309
- pathParamsType,
1310
- typeSchemas,
1311
- paramsCasing
1312
- });
1313
- const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
1314
- let getNextPageParamExpr;
1315
- let getPreviousPageParamExpr;
1316
- if (hasNewParams) {
1317
- if (nextParam) {
1318
- const accessor = getNestedAccessor(nextParam, "lastPage");
1319
- if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
1320
- }
1321
- if (previousParam) {
1322
- const accessor = getNestedAccessor(previousParam, "firstPage");
1323
- if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
1324
- }
1325
- } else if (cursorParam) {
1326
- getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
1327
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
1328
- } else {
1329
- if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
1330
- else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
1331
- getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
1332
- }
1333
- const queryOptions = [
1334
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1335
- getNextPageParamExpr,
1336
- getPreviousPageParamExpr
1337
- ].filter(Boolean);
1338
- const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
1339
- params = {
1340
- ...(params ?? {}),
1341
- ['${queryParam}']: pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}'],
1342
- } as ${typeSchemas.queryParams?.name}` : "";
1343
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => {
1344
- return item && !item.optional && !item.default ? key : void 0;
1345
- }).filter(Boolean).join("&& ");
1346
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
1347
- if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1348
- name,
1349
- isExportable: true,
1350
- isIndexable: true,
1351
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1352
- name,
1353
- export: true,
1354
- params: params.toConstructor(),
1355
- children: `
1356
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
1357
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1358
- ${enabledText}
1359
- queryKey,
1360
- queryFn: async ({ signal, pageParam }) => {
1361
- ${infiniteOverrideParams}
1362
- return ${clientName}(${clientParams.toCall({ transformName(name) {
1363
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
1364
- return name;
1365
- } })})
1366
- },
1367
- ${queryOptions.join(",\n")}
1368
- })
1369
- `
1370
- })
1371
- });
1372
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1373
- name,
1374
- isExportable: true,
1375
- isIndexable: true,
1376
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1377
- name,
1378
- export: true,
1379
- params: params.toConstructor(),
1380
- children: `
1381
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
1382
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1383
- ${enabledText}
1384
- queryKey,
1385
- queryFn: async ({ signal }) => {
1386
- return ${clientName}(${clientParams.toCall({ transformName(name) {
1387
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
1388
- return name;
1389
- } })})
1390
- },
1391
- ${queryOptions.join(",\n")}
1392
- })
1393
- `
1394
- })
1395
- });
1396
- }
1397
- SuspenseInfiniteQueryOptions.getParams = getParams$1;
1398
- //#endregion
1399
- //#region src/components/SuspenseQuery.tsx
1400
- function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
1401
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
1402
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
1403
- if (paramsType === "object") {
1404
- const children = {
1405
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
1406
- typed: true,
1407
- casing: paramsCasing
1408
- }),
1409
- data: typeSchemas.request?.name ? {
1410
- type: typeSchemas.request?.name,
1411
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
1412
- } : void 0,
1413
- params: typeSchemas.queryParams?.name ? {
1414
- type: typeSchemas.queryParams?.name,
1415
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
1416
- } : void 0,
1417
- headers: typeSchemas.headerParams?.name ? {
1418
- type: typeSchemas.headerParams?.name,
1419
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
1420
- } : void 0
1421
- };
1422
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
1423
- return _kubb_react_fabric.FunctionParams.factory({
1424
- data: {
1425
- mode: "object",
1426
- children,
1427
- default: allChildrenAreOptional ? "{}" : void 0
1428
- },
1429
- options: {
1430
- type: `
1431
- {
1432
- query?: Partial<UseSuspenseQueryOptions<${[
1433
- TData,
1434
- TError,
1435
- "TData",
1436
- "TQueryKey"
1437
- ].join(", ")}>> & { client?: QueryClient },
1438
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1439
- }
1440
- `,
1441
- default: "{}"
1442
- }
1443
- });
1444
- }
1445
- return _kubb_react_fabric.FunctionParams.factory({
1446
- pathParams: typeSchemas.pathParams?.name ? {
1447
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
1448
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
1449
- typed: true,
1450
- casing: paramsCasing
1451
- }),
1452
- default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
1453
- } : void 0,
1454
- data: typeSchemas.request?.name ? {
1455
- type: typeSchemas.request?.name,
1456
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
1457
- } : void 0,
1458
- params: typeSchemas.queryParams?.name ? {
1459
- type: typeSchemas.queryParams?.name,
1460
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
1461
- } : void 0,
1462
- headers: typeSchemas.headerParams?.name ? {
1463
- type: typeSchemas.headerParams?.name,
1464
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
1465
- } : void 0,
1466
- options: {
1467
- type: `
1468
- {
1469
- query?: Partial<UseSuspenseQueryOptions<${[
1470
- TData,
1471
- TError,
1472
- "TData",
1473
- "TQueryKey"
1474
- ].join(", ")}>> & { client?: QueryClient },
1475
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1476
- }
1477
- `,
1478
- default: "{}"
1479
- }
1480
- });
1481
- }
1482
- /**
1483
- * Generates a strongly-typed React Query Suspense hook function for an OpenAPI operation.
1484
- *
1485
- * The generated function wraps `useSuspenseQuery`, providing type-safe parameters and return types based on the supplied OpenAPI schemas and configuration.
1486
- *
1487
- * @returns A React component source node containing the generated query function.
1488
- */
1489
- function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, customOptions }) {
1490
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
1491
- const returnType = `UseSuspenseQueryResult<${["TData", `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`].join(", ")}> & { queryKey: TQueryKey }`;
1492
- const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
1493
- const queryKeyParams = QueryKey.getParams({
1494
- pathParamsType,
1495
- typeSchemas,
1496
- paramsCasing
1497
- });
1498
- const queryOptionsParams = QueryOptions.getParams({
1499
- paramsCasing,
1500
- paramsType,
1501
- pathParamsType,
1502
- typeSchemas
1503
- });
1504
- const params = getParams({
1505
- paramsCasing,
1506
- paramsType,
1507
- pathParamsType,
1508
- dataReturnType,
1509
- typeSchemas
1510
- });
1511
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
1512
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1513
- name,
1514
- isExportable: true,
1515
- isIndexable: true,
1516
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1517
- name,
1518
- export: true,
1519
- generics: generics.join(", "),
1520
- params: params.toConstructor(),
1521
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
1522
- children: `
1523
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1524
- const { client: queryClient, ...resolvedOptions } = queryConfig
1525
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
1526
- ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ""}
1527
-
1528
- const query = useSuspenseQuery({
1529
- ...${queryOptions},${customOptions ? "\n...customOptions," : ""}
1530
- ...resolvedOptions,
1531
- queryKey,
1532
- } as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
1533
-
1534
- query.queryKey = queryKey as TQueryKey
1535
-
1536
- return query
1537
- `
1538
- })
1539
- });
1540
- }
1541
- SuspenseQuery.getParams = getParams;
1542
- //#endregion
1543
- Object.defineProperty(exports, "InfiniteQuery", {
1544
- enumerable: true,
1545
- get: function() {
1546
- return InfiniteQuery;
1547
- }
1548
- });
1549
- Object.defineProperty(exports, "InfiniteQueryOptions", {
1550
- enumerable: true,
1551
- get: function() {
1552
- return InfiniteQueryOptions;
1553
- }
1554
- });
1555
- Object.defineProperty(exports, "Mutation", {
1556
- enumerable: true,
1557
- get: function() {
1558
- return Mutation;
1559
- }
1560
- });
1561
- Object.defineProperty(exports, "MutationKey", {
1562
- enumerable: true,
1563
- get: function() {
1564
- return MutationKey;
1565
- }
1566
- });
1567
- Object.defineProperty(exports, "MutationOptions", {
1568
- enumerable: true,
1569
- get: function() {
1570
- return MutationOptions;
1571
- }
1572
- });
1573
- Object.defineProperty(exports, "Query", {
1574
- enumerable: true,
1575
- get: function() {
1576
- return Query;
1577
- }
1578
- });
1579
- Object.defineProperty(exports, "QueryKey", {
1580
- enumerable: true,
1581
- get: function() {
1582
- return QueryKey;
1583
- }
1584
- });
1585
- Object.defineProperty(exports, "QueryOptions", {
1586
- enumerable: true,
1587
- get: function() {
1588
- return QueryOptions;
1589
- }
1590
- });
1591
- Object.defineProperty(exports, "SuspenseInfiniteQuery", {
1592
- enumerable: true,
1593
- get: function() {
1594
- return SuspenseInfiniteQuery;
1595
- }
1596
- });
1597
- Object.defineProperty(exports, "SuspenseInfiniteQueryOptions", {
1598
- enumerable: true,
1599
- get: function() {
1600
- return SuspenseInfiniteQueryOptions;
1601
- }
1602
- });
1603
- Object.defineProperty(exports, "SuspenseQuery", {
1604
- enumerable: true,
1605
- get: function() {
1606
- return SuspenseQuery;
1607
- }
1608
- });
1609
- Object.defineProperty(exports, "__name", {
1610
- enumerable: true,
1611
- get: function() {
1612
- return __name;
1613
- }
1614
- });
1615
- Object.defineProperty(exports, "__toESM", {
1616
- enumerable: true,
1617
- get: function() {
1618
- return __toESM;
1619
- }
1620
- });
1621
- Object.defineProperty(exports, "camelCase", {
1622
- enumerable: true,
1623
- get: function() {
1624
- return camelCase;
1625
- }
1626
- });
1627
- Object.defineProperty(exports, "pascalCase", {
1628
- enumerable: true,
1629
- get: function() {
1630
- return pascalCase;
1631
- }
1632
- });
1633
-
1634
- //# sourceMappingURL=components-BHQT9ZLc.cjs.map