@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.4

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 (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-D1UhYFgY.js +1277 -0
  4. package/dist/components-D1UhYFgY.js.map +1 -0
  5. package/dist/components-qfOFRSoM.cjs +1367 -0
  6. package/dist/components-qfOFRSoM.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +118 -109
  9. package/dist/components.js +1 -1
  10. package/dist/generators-C4gs_P1i.cjs +726 -0
  11. package/dist/generators-C4gs_P1i.cjs.map +1 -0
  12. package/dist/generators-CbnIVBgY.js +709 -0
  13. package/dist/generators-CbnIVBgY.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +5 -501
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +106 -121
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +102 -121
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-nVDTfuS1.d.ts +194 -0
  23. package/extension.yaml +793 -0
  24. package/package.json +61 -64
  25. package/src/components/InfiniteQuery.tsx +104 -153
  26. package/src/components/InfiniteQueryOptions.tsx +122 -162
  27. package/src/components/Mutation.tsx +110 -136
  28. package/src/components/Query.tsx +102 -151
  29. package/src/components/QueryKey.tsx +68 -58
  30. package/src/components/QueryOptions.tsx +147 -139
  31. package/src/generators/infiniteQueryGenerator.tsx +165 -170
  32. package/src/generators/mutationGenerator.tsx +117 -124
  33. package/src/generators/queryGenerator.tsx +138 -136
  34. package/src/index.ts +1 -1
  35. package/src/plugin.ts +124 -175
  36. package/src/resolvers/resolverVueQuery.ts +19 -0
  37. package/src/types.ts +68 -48
  38. package/src/utils.ts +37 -0
  39. package/dist/components-Yjoe78Y7.cjs +0 -1119
  40. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  41. package/dist/components-_AMBl0g-.js +0 -1029
  42. package/dist/components-_AMBl0g-.js.map +0 -1
  43. package/dist/generators-CR34GjVu.js +0 -661
  44. package/dist/generators-CR34GjVu.js.map +0 -1
  45. package/dist/generators-DH8VkK1q.cjs +0 -678
  46. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  47. package/dist/types-CgDFUvfZ.d.ts +0 -211
@@ -1,1119 +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 src/components/QueryKey.tsx
218
- function getParams$6({ pathParamsType, paramsCasing, typeSchemas }) {
219
- return _kubb_react_fabric.FunctionParams.factory({
220
- pathParams: {
221
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
222
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
223
- typed: true,
224
- casing: paramsCasing,
225
- override(item) {
226
- return {
227
- ...item,
228
- type: `MaybeRefOrGetter<${item.type}>`
229
- };
230
- }
231
- })
232
- },
233
- data: typeSchemas.request?.name ? {
234
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
235
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
236
- } : void 0,
237
- params: typeSchemas.queryParams?.name ? {
238
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
239
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
240
- } : void 0
241
- });
242
- }
243
- __name(getParams$6, "getParams");
244
- const getTransformer$1 = /* @__PURE__ */ __name(({ operation, schemas, casing }) => {
245
- return [
246
- new URLPath(operation.path, { casing }).toObject({
247
- type: "path",
248
- stringify: true
249
- }),
250
- schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
251
- schemas.request?.name ? "...(data ? [data] : [])" : void 0
252
- ].filter(Boolean);
253
- }, "getTransformer");
254
- function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer$1 }) {
255
- const params = getParams$6({
256
- pathParamsType,
257
- typeSchemas,
258
- paramsCasing
259
- });
260
- const keys = transformer({
261
- operation,
262
- schemas: typeSchemas,
263
- casing: paramsCasing
264
- });
265
- 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, {
266
- name,
267
- isExportable: true,
268
- isIndexable: true,
269
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function.Arrow, {
270
- name,
271
- export: true,
272
- params: params.toConstructor(),
273
- singleLine: true,
274
- children: `[${keys.join(", ")}] as const`
275
- })
276
- }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
277
- name: typeName,
278
- isExportable: true,
279
- isIndexable: true,
280
- isTypeOnly: true,
281
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
282
- name: typeName,
283
- export: true,
284
- children: `ReturnType<typeof ${name}>`
285
- })
286
- })] });
287
- }
288
- QueryKey.getParams = getParams$6;
289
- QueryKey.getTransformer = getTransformer$1;
290
- //#endregion
291
- //#region src/components/QueryOptions.tsx
292
- function getParams$5({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
293
- if (paramsType === "object") {
294
- const children = {
295
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
296
- typed: true,
297
- casing: paramsCasing,
298
- override(item) {
299
- return {
300
- ...item,
301
- type: `MaybeRefOrGetter<${item.type}>`
302
- };
303
- }
304
- }),
305
- data: typeSchemas.request?.name ? {
306
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
307
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
308
- } : void 0,
309
- params: typeSchemas.queryParams?.name ? {
310
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
311
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
312
- } : void 0,
313
- headers: typeSchemas.headerParams?.name ? {
314
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
315
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
316
- } : void 0
317
- };
318
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
319
- return _kubb_react_fabric.FunctionParams.factory({
320
- data: {
321
- mode: "object",
322
- children,
323
- default: allChildrenAreOptional ? "{}" : void 0
324
- },
325
- config: {
326
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
327
- default: "{}"
328
- }
329
- });
330
- }
331
- return _kubb_react_fabric.FunctionParams.factory({
332
- pathParams: {
333
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
334
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
335
- typed: true,
336
- casing: paramsCasing,
337
- override(item) {
338
- return {
339
- ...item,
340
- type: `MaybeRefOrGetter<${item.type}>`
341
- };
342
- }
343
- }),
344
- default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
345
- },
346
- data: typeSchemas.request?.name ? {
347
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
348
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
349
- } : void 0,
350
- params: typeSchemas.queryParams?.name ? {
351
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
352
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
353
- } : void 0,
354
- headers: typeSchemas.headerParams?.name ? {
355
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
356
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
357
- } : void 0,
358
- config: {
359
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
360
- default: "{}"
361
- }
362
- });
363
- }
364
- __name(getParams$5, "getParams");
365
- function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
366
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
367
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
368
- const params = getParams$5({
369
- paramsType,
370
- paramsCasing,
371
- pathParamsType,
372
- typeSchemas
373
- });
374
- const clientParams = _kubb_plugin_client_components.Client.getParams({
375
- paramsType,
376
- paramsCasing,
377
- typeSchemas,
378
- pathParamsType,
379
- isConfigurable: true
380
- });
381
- const queryKeyParams = QueryKey.getParams({
382
- pathParamsType,
383
- typeSchemas,
384
- paramsCasing
385
- });
386
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => {
387
- return item && !item.optional && !item.default ? key : void 0;
388
- }).filter(Boolean).join("&& ");
389
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
390
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
391
- name,
392
- isExportable: true,
393
- isIndexable: true,
394
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
395
- name,
396
- export: true,
397
- params: params.toConstructor(),
398
- children: `
399
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
400
- return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
401
- ${enabledText}
402
- queryKey,
403
- queryFn: async ({ signal }) => {
404
- return ${clientName}(${clientParams.toCall({ transformName(name) {
405
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
406
- return `toValue(${name})`;
407
- } })})
408
- },
409
- })
410
- `
411
- })
412
- });
413
- }
414
- QueryOptions.getParams = getParams$5;
415
- //#endregion
416
- //#region src/components/InfiniteQuery.tsx
417
- function getParams$4({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
418
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
419
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
420
- if (paramsType === "object") {
421
- const children = {
422
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
423
- typed: true,
424
- casing: paramsCasing,
425
- override(item) {
426
- return {
427
- ...item,
428
- type: `MaybeRefOrGetter<${item.type}>`
429
- };
430
- }
431
- }),
432
- data: typeSchemas.request?.name ? {
433
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
434
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
435
- } : void 0,
436
- params: typeSchemas.queryParams?.name ? {
437
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
438
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
439
- } : void 0,
440
- headers: typeSchemas.headerParams?.name ? {
441
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
442
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
443
- } : void 0
444
- };
445
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
446
- return _kubb_react_fabric.FunctionParams.factory({
447
- data: {
448
- mode: "object",
449
- children,
450
- default: allChildrenAreOptional ? "{}" : void 0
451
- },
452
- options: {
453
- type: `
454
- {
455
- query?: Partial<UseInfiniteQueryOptions<${[
456
- TData,
457
- TError,
458
- "TQueryData",
459
- "TQueryKey",
460
- "TQueryData"
461
- ].join(", ")}>> & { client?: QueryClient },
462
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
463
- }
464
- `,
465
- default: "{}"
466
- }
467
- });
468
- }
469
- return _kubb_react_fabric.FunctionParams.factory({
470
- pathParams: typeSchemas.pathParams?.name ? {
471
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
472
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
473
- typed: true,
474
- casing: paramsCasing,
475
- override(item) {
476
- return {
477
- ...item,
478
- type: `MaybeRefOrGetter<${item.type}>`
479
- };
480
- }
481
- }),
482
- default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
483
- } : void 0,
484
- data: typeSchemas.request?.name ? {
485
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
486
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
487
- } : void 0,
488
- params: typeSchemas.queryParams?.name ? {
489
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
490
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
491
- } : void 0,
492
- headers: typeSchemas.headerParams?.name ? {
493
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
494
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
495
- } : void 0,
496
- options: {
497
- type: `
498
- {
499
- query?: Partial<UseInfiniteQueryOptions<${[
500
- TData,
501
- TError,
502
- "TQueryData",
503
- "TQueryKey",
504
- "TQueryData"
505
- ].join(", ")}>> & { 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$4, "getParams");
514
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, pathParamsType, paramsCasing, dataReturnType, typeSchemas, operation }) {
515
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
516
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
517
- const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
518
- const generics = [
519
- `TData = InfiniteData<${TData}>`,
520
- `TQueryData = ${TData}`,
521
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
522
- ];
523
- const queryKeyParams = QueryKey.getParams({
524
- pathParamsType,
525
- typeSchemas,
526
- paramsCasing
527
- });
528
- const queryOptionsParams = QueryOptions.getParams({
529
- paramsType,
530
- pathParamsType,
531
- typeSchemas,
532
- paramsCasing
533
- });
534
- const params = getParams$4({
535
- paramsCasing,
536
- paramsType,
537
- pathParamsType,
538
- dataReturnType,
539
- typeSchemas
540
- });
541
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
542
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
543
- name,
544
- isExportable: true,
545
- isIndexable: true,
546
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
547
- name,
548
- export: true,
549
- generics: generics.join(", "),
550
- params: params.toConstructor(),
551
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
552
- children: `
553
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
554
- const { client: queryClient, ...resolvedOptions } = queryConfig
555
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParams.toCall()})
556
-
557
- const query = useInfiniteQuery({
558
- ...${queryOptions},
559
- ...resolvedOptions,
560
- queryKey
561
- } as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
562
-
563
- query.queryKey = queryKey as TQueryKey
564
-
565
- return query
566
- `
567
- })
568
- });
569
- }
570
- InfiniteQuery.getParams = getParams$4;
571
- //#endregion
572
- //#region src/components/InfiniteQueryOptions.tsx
573
- function getParams$3({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
574
- if (paramsType === "object") {
575
- const children = {
576
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
577
- typed: true,
578
- casing: paramsCasing,
579
- override(item) {
580
- return {
581
- ...item,
582
- type: `MaybeRefOrGetter<${item.type}>`
583
- };
584
- }
585
- }),
586
- data: typeSchemas.request?.name ? {
587
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
588
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
589
- } : void 0,
590
- params: typeSchemas.queryParams?.name ? {
591
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
592
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
593
- } : void 0,
594
- headers: typeSchemas.headerParams?.name ? {
595
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
596
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
597
- } : void 0
598
- };
599
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
600
- return _kubb_react_fabric.FunctionParams.factory({
601
- data: {
602
- mode: "object",
603
- children,
604
- default: allChildrenAreOptional ? "{}" : void 0
605
- },
606
- config: {
607
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
608
- default: "{}"
609
- }
610
- });
611
- }
612
- return _kubb_react_fabric.FunctionParams.factory({
613
- pathParams: {
614
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
615
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
616
- typed: true,
617
- casing: paramsCasing,
618
- override(item) {
619
- return {
620
- ...item,
621
- type: `MaybeRefOrGetter<${item.type}>`
622
- };
623
- }
624
- }),
625
- default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
626
- },
627
- data: typeSchemas.request?.name ? {
628
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
629
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
630
- } : void 0,
631
- params: typeSchemas.queryParams?.name ? {
632
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
633
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
634
- } : void 0,
635
- headers: typeSchemas.headerParams?.name ? {
636
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
637
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
638
- } : void 0,
639
- config: {
640
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
641
- default: "{}"
642
- }
643
- });
644
- }
645
- __name(getParams$3, "getParams");
646
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, typeSchemas, paramsType, paramsCasing, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
647
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
648
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
649
- const params = getParams$3({
650
- paramsType,
651
- paramsCasing,
652
- pathParamsType,
653
- typeSchemas
654
- });
655
- const clientParams = _kubb_plugin_client_components.Client.getParams({
656
- paramsType,
657
- paramsCasing,
658
- typeSchemas,
659
- pathParamsType,
660
- isConfigurable: true
661
- });
662
- const queryKeyParams = QueryKey.getParams({
663
- paramsCasing,
664
- pathParamsType,
665
- typeSchemas
666
- });
667
- const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
668
- let getNextPageParamExpr;
669
- let getPreviousPageParamExpr;
670
- if (hasNewParams) {
671
- if (nextParam) {
672
- const accessor = getNestedAccessor(nextParam, "lastPage");
673
- if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
674
- }
675
- if (previousParam) {
676
- const accessor = getNestedAccessor(previousParam, "firstPage");
677
- if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
678
- }
679
- } else if (cursorParam) {
680
- getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
681
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
682
- } else {
683
- if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
684
- else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
685
- getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
686
- }
687
- const queryOptions = [
688
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
689
- getNextPageParamExpr,
690
- getPreviousPageParamExpr
691
- ].filter(Boolean);
692
- const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
693
- if (!params) {
694
- params = { }
695
- }
696
- params['${queryParam}'] = pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}']` : "";
697
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => {
698
- return item && !item.optional && !item.default ? key : void 0;
699
- }).filter(Boolean).join("&& ");
700
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
701
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
702
- name,
703
- isExportable: true,
704
- isIndexable: true,
705
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
706
- name,
707
- export: true,
708
- params: params.toConstructor(),
709
- children: `
710
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
711
- return infiniteQueryOptions<${TData}, ${TError}, ${TData}, typeof queryKey, number>({
712
- ${enabledText}
713
- queryKey,
714
- queryFn: async ({ signal, pageParam }) => {
715
- ${infiniteOverrideParams}
716
- return ${clientName}(${clientParams.toCall({ transformName(name) {
717
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
718
- return `toValue(${name})`;
719
- } })})
720
- },
721
- ${queryOptions.join(",\n")}
722
- })
723
- `
724
- })
725
- });
726
- }
727
- InfiniteQueryOptions.getParams = getParams$3;
728
- //#endregion
729
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
730
- function getParams$2({}) {
731
- return _kubb_react_fabric.FunctionParams.factory({});
732
- }
733
- __name(getParams$2, "getParams");
734
- const getTransformer = ({ operation, casing }) => {
735
- return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
736
- };
737
- function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }) {
738
- const params = getParams$2({
739
- pathParamsType,
740
- typeSchemas
741
- });
742
- const keys = transformer({
743
- operation,
744
- schemas: typeSchemas,
745
- casing: paramsCasing
746
- });
747
- 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, {
748
- name,
749
- isExportable: true,
750
- isIndexable: true,
751
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function.Arrow, {
752
- name,
753
- export: true,
754
- params: params.toConstructor(),
755
- singleLine: true,
756
- children: `[${keys.join(", ")}] as const`
757
- })
758
- }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
759
- name: typeName,
760
- isExportable: true,
761
- isIndexable: true,
762
- isTypeOnly: true,
763
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
764
- name: typeName,
765
- export: true,
766
- children: `ReturnType<typeof ${name}>`
767
- })
768
- })] });
769
- }
770
- MutationKey.getParams = getParams$2;
771
- MutationKey.getTransformer = getTransformer;
772
- //#endregion
773
- //#region src/components/Mutation.tsx
774
- function getParams$1({ paramsCasing, dataReturnType, typeSchemas }) {
775
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
776
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
777
- const TRequest = _kubb_react_fabric.FunctionParams.factory({
778
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
779
- typed: true,
780
- casing: paramsCasing,
781
- override(item) {
782
- return {
783
- ...item,
784
- type: `MaybeRefOrGetter<${item.type}>`
785
- };
786
- }
787
- }),
788
- data: typeSchemas.request?.name ? {
789
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
790
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
791
- } : void 0,
792
- params: typeSchemas.queryParams?.name ? {
793
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
794
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
795
- } : void 0,
796
- headers: typeSchemas.headerParams?.name ? {
797
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
798
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
799
- } : void 0
800
- }).toConstructor();
801
- return _kubb_react_fabric.FunctionParams.factory({ options: {
802
- type: `
803
- {
804
- mutation?: MutationObserverOptions<${[
805
- TData,
806
- TError,
807
- TRequest ? `{${TRequest}}` : "void",
808
- "TContext"
809
- ].join(", ")}> & { client?: QueryClient },
810
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
811
- }
812
- `,
813
- default: "{}"
814
- } });
815
- }
816
- __name(getParams$1, "getParams");
817
- function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }) {
818
- const mutationKeyParams = MutationKey.getParams({
819
- pathParamsType,
820
- typeSchemas
821
- });
822
- const params = getParams$1({
823
- paramsCasing,
824
- pathParamsType,
825
- dataReturnType,
826
- typeSchemas
827
- });
828
- const clientParams = _kubb_plugin_client_components.Client.getParams({
829
- paramsCasing,
830
- paramsType,
831
- typeSchemas,
832
- pathParamsType,
833
- isConfigurable: true
834
- });
835
- const mutationParams = _kubb_react_fabric.FunctionParams.factory({
836
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
837
- typed: true,
838
- casing: paramsCasing
839
- }),
840
- data: typeSchemas.request?.name ? {
841
- type: typeSchemas.request?.name,
842
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
843
- } : void 0,
844
- params: typeSchemas.queryParams?.name ? {
845
- type: typeSchemas.queryParams?.name,
846
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
847
- } : void 0,
848
- headers: typeSchemas.headerParams?.name ? {
849
- type: typeSchemas.headerParams?.name,
850
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
851
- } : void 0
852
- });
853
- const dataParams = _kubb_react_fabric.FunctionParams.factory({ data: {
854
- mode: "object",
855
- children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
856
- if (value) acc[key] = {
857
- ...value,
858
- type: void 0
859
- };
860
- return acc;
861
- }, {})
862
- } });
863
- const TRequest = mutationParams.toConstructor();
864
- const generics = [
865
- dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`,
866
- `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`,
867
- TRequest ? `{${TRequest}}` : "void",
868
- "TContext"
869
- ].join(", ");
870
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
871
- name,
872
- isExportable: true,
873
- isIndexable: true,
874
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
875
- name,
876
- export: true,
877
- params: params.toConstructor(),
878
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
879
- generics: ["TContext"],
880
- children: `
881
- const { mutation = {}, client: config = {} } = options ?? {}
882
- const { client: queryClient, ...mutationOptions } = mutation;
883
- const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
884
-
885
- return useMutation<${generics}>({
886
- mutationFn: async(${dataParams.toConstructor()}) => {
887
- return ${clientName}(${clientParams.toCall()})
888
- },
889
- mutationKey,
890
- ...mutationOptions
891
- }, queryClient)
892
- `
893
- })
894
- });
895
- }
896
- //#endregion
897
- //#region src/components/Query.tsx
898
- function getParams({ paramsCasing, paramsType, pathParamsType, dataReturnType, typeSchemas }) {
899
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
900
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
901
- if (paramsType === "object") {
902
- const children = {
903
- ...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
904
- typed: true,
905
- casing: paramsCasing,
906
- override(item) {
907
- return {
908
- ...item,
909
- type: `MaybeRefOrGetter<${item.type}>`
910
- };
911
- }
912
- }),
913
- data: typeSchemas.request?.name ? {
914
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
915
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
916
- } : void 0,
917
- params: typeSchemas.queryParams?.name ? {
918
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
919
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
920
- } : void 0,
921
- headers: typeSchemas.headerParams?.name ? {
922
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
923
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
924
- } : void 0
925
- };
926
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
927
- return _kubb_react_fabric.FunctionParams.factory({
928
- data: {
929
- mode: "object",
930
- children,
931
- default: allChildrenAreOptional ? "{}" : void 0
932
- },
933
- options: {
934
- type: `
935
- {
936
- query?: Partial<UseQueryOptions<${[
937
- TData,
938
- TError,
939
- "TData",
940
- "TQueryData",
941
- "TQueryKey"
942
- ].join(", ")}>> & { client?: QueryClient },
943
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
944
- }
945
- `,
946
- default: "{}"
947
- }
948
- });
949
- }
950
- return _kubb_react_fabric.FunctionParams.factory({
951
- pathParams: typeSchemas.pathParams?.name ? {
952
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
953
- children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
954
- typed: true,
955
- casing: paramsCasing,
956
- override(item) {
957
- return {
958
- ...item,
959
- type: `MaybeRefOrGetter<${item.type}>`
960
- };
961
- }
962
- }),
963
- default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
964
- } : void 0,
965
- data: typeSchemas.request?.name ? {
966
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
967
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
968
- } : void 0,
969
- params: typeSchemas.queryParams?.name ? {
970
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
971
- optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
972
- } : void 0,
973
- headers: typeSchemas.headerParams?.name ? {
974
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
975
- optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
976
- } : void 0,
977
- options: {
978
- type: `
979
- {
980
- query?: Partial<UseQueryOptions<${[
981
- TData,
982
- TError,
983
- "TData",
984
- "TQueryData",
985
- "TQueryKey"
986
- ].join(", ")}>> & { client?: QueryClient },
987
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
988
- }
989
- `,
990
- default: "{}"
991
- }
992
- });
993
- }
994
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation }) {
995
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
996
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
997
- const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
998
- const generics = [
999
- `TData = ${TData}`,
1000
- `TQueryData = ${TData}`,
1001
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1002
- ];
1003
- const queryKeyParams = QueryKey.getParams({
1004
- pathParamsType,
1005
- typeSchemas,
1006
- paramsCasing
1007
- });
1008
- const queryOptionsParams = QueryOptions.getParams({
1009
- paramsType,
1010
- pathParamsType,
1011
- typeSchemas,
1012
- paramsCasing
1013
- });
1014
- const params = getParams({
1015
- paramsCasing,
1016
- paramsType,
1017
- pathParamsType,
1018
- dataReturnType,
1019
- typeSchemas
1020
- });
1021
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
1022
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1023
- name,
1024
- isExportable: true,
1025
- isIndexable: true,
1026
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1027
- name,
1028
- export: true,
1029
- generics: generics.join(", "),
1030
- params: params.toConstructor(),
1031
- JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
1032
- children: `
1033
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1034
- const { client: queryClient, ...resolvedOptions } = queryConfig
1035
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParams.toCall()})
1036
-
1037
- const query = useQuery({
1038
- ...${queryOptions},
1039
- ...resolvedOptions,
1040
- queryKey
1041
- } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
1042
-
1043
- query.queryKey = queryKey as TQueryKey
1044
-
1045
- return query
1046
- `
1047
- })
1048
- });
1049
- }
1050
- Query.getParams = getParams;
1051
- //#endregion
1052
- Object.defineProperty(exports, "InfiniteQuery", {
1053
- enumerable: true,
1054
- get: function() {
1055
- return InfiniteQuery;
1056
- }
1057
- });
1058
- Object.defineProperty(exports, "InfiniteQueryOptions", {
1059
- enumerable: true,
1060
- get: function() {
1061
- return InfiniteQueryOptions;
1062
- }
1063
- });
1064
- Object.defineProperty(exports, "Mutation", {
1065
- enumerable: true,
1066
- get: function() {
1067
- return Mutation;
1068
- }
1069
- });
1070
- Object.defineProperty(exports, "MutationKey", {
1071
- enumerable: true,
1072
- get: function() {
1073
- return MutationKey;
1074
- }
1075
- });
1076
- Object.defineProperty(exports, "Query", {
1077
- enumerable: true,
1078
- get: function() {
1079
- return Query;
1080
- }
1081
- });
1082
- Object.defineProperty(exports, "QueryKey", {
1083
- enumerable: true,
1084
- get: function() {
1085
- return QueryKey;
1086
- }
1087
- });
1088
- Object.defineProperty(exports, "QueryOptions", {
1089
- enumerable: true,
1090
- get: function() {
1091
- return QueryOptions;
1092
- }
1093
- });
1094
- Object.defineProperty(exports, "__name", {
1095
- enumerable: true,
1096
- get: function() {
1097
- return __name;
1098
- }
1099
- });
1100
- Object.defineProperty(exports, "__toESM", {
1101
- enumerable: true,
1102
- get: function() {
1103
- return __toESM;
1104
- }
1105
- });
1106
- Object.defineProperty(exports, "camelCase", {
1107
- enumerable: true,
1108
- get: function() {
1109
- return camelCase;
1110
- }
1111
- });
1112
- Object.defineProperty(exports, "pascalCase", {
1113
- enumerable: true,
1114
- get: function() {
1115
- return pascalCase;
1116
- }
1117
- });
1118
-
1119
- //# sourceMappingURL=components-Yjoe78Y7.cjs.map