@kubb/plugin-react-query 3.0.0-alpha.1 → 3.0.0-alpha.11

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