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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +14 -5
  2. package/dist/chunk-4EGGCGSE.js +217 -0
  3. package/dist/chunk-4EGGCGSE.js.map +1 -0
  4. package/dist/chunk-H23WKEYP.js +243 -0
  5. package/dist/chunk-H23WKEYP.js.map +1 -0
  6. package/dist/chunk-JWGWABV5.cjs +249 -0
  7. package/dist/chunk-JWGWABV5.cjs.map +1 -0
  8. package/dist/chunk-PTOQHHST.cjs +220 -0
  9. package/dist/chunk-PTOQHHST.cjs.map +1 -0
  10. package/dist/components.cjs +23 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +88 -6
  13. package/dist/components.d.ts +88 -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 +11 -0
  19. package/dist/generators.d.ts +11 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +93 -123
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +2 -4
  25. package/dist/index.d.ts +2 -4
  26. package/dist/index.js +77 -114
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DaH2Sc1M.d.cts +103 -0
  29. package/dist/types-DaH2Sc1M.d.ts +103 -0
  30. package/package.json +23 -17
  31. package/src/components/Mutation.tsx +93 -227
  32. package/src/components/MutationKey.tsx +48 -0
  33. package/src/components/Query.tsx +93 -259
  34. package/src/components/QueryKey.tsx +73 -0
  35. package/src/components/QueryOptions.tsx +54 -177
  36. package/src/components/index.ts +2 -0
  37. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +43 -0
  38. package/src/generators/__snapshots__/clientGetImportPath.ts +43 -0
  39. package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
  40. package/src/generators/__snapshots__/findByTags.ts +43 -0
  41. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +43 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +43 -0
  43. package/src/generators/__snapshots__/getAsMutation.ts +34 -0
  44. package/src/generators/__snapshots__/postAsQuery.ts +41 -0
  45. package/src/generators/__snapshots__/updatePetById.ts +32 -0
  46. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +36 -0
  47. package/src/generators/index.ts +2 -0
  48. package/src/generators/mutationGenerator.tsx +109 -0
  49. package/src/generators/queryGenerator.tsx +114 -0
  50. package/src/plugin.ts +71 -52
  51. package/src/types.ts +62 -78
  52. package/dist/chunk-TGLXUPN4.cjs +0 -536
  53. package/dist/chunk-TGLXUPN4.cjs.map +0 -1
  54. package/dist/chunk-XWXMQJD6.js +0 -536
  55. package/dist/chunk-XWXMQJD6.js.map +0 -1
  56. package/dist/index-B3C-JOIU.d.cts +0 -299
  57. package/dist/index-B3C-JOIU.d.ts +0 -299
  58. package/src/OperationGenerator.tsx +0 -75
  59. package/src/components/SchemaType.tsx +0 -63
  60. package/src/components/__snapshots__/Mutation/Pets.ts +0 -46
  61. package/src/components/__snapshots__/Query/showPetById.ts +0 -59
@@ -1,536 +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.File.Source, { name: clientType, isTypeOnly: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { name: clientType, children: `typeof client<${TResponse}, ${TError}, ${TRequest}>` }) }),
35
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name: factory.name, isTypeOnly: true, children: /* @__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.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__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.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__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.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
- name: [
195
- _optionalChain([schemas, 'access', _24 => _24.request, 'optionalAccess', _25 => _25.name]),
196
- schemas.response.name,
197
- _optionalChain([schemas, 'access', _26 => _26.pathParams, 'optionalAccess', _27 => _27.name]),
198
- _optionalChain([schemas, 'access', _28 => _28.queryParams, 'optionalAccess', _29 => _29.name]),
199
- _optionalChain([schemas, 'access', _30 => _30.headerParams, 'optionalAccess', _31 => _31.name]),
200
- ..._optionalChain([schemas, 'access', _32 => _32.errors, 'optionalAccess', _33 => _33.map, 'call', _34 => _34((error) => error.name)]) || []
201
- ].filter(Boolean),
202
- root: file.path,
203
- path: fileType.path,
204
- isTypeOnly: true
205
- }
206
- ),
207
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SchemaType, { factory }),
208
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Mutation, { Template: Template4, factory })
209
- ] });
210
- };
211
- Mutation.templates = defaultTemplates;
212
-
213
- // src/components/Query.tsx
214
-
215
-
216
-
217
-
218
- var _pluginzod = require('@kubb/plugin-zod');
219
-
220
-
221
- // src/components/QueryOptions.tsx
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
- function Template2({ name, params, generics, returnType, JSDoc, client, dataReturnType, parser }) {
231
- const isFormData = client.contentType === "multipart/form-data";
232
- const headers = [
233
- client.contentType !== "application/json" ? `'Content-Type': '${client.contentType}'` : void 0,
234
- client.withHeaders ? "...headers" : void 0
235
- ].filter(Boolean).join(", ");
236
- const clientOptions = [
237
- `method: "${client.method}"`,
238
- `url: ${client.path.template}`,
239
- client.withQueryParams ? "params" : void 0,
240
- client.withData && !isFormData ? "data" : void 0,
241
- client.withData && isFormData ? "data: formData" : void 0,
242
- headers.length ? `headers: { ${headers}, ...options.headers }` : void 0,
243
- "...options"
244
- ].filter(Boolean);
245
- const resolvedClientOptions = `${_transformers2.default.createIndent(4)}${clientOptions.join(`,
246
- ${_transformers2.default.createIndent(4)}`)}`;
247
- let returnRes = parser ? `return ${parser}(res.data)` : "return res.data";
248
- if (dataReturnType === "full") {
249
- returnRes = parser ? `return {...res, data: ${parser}(res.data)}` : "return res";
250
- }
251
- const formData = isFormData ? `
252
- const formData = new FormData()
253
- if(data) {
254
- Object.keys(data).forEach((key) => {
255
- const value = data[key];
256
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
257
- formData.append(key, value);
258
- }
259
- })
260
- }
261
- ` : void 0;
262
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { name, export: true, generics, returnType, params, JSDoc, children: `
263
- return {
264
- fetcher: async () => {
265
- ${formData || ""}
266
- const res = await client<${client.generics}>({
267
- ${resolvedClientOptions}
268
- })
269
-
270
- ${returnRes}
271
- },
272
- }
273
-
274
- ` }) });
275
- }
276
- var defaultTemplates2 = {
277
- default: Template2
278
- };
279
- function QueryOptions({ factory, dataReturnType, Template: Template4 = defaultTemplates2.default }) {
280
- const {
281
- pluginManager,
282
- plugin: {
283
- key: pluginKey,
284
- options: { parser }
285
- }
286
- } = _react.useApp.call(void 0, );
287
- const { getSchemas } = _hooks.useOperationManager.call(void 0, );
288
- const operation = _hooks.useOperation.call(void 0, );
289
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
290
- const zodSchemas = getSchemas(operation, { pluginKey: [_pluginzod.pluginZodName], type: "function" });
291
- const name = pluginManager.resolveName({
292
- name: `${factory.name}QueryOptions`,
293
- pluginKey
294
- });
295
- const contentType = operation.getContentType();
296
- const generics = new (0, _utils.FunctionParams)();
297
- const params = new (0, _utils.FunctionParams)();
298
- const clientGenerics = ["TData", `${factory.name}['error']`];
299
- const resultGenerics = ["TData", `${factory.name}['error']`];
300
- generics.add([{ type: "TData", default: `${factory.name}['response']` }]);
301
- params.add([
302
- ..._utils3.getASTParams.call(void 0, schemas.pathParams, { typed: true }),
303
- {
304
- name: "params",
305
- type: `${factory.name}['queryParams']`,
306
- enabled: !!_optionalChain([schemas, 'access', _35 => _35.queryParams, 'optionalAccess', _36 => _36.name]),
307
- required: false
308
- },
309
- {
310
- name: "headers",
311
- type: `${factory.name}['headerParams']`,
312
- enabled: !!_optionalChain([schemas, 'access', _37 => _37.headerParams, 'optionalAccess', _38 => _38.name]),
313
- required: false
314
- },
315
- {
316
- name: "options",
317
- type: `${factory.name}['client']['parameters']`,
318
- default: "{}"
319
- }
320
- ]);
321
- const client = {
322
- withQueryParams: !!_optionalChain([schemas, 'access', _39 => _39.queryParams, 'optionalAccess', _40 => _40.name]),
323
- withData: !!_optionalChain([schemas, 'access', _41 => _41.request, 'optionalAccess', _42 => _42.name]),
324
- withPathParams: !!_optionalChain([schemas, 'access', _43 => _43.pathParams, 'optionalAccess', _44 => _44.name]),
325
- withHeaders: !!_optionalChain([schemas, 'access', _45 => _45.headerParams, 'optionalAccess', _46 => _46.name]),
326
- method: operation.method,
327
- path: new (0, _utils.URLPath)(operation.path),
328
- generics: clientGenerics.join(", "),
329
- contentType
330
- };
331
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
332
- Template4,
333
- {
334
- name,
335
- params: params.toString(),
336
- generics: generics.toString(),
337
- returnType: `SWRConfiguration<${resultGenerics.join(", ")}>`,
338
- client,
339
- dataReturnType,
340
- parser: parser === "zod" ? `${zodSchemas.response.name}.parse` : void 0
341
- }
342
- );
343
- }
344
- QueryOptions.templates = defaultTemplates2;
345
-
346
- // src/components/Query.tsx
347
-
348
- function Template3({ name, generics, returnType, params, JSDoc, hook, client }) {
349
- if (client.withQueryParams) {
350
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { name, export: true, generics, returnType, params, JSDoc, children: `
351
- const { query: queryOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
352
-
353
- const url = ${client.path.template}
354
- const query = ${hook.name}<${hook.generics}>(
355
- shouldFetch ? [url, params]: null,
356
- {
357
- ...${hook.queryOptions},
358
- ...queryOptions
359
- }
360
- )
361
-
362
- return query
363
- ` }) });
364
- }
365
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { name, export: true, generics, returnType, params, JSDoc, children: `
366
- const { query: queryOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
367
-
368
- const url = ${client.path.template}
369
- const query = ${hook.name}<${hook.generics}>(
370
- shouldFetch ? url : null,
371
- {
372
- ...${hook.queryOptions},
373
- ...queryOptions
374
- }
375
- )
376
-
377
- return query
378
- ` }) });
379
- }
380
- var defaultTemplates3 = {
381
- default: Template3
382
- };
383
- function Query({ factory, Template: Template4 = defaultTemplates3.default, QueryOptionsTemplate = QueryOptions.templates.default }) {
384
- const {
385
- pluginManager,
386
- plugin: {
387
- key: pluginKey,
388
- options: { dataReturnType }
389
- }
390
- } = _react.useApp.call(void 0, );
391
- const operation = _hooks.useOperation.call(void 0, );
392
- const { getSchemas, getName } = _hooks.useOperationManager.call(void 0, );
393
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
394
- const zodSchemas = getSchemas(operation, { pluginKey: [_pluginzod.pluginZodName], type: "function" });
395
- const name = getName(operation, { type: "function" });
396
- const queryOptionsName = pluginManager.resolveName({
397
- name: `${factory.name}QueryOptions`,
398
- pluginKey
399
- });
400
- const generics = new (0, _utils.FunctionParams)();
401
- const params = new (0, _utils.FunctionParams)();
402
- const queryParams = new (0, _utils.FunctionParams)();
403
- const client = {
404
- method: operation.method,
405
- path: new (0, _utils.URLPath)(operation.path),
406
- withQueryParams: !!_optionalChain([schemas, 'access', _47 => _47.queryParams, 'optionalAccess', _48 => _48.name]),
407
- withData: !!_optionalChain([schemas, 'access', _49 => _49.request, 'optionalAccess', _50 => _50.name]),
408
- withPathParams: !!_optionalChain([schemas, 'access', _51 => _51.pathParams, 'optionalAccess', _52 => _52.name]),
409
- withHeaders: !!_optionalChain([schemas, 'access', _53 => _53.headerParams, 'optionalAccess', _54 => _54.name])
410
- };
411
- const resultGenerics = ["TData", `${factory.name}["error"]`];
412
- generics.add([{ type: "TData", default: `${factory.name}["response"]` }]);
413
- const queryOptionsGenerics = ["TData"];
414
- params.add([
415
- ..._utils3.getASTParams.call(void 0, schemas.pathParams, { typed: true }),
416
- {
417
- name: "params",
418
- type: `${factory.name}['queryParams']`,
419
- enabled: client.withQueryParams,
420
- required: false
421
- },
422
- {
423
- name: "headers",
424
- type: `${factory.name}['headerParams']`,
425
- enabled: client.withHeaders,
426
- required: false
427
- },
428
- {
429
- name: "options",
430
- required: false,
431
- type: `{
432
- query?: SWRConfiguration<${resultGenerics.join(", ")}>,
433
- client?: ${factory.name}['client']['parameters'],
434
- shouldFetch?: boolean,
435
- }`,
436
- default: "{}"
437
- }
438
- ]);
439
- queryParams.add([
440
- ..._utils3.getASTParams.call(void 0, schemas.pathParams, { typed: false }),
441
- {
442
- name: "params",
443
- enabled: client.withQueryParams,
444
- required: false
445
- },
446
- {
447
- name: "headers",
448
- enabled: client.withHeaders,
449
- required: false
450
- },
451
- {
452
- name: "clientOptions",
453
- required: false
454
- }
455
- ]);
456
- const hook = {
457
- name: "useSWR",
458
- generics: [...resultGenerics, client.withQueryParams ? "[typeof url, typeof params] | null" : "typeof url | null"].join(", "),
459
- queryOptions: `${queryOptionsName}<${queryOptionsGenerics.join(", ")}>(${queryParams.toString()})`
460
- };
461
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
462
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, QueryOptions, { factory, Template: QueryOptionsTemplate, dataReturnType }),
463
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
464
- Template4,
465
- {
466
- name,
467
- generics: generics.toString(),
468
- JSDoc: { comments: _utils3.getComments.call(void 0, operation) },
469
- client,
470
- hook,
471
- params: params.toString(),
472
- returnType: `SWRResponse<${resultGenerics.join(", ")}>`
473
- }
474
- )
475
- ] });
476
- }
477
- Query.File = function({ templates }) {
478
- const {
479
- pluginManager,
480
- plugin: {
481
- options: {
482
- extName,
483
- client: { importPath },
484
- parser
485
- }
486
- }
487
- } = _react.useApp.call(void 0, );
488
- const { getSchemas, getFile, getName } = _hooks.useOperationManager.call(void 0, );
489
- const operation = _hooks.useOperation.call(void 0, );
490
- const file = getFile(operation);
491
- const schemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
492
- const zodSchemas = getSchemas(operation, { pluginKey: [_pluginzod.pluginZodName], type: "function" });
493
- const fileType = getFile(operation, { pluginKey: [_plugints.pluginTsName] });
494
- const fileZodSchemas = getFile(operation, {
495
- pluginKey: [_pluginzod.pluginZodName]
496
- });
497
- const factoryName = getName(operation, { type: "type" });
498
- const Template4 = _optionalChain([templates, 'optionalAccess', _55 => _55.query, 'access', _56 => _56.default]) || defaultTemplates3.default;
499
- const QueryOptionsTemplate = _optionalChain([templates, 'optionalAccess', _57 => _57.queryOptions, 'access', _58 => _58.default]) || QueryOptions.templates.default;
500
- const factory = {
501
- name: factoryName
502
- };
503
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
504
- parser === "zod" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: [zodSchemas.response.name], root: file.path, path: fileZodSchemas.path }),
505
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "useSWR", path: "swr" }),
506
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["SWRConfiguration", "SWRResponse"], path: "swr", isTypeOnly: true }),
507
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "client", path: importPath }),
508
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["ResponseConfig"], path: importPath, isTypeOnly: true }),
509
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
510
- _react.File.Import,
511
- {
512
- name: [
513
- _optionalChain([schemas, 'access', _59 => _59.request, 'optionalAccess', _60 => _60.name]),
514
- schemas.response.name,
515
- _optionalChain([schemas, 'access', _61 => _61.pathParams, 'optionalAccess', _62 => _62.name]),
516
- _optionalChain([schemas, 'access', _63 => _63.queryParams, 'optionalAccess', _64 => _64.name]),
517
- _optionalChain([schemas, 'access', _65 => _65.headerParams, 'optionalAccess', _66 => _66.name]),
518
- ..._optionalChain([schemas, 'access', _67 => _67.statusCodes, 'optionalAccess', _68 => _68.map, 'call', _69 => _69((item) => item.name)]) || []
519
- ].filter(Boolean),
520
- root: file.path,
521
- path: fileType.path,
522
- isTypeOnly: true
523
- }
524
- ),
525
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SchemaType, { factory }),
526
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Query, { factory, Template: Template4, QueryOptionsTemplate })
527
- ] });
528
- };
529
- Query.templates = defaultTemplates3;
530
-
531
-
532
-
533
-
534
-
535
- exports.Mutation = Mutation; exports.QueryOptions = QueryOptions; exports.Query = Query;
536
- //# sourceMappingURL=chunk-TGLXUPN4.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-swr/dist/chunk-TGLXUPN4.cjs","../src/components/Mutation.tsx","../src/components/SchemaType.tsx","../src/components/Query.tsx","../src/components/QueryOptions.tsx"],"names":["useOperation","Template","jsx","File","transformers","Function","defaultTemplates","FunctionParams","URLPath","Fragment","pluginZodName"],"mappings":"AAAA;ACAA,mHAAyB;AACzB,yCAAw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AAAA;AACAA,oBAAAA;AACAA,oBAAAA;AACAA,oBAAAA;AACAA,oBAAAA;AAAM,MAAA;AAAL,MAAA;AACO,QAAA;AACI,0BAAA;AACA,UAAA;AACA,0BAAA;AACA,0BAAA;AACA,0BAAA;AACI,UAAA;AACL,QAAA;AACE,QAAA;AACL,QAAA;AACI,QAAA;AAAA,MAAA;AACZ,IAAA;AAEAA,oBAAAA;AACAA,oBAAAA;AACF,EAAA;AAEJ;AAEkBI;AHsPI;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-swr/dist/chunk-TGLXUPN4.cjs","sourcesContent":[null,"import transformers from '@kubb/core/transformers'\nimport { FunctionParams, URLPath } from '@kubb/core/utils'\nimport { 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 <File.Source name={name} isExportable isIndexable>\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 </File.Source>\n )\n }\n\n return (\n <File.Source name={name} isExportable isIndexable>\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 </File.Source>\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 <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 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 <SchemaType factory={factory} />\n <Mutation Template={Template} factory={factory} />\n </File>\n )\n}\n\nMutation.templates = defaultTemplates\n","import { File, Type, useApp } from '@kubb/react'\n\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport type { ReactNode } from 'react'\nimport type { PluginSwr } from '../types.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 <File.Source name={clientType} isTypeOnly>\n <Type name={clientType}>{`typeof client<${TResponse}, ${TError}, ${TRequest}>`}</Type>\n </File.Source>\n <File.Source name={factory.name} isTypeOnly>\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 </File.Source>\n </>\n )\n}\n","import { FunctionParams, URLPath } from '@kubb/core/utils'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getASTParams, getComments } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, Function, useApp } from '@kubb/react'\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 <File.Source name={name} isExportable isIndexable>\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 </File.Source>\n )\n }\n\n return (\n <File.Source name={name} isExportable isIndexable>\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 </File.Source>\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 <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 <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n {parser === 'zod' && <File.Import 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 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 <SchemaType factory={factory} />\n <Query factory={factory} Template={Template} QueryOptionsTemplate={QueryOptionsTemplate} />\n </File>\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, File, 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 <File.Source name={name} isExportable isIndexable>\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 </File.Source>\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"]}