@kubb/plugin-swr 3.16.1 → 3.16.3

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 (39) hide show
  1. package/dist/components-BQIcQmn3.js +435 -0
  2. package/dist/components-BQIcQmn3.js.map +1 -0
  3. package/dist/components-Zv6v8ZAm.cjs +493 -0
  4. package/dist/components-Zv6v8ZAm.cjs.map +1 -0
  5. package/dist/components.cjs +6 -27
  6. package/dist/components.d.cts +177 -78
  7. package/dist/components.d.ts +177 -78
  8. package/dist/components.js +3 -3
  9. package/dist/generators-B-fWjDXL.js +328 -0
  10. package/dist/generators-B-fWjDXL.js.map +1 -0
  11. package/dist/generators-ByyKDjyt.cjs +339 -0
  12. package/dist/generators-ByyKDjyt.cjs.map +1 -0
  13. package/dist/generators.cjs +4 -16
  14. package/dist/generators.d.cts +8 -9
  15. package/dist/generators.d.ts +8 -9
  16. package/dist/generators.js +4 -4
  17. package/dist/index.cjs +107 -136
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +6 -8
  20. package/dist/index.d.ts +6 -8
  21. package/dist/index.js +107 -130
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-CSnGy9Uj.d.ts +1355 -0
  24. package/dist/types-CjDGkyWH.d.cts +1355 -0
  25. package/package.json +25 -30
  26. package/dist/chunk-2N4Q32XH.cjs +0 -285
  27. package/dist/chunk-2N4Q32XH.cjs.map +0 -1
  28. package/dist/chunk-GWLPXHRE.js +0 -282
  29. package/dist/chunk-GWLPXHRE.js.map +0 -1
  30. package/dist/chunk-MNOTKHSE.cjs +0 -367
  31. package/dist/chunk-MNOTKHSE.cjs.map +0 -1
  32. package/dist/chunk-RZTUH4QW.js +0 -361
  33. package/dist/chunk-RZTUH4QW.js.map +0 -1
  34. package/dist/components.cjs.map +0 -1
  35. package/dist/components.js.map +0 -1
  36. package/dist/generators.cjs.map +0 -1
  37. package/dist/generators.js.map +0 -1
  38. package/dist/types-DVQ2siUx.d.cts +0 -134
  39. package/dist/types-DVQ2siUx.d.ts +0 -134
@@ -0,0 +1,339 @@
1
+ const require_components = require('./components-Zv6v8ZAm.cjs');
2
+ const __kubb_plugin_oas = require_components.__toESM(require("@kubb/plugin-oas"));
3
+ const __kubb_plugin_ts = require_components.__toESM(require("@kubb/plugin-ts"));
4
+ const __kubb_plugin_zod = require_components.__toESM(require("@kubb/plugin-zod"));
5
+ const __kubb_react = require_components.__toESM(require("@kubb/react"));
6
+ const __kubb_plugin_client_components = require_components.__toESM(require("@kubb/plugin-client/components"));
7
+ const __kubb_plugin_oas_utils = require_components.__toESM(require("@kubb/plugin-oas/utils"));
8
+ const __kubb_react_jsx_runtime = require_components.__toESM(require("@kubb/react/jsx-runtime"));
9
+ const __kubb_plugin_client = require_components.__toESM(require("@kubb/plugin-client"));
10
+ const __kubb_plugin_oas_hooks = require_components.__toESM(require("@kubb/plugin-oas/hooks"));
11
+ const remeda = require_components.__toESM(require("remeda"));
12
+
13
+ //#region src/generators/queryGenerator.tsx
14
+ const queryGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
15
+ name: "swr-query",
16
+ Operation({ options, operation }) {
17
+ const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
18
+ const oas = (0, __kubb_plugin_oas_hooks.useOas)();
19
+ const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
20
+ const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
21
+ const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
22
+ const importPath = options.query ? options.query.importPath : "swr/mutation";
23
+ const query = {
24
+ name: getName(operation, {
25
+ type: "function",
26
+ prefix: "use"
27
+ }),
28
+ typeName: getName(operation, { type: "type" }),
29
+ file: getFile(operation, { prefix: "use" })
30
+ };
31
+ const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
32
+ const client = {
33
+ name: hasClientPlugin ? getName(operation, {
34
+ type: "function",
35
+ pluginKey: [__kubb_plugin_client.pluginClientName]
36
+ }) : getName(operation, { type: "function" }),
37
+ file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
38
+ };
39
+ const queryOptions = { name: getName(operation, {
40
+ type: "function",
41
+ suffix: "QueryOptions"
42
+ }) };
43
+ const queryKey = {
44
+ name: getName(operation, {
45
+ type: "const",
46
+ suffix: "QueryKey"
47
+ }),
48
+ typeName: getName(operation, {
49
+ type: "type",
50
+ suffix: "QueryKey"
51
+ })
52
+ };
53
+ const type = {
54
+ file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
55
+ schemas: getSchemas(operation, {
56
+ pluginKey: [__kubb_plugin_ts.pluginTsName],
57
+ type: "type"
58
+ })
59
+ };
60
+ const zod = {
61
+ file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
62
+ schemas: getSchemas(operation, {
63
+ pluginKey: [__kubb_plugin_zod.pluginZodName],
64
+ type: "function"
65
+ })
66
+ };
67
+ if (!isQuery || isMutation) return null;
68
+ return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
69
+ baseName: query.file.baseName,
70
+ path: query.file.path,
71
+ meta: query.file.meta,
72
+ banner: (0, __kubb_plugin_oas_utils.getBanner)({
73
+ oas,
74
+ output,
75
+ config: pluginManager.config
76
+ }),
77
+ footer: (0, __kubb_plugin_oas_utils.getFooter)({
78
+ oas,
79
+ output
80
+ }),
81
+ children: [
82
+ options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
83
+ name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
84
+ root: query.file.path,
85
+ path: zod.file.path
86
+ }),
87
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
88
+ name: "fetch",
89
+ path: options.client.importPath
90
+ }),
91
+ !!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
92
+ name: [client.name],
93
+ root: query.file.path,
94
+ path: client.file.path
95
+ }),
96
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
97
+ name: ["RequestConfig", "ResponseErrorConfig"],
98
+ path: options.client.importPath,
99
+ isTypeOnly: true
100
+ }),
101
+ options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
102
+ name: ["ResponseConfig"],
103
+ path: options.client.importPath,
104
+ isTypeOnly: true
105
+ }),
106
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
107
+ name: [
108
+ type.schemas.request?.name,
109
+ type.schemas.response.name,
110
+ type.schemas.pathParams?.name,
111
+ type.schemas.queryParams?.name,
112
+ type.schemas.headerParams?.name,
113
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
114
+ ].filter(Boolean),
115
+ root: query.file.path,
116
+ path: type.file.path,
117
+ isTypeOnly: true
118
+ }),
119
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryKey, {
120
+ name: queryKey.name,
121
+ typeName: queryKey.typeName,
122
+ operation,
123
+ pathParamsType: options.pathParamsType,
124
+ typeSchemas: type.schemas,
125
+ paramsCasing: options.paramsCasing,
126
+ transformer: options.queryKey
127
+ }),
128
+ !hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
129
+ name: client.name,
130
+ baseURL: options.client.baseURL,
131
+ operation,
132
+ typeSchemas: type.schemas,
133
+ zodSchemas: zod.schemas,
134
+ dataReturnType: options.client.dataReturnType,
135
+ paramsCasing: options.paramsCasing,
136
+ paramsType: options.paramsType,
137
+ pathParamsType: options.pathParamsType,
138
+ parser: options.parser
139
+ }),
140
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryOptions, {
141
+ name: queryOptions.name,
142
+ clientName: client.name,
143
+ typeSchemas: type.schemas,
144
+ paramsType: options.paramsType,
145
+ paramsCasing: options.paramsCasing,
146
+ pathParamsType: options.pathParamsType
147
+ }),
148
+ options.query && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
149
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
150
+ name: "useSWR",
151
+ path: importPath
152
+ }),
153
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
154
+ name: ["SWRResponse"],
155
+ path: importPath,
156
+ isTypeOnly: true
157
+ }),
158
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Query, {
159
+ name: query.name,
160
+ queryOptionsName: queryOptions.name,
161
+ typeSchemas: type.schemas,
162
+ paramsType: options.paramsType,
163
+ pathParamsType: options.pathParamsType,
164
+ operation,
165
+ dataReturnType: options.client.dataReturnType,
166
+ queryKeyName: queryKey.name,
167
+ paramsCasing: options.paramsCasing,
168
+ queryKeyTypeName: queryKey.typeName
169
+ })
170
+ ] })
171
+ ]
172
+ });
173
+ }
174
+ });
175
+
176
+ //#endregion
177
+ //#region src/generators/mutationGenerator.tsx
178
+ const mutationGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
179
+ name: "swr-mutation",
180
+ Operation({ options, operation }) {
181
+ const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
182
+ const oas = (0, __kubb_plugin_oas_hooks.useOas)();
183
+ const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
184
+ const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method);
185
+ const isMutation = !isQuery && (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
186
+ const importPath = options.mutation ? options.mutation.importPath : "swr";
187
+ const mutation = {
188
+ name: getName(operation, {
189
+ type: "function",
190
+ prefix: "use"
191
+ }),
192
+ typeName: getName(operation, { type: "type" }),
193
+ file: getFile(operation, { prefix: "use" })
194
+ };
195
+ const type = {
196
+ file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
197
+ schemas: getSchemas(operation, {
198
+ pluginKey: [__kubb_plugin_ts.pluginTsName],
199
+ type: "type"
200
+ })
201
+ };
202
+ const zod = {
203
+ file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
204
+ schemas: getSchemas(operation, {
205
+ pluginKey: [__kubb_plugin_zod.pluginZodName],
206
+ type: "function"
207
+ })
208
+ };
209
+ const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
210
+ const client = {
211
+ name: hasClientPlugin ? getName(operation, {
212
+ type: "function",
213
+ pluginKey: [__kubb_plugin_client.pluginClientName]
214
+ }) : getName(operation, { type: "function" }),
215
+ file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
216
+ };
217
+ const mutationKey = {
218
+ name: getName(operation, {
219
+ type: "const",
220
+ suffix: "MutationKey"
221
+ }),
222
+ typeName: getName(operation, {
223
+ type: "type",
224
+ suffix: "MutationKey"
225
+ })
226
+ };
227
+ if (!isMutation) return null;
228
+ return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
229
+ baseName: mutation.file.baseName,
230
+ path: mutation.file.path,
231
+ meta: mutation.file.meta,
232
+ banner: (0, __kubb_plugin_oas_utils.getBanner)({
233
+ oas,
234
+ output,
235
+ config: pluginManager.config
236
+ }),
237
+ footer: (0, __kubb_plugin_oas_utils.getFooter)({
238
+ oas,
239
+ output
240
+ }),
241
+ children: [
242
+ options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
243
+ name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
244
+ root: mutation.file.path,
245
+ path: zod.file.path
246
+ }),
247
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
248
+ name: "useSWRMutation",
249
+ path: importPath
250
+ }),
251
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
252
+ name: ["SWRMutationResponse"],
253
+ path: importPath,
254
+ isTypeOnly: true
255
+ }),
256
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
257
+ name: "fetch",
258
+ path: options.client.importPath
259
+ }),
260
+ !!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
261
+ name: [client.name],
262
+ root: mutation.file.path,
263
+ path: client.file.path
264
+ }),
265
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
266
+ name: [
267
+ "RequestConfig",
268
+ "ResponseConfig",
269
+ "ResponseErrorConfig"
270
+ ],
271
+ path: options.client.importPath,
272
+ isTypeOnly: true
273
+ }),
274
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
275
+ name: [
276
+ type.schemas.request?.name,
277
+ type.schemas.response.name,
278
+ type.schemas.pathParams?.name,
279
+ type.schemas.queryParams?.name,
280
+ type.schemas.headerParams?.name,
281
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
282
+ ].filter(Boolean),
283
+ root: mutation.file.path,
284
+ path: type.file.path,
285
+ isTypeOnly: true
286
+ }),
287
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.MutationKey, {
288
+ name: mutationKey.name,
289
+ typeName: mutationKey.typeName,
290
+ operation,
291
+ pathParamsType: options.pathParamsType,
292
+ typeSchemas: type.schemas,
293
+ paramsCasing: options.paramsCasing,
294
+ transformer: options.mutationKey
295
+ }),
296
+ !hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
297
+ name: client.name,
298
+ baseURL: options.client.baseURL,
299
+ operation,
300
+ typeSchemas: type.schemas,
301
+ zodSchemas: zod.schemas,
302
+ dataReturnType: options.client.dataReturnType,
303
+ paramsCasing: options.paramsCasing,
304
+ paramsType: options.paramsType,
305
+ pathParamsType: options.pathParamsType,
306
+ parser: options.parser
307
+ }),
308
+ options.mutation && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Mutation, {
309
+ name: mutation.name,
310
+ clientName: client.name,
311
+ typeName: mutation.typeName,
312
+ typeSchemas: type.schemas,
313
+ operation,
314
+ dataReturnType: options.client.dataReturnType,
315
+ paramsType: options.paramsType,
316
+ paramsCasing: options.paramsCasing,
317
+ pathParamsType: options.pathParamsType,
318
+ mutationKeyName: mutationKey.name,
319
+ mutationKeyTypeName: mutationKey.typeName
320
+ })
321
+ ]
322
+ });
323
+ }
324
+ });
325
+
326
+ //#endregion
327
+ Object.defineProperty(exports, 'mutationGenerator', {
328
+ enumerable: true,
329
+ get: function () {
330
+ return mutationGenerator;
331
+ }
332
+ });
333
+ Object.defineProperty(exports, 'queryGenerator', {
334
+ enumerable: true,
335
+ get: function () {
336
+ return queryGenerator;
337
+ }
338
+ });
339
+ //# sourceMappingURL=generators-ByyKDjyt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-ByyKDjyt.cjs","names":["pluginClientName","pluginTsName","pluginZodName","File","QueryKey","Client","QueryOptions","Query","pluginTsName","pluginZodName","pluginClientName","File","MutationKey","Client","Mutation"],"sources":["../src/generators/queryGenerator.tsx","../src/generators/mutationGenerator.tsx"],"sourcesContent":["import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { Query, QueryOptions } from '../components'\nimport { QueryKey } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-query',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginSwr>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some(\n (method) => operation.method === method,\n )\n const importPath = options.query ? options.query.importPath : 'swr/mutation'\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n const client = {\n name: hasClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const queryOptions = {\n name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n if (!isQuery || isMutation) {\n return null\n }\n\n return (\n <File\n baseName={query.file.baseName}\n path={query.file.path}\n meta={query.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />\n )}\n <File.Import name={'fetch'} path={options.client.importPath} />\n {!!hasClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n transformer={options.queryKey}\n />\n {!hasClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n />\n {options.query && (\n <>\n <File.Import name=\"useSWR\" path={importPath} />\n <File.Import name={['SWRResponse']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n dataReturnType={options.client.dataReturnType}\n queryKeyName={queryKey.name}\n paramsCasing={options.paramsCasing}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\n )}\n </File>\n )\n },\n})\n","import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { MutationKey } from '../components'\nimport { Mutation } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const mutationGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-mutation',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n pluginManager,\n } = useApp<PluginSwr>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method)\n const isMutation =\n !isQuery &&\n difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method)\n\n const importPath = options.mutation ? options.mutation.importPath : 'swr'\n\n const mutation = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n const client = {\n name: hasClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const mutationKey = {\n name: getName(operation, { type: 'const', suffix: 'MutationKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),\n }\n\n if (!isMutation) {\n return null\n }\n\n return (\n <File\n baseName={mutation.file.baseName}\n path={mutation.file.path}\n meta={mutation.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={mutation.file.path} path={zod.file.path} />\n )}\n <File.Import name=\"useSWRMutation\" path={importPath} />\n <File.Import name={['SWRMutationResponse']} path={importPath} isTypeOnly />\n {<File.Import name={'fetch'} path={options.client.importPath} />}\n {!!hasClientPlugin && <File.Import name={[client.name]} root={mutation.file.path} path={client.file.path} />}\n <File.Import name={['RequestConfig', 'ResponseConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mutation.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <MutationKey\n name={mutationKey.name}\n typeName={mutationKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n transformer={options.mutationKey}\n />\n\n {!hasClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n {options.mutation && (\n <Mutation\n name={mutation.name}\n clientName={client.name}\n typeName={mutation.typeName}\n typeSchemas={type.schemas}\n operation={operation}\n dataReturnType={options.client.dataReturnType}\n paramsType={options.paramsType}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n mutationKeyName={mutationKey.name}\n mutationKeyTypeName={mutationKey.typeName}\n />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,QAAQ;KACtB,aAAa,QAAQ;MACrB;IAED,CAAC,qEACCC;KACC,MAAM,OAAO;KACb,SAAS,QAAQ,OAAO;KACb;KACX,aAAa,KAAK;KAClB,YAAY,IAAI;KAChB,gBAAgB,QAAQ,OAAO;KAC/B,cAAc,QAAQ;KACtB,YAAY,QAAQ;KACpB,gBAAgB,QAAQ;KACxB,QAAQ,QAAQ;MAChB;IAEH,QAAQ,8DACNC;KACC,MAAM,SAAS;KACf,YAAY,OAAO;KACnB,UAAU,SAAS;KACnB,aAAa,KAAK;KACP;KACX,gBAAgB,QAAQ,OAAO;KAC/B,YAAY,QAAQ;KACpB,cAAc,QAAQ;KACtB,gBAAgB,QAAQ;KACxB,iBAAiB,YAAY;KAC7B,qBAAqB,YAAY;MACjC;;IAEC;CAEV;AACF,EAAC"}
@@ -1,17 +1,5 @@
1
- 'use strict';
1
+ require('./components-Zv6v8ZAm.cjs');
2
+ const require_generators = require('./generators-ByyKDjyt.cjs');
2
3
 
3
- var chunk2N4Q32XH_cjs = require('./chunk-2N4Q32XH.cjs');
4
- require('./chunk-MNOTKHSE.cjs');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "mutationGenerator", {
9
- enumerable: true,
10
- get: function () { return chunk2N4Q32XH_cjs.mutationGenerator; }
11
- });
12
- Object.defineProperty(exports, "queryGenerator", {
13
- enumerable: true,
14
- get: function () { return chunk2N4Q32XH_cjs.queryGenerator; }
15
- });
16
- //# sourceMappingURL=generators.cjs.map
17
- //# sourceMappingURL=generators.cjs.map
4
+ exports.mutationGenerator = require_generators.mutationGenerator;
5
+ exports.queryGenerator = require_generators.queryGenerator;
@@ -1,11 +1,10 @@
1
- import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginSwr } from './types-DVQ2siUx.cjs';
3
- import '@kubb/core';
4
- import '@kubb/oas';
5
- import '@kubb/plugin-client';
6
-
7
- declare const queryGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
8
-
9
- declare const mutationGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
1
+ import { Generator, PluginSwr } from "./types-CjDGkyWH.cjs";
10
2
 
3
+ //#region src/generators/queryGenerator.d.ts
4
+ declare const queryGenerator: Generator<PluginSwr>;
5
+ //#endregion
6
+ //#region src/generators/mutationGenerator.d.ts
7
+ declare const mutationGenerator: Generator<PluginSwr>;
8
+ //#endregion
11
9
  export { mutationGenerator, queryGenerator };
10
+ //# sourceMappingURL=generators.d.cts.map
@@ -1,11 +1,10 @@
1
- import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginSwr } from './types-DVQ2siUx.js';
3
- import '@kubb/core';
4
- import '@kubb/oas';
5
- import '@kubb/plugin-client';
6
-
7
- declare const queryGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
8
-
9
- declare const mutationGenerator: _kubb_plugin_oas.Generator<PluginSwr>;
1
+ import { Generator, PluginSwr } from "./types-CSnGy9Uj.js";
10
2
 
3
+ //#region src/generators/queryGenerator.d.ts
4
+ declare const queryGenerator: Generator<PluginSwr>;
5
+ //#endregion
6
+ //#region src/generators/mutationGenerator.d.ts
7
+ declare const mutationGenerator: Generator<PluginSwr>;
8
+ //#endregion
11
9
  export { mutationGenerator, queryGenerator };
10
+ //# sourceMappingURL=generators.d.ts.map
@@ -1,4 +1,4 @@
1
- export { mutationGenerator, queryGenerator } from './chunk-GWLPXHRE.js';
2
- import './chunk-RZTUH4QW.js';
3
- //# sourceMappingURL=generators.js.map
4
- //# sourceMappingURL=generators.js.map
1
+ import "./components-BQIcQmn3.js";
2
+ import { mutationGenerator, queryGenerator } from "./generators-B-fWjDXL.js";
3
+
4
+ export { mutationGenerator, queryGenerator };