@kubb/plugin-react-query 3.0.0-alpha.3 → 3.0.0-alpha.31

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 (81) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-C2H3KPHM.cjs +658 -0
  3. package/dist/chunk-C2H3KPHM.cjs.map +1 -0
  4. package/dist/chunk-J7NSRJSY.js +661 -0
  5. package/dist/chunk-J7NSRJSY.js.map +1 -0
  6. package/dist/chunk-M5RJDPKE.cjs +670 -0
  7. package/dist/chunk-M5RJDPKE.cjs.map +1 -0
  8. package/dist/chunk-Y3DM2P6L.js +647 -0
  9. package/dist/chunk-Y3DM2P6L.js.map +1 -0
  10. package/dist/components.cjs +39 -14
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +161 -7
  13. package/dist/components.d.ts +161 -7
  14. package/dist/components.js +2 -14
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +75 -155
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -5
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.js +58 -145
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-oaGq_oPb.d.cts +169 -0
  29. package/dist/types-oaGq_oPb.d.ts +169 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +129 -0
  32. package/src/components/InfiniteQueryOptions.tsx +130 -0
  33. package/src/components/Mutation.tsx +138 -322
  34. package/src/components/MutationKey.tsx +48 -0
  35. package/src/components/Query.tsx +91 -598
  36. package/src/components/QueryKey.tsx +51 -178
  37. package/src/components/QueryOptions.tsx +72 -466
  38. package/src/components/SuspenseQuery.tsx +129 -0
  39. package/src/components/index.ts +4 -1
  40. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  41. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  42. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  43. package/src/generators/__snapshots__/findByTags.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  45. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  46. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  47. package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
  48. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
  49. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  50. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  51. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  52. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +46 -0
  53. package/src/generators/index.ts +4 -0
  54. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  55. package/src/generators/mutationGenerator.tsx +108 -0
  56. package/src/generators/queryGenerator.tsx +121 -0
  57. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  58. package/src/plugin.ts +58 -83
  59. package/src/types.ts +50 -107
  60. package/dist/chunk-5IL6M74X.js +0 -1504
  61. package/dist/chunk-5IL6M74X.js.map +0 -1
  62. package/dist/chunk-JFX7DCS7.cjs +0 -1504
  63. package/dist/chunk-JFX7DCS7.cjs.map +0 -1
  64. package/dist/index-C9fwRDH7.d.cts +0 -579
  65. package/dist/index-C9fwRDH7.d.ts +0 -579
  66. package/src/OperationGenerator.tsx +0 -86
  67. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
  68. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
  69. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
  70. package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
  71. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
  72. package/src/__snapshots__/upload/UploadFile.ts +0 -67
  73. package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
  74. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
  75. package/src/components/Operations.tsx +0 -74
  76. package/src/components/QueryImports.tsx +0 -167
  77. package/src/components/SchemaType.tsx +0 -55
  78. package/src/components/__snapshots__/gen/showPetById.ts +0 -57
  79. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  80. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
  81. package/src/utils.ts +0 -96
@@ -1,1504 +0,0 @@
1
- // src/components/Mutation.tsx
2
- import transformers from "@kubb/core/transformers";
3
- import { FunctionParams, URLPath } from "@kubb/core/utils";
4
- import { useOperation as useOperation2, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
5
- import { getASTParams, getComments } from "@kubb/plugin-oas/utils";
6
- import { File, Function, Parser, useApp as useApp2 } from "@kubb/react";
7
- import { pluginTsName as pluginTsName2 } from "@kubb/plugin-ts";
8
-
9
- // src/components/SchemaType.tsx
10
- import { useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
11
- import { Type, useApp } from "@kubb/react";
12
- import { pluginTsName } from "@kubb/plugin-ts";
13
- import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
14
- function SchemaType() {
15
- const {
16
- plugin: {
17
- options: { dataReturnType }
18
- }
19
- } = useApp();
20
- const { getSchemas, getName } = useOperationManager();
21
- const operation = useOperation();
22
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: "type" });
23
- const [TData, TError, TRequest, TPathParams, TQueryParams, THeaderParams, TResponse] = [
24
- schemas.response.name,
25
- schemas.errors?.map((item) => item.name).join(" | ") || "never",
26
- schemas.request?.name || "never",
27
- schemas.pathParams?.name || "never",
28
- schemas.queryParams?.name || "never",
29
- schemas.headerParams?.name || "never",
30
- schemas.response.name
31
- ];
32
- const factoryName = getName(operation, { type: "type" });
33
- const clientType = `${factoryName}Client`;
34
- const isFormData = operation.getContentType() === "multipart/form-data";
35
- return /* @__PURE__ */ jsxs(Fragment, { children: [
36
- /* @__PURE__ */ jsx(Type, { name: clientType, children: `typeof client<${TResponse}, ${TError}, ${isFormData ? "FormData" : TRequest}>` }),
37
- /* @__PURE__ */ jsx(Type, { name: factoryName, children: `
38
- {
39
- data: ${TData}
40
- error: ${TError}
41
- request: ${isFormData ? "FormData" : TRequest}
42
- pathParams: ${TPathParams}
43
- queryParams: ${TQueryParams}
44
- headerParams: ${THeaderParams}
45
- response: ${dataReturnType === "data" ? TData : `Awaited<ReturnType<${clientType}>>`}
46
- client: {
47
- parameters: Partial<Parameters<${clientType}>[0]>
48
- return: Awaited<ReturnType<${clientType}>>
49
- }
50
- }
51
- ` })
52
- ] });
53
- }
54
-
55
- // src/components/Mutation.tsx
56
- import { isRequired } from "@kubb/oas";
57
- import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
58
- function Template({ name, params, mutateParams, JSDoc, client, hook, dataReturnType }) {
59
- const isFormData = client.contentType === "multipart/form-data";
60
- const headers = [
61
- client.contentType !== "application/json" ? `'Content-Type': '${client.contentType}'` : void 0,
62
- client.withHeaders ? "...headers" : void 0
63
- ].filter(Boolean).join(", ");
64
- const clientOptions = [
65
- `method: "${client.method}"`,
66
- `url: ${client.path.template}`,
67
- client.withQueryParams ? "params" : void 0,
68
- client.withData && !isFormData ? "data" : void 0,
69
- client.withData && isFormData ? "data: formData" : void 0,
70
- headers.length ? `headers: { ${headers}, ...clientOptions.headers }` : void 0,
71
- "...clientOptions"
72
- ].filter(Boolean);
73
- const resolvedClientOptions = `${transformers.createIndent(4)}${clientOptions.join(`,
74
- ${transformers.createIndent(4)}`)}`;
75
- const formData = isFormData ? `
76
- const formData = new FormData()
77
- if(data) {
78
- Object.keys(data).forEach((key) => {
79
- const value = data[key];
80
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
81
- formData.append(key, value);
82
- }
83
- })
84
- }
85
- ` : void 0;
86
- return /* @__PURE__ */ jsx2(Function, { export: true, name, params, JSDoc, children: `
87
- const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
88
-
89
- return ${hook.name}({
90
- mutationFn: async(${mutateParams}) => {
91
- ${hook.children || ""}
92
- ${formData || ""}
93
- const res = await client<${client.generics}>({
94
- ${resolvedClientOptions}
95
- })
96
-
97
- return ${dataReturnType === "data" ? "res.data" : "res"}
98
- },
99
- ...mutationOptions
100
- })` });
101
- }
102
- function RootTemplate({ children }) {
103
- const {
104
- plugin: {
105
- options: {
106
- client: { importPath },
107
- mutate
108
- }
109
- }
110
- } = useApp2();
111
- const { getSchemas, getFile } = useOperationManager2();
112
- const operation = useOperation2();
113
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName2], type: "type" });
114
- const file = getFile(operation);
115
- const fileType = getFile(operation, { pluginKey: [pluginTsName2] });
116
- return /* @__PURE__ */ jsx2(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs2(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
117
- /* @__PURE__ */ jsx2(File.Import, { name: "client", path: importPath }),
118
- /* @__PURE__ */ jsx2(File.Import, { name: ["ResponseConfig"], path: importPath, isTypeOnly: true }),
119
- /* @__PURE__ */ jsx2(
120
- File.Import,
121
- {
122
- name: [
123
- schemas.request?.name,
124
- schemas.response.name,
125
- schemas.pathParams?.name,
126
- schemas.queryParams?.name,
127
- schemas.headerParams?.name,
128
- ...schemas.errors?.map((error) => error.name) || []
129
- ].filter(Boolean),
130
- root: file.path,
131
- path: fileType.path,
132
- isTypeOnly: true
133
- }
134
- ),
135
- /* @__PURE__ */ jsx2(
136
- File.Import,
137
- {
138
- name: ["UseMutationOptions", "UseMutationResult"],
139
- path: typeof mutate !== "boolean" && mutate.importPath ? mutate.importPath : "@tanstack/react-query",
140
- isTypeOnly: true
141
- }
142
- ),
143
- /* @__PURE__ */ jsx2(File.Import, { name: ["useMutation"], path: typeof mutate !== "boolean" && mutate.importPath ? mutate.importPath : "@tanstack/react-query" }),
144
- /* @__PURE__ */ jsx2(File.Source, { children })
145
- ] }) });
146
- }
147
- var defaultTemplates = { default: Template, root: RootTemplate };
148
- function Mutation({ Template: Template7 = defaultTemplates.default }) {
149
- const {
150
- plugin: {
151
- options: { dataReturnType, mutate }
152
- }
153
- } = useApp2();
154
- const operation = useOperation2();
155
- const { getSchemas, getName } = useOperationManager2();
156
- const name = getName(operation, { type: "function" });
157
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName2], type: "type" });
158
- const contentType = operation.getContentType();
159
- const params = new FunctionParams();
160
- const mutateParams = new FunctionParams();
161
- const factoryName = getName(operation, { type: "type" });
162
- const requestType = mutate && mutate.variablesType === "mutate" ? FunctionParams.toObject([
163
- ...getASTParams(schemas.pathParams, { typed: true }),
164
- {
165
- name: "params",
166
- type: `${factoryName}['queryParams']`,
167
- enabled: !!schemas.queryParams?.name,
168
- required: isRequired(schemas.queryParams?.schema)
169
- },
170
- {
171
- name: "headers",
172
- type: `${factoryName}['headerParams']`,
173
- enabled: !!schemas.headerParams?.name,
174
- required: isRequired(schemas.headerParams?.schema)
175
- },
176
- {
177
- name: "data",
178
- type: `${factoryName}['request']`,
179
- enabled: !!schemas.request?.name,
180
- required: isRequired(schemas.request?.schema)
181
- }
182
- ])?.type : schemas.request?.name ? `${factoryName}['request']` : "never";
183
- const client = {
184
- method: operation.method,
185
- path: new URLPath(operation.path),
186
- generics: [`${factoryName}["data"]`, `${factoryName}["error"]`, requestType ? `${factoryName}["request"]` : "void"].join(", "),
187
- withQueryParams: !!schemas.queryParams?.name,
188
- withData: !!schemas.request?.name,
189
- withPathParams: !!schemas.pathParams?.name,
190
- withHeaders: !!schemas.headerParams?.name,
191
- contentType
192
- };
193
- const hook = {
194
- name: "useMutation",
195
- generics: [`${factoryName}['response']`, `${factoryName}["error"]`, requestType ? `${requestType}` : "void"].join(", ")
196
- };
197
- const resultGenerics = [
198
- `${factoryName}["response"]`,
199
- `${factoryName}["error"]`,
200
- mutate && mutate?.variablesType === "mutate" ? requestType : `${factoryName}["request"]`
201
- ];
202
- if (mutate && mutate?.variablesType === "mutate") {
203
- params.add([
204
- {
205
- name: "options",
206
- type: `{
207
- mutation?: UseMutationOptions<${resultGenerics.join(", ")}>,
208
- client?: ${factoryName}['client']['parameters']
209
- }`,
210
- default: "{}"
211
- }
212
- ]);
213
- mutateParams.add([
214
- [
215
- ...getASTParams(schemas.pathParams, { typed: false }),
216
- {
217
- name: "params",
218
- enabled: client.withQueryParams,
219
- required: isRequired(schemas.queryParams?.schema)
220
- },
221
- {
222
- name: "headers",
223
- enabled: client.withHeaders,
224
- required: isRequired(schemas.headerParams?.schema)
225
- },
226
- {
227
- name: "data",
228
- enabled: !!schemas.request?.name,
229
- required: isRequired(schemas.request?.schema)
230
- }
231
- ]
232
- ]);
233
- } else {
234
- params.add([
235
- ...getASTParams(schemas.pathParams, { typed: true }),
236
- {
237
- name: "params",
238
- type: `${factoryName}['queryParams']`,
239
- enabled: client.withQueryParams,
240
- required: isRequired(schemas.queryParams?.schema)
241
- },
242
- {
243
- name: "headers",
244
- type: `${factoryName}['headerParams']`,
245
- enabled: client.withHeaders,
246
- required: isRequired(schemas.headerParams?.schema)
247
- },
248
- {
249
- name: "options",
250
- type: `{
251
- mutation?: UseMutationOptions<${resultGenerics.join(", ")}>,
252
- client?: ${factoryName}['client']['parameters']
253
- }`,
254
- default: "{}"
255
- }
256
- ]);
257
- mutateParams.add([
258
- {
259
- name: "data",
260
- enabled: !!schemas.request?.name,
261
- required: isRequired(schemas.request?.schema)
262
- }
263
- ]);
264
- }
265
- if (!mutate) {
266
- return null;
267
- }
268
- return /* @__PURE__ */ jsx2(Fragment2, { children: /* @__PURE__ */ jsx2(
269
- Template7,
270
- {
271
- name,
272
- JSDoc: { comments: getComments(operation) },
273
- client,
274
- hook,
275
- params: params.toString(),
276
- mutateParams: mutateParams.toString(),
277
- dataReturnType
278
- }
279
- ) });
280
- }
281
- Mutation.File = function({ ...props }) {
282
- const templates = { ...defaultTemplates, ...props.templates };
283
- const Template7 = templates.default;
284
- const RootTemplate3 = templates.root;
285
- return /* @__PURE__ */ jsxs2(RootTemplate3, { children: [
286
- /* @__PURE__ */ jsx2(SchemaType, {}),
287
- /* @__PURE__ */ jsx2(Mutation, { Template: Template7 })
288
- ] });
289
- };
290
- Mutation.templates = defaultTemplates;
291
-
292
- // src/components/Operations.tsx
293
- import { Parser as Parser2, File as File2, useApp as useApp3 } from "@kubb/react";
294
- import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
295
- function Template2({}) {
296
- return null;
297
- }
298
- function RootTemplate2({ children }) {
299
- const {
300
- pluginManager,
301
- plugin: { key: pluginKey }
302
- } = useApp3();
303
- const file = pluginManager.getFile({
304
- name: "operations",
305
- mode: "split",
306
- extName: ".ts",
307
- pluginKey
308
- });
309
- return /* @__PURE__ */ jsx3(Parser2, { language: "typescript", children: /* @__PURE__ */ jsx3(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: /* @__PURE__ */ jsx3(File2.Source, { children }) }) });
310
- }
311
- var defaultTemplates2 = { default: Template2, root: RootTemplate2 };
312
- function Operations({ Template: Template7 = defaultTemplates2.default }) {
313
- return /* @__PURE__ */ jsx3(Template7, {});
314
- }
315
- Operations.File = function(props) {
316
- const templates = { ...defaultTemplates2, ...props.templates };
317
- const Template7 = templates.default;
318
- const RootTemplate3 = templates.root;
319
- return /* @__PURE__ */ jsx3(RootTemplate3, { children: /* @__PURE__ */ jsx3(Operations, { Template: Template7 }) });
320
- };
321
- Operations.templates = defaultTemplates2;
322
-
323
- // src/components/Query.tsx
324
- import { PackageManager as PackageManager4 } from "@kubb/core";
325
- import transformers3 from "@kubb/core/transformers";
326
- import { FunctionParams as FunctionParams4, URLPath as URLPath4 } from "@kubb/core/utils";
327
- import { Parser as Parser3, File as File4, Function as Function4, useApp as useApp6 } from "@kubb/react";
328
- import { pluginTsName as pluginTsName5 } from "@kubb/plugin-ts";
329
- import { pluginZodName as pluginZodName2 } from "@kubb/plugin-zod";
330
- import { useOperation as useOperation5, useOperationManager as useOperationManager5 } from "@kubb/plugin-oas/hooks";
331
- import { getASTParams as getASTParams4, getComments as getComments2 } from "@kubb/plugin-oas/utils";
332
-
333
- // src/utils.ts
334
- import { PackageManager } from "@kubb/core";
335
- var reactQueryDepRegex = /@tanstack\/(react|solid|vue|svelte)-query/;
336
- function getImportNames() {
337
- const isV5 = new PackageManager().isValidSync(reactQueryDepRegex, ">=5");
338
- return {
339
- mutation: {
340
- react: {
341
- path: "@tanstack/react-query",
342
- hookName: "useMutation",
343
- optionsType: "UseMutationOptions",
344
- resultType: "UseMutationResult"
345
- },
346
- solid: {
347
- path: "@tanstack/solid-query",
348
- hookName: "createMutation",
349
- optionsType: "CreateMutationOptions",
350
- resultType: "CreateMutationResult"
351
- },
352
- svelte: {
353
- path: "@tanstack/svelte-query",
354
- hookName: "createMutation",
355
- optionsType: "CreateMutationOptions",
356
- resultType: "CreateMutationResult"
357
- },
358
- vue: {
359
- path: "@tanstack/vue-query",
360
- hookName: "useMutation",
361
- optionsType: isV5 ? "UseMutationOptions" : "VueMutationObserverOptions",
362
- resultType: "UseMutationReturnType"
363
- }
364
- },
365
- query: {
366
- react: {
367
- path: "@tanstack/react-query",
368
- hookName: "useQuery",
369
- optionsType: isV5 ? "QueryObserverOptions" : "UseBaseQueryOptions",
370
- resultType: "UseQueryResult"
371
- },
372
- solid: {
373
- path: "@tanstack/solid-query",
374
- hookName: "createQuery",
375
- optionsType: "CreateBaseQueryOptions",
376
- resultType: "CreateQueryResult"
377
- },
378
- svelte: {
379
- path: "@tanstack/svelte-query",
380
- hookName: "createQuery",
381
- optionsType: "CreateBaseQueryOptions",
382
- resultType: "CreateQueryResult"
383
- },
384
- vue: {
385
- path: "@tanstack/vue-query",
386
- hookName: "useQuery",
387
- optionsType: isV5 ? "QueryObserverOptions" : "VueQueryObserverOptions",
388
- resultType: isV5 ? "UseQueryReturnType" : "UseQueryReturnType"
389
- }
390
- },
391
- queryInfinite: {
392
- react: {
393
- path: "@tanstack/react-query",
394
- hookName: "useInfiniteQuery",
395
- optionsType: isV5 ? "InfiniteQueryObserverOptions" : "UseInfiniteQueryOptions",
396
- resultType: "UseInfiniteQueryResult"
397
- },
398
- solid: {
399
- path: "@tanstack/solid-query",
400
- hookName: "createInfiniteQuery",
401
- optionsType: "CreateInfiniteQueryOptions",
402
- resultType: "CreateInfiniteQueryResult"
403
- },
404
- svelte: {
405
- path: "@tanstack/svelte-query",
406
- hookName: "createInfiniteQuery",
407
- optionsType: "CreateInfiniteQueryOptions",
408
- resultType: "CreateInfiniteQueryResult"
409
- },
410
- vue: {
411
- path: "@tanstack/vue-query",
412
- hookName: "useInfiniteQuery",
413
- optionsType: isV5 ? "UseInfiniteQueryOptions" : "VueInfiniteQueryObserverOptions",
414
- resultType: isV5 ? "UseInfiniteQueryReturnType" : "VueInfiniteQueryObserverOptions"
415
- }
416
- },
417
- querySuspense: {
418
- react: {
419
- path: "@tanstack/react-query",
420
- hookName: "useSuspenseQuery",
421
- optionsType: "UseSuspenseQueryOptions",
422
- resultType: "UseSuspenseQueryResult"
423
- }
424
- }
425
- };
426
- }
427
-
428
- // src/components/QueryImports.tsx
429
- import { PackageManager as PackageManager2 } from "@kubb/core";
430
- import { File as File3 } from "@kubb/react";
431
- import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
432
- function Template3({ path, hookPath = path, isInfinite, hookName, queryOptions, optionsType, resultType }) {
433
- return /* @__PURE__ */ jsxs3(Fragment3, { children: [
434
- /* @__PURE__ */ jsx4(File3.Import, { name: [optionsType, resultType], path, isTypeOnly: true }),
435
- /* @__PURE__ */ jsx4(File3.Import, { name: [hookName], path: hookPath }),
436
- queryOptions && /* @__PURE__ */ jsx4(File3.Import, { name: [queryOptions].filter(Boolean), path }),
437
- /* @__PURE__ */ jsx4(File3.Import, { name: ["QueryKey", "WithRequired", isInfinite ? "InfiniteData" : void 0].filter(Boolean), path, isTypeOnly: true })
438
- ] });
439
- }
440
- var defaultTemplates3 = {
441
- get react() {
442
- return function({ context, hookPath, ...rest }) {
443
- const importNames = getImportNames();
444
- const isV5 = new PackageManager2().isValidSync(reactQueryDepRegex, ">=5");
445
- const { isInfinite, isSuspense } = context;
446
- return /* @__PURE__ */ jsx4(
447
- Template3,
448
- {
449
- isInfinite,
450
- ...isSuspense ? importNames.querySuspense.react : isInfinite ? importNames.queryInfinite.react : importNames.query.react,
451
- queryOptions: isV5 ? isInfinite ? "infiniteQueryOptions" : "queryOptions" : void 0,
452
- hookPath,
453
- ...rest
454
- }
455
- );
456
- };
457
- },
458
- get solid() {
459
- return function({ context, hookPath, ...rest }) {
460
- const importNames = getImportNames();
461
- const isV5 = new PackageManager2().isValidSync(reactQueryDepRegex, ">=5");
462
- const { isInfinite } = context;
463
- return /* @__PURE__ */ jsx4(
464
- Template3,
465
- {
466
- isInfinite,
467
- ...isInfinite ? importNames.queryInfinite.solid : importNames.query.solid,
468
- queryOptions: isV5 ? isInfinite ? "infiniteQueryOptions" : "queryOptions" : void 0,
469
- hookPath,
470
- ...rest
471
- }
472
- );
473
- };
474
- },
475
- get svelte() {
476
- return function({ context, hookPath, ...rest }) {
477
- const importNames = getImportNames();
478
- const isV5 = new PackageManager2().isValidSync(reactQueryDepRegex, ">=5");
479
- const { isInfinite } = context;
480
- return /* @__PURE__ */ jsx4(
481
- Template3,
482
- {
483
- isInfinite,
484
- ...isInfinite ? importNames.queryInfinite.svelte : importNames.query.svelte,
485
- queryOptions: isV5 ? isInfinite ? "infiniteQueryOptions" : "queryOptions" : void 0,
486
- hookPath,
487
- ...rest
488
- }
489
- );
490
- };
491
- },
492
- get vue() {
493
- return function({ context, hookPath, ...rest }) {
494
- const importNames = getImportNames();
495
- const isV5 = new PackageManager2().isValidSync(reactQueryDepRegex, ">=5");
496
- const { isInfinite } = context;
497
- const path = "@tanstack/vue-query";
498
- return /* @__PURE__ */ jsxs3(Fragment3, { children: [
499
- isV5 && /* @__PURE__ */ jsxs3(Fragment3, { children: [
500
- /* @__PURE__ */ jsx4(
501
- Template3,
502
- {
503
- isInfinite,
504
- ...isInfinite ? importNames.queryInfinite.vue : importNames.query.vue,
505
- queryOptions: isInfinite ? "infiniteQueryOptions" : "queryOptions",
506
- hookPath,
507
- ...rest
508
- }
509
- ),
510
- /* @__PURE__ */ jsx4(File3.Import, { name: ["QueryObserverOptions"], path, isTypeOnly: true })
511
- ] }),
512
- !isV5 && isInfinite && /* @__PURE__ */ jsxs3(Fragment3, { children: [
513
- /* @__PURE__ */ jsx4(File3.Import, { name: [importNames.queryInfinite.vue.resultType], path, isTypeOnly: true }),
514
- /* @__PURE__ */ jsx4(File3.Import, { name: [importNames.queryInfinite.vue.optionsType], path: "@tanstack/vue-query/build/lib/types", isTypeOnly: true }),
515
- /* @__PURE__ */ jsx4(File3.Import, { name: [importNames.queryInfinite.vue.hookName], path })
516
- ] }),
517
- !isV5 && !isInfinite && /* @__PURE__ */ jsxs3(Fragment3, { children: [
518
- /* @__PURE__ */ jsx4(File3.Import, { name: [importNames.query.vue.resultType], path, isTypeOnly: true }),
519
- /* @__PURE__ */ jsx4(File3.Import, { name: [importNames.query.vue.optionsType], path: "@tanstack/vue-query/build/lib/types", isTypeOnly: true }),
520
- /* @__PURE__ */ jsx4(File3.Import, { name: [importNames.query.vue.hookName], path })
521
- ] }),
522
- /* @__PURE__ */ jsx4(File3.Import, { name: ["unref"], path: "vue" }),
523
- /* @__PURE__ */ jsx4(File3.Import, { name: ["MaybeRef"], path: "vue", isTypeOnly: true }),
524
- /* @__PURE__ */ jsx4(File3.Import, { name: ["QueryKey", "WithRequired"], path, isTypeOnly: true })
525
- ] });
526
- };
527
- }
528
- };
529
- function QueryImports({ hookPath, isInfinite, isSuspense, Template: Template7 = defaultTemplates3.react }) {
530
- return /* @__PURE__ */ jsx4(
531
- Template7,
532
- {
533
- hookPath,
534
- context: {
535
- isInfinite,
536
- isSuspense
537
- }
538
- }
539
- );
540
- }
541
- QueryImports.templates = defaultTemplates3;
542
-
543
- // src/components/QueryKey.tsx
544
- import { FunctionParams as FunctionParams2, URLPath as URLPath2 } from "@kubb/core/utils";
545
- import { Function as Function2, Type as Type2, useApp as useApp4 } from "@kubb/react";
546
- import { useOperation as useOperation3, useOperationManager as useOperationManager3 } from "@kubb/plugin-oas/hooks";
547
- import { getASTParams as getASTParams2 } from "@kubb/plugin-oas/utils";
548
- import { isRequired as isRequired2 } from "@kubb/oas";
549
- import { pluginTsName as pluginTsName3 } from "@kubb/plugin-ts";
550
- import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
551
- function Template4({ name, typeName, params, generics, returnType, JSDoc, keys }) {
552
- return /* @__PURE__ */ jsxs4(Fragment4, { children: [
553
- /* @__PURE__ */ jsx5(Function2.Arrow, { name, export: true, generics, params, returnType, singleLine: true, JSDoc, children: `[${keys}] as const` }),
554
- /* @__PURE__ */ jsx5(Type2, { name: typeName, export: true, children: `ReturnType<typeof ${name}>` })
555
- ] });
556
- }
557
- var defaultTemplates4 = {
558
- get react() {
559
- return function(props) {
560
- return /* @__PURE__ */ jsx5(Template4, { ...props });
561
- };
562
- },
563
- get solid() {
564
- return function(props) {
565
- return /* @__PURE__ */ jsx5(Template4, { ...props });
566
- };
567
- },
568
- get svelte() {
569
- return function(props) {
570
- return /* @__PURE__ */ jsx5(Template4, { ...props });
571
- };
572
- },
573
- get vue() {
574
- return function({ context, ...rest }) {
575
- const { factory } = context;
576
- const {
577
- plugin: {
578
- options: { pathParamsType, query }
579
- }
580
- } = useApp4();
581
- const { getSchemas } = useOperationManager3();
582
- const operation = useOperation3();
583
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName3], type: "type" });
584
- const path = new URLPath2(operation.path);
585
- const params = new FunctionParams2();
586
- const withQueryParams = !!schemas.queryParams?.name;
587
- const withRequest = !!schemas.request?.name;
588
- params.add([
589
- ...pathParamsType === "object" ? [
590
- getASTParams2(schemas.pathParams, {
591
- typed: true,
592
- override: (item) => ({
593
- ...item,
594
- type: `MaybeRef<${item.type}>`
595
- })
596
- })
597
- ] : getASTParams2(schemas.pathParams, {
598
- typed: true,
599
- override: (item) => ({
600
- ...item,
601
- type: `MaybeRef<${item.type}>`
602
- })
603
- }),
604
- {
605
- name: "params",
606
- type: `MaybeRef<${`${factory.name}["queryParams"]`}>`,
607
- enabled: withQueryParams,
608
- required: isRequired2(schemas.queryParams?.schema)
609
- },
610
- {
611
- name: "request",
612
- type: `MaybeRef<${`${factory.name}["request"]`}>`,
613
- enabled: withRequest,
614
- required: isRequired2(schemas.request?.schema)
615
- }
616
- ]);
617
- const keys = [
618
- path.toObject({
619
- type: "path",
620
- stringify: true,
621
- replacer: (pathParam) => `unref(${pathParam})`
622
- }),
623
- withQueryParams ? "...(params ? [params] : [])" : void 0,
624
- withRequest ? "...(request ? [request] : [])" : void 0
625
- ].filter(Boolean);
626
- return /* @__PURE__ */ jsx5(Template4, { ...rest, params: params.toString(), keys: keys.join(", ") });
627
- };
628
- }
629
- };
630
- function QueryKey({ name, typeName, factory, keysFn, Template: Template7 = defaultTemplates4.react }) {
631
- const {
632
- plugin: {
633
- options: { pathParamsType }
634
- }
635
- } = useApp4();
636
- const { getSchemas } = useOperationManager3();
637
- const operation = useOperation3();
638
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName3], type: "type" });
639
- const path = new URLPath2(operation.path);
640
- const params = new FunctionParams2();
641
- const withQueryParams = !!schemas.queryParams?.name;
642
- const withRequest = !!schemas.request?.name;
643
- params.add([
644
- ...pathParamsType === "object" ? [getASTParams2(schemas.pathParams, { typed: true })] : getASTParams2(schemas.pathParams, { typed: true }),
645
- {
646
- name: "params",
647
- type: `${factory.name}["queryParams"]`,
648
- enabled: withQueryParams,
649
- required: isRequired2(schemas.queryParams?.schema)
650
- },
651
- {
652
- name: "data",
653
- type: `${factory.name}["request"]`,
654
- enabled: withRequest,
655
- required: isRequired2(schemas.request?.schema)
656
- }
657
- ]);
658
- const keys = [
659
- path.toObject({
660
- type: "path",
661
- stringify: true
662
- }),
663
- withQueryParams ? "...(params ? [params] : [])" : void 0,
664
- withRequest ? "...(data ? [data] : [])" : void 0
665
- ].filter(Boolean);
666
- return /* @__PURE__ */ jsx5(Template7, { typeName, name, params: params.toString(), keys: keysFn(keys).join(", "), context: { factory } });
667
- }
668
- QueryKey.templates = defaultTemplates4;
669
-
670
- // src/components/QueryOptions.tsx
671
- import { PackageManager as PackageManager3 } from "@kubb/core";
672
- import transformers2 from "@kubb/core/transformers";
673
- import { FunctionParams as FunctionParams3, URLPath as URLPath3 } from "@kubb/core/utils";
674
- import { useOperation as useOperation4, useOperationManager as useOperationManager4 } from "@kubb/plugin-oas/hooks";
675
- import { getASTParams as getASTParams3 } from "@kubb/plugin-oas/utils";
676
- import { Function as Function3, useApp as useApp5 } from "@kubb/react";
677
- import { pluginZodName } from "@kubb/plugin-zod";
678
- import { isRequired as isRequired3 } from "@kubb/oas";
679
- import { pluginTsName as pluginTsName4 } from "@kubb/plugin-ts";
680
- import { jsx as jsx6 } from "@kubb/react/jsx-runtime";
681
- function Template5({ name, params, generics, returnType, JSDoc, hook, client, infinite, dataReturnType, parser }) {
682
- const isV5 = new PackageManager3().isValidSync(reactQueryDepRegex, ">=5");
683
- const isFormData = client.contentType === "multipart/form-data";
684
- const headers = [
685
- client.contentType !== "application/json" ? `'Content-Type': '${client.contentType}'` : void 0,
686
- client.withHeaders ? "...headers" : void 0
687
- ].filter(Boolean).join(", ");
688
- const clientOptions = [
689
- `method: "${client.method}"`,
690
- `url: ${client.path.template}`,
691
- client.withQueryParams && !infinite ? "params" : void 0,
692
- client.withData && !isFormData ? "data" : void 0,
693
- client.withData && isFormData ? "data: formData" : void 0,
694
- headers.length ? `headers: { ${headers}, ...options.headers }` : void 0,
695
- "...options",
696
- client.withQueryParams && !!infinite ? `params: {
697
- ...params,
698
- ['${infinite.queryParam}']: pageParam,
699
- ...(options.params || {}),
700
- }` : void 0
701
- ].filter(Boolean);
702
- const queryOptions = [
703
- isV5 && !!infinite ? `initialPageParam: ${infinite.initialPageParam}` : void 0,
704
- isV5 && !!infinite && !!infinite.cursorParam ? `getNextPageParam: (lastPage) => lastPage['${infinite.cursorParam}']` : void 0,
705
- isV5 && !!infinite && !!infinite.cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${infinite.cursorParam}']` : void 0,
706
- isV5 && !!infinite && !infinite.cursorParam && dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : void 0,
707
- isV5 && !!infinite && !infinite.cursorParam && dataReturnType === "data" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1" : void 0,
708
- isV5 && !!infinite && !infinite.cursorParam ? "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1" : void 0
709
- ].filter(Boolean);
710
- const resolvedClientOptions = `${transformers2.createIndent(4)}${clientOptions.join(`,
711
- ${transformers2.createIndent(4)}`)}`;
712
- const resolvedQueryOptions = `${transformers2.createIndent(4)}${queryOptions.join(`,
713
- ${transformers2.createIndent(4)}`)}`;
714
- let returnRes = parser ? `return ${parser}(res.data)` : "return res.data";
715
- if (dataReturnType === "full") {
716
- returnRes = parser ? `return {...res, data: ${parser}(res.data)}` : "return res";
717
- }
718
- const formData = isFormData ? `
719
- const formData = new FormData()
720
- if(data) {
721
- Object.keys(data).forEach((key) => {
722
- const value = data[key];
723
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
724
- formData.append(key, value);
725
- }
726
- })
727
- }
728
- ` : void 0;
729
- if (infinite) {
730
- if (isV5) {
731
- return /* @__PURE__ */ jsx6(Function3, { name, export: true, params, JSDoc, children: `
732
- const queryKey = ${hook.queryKey}
733
-
734
- return infiniteQueryOptions({
735
- queryKey,
736
- queryFn: async ({ pageParam }) => {
737
- ${hook.children || ""}
738
- ${formData || ""}
739
- const res = await client<${client.generics}>({
740
- ${resolvedClientOptions}
741
- })
742
-
743
- ${returnRes}
744
- },
745
- ${resolvedQueryOptions}
746
- })
747
-
748
- ` });
749
- }
750
- return /* @__PURE__ */ jsx6(Function3, { name, export: true, generics, returnType, params, JSDoc, children: `
751
- const queryKey = ${hook.queryKey}
752
-
753
- return {
754
- queryKey,
755
- queryFn: async ({ pageParam }) => {
756
- ${hook.children || ""}
757
- ${formData || ""}
758
- const res = await client<${client.generics}>({
759
- ${resolvedClientOptions}
760
- })
761
-
762
- ${returnRes}
763
- },
764
- ${resolvedQueryOptions}
765
- }
766
-
767
- ` });
768
- }
769
- if (isV5) {
770
- return /* @__PURE__ */ jsx6(Function3, { name, export: true, params, JSDoc, children: `
771
- const queryKey = ${hook.queryKey}
772
-
773
- return queryOptions({
774
- queryKey,
775
- queryFn: async () => {
776
- ${hook.children || ""}
777
- ${formData || ""}
778
- const res = await client<${client.generics}>({
779
- ${resolvedClientOptions}
780
- })
781
-
782
- ${returnRes}
783
- },
784
- ${resolvedQueryOptions}
785
- })
786
-
787
- ` });
788
- }
789
- return /* @__PURE__ */ jsx6(Function3, { name, export: true, generics, returnType, params, JSDoc, children: `
790
- const queryKey = ${hook.queryKey}
791
-
792
- return {
793
- queryKey,
794
- queryFn: async () => {
795
- ${hook.children || ""}
796
- ${formData || ""}
797
- const res = await client<${client.generics}>({
798
- ${resolvedClientOptions}
799
- })
800
-
801
- ${returnRes}
802
- },
803
- ${resolvedQueryOptions}
804
- }
805
-
806
- ` });
807
- }
808
- var defaultTemplates5 = {
809
- get react() {
810
- return function(props) {
811
- return /* @__PURE__ */ jsx6(Template5, { ...props });
812
- };
813
- },
814
- get solid() {
815
- return function(props) {
816
- return /* @__PURE__ */ jsx6(Template5, { ...props });
817
- };
818
- },
819
- get svelte() {
820
- return function(props) {
821
- return /* @__PURE__ */ jsx6(Template5, { ...props });
822
- };
823
- },
824
- get vue() {
825
- return function({ client, context, ...rest }) {
826
- const { factory, queryKey } = context;
827
- const {
828
- plugin: {
829
- options: { pathParamsType }
830
- }
831
- } = useApp5();
832
- const { getSchemas } = useOperationManager4();
833
- const operation = useOperation4();
834
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName4], type: "type" });
835
- const params = new FunctionParams3();
836
- const queryKeyParams = new FunctionParams3();
837
- params.add([
838
- ...pathParamsType === "object" ? [
839
- getASTParams3(schemas.pathParams, {
840
- typed: true,
841
- override: (item) => ({
842
- ...item,
843
- name: item.name ? `ref${transformers2.pascalCase(item.name)}` : void 0,
844
- type: `MaybeRef<${item.type}>`
845
- })
846
- })
847
- ] : getASTParams3(schemas.pathParams, {
848
- typed: true,
849
- override: (item) => ({
850
- ...item,
851
- name: item.name ? `ref${transformers2.pascalCase(item.name)}` : void 0,
852
- type: `MaybeRef<${item.type}>`
853
- })
854
- }),
855
- {
856
- name: "refParams",
857
- type: `MaybeRef<${schemas.queryParams?.name}>`,
858
- enabled: client.withQueryParams,
859
- required: isRequired3(schemas.queryParams?.schema)
860
- },
861
- {
862
- name: "refHeaders",
863
- type: `MaybeRef<${schemas.headerParams?.name}>`,
864
- enabled: client.withHeaders,
865
- required: isRequired3(schemas.headerParams?.schema)
866
- },
867
- {
868
- name: "refData",
869
- type: `MaybeRef<${schemas.request?.name}>`,
870
- enabled: client.withData,
871
- required: isRequired3(schemas.request?.schema)
872
- },
873
- {
874
- name: "options",
875
- type: `${factory.name}['client']['parameters']`,
876
- default: "{}"
877
- }
878
- ]);
879
- queryKeyParams.add([
880
- ...pathParamsType === "object" ? [
881
- getASTParams3(schemas.pathParams, {
882
- override: (item) => ({
883
- ...item,
884
- name: item.name ? `ref${transformers2.pascalCase(item.name)}` : void 0
885
- })
886
- })
887
- ] : getASTParams3(schemas.pathParams, {
888
- override: (item) => ({
889
- ...item,
890
- name: item.name ? `ref${transformers2.pascalCase(item.name)}` : void 0
891
- })
892
- }),
893
- {
894
- name: "refParams",
895
- enabled: client.withQueryParams,
896
- required: isRequired3(schemas.queryParams?.schema)
897
- },
898
- {
899
- name: "refData",
900
- enabled: client.withData,
901
- required: isRequired3(schemas.request?.schema)
902
- }
903
- ]);
904
- const unrefs = params.items.filter((item) => item.enabled).map((item) => {
905
- return item.name ? `const ${transformers2.camelCase(item.name.replace("ref", ""))} = unref(${item.name})` : void 0;
906
- }).join("\n");
907
- const hook = {
908
- queryKey: `${queryKey}(${queryKeyParams.toString()})`,
909
- children: unrefs
910
- };
911
- return /* @__PURE__ */ jsx6(Template5, { ...rest, params: params.toString(), hook, client });
912
- };
913
- }
914
- };
915
- function QueryOptions({ factory, infinite, suspense, resultType, dataReturnType, Template: Template7 = defaultTemplates5.react }) {
916
- const {
917
- pluginManager,
918
- plugin: {
919
- key: pluginKey,
920
- options: { parser, pathParamsType, queryOptions }
921
- }
922
- } = useApp5();
923
- const { getSchemas } = useOperationManager4();
924
- const operation = useOperation4();
925
- const contentType = operation.getContentType();
926
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName4], type: "type" });
927
- const zodSchemas = getSchemas(operation, { pluginKey: [pluginZodName], type: "function" });
928
- const queryKey = pluginManager.resolveName({
929
- name: [factory.name, infinite ? "Infinite" : void 0, suspense ? "Suspense" : void 0, "QueryKey"].filter(Boolean).join(""),
930
- pluginKey
931
- });
932
- const queryOptionsName = pluginManager.resolveName({
933
- name: [factory.name, infinite ? "Infinite" : void 0, suspense ? "Suspense" : void 0, "QueryOptions"].filter(Boolean).join(""),
934
- pluginKey
935
- });
936
- const generics = new FunctionParams3();
937
- const params = new FunctionParams3();
938
- const queryKeyParams = new FunctionParams3();
939
- const clientGenerics = [`${factory.name}['data']`, `${factory.name}['error']`];
940
- const resultGenerics = suspense ? [`${factory.name}['response']`, `${factory.name}["error"]`, "TData"] : [`${factory.name}['response']`, `${factory.name}["error"]`, "TData", "TQueryData"];
941
- const client = {
942
- withQueryParams: !!schemas.queryParams?.name,
943
- withData: !!schemas.request?.name,
944
- withPathParams: !!schemas.pathParams?.name,
945
- withHeaders: !!schemas.headerParams?.name,
946
- method: operation.method,
947
- path: new URLPath3(operation.path),
948
- generics: clientGenerics.toString(),
949
- contentType
950
- };
951
- generics.add([
952
- { type: "TData", default: `${factory.name}["response"]` },
953
- suspense ? void 0 : { type: "TQueryData", default: `${factory.name}["response"]` }
954
- ]);
955
- params.add([
956
- ...pathParamsType === "object" ? [getASTParams3(schemas.pathParams, { typed: true })] : getASTParams3(schemas.pathParams, { typed: true }),
957
- {
958
- name: "params",
959
- type: `${factory.name}['queryParams']`,
960
- enabled: client.withQueryParams,
961
- required: isRequired3(schemas.queryParams?.schema)
962
- },
963
- {
964
- name: "headers",
965
- type: `${factory.name}['headerParams']`,
966
- enabled: client.withHeaders,
967
- required: isRequired3(schemas.headerParams?.schema)
968
- },
969
- {
970
- name: "data",
971
- type: `${factory.name}['request']`,
972
- enabled: client.withData,
973
- required: isRequired3(schemas.request?.schema)
974
- },
975
- {
976
- name: "options",
977
- type: `${factory.name}['client']['parameters']`,
978
- default: "{}"
979
- }
980
- ]);
981
- queryKeyParams.add([
982
- ...pathParamsType === "object" ? [getASTParams3(schemas.pathParams)] : getASTParams3(schemas.pathParams),
983
- {
984
- name: "params",
985
- enabled: client.withQueryParams,
986
- required: isRequired3(schemas.queryParams?.schema)
987
- },
988
- {
989
- name: "data",
990
- enabled: client.withData,
991
- required: isRequired3(schemas.request?.schema)
992
- }
993
- ]);
994
- const hook = {
995
- queryKey: `${queryKey}(${queryKeyParams.toString()})`
996
- };
997
- if (!queryOptions) {
998
- return null;
999
- }
1000
- return /* @__PURE__ */ jsx6(
1001
- Template7,
1002
- {
1003
- name: queryOptionsName,
1004
- params: params.toString(),
1005
- generics: generics.toString(),
1006
- returnType: `WithRequired<${resultType}<${resultGenerics.join(", ")}>, 'queryKey'>`,
1007
- client,
1008
- hook,
1009
- infinite,
1010
- dataReturnType,
1011
- parser: parser === "zod" ? `${zodSchemas.response.name}.parse` : void 0,
1012
- context: {
1013
- factory,
1014
- queryKey
1015
- }
1016
- }
1017
- );
1018
- }
1019
- QueryOptions.templates = defaultTemplates5;
1020
-
1021
- // src/components/Query.tsx
1022
- import { isRequired as isRequired4 } from "@kubb/oas";
1023
- import { Fragment as Fragment5, jsx as jsx7, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
1024
- function Template6({ name, generics, returnType, params, JSDoc, hook, infinite }) {
1025
- const isV5 = new PackageManager4().isValidSync(reactQueryDepRegex, ">=5");
1026
- const resolvedReturnType = `${returnType} & { queryKey: TQueryKey }`;
1027
- if (isV5) {
1028
- return /* @__PURE__ */ jsx7(Fragment5, { children: /* @__PURE__ */ jsx7(Function4, { name, export: true, generics, returnType: resolvedReturnType, params, JSDoc, children: `
1029
- const { query: queryOptions, client: clientOptions = {} } = options ?? {}
1030
- const queryKey = queryOptions?.queryKey ?? ${hook.queryKey}
1031
-
1032
- const query = ${hook.name}({
1033
- ...${hook.queryOptions} as unknown as ${infinite ? "InfiniteQueryObserverOptions" : "QueryObserverOptions"},
1034
- queryKey,
1035
- ...queryOptions as unknown as ${infinite ? 'Omit<InfiniteQueryObserverOptions, "queryKey">' : 'Omit<QueryObserverOptions, "queryKey">'}
1036
- }) as ${resolvedReturnType}
1037
-
1038
- query.queryKey = queryKey as TQueryKey
1039
-
1040
- return query
1041
-
1042
- ` }) });
1043
- }
1044
- return /* @__PURE__ */ jsx7(Fragment5, { children: /* @__PURE__ */ jsx7(Function4, { name, export: true, generics, returnType: resolvedReturnType, params, JSDoc, children: `
1045
- const { query: queryOptions, client: clientOptions = {} } = options ?? {}
1046
- const queryKey = queryOptions?.queryKey ?? ${hook.queryKey}
1047
-
1048
- const query = ${hook.name}<${hook.generics}>({
1049
- ...${hook.queryOptions},
1050
- queryKey,
1051
- ...queryOptions
1052
- }) as ${resolvedReturnType}
1053
-
1054
- query.queryKey = queryKey as TQueryKey
1055
-
1056
- return query
1057
-
1058
- ` }) });
1059
- }
1060
- var defaultTemplates6 = {
1061
- get react() {
1062
- return function(props) {
1063
- return /* @__PURE__ */ jsx7(Template6, { ...props });
1064
- };
1065
- },
1066
- get solid() {
1067
- return function(props) {
1068
- return /* @__PURE__ */ jsx7(Template6, { ...props });
1069
- };
1070
- },
1071
- get svelte() {
1072
- return function(props) {
1073
- return /* @__PURE__ */ jsx7(Template6, { ...props });
1074
- };
1075
- },
1076
- get vue() {
1077
- return function({ context, hook, ...rest }) {
1078
- const { factory, queryKey } = context;
1079
- const {
1080
- pluginManager,
1081
- plugin: {
1082
- key: pluginKey,
1083
- options: { pathParamsType }
1084
- }
1085
- } = useApp6();
1086
- const operation = useOperation5();
1087
- const { getSchemas } = useOperationManager5();
1088
- const importNames = getImportNames();
1089
- const queryOptions = pluginManager.resolveName({
1090
- name: `${factory.name}QueryOptions`,
1091
- pluginKey
1092
- });
1093
- const hookName = rest.infinite ? importNames.queryInfinite.vue.hookName : importNames.query.vue.hookName;
1094
- const resultType = rest.infinite ? importNames.queryInfinite.vue.resultType : importNames.query.vue.resultType;
1095
- const optionsType = rest.infinite ? importNames.queryInfinite.vue.optionsType : importNames.query.vue.optionsType;
1096
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName5], type: "type" });
1097
- const isV5 = new PackageManager4().isValidSync(reactQueryDepRegex, ">=5");
1098
- const params = new FunctionParams4();
1099
- const queryParams = new FunctionParams4();
1100
- const queryKeyParams = new FunctionParams4();
1101
- const client = {
1102
- withQueryParams: !!schemas.queryParams?.name,
1103
- withData: !!schemas.request?.name,
1104
- withPathParams: !!schemas.pathParams?.name,
1105
- withHeaders: !!schemas.headerParams?.name
1106
- };
1107
- const resultGenerics = ["TData", `${factory.name}['error']`];
1108
- const queryOptionsOverrideGenerics = [`${factory.name}['response']`, `${factory.name}['error']`, "TData", "TQueryKey"];
1109
- const queryOptionsGenerics = ["TData", "TQueryData"];
1110
- params.add([
1111
- ...pathParamsType === "object" ? [
1112
- getASTParams4(schemas.pathParams, {
1113
- typed: true,
1114
- override: (item) => ({
1115
- ...item,
1116
- name: item.name ? `ref${transformers3.pascalCase(item.name)}` : void 0
1117
- })
1118
- })
1119
- ] : getASTParams4(schemas.pathParams, {
1120
- typed: true,
1121
- override: (item) => ({
1122
- ...item,
1123
- name: item.name ? `ref${transformers3.pascalCase(item.name)}` : void 0
1124
- })
1125
- }),
1126
- {
1127
- name: "refParams",
1128
- type: `MaybeRef<${schemas.queryParams?.name}>`,
1129
- enabled: client.withQueryParams,
1130
- required: isRequired4(schemas.queryParams?.schema)
1131
- },
1132
- {
1133
- name: "refHeaders",
1134
- type: `MaybeRef<${schemas.headerParams?.name}>`,
1135
- enabled: client.withHeaders,
1136
- required: isRequired4(schemas.headerParams?.schema)
1137
- },
1138
- {
1139
- name: "refData",
1140
- type: `MaybeRef<${schemas.request?.name}>`,
1141
- enabled: client.withData,
1142
- required: isRequired4(schemas.request?.schema)
1143
- },
1144
- {
1145
- name: "options",
1146
- type: `{
1147
- query?: Partial<${optionsType}<${queryOptionsOverrideGenerics.join(", ")}>>,
1148
- client?: ${factory.name}['client']['parameters']
1149
- }`,
1150
- default: "{}"
1151
- }
1152
- ]);
1153
- queryParams.add([
1154
- ...getASTParams4(schemas.pathParams, {
1155
- typed: false,
1156
- override: (item) => ({
1157
- ...item,
1158
- name: item.name ? `ref${transformers3.pascalCase(item.name)}` : void 0
1159
- })
1160
- }),
1161
- {
1162
- name: "refParams",
1163
- enabled: client.withQueryParams,
1164
- required: isRequired4(schemas.queryParams?.schema)
1165
- },
1166
- {
1167
- name: "refHeaders",
1168
- enabled: client.withHeaders,
1169
- required: isRequired4(schemas.headerParams?.schema)
1170
- },
1171
- {
1172
- name: "clientOptions",
1173
- required: false
1174
- }
1175
- ]);
1176
- queryKeyParams.add([
1177
- ...pathParamsType === "object" ? [
1178
- getASTParams4(schemas.pathParams, {
1179
- override: (item) => ({
1180
- ...item,
1181
- name: item.name ? `ref${transformers3.pascalCase(item.name)}` : void 0
1182
- })
1183
- })
1184
- ] : getASTParams4(schemas.pathParams, {
1185
- override: (item) => ({
1186
- ...item,
1187
- name: item.name ? `ref${transformers3.pascalCase(item.name)}` : void 0
1188
- })
1189
- }),
1190
- {
1191
- name: "refParams",
1192
- enabled: client.withQueryParams,
1193
- required: isRequired4(schemas.queryParams?.schema)
1194
- },
1195
- {
1196
- name: "refData",
1197
- enabled: client.withData,
1198
- required: isRequired4(schemas.request?.schema)
1199
- }
1200
- ]);
1201
- return /* @__PURE__ */ jsx7(
1202
- Template6,
1203
- {
1204
- ...rest,
1205
- params: params.toString(),
1206
- returnType: `${resultType}<${resultGenerics.join(", ")}>`,
1207
- hook: {
1208
- ...hook,
1209
- name: hookName,
1210
- queryOptions: isV5 ? `${queryOptions}(${queryParams.toString()})` : `${queryOptions}<${queryOptionsGenerics.join(", ")}>(${queryParams.toString()})`,
1211
- queryKey: `${queryKey}(${queryKeyParams.toString()})`
1212
- }
1213
- }
1214
- );
1215
- };
1216
- }
1217
- };
1218
- function Query({
1219
- factory,
1220
- optionsType,
1221
- hookName,
1222
- resultType,
1223
- Template: Template7 = defaultTemplates6.react,
1224
- QueryKeyTemplate = QueryKey.templates.react,
1225
- QueryOptionsTemplate = QueryOptions.templates.react,
1226
- ...props
1227
- }) {
1228
- const {
1229
- pluginManager,
1230
- plugin: {
1231
- key: pluginKey,
1232
- options: { dataReturnType, pathParamsType }
1233
- }
1234
- } = useApp6();
1235
- const operation = useOperation5();
1236
- const { getSchemas, getName } = useOperationManager5();
1237
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName5], type: "type" });
1238
- const name = getName(operation, { type: "function" });
1239
- const isV5 = new PackageManager4().isValidSync(reactQueryDepRegex, ">=5");
1240
- const queryKey = pluginManager.resolveName({
1241
- name: [factory.name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0, "QueryKey"].filter(Boolean).join(""),
1242
- pluginKey
1243
- });
1244
- const queryKeyType = pluginManager.resolveName({
1245
- name: [factory.name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0, "QueryKey"].filter(Boolean).join(""),
1246
- type: "type",
1247
- pluginKey
1248
- });
1249
- const queryOptions = pluginManager.resolveName({
1250
- name: [factory.name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0, "QueryOptions"].filter(Boolean).join(""),
1251
- pluginKey
1252
- });
1253
- const generics = new FunctionParams4();
1254
- const params = new FunctionParams4();
1255
- const queryParams = new FunctionParams4();
1256
- const queryKeyParams = new FunctionParams4();
1257
- const client = {
1258
- method: operation.method,
1259
- path: new URLPath4(operation.path),
1260
- withQueryParams: !!schemas.queryParams?.name,
1261
- withData: !!schemas.request?.name,
1262
- withPathParams: !!schemas.pathParams?.name,
1263
- withHeaders: !!schemas.headerParams?.name
1264
- };
1265
- generics.add([
1266
- {
1267
- type: "TData",
1268
- default: props.infinite ? `InfiniteData<${factory.name}["response"]>` : `${factory.name}["response"]`
1269
- },
1270
- props.suspense ? void 0 : { type: "TQueryData", default: `${factory.name}["response"]` },
1271
- { type: "TQueryKey extends QueryKey", default: queryKeyType }
1272
- ]);
1273
- const resultGenerics = ["TData", `${factory.name}['error']`];
1274
- const queryOptionsOverrideGenerics = props.suspense ? [`${factory.name}['response']`, `${factory.name}['error']`, "TData", "TQueryKey"] : [`${factory.name}['response']`, `${factory.name}['error']`, "TData", "TQueryData", "TQueryKey"];
1275
- const queryOptionsGenerics = props.suspense ? ["TData"] : ["TData", "TQueryData"];
1276
- params.add([
1277
- ...pathParamsType === "object" ? [getASTParams4(schemas.pathParams, { typed: true })] : getASTParams4(schemas.pathParams, { typed: true }),
1278
- {
1279
- name: "params",
1280
- type: `${factory.name}['queryParams']`,
1281
- enabled: client.withQueryParams,
1282
- required: isRequired4(schemas.queryParams?.schema)
1283
- },
1284
- {
1285
- name: "headers",
1286
- type: `${factory.name}['headerParams']`,
1287
- enabled: client.withHeaders,
1288
- required: isRequired4(schemas.headerParams?.schema)
1289
- },
1290
- {
1291
- name: "data",
1292
- type: `${factory.name}['request']`,
1293
- enabled: client.withData,
1294
- required: isRequired4(schemas.request?.schema)
1295
- },
1296
- {
1297
- name: "options",
1298
- type: `{
1299
- query?: Partial<${optionsType}<${queryOptionsOverrideGenerics.join(", ")}>>,
1300
- client?: ${factory.name}['client']['parameters']
1301
- }`,
1302
- default: "{}"
1303
- }
1304
- ]);
1305
- queryParams.add([
1306
- ...pathParamsType === "object" ? [getASTParams4(schemas.pathParams)] : getASTParams4(schemas.pathParams),
1307
- {
1308
- name: "params",
1309
- enabled: client.withQueryParams,
1310
- required: isRequired4(schemas.queryParams?.schema)
1311
- },
1312
- {
1313
- name: "headers",
1314
- enabled: client.withHeaders,
1315
- required: isRequired4(schemas.headerParams?.schema)
1316
- },
1317
- {
1318
- name: "data",
1319
- enabled: client.withData,
1320
- required: isRequired4(schemas.request?.schema)
1321
- },
1322
- {
1323
- name: "clientOptions",
1324
- required: false
1325
- }
1326
- ]);
1327
- queryKeyParams.add([
1328
- ...pathParamsType === "object" ? [getASTParams4(schemas.pathParams)] : getASTParams4(schemas.pathParams),
1329
- {
1330
- name: "params",
1331
- enabled: client.withQueryParams,
1332
- required: isRequired4(schemas.queryParams?.schema)
1333
- },
1334
- {
1335
- name: "data",
1336
- enabled: client.withData,
1337
- required: isRequired4(schemas.request?.schema)
1338
- }
1339
- ]);
1340
- const hook = {
1341
- name: hookName,
1342
- generics: [isV5 ? "any" : `${factory.name}['data']`, `${factory.name}['error']`, "TData", "any"].join(", "),
1343
- queryOptions: isV5 ? `${queryOptions}(${queryParams.toString()})` : `${queryOptions}<${queryOptionsGenerics.join(", ")}>(${queryParams.toString()})`,
1344
- queryKey: `${queryKey}(${queryKeyParams.toString()})`
1345
- };
1346
- return /* @__PURE__ */ jsxs5(Fragment5, { children: [
1347
- /* @__PURE__ */ jsx7(
1348
- QueryKey,
1349
- {
1350
- keysFn: props.query ? props.query.queryKey : (keys) => keys,
1351
- Template: QueryKeyTemplate,
1352
- factory,
1353
- name: queryKey,
1354
- typeName: queryKeyType
1355
- }
1356
- ),
1357
- props.queryOptions && /* @__PURE__ */ jsx7(
1358
- QueryOptions,
1359
- {
1360
- Template: QueryOptionsTemplate,
1361
- factory,
1362
- resultType: optionsType,
1363
- dataReturnType,
1364
- infinite: props.infinite,
1365
- suspense: props.suspense
1366
- }
1367
- ),
1368
- props.query && /* @__PURE__ */ jsx7(
1369
- Template7,
1370
- {
1371
- name: [name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0].filter(Boolean).join(""),
1372
- generics: generics.toString(),
1373
- JSDoc: { comments: getComments2(operation) },
1374
- params: params.toString(),
1375
- returnType: `${resultType}<${resultGenerics.join(", ")}>`,
1376
- hook,
1377
- infinite: props.infinite,
1378
- context: {
1379
- factory,
1380
- queryKey
1381
- }
1382
- }
1383
- )
1384
- ] });
1385
- }
1386
- Query.File = function({ templates }) {
1387
- const {
1388
- plugin: {
1389
- options: {
1390
- client: { importPath },
1391
- infinite,
1392
- suspense,
1393
- query,
1394
- queryOptions,
1395
- parser
1396
- }
1397
- }
1398
- } = useApp6();
1399
- const { getSchemas, getFile, getName } = useOperationManager5();
1400
- const operation = useOperation5();
1401
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName5], type: "type" });
1402
- const zodSchemas = getSchemas(operation, { pluginKey: [pluginZodName2], type: "function" });
1403
- const file = getFile(operation);
1404
- const fileType = getFile(operation, { pluginKey: [pluginTsName5] });
1405
- const fileZodSchemas = getFile(operation, {
1406
- pluginKey: [pluginZodName2]
1407
- });
1408
- const factoryName = getName(operation, { type: "type" });
1409
- const importNames = getImportNames();
1410
- const isV5 = new PackageManager4().isValidSync(reactQueryDepRegex, ">=5");
1411
- const Template7 = templates?.query["react"] || defaultTemplates6["react"];
1412
- const QueryOptionsTemplate = templates?.queryOptions["react"] || QueryOptions.templates["react"];
1413
- const QueryKeyTemplate = templates?.queryKey["react"] || QueryKey.templates["react"];
1414
- const Import = templates?.queryImports["react"] || QueryImports.templates["react"];
1415
- const factory = {
1416
- name: factoryName
1417
- };
1418
- return /* @__PURE__ */ jsx7(Parser3, { language: "typescript", children: /* @__PURE__ */ jsxs5(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
1419
- parser === "zod" && /* @__PURE__ */ jsx7(File4.Import, { name: [zodSchemas.response?.name], root: file.path, path: fileZodSchemas.path }),
1420
- /* @__PURE__ */ jsx7(File4.Import, { name: "client", path: importPath }),
1421
- /* @__PURE__ */ jsx7(File4.Import, { name: ["ResponseConfig"], path: importPath, isTypeOnly: true }),
1422
- /* @__PURE__ */ jsx7(
1423
- File4.Import,
1424
- {
1425
- name: [
1426
- schemas.request?.name,
1427
- schemas.response.name,
1428
- schemas.pathParams?.name,
1429
- schemas.queryParams?.name,
1430
- schemas.headerParams?.name,
1431
- ...schemas.errors?.map((error) => error.name) || []
1432
- ].filter(Boolean),
1433
- root: file.path,
1434
- path: fileType.path,
1435
- isTypeOnly: true
1436
- }
1437
- ),
1438
- /* @__PURE__ */ jsx7(QueryImports, { hookPath: typeof query !== "boolean" ? query.importPath : void 0, Template: Import, isInfinite: false, isSuspense: false }),
1439
- !!infinite && /* @__PURE__ */ jsx7(QueryImports, { hookPath: typeof query !== "boolean" ? query.importPath : void 0, Template: Import, isInfinite: true, isSuspense: false }),
1440
- !!suspense && isV5 && /* @__PURE__ */ jsx7(QueryImports, { hookPath: typeof query !== "boolean" ? query.importPath : void 0, Template: Import, isInfinite: false, isSuspense: true }),
1441
- /* @__PURE__ */ jsxs5(File4.Source, { children: [
1442
- /* @__PURE__ */ jsx7(SchemaType, {}),
1443
- /* @__PURE__ */ jsx7(
1444
- Query,
1445
- {
1446
- factory,
1447
- Template: Template7,
1448
- QueryKeyTemplate,
1449
- QueryOptionsTemplate,
1450
- infinite: false,
1451
- suspense: false,
1452
- query,
1453
- queryOptions,
1454
- hookName: importNames.query["react"].hookName,
1455
- resultType: importNames.query["react"].resultType,
1456
- optionsType: importNames.query["react"].optionsType
1457
- }
1458
- ),
1459
- !!infinite && /* @__PURE__ */ jsx7(
1460
- Query,
1461
- {
1462
- factory,
1463
- Template: Template7,
1464
- QueryKeyTemplate,
1465
- QueryOptionsTemplate,
1466
- infinite,
1467
- suspense: false,
1468
- query,
1469
- queryOptions,
1470
- hookName: importNames.queryInfinite["react"].hookName,
1471
- resultType: importNames.queryInfinite["react"].resultType,
1472
- optionsType: importNames.queryInfinite["react"].optionsType
1473
- }
1474
- ),
1475
- !!suspense && isV5 && /* @__PURE__ */ jsx7(
1476
- Query,
1477
- {
1478
- factory,
1479
- Template: Template7,
1480
- QueryKeyTemplate,
1481
- QueryOptionsTemplate,
1482
- infinite: false,
1483
- suspense,
1484
- query,
1485
- queryOptions,
1486
- hookName: importNames.querySuspense["react"].hookName,
1487
- resultType: importNames.querySuspense["react"].resultType,
1488
- optionsType: importNames.querySuspense["react"].optionsType
1489
- }
1490
- )
1491
- ] })
1492
- ] }) });
1493
- };
1494
- Query.templates = defaultTemplates6;
1495
-
1496
- export {
1497
- Mutation,
1498
- Operations,
1499
- QueryImports,
1500
- QueryKey,
1501
- QueryOptions,
1502
- Query
1503
- };
1504
- //# sourceMappingURL=chunk-5IL6M74X.js.map