@kubb/plugin-react-query 3.0.0-alpha.14 → 3.0.0-alpha.16

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