@kubb/plugin-swr 3.0.0-alpha.2 → 3.0.0-alpha.20

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 (58) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-7WG6LPZJ.js +185 -0
  3. package/dist/chunk-7WG6LPZJ.js.map +1 -0
  4. package/dist/chunk-DGY6XSP2.js +187 -0
  5. package/dist/chunk-DGY6XSP2.js.map +1 -0
  6. package/dist/chunk-RMG5RYPG.cjs +189 -0
  7. package/dist/chunk-RMG5RYPG.cjs.map +1 -0
  8. package/dist/chunk-WI3XUYBA.cjs +194 -0
  9. package/dist/chunk-WI3XUYBA.cjs.map +1 -0
  10. package/dist/components.cjs +15 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +49 -6
  13. package/dist/components.d.ts +49 -6
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +10 -0
  19. package/dist/generators.d.ts +10 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +90 -127
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -4
  25. package/dist/index.d.ts +1 -4
  26. package/dist/index.js +70 -114
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-BCd4p4VZ.d.cts +127 -0
  29. package/dist/types-BCd4p4VZ.d.ts +127 -0
  30. package/package.json +22 -16
  31. package/src/components/Mutation.tsx +82 -227
  32. package/src/components/Query.tsx +86 -264
  33. package/src/components/QueryOptions.tsx +58 -179
  34. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +40 -0
  35. package/src/generators/__snapshots__/clientGetImportPath.ts +40 -0
  36. package/src/generators/__snapshots__/clientPostImportPath.ts +30 -0
  37. package/src/generators/__snapshots__/findByTags.ts +40 -0
  38. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +40 -0
  39. package/src/generators/__snapshots__/findByTagsWithZod.ts +40 -0
  40. package/src/generators/__snapshots__/getAsMutation.ts +32 -0
  41. package/src/generators/__snapshots__/postAsQuery.ts +39 -0
  42. package/src/generators/__snapshots__/updatePetById.ts +30 -0
  43. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
  44. package/src/generators/index.ts +2 -0
  45. package/src/generators/mutationGenerator.tsx +96 -0
  46. package/src/generators/queryGenerator.tsx +101 -0
  47. package/src/plugin.ts +61 -50
  48. package/src/types.ts +63 -55
  49. package/dist/chunk-ECJ346AA.js +0 -542
  50. package/dist/chunk-ECJ346AA.js.map +0 -1
  51. package/dist/chunk-H4LHXYRJ.cjs +0 -542
  52. package/dist/chunk-H4LHXYRJ.cjs.map +0 -1
  53. package/dist/index-B3C-JOIU.d.cts +0 -299
  54. package/dist/index-B3C-JOIU.d.ts +0 -299
  55. package/src/OperationGenerator.tsx +0 -75
  56. package/src/components/SchemaType.tsx +0 -59
  57. package/src/components/__snapshots__/Mutation/Pets.ts +0 -42
  58. package/src/components/__snapshots__/Query/showPetById.ts +0 -55
@@ -1,542 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/Mutation.tsx
2
- var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
3
- var _utils = require('@kubb/core/utils');
4
- var _react = require('@kubb/react');
5
- var _plugints = require('@kubb/plugin-ts');
6
- var _hooks = require('@kubb/plugin-oas/hooks');
7
- var _utils3 = require('@kubb/plugin-oas/utils');
8
-
9
- // src/components/SchemaType.tsx
10
-
11
-
12
-
13
- var _jsxruntime = require('@kubb/react/jsx-runtime');
14
- function SchemaType({ factory }) {
15
- const {
16
- plugin: {
17
- options: { dataReturnType }
18
- }
19
- } = _react.useApp.call(void 0, );
20
- const { getSchemas } = _hooks.useOperationManager.call(void 0, );
21
- const operation = _hooks.useOperation.call(void 0, );
22
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
23
- const [TData, TError, TRequest, TPathParams, TQueryParams, THeaderParams, TResponse] = [
24
- schemas.response.name,
25
- _optionalChain([schemas, 'access', _ => _.errors, 'optionalAccess', _2 => _2.map, 'call', _3 => _3((item) => item.name), 'access', _4 => _4.join, 'call', _5 => _5(" | ")]) || "never",
26
- _optionalChain([schemas, 'access', _6 => _6.request, 'optionalAccess', _7 => _7.name]) || "never",
27
- _optionalChain([schemas, 'access', _8 => _8.pathParams, 'optionalAccess', _9 => _9.name]) || "never",
28
- _optionalChain([schemas, 'access', _10 => _10.queryParams, 'optionalAccess', _11 => _11.name]) || "never",
29
- _optionalChain([schemas, 'access', _12 => _12.headerParams, 'optionalAccess', _13 => _13.name]) || "never",
30
- schemas.response.name
31
- ];
32
- const clientType = `${factory.name}Client`;
33
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
34
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { name: clientType, children: `typeof client<${TResponse}, ${TError}, ${TRequest}>` }),
35
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { name: factory.name, children: `
36
- {
37
- data: ${TData}
38
- error: ${TError}
39
- request: ${TRequest}
40
- pathParams: ${TPathParams}
41
- queryParams: ${TQueryParams}
42
- headerParams: ${THeaderParams}
43
- response: ${dataReturnType === "data" ? TData : `Awaited<ReturnType<${clientType}>>`}
44
- client: {
45
- parameters: Partial<Parameters<${clientType}>[0]>
46
- return: Awaited<ReturnType<${clientType}>>
47
- }
48
- }
49
- ` })
50
- ] });
51
- }
52
-
53
- // src/components/Mutation.tsx
54
-
55
- function Template({ name, generics, returnType, params, JSDoc, client, hook, dataReturnType }) {
56
- const clientOptions = [
57
- `method: "${client.method}"`,
58
- "url",
59
- client.withQueryParams ? "params" : void 0,
60
- client.withData ? "data" : void 0,
61
- client.withHeaders ? "headers: { ...headers, ...clientOptions.headers }" : void 0,
62
- "...clientOptions"
63
- ].filter(Boolean);
64
- const resolvedClientOptions = `${_transformers2.default.createIndent(4)}${clientOptions.join(`,
65
- ${_transformers2.default.createIndent(4)}`)}`;
66
- if (client.withQueryParams) {
67
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { export: true, name, generics, returnType, params, JSDoc, children: `
68
- const { mutation: mutationOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
69
-
70
- const url = ${client.path.template} as const
71
- return ${hook.name}<${hook.generics}>(
72
- shouldFetch ? [url, params]: null,
73
- async (_url${client.withData ? ", { arg: data }" : ""}) => {
74
- const res = await client<${client.generics}>({
75
- ${resolvedClientOptions}
76
- })
77
-
78
- return ${dataReturnType === "data" ? "res.data" : "res"}
79
- },
80
- mutationOptions
81
- )
82
- ` });
83
- }
84
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { export: true, name, generics, returnType, params, JSDoc, children: `
85
- const { mutation: mutationOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
86
-
87
- const url = ${client.path.template} as const
88
- return ${hook.name}<${hook.generics}>(
89
- shouldFetch ? url : null,
90
- async (_url${client.withData ? ", { arg: data }" : ""}) => {
91
- const res = await client<${client.generics}>({
92
- ${resolvedClientOptions}
93
- })
94
-
95
- return ${dataReturnType === "data" ? "res.data" : "res"}
96
- },
97
- mutationOptions
98
- )
99
- ` });
100
- }
101
- var defaultTemplates = {
102
- default: Template
103
- };
104
- function Mutation({ factory, Template: Template4 = defaultTemplates.default }) {
105
- const {
106
- plugin: {
107
- options: { dataReturnType }
108
- }
109
- } = _react.useApp.call(void 0, );
110
- const { getSchemas, getName } = _hooks.useOperationManager.call(void 0, );
111
- const operation = _hooks.useOperation.call(void 0, );
112
- const name = getName(operation, { type: "function" });
113
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
114
- const params = new (0, _utils.FunctionParams)();
115
- const client = {
116
- method: operation.method,
117
- path: new (0, _utils.URLPath)(operation.path),
118
- generics: [`${factory.name}["data"]`, `${factory.name}["error"]`, _optionalChain([schemas, 'access', _14 => _14.request, 'optionalAccess', _15 => _15.name]) ? `${factory.name}["request"]` : ""].filter(Boolean).join(", "),
119
- withQueryParams: !!_optionalChain([schemas, 'access', _16 => _16.queryParams, 'optionalAccess', _17 => _17.name]),
120
- withData: !!_optionalChain([schemas, 'access', _18 => _18.request, 'optionalAccess', _19 => _19.name]),
121
- withPathParams: !!_optionalChain([schemas, 'access', _20 => _20.pathParams, 'optionalAccess', _21 => _21.name]),
122
- withHeaders: !!_optionalChain([schemas, 'access', _22 => _22.headerParams, 'optionalAccess', _23 => _23.name])
123
- };
124
- const resultGenerics = [`${factory.name}["response"]`, `${factory.name}["error"]`];
125
- params.add([
126
- ..._utils3.getASTParams.call(void 0, schemas.pathParams, { typed: true }),
127
- {
128
- name: "params",
129
- type: `${factory.name}['queryParams']`,
130
- enabled: client.withQueryParams,
131
- required: false
132
- },
133
- {
134
- name: "headers",
135
- type: `${factory.name}['headerParams']`,
136
- enabled: client.withHeaders,
137
- required: false
138
- },
139
- {
140
- name: "options",
141
- required: false,
142
- type: `{
143
- mutation?: SWRMutationConfiguration<${resultGenerics.join(", ")}>,
144
- client?: ${factory.name}['client']['parameters'],
145
- shouldFetch?: boolean,
146
- }`,
147
- default: "{}"
148
- }
149
- ]);
150
- const hook = {
151
- name: "useSWRMutation",
152
- generics: [...resultGenerics, client.withQueryParams ? "[typeof url, typeof params] | null" : "typeof url | null"].join(", ")
153
- };
154
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
155
- Template4,
156
- {
157
- name,
158
- JSDoc: { comments: _utils3.getComments.call(void 0, operation) },
159
- client,
160
- hook,
161
- params: params.toString(),
162
- returnType: `SWRMutationResponse<${resultGenerics.join(", ")}>`,
163
- dataReturnType
164
- }
165
- );
166
- }
167
- Mutation.File = function({ templates = defaultTemplates }) {
168
- const {
169
- plugin: {
170
- options: {
171
- extName,
172
- client: { importPath }
173
- }
174
- }
175
- } = _react.useApp.call(void 0, );
176
- const { getSchemas, getFile, getName } = _hooks.useOperationManager.call(void 0, );
177
- const operation = _hooks.useOperation.call(void 0, );
178
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
179
- const file = getFile(operation);
180
- const fileType = getFile(operation, { pluginKey: [_plugints.pluginTsName] });
181
- const factoryName = getName(operation, { type: "type" });
182
- const Template4 = templates.default;
183
- const factory = {
184
- name: factoryName
185
- };
186
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
187
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "useSWRMutation", path: "swr/mutation" }),
188
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["SWRMutationConfiguration", "SWRMutationResponse"], path: "swr/mutation", isTypeOnly: true }),
189
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "client", path: importPath }),
190
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["ResponseConfig"], path: importPath, isTypeOnly: true }),
191
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
192
- _react.File.Import,
193
- {
194
- extName,
195
- name: [
196
- _optionalChain([schemas, 'access', _24 => _24.request, 'optionalAccess', _25 => _25.name]),
197
- schemas.response.name,
198
- _optionalChain([schemas, 'access', _26 => _26.pathParams, 'optionalAccess', _27 => _27.name]),
199
- _optionalChain([schemas, 'access', _28 => _28.queryParams, 'optionalAccess', _29 => _29.name]),
200
- _optionalChain([schemas, 'access', _30 => _30.headerParams, 'optionalAccess', _31 => _31.name]),
201
- ..._optionalChain([schemas, 'access', _32 => _32.errors, 'optionalAccess', _33 => _33.map, 'call', _34 => _34((error) => error.name)]) || []
202
- ].filter(Boolean),
203
- root: file.path,
204
- path: fileType.path,
205
- isTypeOnly: true
206
- }
207
- ),
208
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File.Source, { children: [
209
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SchemaType, { factory }),
210
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Mutation, { Template: Template4, factory })
211
- ] })
212
- ] }) });
213
- };
214
- Mutation.templates = defaultTemplates;
215
-
216
- // src/components/Query.tsx
217
-
218
-
219
-
220
-
221
-
222
- var _pluginzod = require('@kubb/plugin-zod');
223
-
224
- // src/components/QueryOptions.tsx
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
- function Template2({ name, params, generics, returnType, JSDoc, client, dataReturnType, parser }) {
234
- const isFormData = client.contentType === "multipart/form-data";
235
- const headers = [
236
- client.contentType !== "application/json" ? `'Content-Type': '${client.contentType}'` : void 0,
237
- client.withHeaders ? "...headers" : void 0
238
- ].filter(Boolean).join(", ");
239
- const clientOptions = [
240
- `method: "${client.method}"`,
241
- `url: ${client.path.template}`,
242
- client.withQueryParams ? "params" : void 0,
243
- client.withData && !isFormData ? "data" : void 0,
244
- client.withData && isFormData ? "data: formData" : void 0,
245
- headers.length ? `headers: { ${headers}, ...options.headers }` : void 0,
246
- "...options"
247
- ].filter(Boolean);
248
- const resolvedClientOptions = `${_transformers2.default.createIndent(4)}${clientOptions.join(`,
249
- ${_transformers2.default.createIndent(4)}`)}`;
250
- let returnRes = parser ? `return ${parser}(res.data)` : "return res.data";
251
- if (dataReturnType === "full") {
252
- returnRes = parser ? `return {...res, data: ${parser}(res.data)}` : "return res";
253
- }
254
- const formData = isFormData ? `
255
- const formData = new FormData()
256
- if(data) {
257
- Object.keys(data).forEach((key) => {
258
- const value = data[key];
259
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
260
- formData.append(key, value);
261
- }
262
- })
263
- }
264
- ` : void 0;
265
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { name, export: true, generics, returnType, params, JSDoc, children: `
266
- return {
267
- fetcher: async () => {
268
- ${formData || ""}
269
- const res = await client<${client.generics}>({
270
- ${resolvedClientOptions}
271
- })
272
-
273
- ${returnRes}
274
- },
275
- }
276
-
277
- ` });
278
- }
279
- var defaultTemplates2 = {
280
- default: Template2
281
- };
282
- function QueryOptions({ factory, dataReturnType, Template: Template4 = defaultTemplates2.default }) {
283
- const {
284
- pluginManager,
285
- plugin: {
286
- key: pluginKey,
287
- options: { parser }
288
- }
289
- } = _react.useApp.call(void 0, );
290
- const { getSchemas } = _hooks.useOperationManager.call(void 0, );
291
- const operation = _hooks.useOperation.call(void 0, );
292
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
293
- const zodSchemas = getSchemas(operation, { pluginKey: [_pluginzod.pluginZodName], type: "function" });
294
- const name = pluginManager.resolveName({
295
- name: `${factory.name}QueryOptions`,
296
- pluginKey
297
- });
298
- const contentType = operation.getContentType();
299
- const generics = new (0, _utils.FunctionParams)();
300
- const params = new (0, _utils.FunctionParams)();
301
- const clientGenerics = ["TData", `${factory.name}['error']`];
302
- const resultGenerics = ["TData", `${factory.name}['error']`];
303
- generics.add([{ type: "TData", default: `${factory.name}['response']` }]);
304
- params.add([
305
- ..._utils3.getASTParams.call(void 0, schemas.pathParams, { typed: true }),
306
- {
307
- name: "params",
308
- type: `${factory.name}['queryParams']`,
309
- enabled: !!_optionalChain([schemas, 'access', _35 => _35.queryParams, 'optionalAccess', _36 => _36.name]),
310
- required: false
311
- },
312
- {
313
- name: "headers",
314
- type: `${factory.name}['headerParams']`,
315
- enabled: !!_optionalChain([schemas, 'access', _37 => _37.headerParams, 'optionalAccess', _38 => _38.name]),
316
- required: false
317
- },
318
- {
319
- name: "options",
320
- type: `${factory.name}['client']['parameters']`,
321
- default: "{}"
322
- }
323
- ]);
324
- const client = {
325
- withQueryParams: !!_optionalChain([schemas, 'access', _39 => _39.queryParams, 'optionalAccess', _40 => _40.name]),
326
- withData: !!_optionalChain([schemas, 'access', _41 => _41.request, 'optionalAccess', _42 => _42.name]),
327
- withPathParams: !!_optionalChain([schemas, 'access', _43 => _43.pathParams, 'optionalAccess', _44 => _44.name]),
328
- withHeaders: !!_optionalChain([schemas, 'access', _45 => _45.headerParams, 'optionalAccess', _46 => _46.name]),
329
- method: operation.method,
330
- path: new (0, _utils.URLPath)(operation.path),
331
- generics: clientGenerics.join(", "),
332
- contentType
333
- };
334
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
335
- Template4,
336
- {
337
- name,
338
- params: params.toString(),
339
- generics: generics.toString(),
340
- returnType: `SWRConfiguration<${resultGenerics.join(", ")}>`,
341
- client,
342
- dataReturnType,
343
- parser: parser === "zod" ? `${zodSchemas.response.name}.parse` : void 0
344
- }
345
- );
346
- }
347
- QueryOptions.templates = defaultTemplates2;
348
-
349
- // src/components/Query.tsx
350
-
351
- function Template3({ name, generics, returnType, params, JSDoc, hook, client }) {
352
- if (client.withQueryParams) {
353
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { name, export: true, generics, returnType, params, JSDoc, children: `
354
- const { query: queryOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
355
-
356
- const url = ${client.path.template}
357
- const query = ${hook.name}<${hook.generics}>(
358
- shouldFetch ? [url, params]: null,
359
- {
360
- ...${hook.queryOptions},
361
- ...queryOptions
362
- }
363
- )
364
-
365
- return query
366
- ` }) });
367
- }
368
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { name, export: true, generics, returnType, params, JSDoc, children: `
369
- const { query: queryOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
370
-
371
- const url = ${client.path.template}
372
- const query = ${hook.name}<${hook.generics}>(
373
- shouldFetch ? url : null,
374
- {
375
- ...${hook.queryOptions},
376
- ...queryOptions
377
- }
378
- )
379
-
380
- return query
381
- ` }) });
382
- }
383
- var defaultTemplates3 = {
384
- default: Template3
385
- };
386
- function Query({ factory, Template: Template4 = defaultTemplates3.default, QueryOptionsTemplate = QueryOptions.templates.default }) {
387
- const {
388
- pluginManager,
389
- plugin: {
390
- key: pluginKey,
391
- options: { dataReturnType }
392
- }
393
- } = _react.useApp.call(void 0, );
394
- const operation = _hooks.useOperation.call(void 0, );
395
- const { getSchemas, getName } = _hooks.useOperationManager.call(void 0, );
396
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
397
- const zodSchemas = getSchemas(operation, { pluginKey: [_pluginzod.pluginZodName], type: "function" });
398
- const name = getName(operation, { type: "function" });
399
- const queryOptionsName = pluginManager.resolveName({
400
- name: `${factory.name}QueryOptions`,
401
- pluginKey
402
- });
403
- const generics = new (0, _utils.FunctionParams)();
404
- const params = new (0, _utils.FunctionParams)();
405
- const queryParams = new (0, _utils.FunctionParams)();
406
- const client = {
407
- method: operation.method,
408
- path: new (0, _utils.URLPath)(operation.path),
409
- withQueryParams: !!_optionalChain([schemas, 'access', _47 => _47.queryParams, 'optionalAccess', _48 => _48.name]),
410
- withData: !!_optionalChain([schemas, 'access', _49 => _49.request, 'optionalAccess', _50 => _50.name]),
411
- withPathParams: !!_optionalChain([schemas, 'access', _51 => _51.pathParams, 'optionalAccess', _52 => _52.name]),
412
- withHeaders: !!_optionalChain([schemas, 'access', _53 => _53.headerParams, 'optionalAccess', _54 => _54.name])
413
- };
414
- const resultGenerics = ["TData", `${factory.name}["error"]`];
415
- generics.add([{ type: "TData", default: `${factory.name}["response"]` }]);
416
- const queryOptionsGenerics = ["TData"];
417
- params.add([
418
- ..._utils3.getASTParams.call(void 0, schemas.pathParams, { typed: true }),
419
- {
420
- name: "params",
421
- type: `${factory.name}['queryParams']`,
422
- enabled: client.withQueryParams,
423
- required: false
424
- },
425
- {
426
- name: "headers",
427
- type: `${factory.name}['headerParams']`,
428
- enabled: client.withHeaders,
429
- required: false
430
- },
431
- {
432
- name: "options",
433
- required: false,
434
- type: `{
435
- query?: SWRConfiguration<${resultGenerics.join(", ")}>,
436
- client?: ${factory.name}['client']['parameters'],
437
- shouldFetch?: boolean,
438
- }`,
439
- default: "{}"
440
- }
441
- ]);
442
- queryParams.add([
443
- ..._utils3.getASTParams.call(void 0, schemas.pathParams, { typed: false }),
444
- {
445
- name: "params",
446
- enabled: client.withQueryParams,
447
- required: false
448
- },
449
- {
450
- name: "headers",
451
- enabled: client.withHeaders,
452
- required: false
453
- },
454
- {
455
- name: "clientOptions",
456
- required: false
457
- }
458
- ]);
459
- const hook = {
460
- name: "useSWR",
461
- generics: [...resultGenerics, client.withQueryParams ? "[typeof url, typeof params] | null" : "typeof url | null"].join(", "),
462
- queryOptions: `${queryOptionsName}<${queryOptionsGenerics.join(", ")}>(${queryParams.toString()})`
463
- };
464
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
465
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, QueryOptions, { factory, Template: QueryOptionsTemplate, dataReturnType }),
466
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
467
- Template4,
468
- {
469
- name,
470
- generics: generics.toString(),
471
- JSDoc: { comments: _utils3.getComments.call(void 0, operation) },
472
- client,
473
- hook,
474
- params: params.toString(),
475
- returnType: `SWRResponse<${resultGenerics.join(", ")}>`
476
- }
477
- )
478
- ] });
479
- }
480
- Query.File = function({ templates }) {
481
- const {
482
- pluginManager,
483
- plugin: {
484
- options: {
485
- extName,
486
- client: { importPath },
487
- parser
488
- }
489
- }
490
- } = _react.useApp.call(void 0, );
491
- const { getSchemas, getFile, getName } = _hooks.useOperationManager.call(void 0, );
492
- const operation = _hooks.useOperation.call(void 0, );
493
- const file = getFile(operation);
494
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
495
- const zodSchemas = getSchemas(operation, { pluginKey: [_pluginzod.pluginZodName], type: "function" });
496
- const fileType = getFile(operation, { pluginKey: [_plugints.pluginTsName] });
497
- const fileZodSchemas = getFile(operation, {
498
- pluginKey: [_pluginzod.pluginZodName]
499
- });
500
- const factoryName = getName(operation, { type: "type" });
501
- const Template4 = _optionalChain([templates, 'optionalAccess', _55 => _55.query, 'access', _56 => _56.default]) || defaultTemplates3.default;
502
- const QueryOptionsTemplate = _optionalChain([templates, 'optionalAccess', _57 => _57.queryOptions, 'access', _58 => _58.default]) || QueryOptions.templates.default;
503
- const factory = {
504
- name: factoryName
505
- };
506
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
507
- parser === "zod" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { extName, name: [zodSchemas.response.name], root: file.path, path: fileZodSchemas.path }),
508
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "useSWR", path: "swr" }),
509
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["SWRConfiguration", "SWRResponse"], path: "swr", isTypeOnly: true }),
510
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "client", path: importPath }),
511
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["ResponseConfig"], path: importPath, isTypeOnly: true }),
512
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
513
- _react.File.Import,
514
- {
515
- extName,
516
- name: [
517
- _optionalChain([schemas, 'access', _59 => _59.request, 'optionalAccess', _60 => _60.name]),
518
- schemas.response.name,
519
- _optionalChain([schemas, 'access', _61 => _61.pathParams, 'optionalAccess', _62 => _62.name]),
520
- _optionalChain([schemas, 'access', _63 => _63.queryParams, 'optionalAccess', _64 => _64.name]),
521
- _optionalChain([schemas, 'access', _65 => _65.headerParams, 'optionalAccess', _66 => _66.name]),
522
- ..._optionalChain([schemas, 'access', _67 => _67.statusCodes, 'optionalAccess', _68 => _68.map, 'call', _69 => _69((item) => item.name)]) || []
523
- ].filter(Boolean),
524
- root: file.path,
525
- path: fileType.path,
526
- isTypeOnly: true
527
- }
528
- ),
529
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File.Source, { children: [
530
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SchemaType, { factory }),
531
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Query, { factory, Template: Template4, QueryOptionsTemplate })
532
- ] })
533
- ] }) });
534
- };
535
- Query.templates = defaultTemplates3;
536
-
537
-
538
-
539
-
540
-
541
- exports.Mutation = Mutation; exports.QueryOptions = QueryOptions; exports.Query = Query;
542
- //# sourceMappingURL=chunk-H4LHXYRJ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-swr/dist/chunk-H4LHXYRJ.cjs","../src/components/Mutation.tsx","../src/components/SchemaType.tsx","../src/components/Query.tsx","../src/components/QueryOptions.tsx"],"names":["useOperation","Template","jsx","jsxs","Parser","transformers","Function","defaultTemplates","FunctionParams","URLPath","Fragment","pluginZodName"],"mappings":"AAAA;ACAA,mHAAyB;AACzB,yCAAwC;AACxC,oCAA+C;AAC/C,2CAA6B;AAC7B,+CAAkD;AAClD,gDAA0C;ADE1C;AACA;AERA;AAEA;AAGA;AAgCI,qDAAA;AAxBG,SAAS,UAAA,CAAW,EAAE,QAAQ,CAAA,EAAqB;AACxD,EAAA,MAAM;AA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A;AACA,0BAAA;AACA,0BAAA;AACI,UAAA;AACL,QAAA;AACE,QAAA;AACL,QAAA;AACI,QAAA;AAAA,MAAA;AACZ,IAAA;AAEAC,oBAAAA;AACED,sBAAAA;AACAA,sBAAAA;AACF,IAAA;AAEJ,EAAA;AAEJ;AAEkBK;AHsPI;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-swr/dist/chunk-H4LHXYRJ.cjs","sourcesContent":[null,"import transformers from '@kubb/core/transformers'\nimport { FunctionParams, URLPath } from '@kubb/core/utils'\nimport { Parser, File, Function, useApp } from '@kubb/react'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getASTParams, getComments } from '@kubb/plugin-oas/utils'\n\nimport { SchemaType } from './SchemaType.tsx'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginSwr } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n /**\n * Parameters/options/props that need to be used\n */\n params: string\n /**\n * Generics that needs to be added for TypeScript\n */\n generics?: string\n /**\n * ReturnType(see async for adding Promise type)\n */\n returnType?: string\n /**\n * Options for JSdocs\n */\n JSDoc?: {\n comments: string[]\n }\n hook: {\n name: string\n generics?: string\n }\n client: {\n method: HttpMethod\n generics: string\n withQueryParams: boolean\n withPathParams: boolean\n withData: boolean\n withHeaders: boolean\n path: URLPath\n }\n dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>\n}\n\nfunction Template({ name, generics, returnType, params, JSDoc, client, hook, dataReturnType }: TemplateProps): ReactNode {\n const clientOptions = [\n `method: \"${client.method}\"`,\n 'url',\n client.withQueryParams ? 'params' : undefined,\n client.withData ? 'data' : undefined,\n client.withHeaders ? 'headers: { ...headers, ...clientOptions.headers }' : undefined,\n '...clientOptions',\n ].filter(Boolean)\n\n const resolvedClientOptions = `${transformers.createIndent(4)}${clientOptions.join(`,\\n${transformers.createIndent(4)}`)}`\n if (client.withQueryParams) {\n return (\n <Function export name={name} generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>\n {`\n const { mutation: mutationOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}\n\n const url = ${client.path.template} as const\n return ${hook.name}<${hook.generics}>(\n shouldFetch ? [url, params]: null,\n async (_url${client.withData ? ', { arg: data }' : ''}) => {\n const res = await client<${client.generics}>({\n ${resolvedClientOptions}\n })\n\n return ${dataReturnType === 'data' ? 'res.data' : 'res'}\n },\n mutationOptions\n )\n `}\n </Function>\n )\n }\n return (\n <Function export name={name} generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>\n {`\n const { mutation: mutationOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}\n\n const url = ${client.path.template} as const\n return ${hook.name}<${hook.generics}>(\n shouldFetch ? url : null,\n async (_url${client.withData ? ', { arg: data }' : ''}) => {\n const res = await client<${client.generics}>({\n ${resolvedClientOptions}\n })\n\n return ${dataReturnType === 'data' ? 'res.data' : 'res'}\n },\n mutationOptions\n )\n `}\n </Function>\n )\n}\n\nconst defaultTemplates = {\n default: Template,\n} as const\n\ntype Props = {\n factory: {\n name: string\n }\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<TemplateProps>\n}\n\nexport function Mutation({ factory, Template = defaultTemplates.default }: Props): ReactNode {\n const {\n plugin: {\n options: { dataReturnType },\n },\n } = useApp<PluginSwr>()\n const { getSchemas, getName } = useOperationManager()\n const operation = useOperation()\n\n const name = getName(operation, { type: 'function' })\n const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n\n const params = new FunctionParams()\n const client = {\n method: operation.method,\n path: new URLPath(operation.path),\n generics: [`${factory.name}[\"data\"]`, `${factory.name}[\"error\"]`, schemas.request?.name ? `${factory.name}[\"request\"]` : ''].filter(Boolean).join(', '),\n withQueryParams: !!schemas.queryParams?.name,\n withData: !!schemas.request?.name,\n withPathParams: !!schemas.pathParams?.name,\n withHeaders: !!schemas.headerParams?.name,\n }\n\n const resultGenerics = [`${factory.name}[\"response\"]`, `${factory.name}[\"error\"]`]\n\n params.add([\n ...getASTParams(schemas.pathParams, { typed: true }),\n {\n name: 'params',\n type: `${factory.name}['queryParams']`,\n enabled: client.withQueryParams,\n required: false,\n },\n {\n name: 'headers',\n type: `${factory.name}['headerParams']`,\n enabled: client.withHeaders,\n required: false,\n },\n {\n name: 'options',\n required: false,\n type: `{\n mutation?: SWRMutationConfiguration<${resultGenerics.join(', ')}>,\n client?: ${factory.name}['client']['parameters'],\n shouldFetch?: boolean,\n }`,\n default: '{}',\n },\n ])\n\n const hook = {\n name: 'useSWRMutation',\n generics: [...resultGenerics, client.withQueryParams ? '[typeof url, typeof params] | null' : 'typeof url | null'].join(', '),\n }\n\n return (\n <Template\n name={name}\n JSDoc={{ comments: getComments(operation) }}\n client={client}\n hook={hook}\n params={params.toString()}\n returnType={`SWRMutationResponse<${resultGenerics.join(', ')}>`}\n dataReturnType={dataReturnType}\n />\n )\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: typeof defaultTemplates\n}\n\nMutation.File = function ({ templates = defaultTemplates }: FileProps): ReactNode {\n const {\n plugin: {\n options: {\n extName,\n client: { importPath },\n },\n },\n } = useApp<PluginSwr>()\n\n const { getSchemas, getFile, getName } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const file = getFile(operation)\n const fileType = getFile(operation, { pluginKey: [pluginTsName] })\n const factoryName = getName(operation, { type: 'type' })\n\n const Template = templates.default\n const factory = {\n name: factoryName,\n }\n\n return (\n <Parser language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name=\"useSWRMutation\" path=\"swr/mutation\" />\n <File.Import name={['SWRMutationConfiguration', 'SWRMutationResponse']} path=\"swr/mutation\" isTypeOnly />\n <File.Import name={'client'} path={importPath} />\n <File.Import name={['ResponseConfig']} path={importPath} isTypeOnly />\n <File.Import\n extName={extName}\n name={[\n schemas.request?.name,\n schemas.response.name,\n schemas.pathParams?.name,\n schemas.queryParams?.name,\n schemas.headerParams?.name,\n ...(schemas.errors?.map((error) => error.name) || []),\n ].filter(Boolean)}\n root={file.path}\n path={fileType.path}\n isTypeOnly\n />\n\n <File.Source>\n <SchemaType factory={factory} />\n <Mutation Template={Template} factory={factory} />\n </File.Source>\n </File>\n </Parser>\n )\n}\n\nMutation.templates = defaultTemplates\n","import { Type, useApp } from '@kubb/react'\n\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport type { ReactNode } from 'react'\nimport type { PluginSwr } from '../types.ts'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\ntype Props = {\n factory: {\n name: string\n }\n}\n\nexport function SchemaType({ factory }: Props): ReactNode {\n const {\n plugin: {\n options: { dataReturnType },\n },\n } = useApp<PluginSwr>()\n const { getSchemas } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n\n const [TData, TError, TRequest, TPathParams, TQueryParams, THeaderParams, TResponse] = [\n schemas.response.name,\n schemas.errors?.map((item) => item.name).join(' | ') || 'never',\n schemas.request?.name || 'never',\n schemas.pathParams?.name || 'never',\n schemas.queryParams?.name || 'never',\n schemas.headerParams?.name || 'never',\n schemas.response.name,\n ]\n\n const clientType = `${factory.name}Client`\n\n return (\n <>\n <Type name={clientType}>{`typeof client<${TResponse}, ${TError}, ${TRequest}>`}</Type>\n <Type name={factory.name}>\n {`\n {\n data: ${TData}\n error: ${TError}\n request: ${TRequest}\n pathParams: ${TPathParams}\n queryParams: ${TQueryParams}\n headerParams: ${THeaderParams}\n response: ${dataReturnType === 'data' ? TData : `Awaited<ReturnType<${clientType}>>`}\n client: {\n parameters: Partial<Parameters<${clientType}>[0]>\n return: Awaited<ReturnType<${clientType}>>\n }\n }\n `}\n </Type>\n </>\n )\n}\n","import { FunctionParams, URLPath } from '@kubb/core/utils'\nimport { Parser, File, Function, useApp } from '@kubb/react'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getASTParams, getComments } from '@kubb/plugin-oas/utils'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport { QueryOptions } from './QueryOptions.tsx'\nimport { SchemaType } from './SchemaType.tsx'\n\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginSwr } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n /**\n * Parameters/options/props that need to be used\n */\n params: string\n /**\n * Generics that needs to be added for TypeScript\n */\n generics?: string\n /**\n * ReturnType(see async for adding Promise type)\n */\n returnType?: string\n /**\n * Options for JSdocs\n */\n JSDoc?: {\n comments: string[]\n }\n hook: {\n name: string\n generics?: string\n queryOptions: string\n }\n client: {\n path: URLPath\n withQueryParams: boolean\n }\n}\n\nfunction Template({ name, generics, returnType, params, JSDoc, hook, client }: TemplateProps): ReactNode {\n if (client.withQueryParams) {\n return (\n <>\n <Function name={name} export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>\n {`\n const { query: queryOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}\n\n const url = ${client.path.template}\n const query = ${hook.name}<${hook.generics}>(\n shouldFetch ? [url, params]: null,\n {\n ...${hook.queryOptions},\n ...queryOptions\n }\n )\n\n return query\n `}\n </Function>\n </>\n )\n }\n\n return (\n <>\n <Function name={name} export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>\n {`\n const { query: queryOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}\n\n const url = ${client.path.template}\n const query = ${hook.name}<${hook.generics}>(\n shouldFetch ? url : null,\n {\n ...${hook.queryOptions},\n ...queryOptions\n }\n )\n\n return query\n `}\n </Function>\n </>\n )\n}\n\nconst defaultTemplates = {\n default: Template,\n} as const\n\ntype Props = {\n factory: {\n name: string\n }\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<TemplateProps>\n /**\n * This will make it possible to override the default behaviour.\n */\n QueryOptionsTemplate?: React.ComponentType<React.ComponentProps<typeof QueryOptions.templates.default>>\n}\n\nexport function Query({ factory, Template = defaultTemplates.default, QueryOptionsTemplate = QueryOptions.templates.default }: Props): ReactNode {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { dataReturnType },\n },\n } = useApp<PluginSwr>()\n\n const operation = useOperation()\n const { getSchemas, getName } = useOperationManager()\n\n const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const zodSchemas = getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' })\n\n const name = getName(operation, { type: 'function' })\n\n const queryOptionsName = pluginManager.resolveName({\n name: `${factory.name}QueryOptions`,\n pluginKey,\n })\n const generics = new FunctionParams()\n const params = new FunctionParams()\n const queryParams = new FunctionParams()\n const client = {\n method: operation.method,\n path: new URLPath(operation.path),\n withQueryParams: !!schemas.queryParams?.name,\n withData: !!schemas.request?.name,\n withPathParams: !!schemas.pathParams?.name,\n withHeaders: !!schemas.headerParams?.name,\n }\n\n const resultGenerics = ['TData', `${factory.name}[\"error\"]`]\n\n generics.add([{ type: 'TData', default: `${factory.name}[\"response\"]` }])\n\n const queryOptionsGenerics = ['TData']\n\n params.add([\n ...getASTParams(schemas.pathParams, { typed: true }),\n {\n name: 'params',\n type: `${factory.name}['queryParams']`,\n enabled: client.withQueryParams,\n required: false,\n },\n {\n name: 'headers',\n type: `${factory.name}['headerParams']`,\n enabled: client.withHeaders,\n required: false,\n },\n {\n name: 'options',\n required: false,\n type: `{\n query?: SWRConfiguration<${resultGenerics.join(', ')}>,\n client?: ${factory.name}['client']['parameters'],\n shouldFetch?: boolean,\n }`,\n default: '{}',\n },\n ])\n\n queryParams.add([\n ...getASTParams(schemas.pathParams, { typed: false }),\n {\n name: 'params',\n enabled: client.withQueryParams,\n required: false,\n },\n {\n name: 'headers',\n enabled: client.withHeaders,\n required: false,\n },\n {\n name: 'clientOptions',\n required: false,\n },\n ])\n\n const hook = {\n name: 'useSWR',\n generics: [...resultGenerics, client.withQueryParams ? '[typeof url, typeof params] | null' : 'typeof url | null'].join(', '),\n queryOptions: `${queryOptionsName}<${queryOptionsGenerics.join(', ')}>(${queryParams.toString()})`,\n }\n\n return (\n <>\n <QueryOptions factory={factory} Template={QueryOptionsTemplate} dataReturnType={dataReturnType} />\n\n <Template\n name={name}\n generics={generics.toString()}\n JSDoc={{ comments: getComments(operation) }}\n client={client}\n hook={hook}\n params={params.toString()}\n returnType={`SWRResponse<${resultGenerics.join(', ')}>`}\n />\n </>\n )\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: {\n query: typeof defaultTemplates\n queryOptions: typeof QueryOptions.templates\n }\n}\n\nQuery.File = function ({ templates }: FileProps): ReactNode {\n const {\n pluginManager,\n plugin: {\n options: {\n extName,\n client: { importPath },\n parser,\n },\n },\n } = useApp<PluginSwr>()\n const { getSchemas, getFile, getName } = useOperationManager()\n const operation = useOperation()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const zodSchemas = getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' })\n const fileType = getFile(operation, { pluginKey: [pluginTsName] })\n const fileZodSchemas = getFile(operation, {\n pluginKey: [pluginZodName],\n })\n\n const factoryName = getName(operation, { type: 'type' })\n\n const Template = templates?.query.default || defaultTemplates.default\n const QueryOptionsTemplate = templates?.queryOptions.default || QueryOptions.templates.default\n const factory = {\n name: factoryName,\n }\n\n return (\n <Parser language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n {parser === 'zod' && <File.Import extName={extName} name={[zodSchemas.response.name]} root={file.path} path={fileZodSchemas.path} />}\n <File.Import name=\"useSWR\" path=\"swr\" />\n <File.Import name={['SWRConfiguration', 'SWRResponse']} path=\"swr\" isTypeOnly />\n <File.Import name={'client'} path={importPath} />\n <File.Import name={['ResponseConfig']} path={importPath} isTypeOnly />\n <File.Import\n extName={extName}\n name={[\n schemas.request?.name,\n schemas.response.name,\n schemas.pathParams?.name,\n schemas.queryParams?.name,\n schemas.headerParams?.name,\n ...(schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={file.path}\n path={fileType.path}\n isTypeOnly\n />\n\n <File.Source>\n <SchemaType factory={factory} />\n <Query factory={factory} Template={Template} QueryOptionsTemplate={QueryOptionsTemplate} />\n </File.Source>\n </File>\n </Parser>\n )\n}\n\nQuery.templates = defaultTemplates\n","import transformers from '@kubb/core/transformers'\nimport { FunctionParams, URLPath } from '@kubb/core/utils'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getASTParams } from '@kubb/plugin-oas/utils'\nimport { Function, useApp } from '@kubb/react'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport type { PluginSwr } from '../types.ts'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n /**\n * Parameters/options/props that need to be used\n */\n params: string\n /**\n * Generics that needs to be added for TypeScript\n */\n generics?: string\n /**\n * ReturnType(see async for adding Promise type)\n */\n returnType?: string\n /**\n * Options for JSdocs\n */\n JSDoc?: {\n comments: string[]\n }\n client: {\n generics: string\n method: HttpMethod\n path: URLPath\n withQueryParams: boolean\n withPathParams: boolean\n withData: boolean\n withHeaders: boolean\n contentType: string\n }\n dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>\n parser: string | undefined\n}\n\nfunction Template({ name, params, generics, returnType, JSDoc, client, dataReturnType, parser }: TemplateProps): ReactNode {\n const isFormData = client.contentType === 'multipart/form-data'\n const headers = [\n client.contentType !== 'application/json' ? `'Content-Type': '${client.contentType}'` : undefined,\n client.withHeaders ? '...headers' : undefined,\n ]\n .filter(Boolean)\n .join(', ')\n\n const clientOptions = [\n `method: \"${client.method}\"`,\n `url: ${client.path.template}`,\n client.withQueryParams ? 'params' : undefined,\n client.withData && !isFormData ? 'data' : undefined,\n client.withData && isFormData ? 'data: formData' : undefined,\n headers.length ? `headers: { ${headers}, ...options.headers }` : undefined,\n '...options',\n ].filter(Boolean)\n\n const resolvedClientOptions = `${transformers.createIndent(4)}${clientOptions.join(`,\\n${transformers.createIndent(4)}`)}`\n\n let returnRes = parser ? `return ${parser}(res.data)` : 'return res.data'\n\n if (dataReturnType === 'full') {\n returnRes = parser ? `return {...res, data: ${parser}(res.data)}` : 'return res'\n }\n\n const formData = isFormData\n ? `\n const formData = new FormData()\n if(data) {\n Object.keys(data).forEach((key) => {\n const value = data[key];\n if (typeof key === \"string\" && (typeof value === \"string\" || value instanceof Blob)) {\n formData.append(key, value);\n }\n })\n }\n `\n : undefined\n\n return (\n <Function name={name} export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>\n {`\n return {\n fetcher: async () => {\n ${formData || ''}\n const res = await client<${client.generics}>({\n ${resolvedClientOptions}\n })\n\n ${returnRes}\n },\n }\n\n `}\n </Function>\n )\n}\n\nconst defaultTemplates = {\n default: Template,\n} as const\n\ntype Props = {\n factory: {\n name: string\n }\n dataReturnType: NonNullable<PluginSwr['options']['dataReturnType']>\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<TemplateProps>\n}\n\nexport function QueryOptions({ factory, dataReturnType, Template = defaultTemplates.default }: Props): ReactNode {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { parser },\n },\n } = useApp<PluginSwr>()\n const { getSchemas } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const zodSchemas = getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' })\n const name = pluginManager.resolveName({\n name: `${factory.name}QueryOptions`,\n pluginKey,\n })\n const contentType = operation.getContentType()\n\n const generics = new FunctionParams()\n const params = new FunctionParams()\n\n const clientGenerics = ['TData', `${factory.name}['error']`]\n const resultGenerics = ['TData', `${factory.name}['error']`]\n\n generics.add([{ type: 'TData', default: `${factory.name}['response']` }])\n\n params.add([\n ...getASTParams(schemas.pathParams, { typed: true }),\n {\n name: 'params',\n type: `${factory.name}['queryParams']`,\n enabled: !!schemas.queryParams?.name,\n required: false,\n },\n {\n name: 'headers',\n type: `${factory.name}['headerParams']`,\n enabled: !!schemas.headerParams?.name,\n required: false,\n },\n {\n name: 'options',\n type: `${factory.name}['client']['parameters']`,\n default: '{}',\n },\n ])\n\n const client = {\n withQueryParams: !!schemas.queryParams?.name,\n withData: !!schemas.request?.name,\n withPathParams: !!schemas.pathParams?.name,\n withHeaders: !!schemas.headerParams?.name,\n method: operation.method,\n path: new URLPath(operation.path),\n generics: clientGenerics.join(', '),\n contentType,\n }\n\n return (\n <Template\n name={name}\n params={params.toString()}\n generics={generics.toString()}\n returnType={`SWRConfiguration<${resultGenerics.join(', ')}>`}\n client={client}\n dataReturnType={dataReturnType}\n parser={parser === 'zod' ? `${zodSchemas.response.name}.parse` : undefined}\n />\n )\n}\n\nQueryOptions.templates = defaultTemplates\n"]}