@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.2

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