@kubb/plugin-svelte-query 0.0.0-canary-20241104172400

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/chunk-CDRGJAED.cjs +452 -0
  4. package/dist/chunk-CDRGJAED.cjs.map +1 -0
  5. package/dist/chunk-JGITTOE5.js +445 -0
  6. package/dist/chunk-JGITTOE5.js.map +1 -0
  7. package/dist/chunk-KRGCKSGR.cjs +527 -0
  8. package/dist/chunk-KRGCKSGR.cjs.map +1 -0
  9. package/dist/chunk-R6ZVBNG7.js +519 -0
  10. package/dist/chunk-R6ZVBNG7.js.map +1 -0
  11. package/dist/components.cjs +28 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +103 -0
  14. package/dist/components.d.ts +103 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +17 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +10 -0
  20. package/dist/generators.d.ts +10 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +127 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +9 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.js +120 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-B9W9aYra.d.cts +365 -0
  30. package/dist/types-B9W9aYra.d.ts +365 -0
  31. package/package.json +102 -0
  32. package/src/components/Mutation.tsx +158 -0
  33. package/src/components/MutationKey.tsx +54 -0
  34. package/src/components/Query.tsx +176 -0
  35. package/src/components/QueryKey.tsx +83 -0
  36. package/src/components/QueryOptions.tsx +133 -0
  37. package/src/components/index.ts +5 -0
  38. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  39. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  40. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  41. package/src/generators/__snapshots__/findByTags.ts +51 -0
  42. package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  45. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +44 -0
  49. package/src/generators/index.ts +2 -0
  50. package/src/generators/mutationGenerator.tsx +117 -0
  51. package/src/generators/queryGenerator.tsx +129 -0
  52. package/src/index.ts +2 -0
  53. package/src/plugin.ts +141 -0
  54. package/src/types.ts +135 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Stijn Van Hulle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ <div align="center">
2
+
3
+ <!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
4
+ <h1>@kubb/plugin-svelte-query</h1>
5
+
6
+ <p>
7
+ Swagger integration for React-Query to generate all the different hooks based on an OpenAPI specification.
8
+ </p>
9
+ <img src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/banner.png" alt="logo" height="auto" />
10
+
11
+ [![npm version][npm-version-src]][npm-version-href]
12
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
13
+ [![Coverage][coverage-src]][coverage-href]
14
+ [![License][license-src]][license-href]
15
+
16
+ <h4>
17
+ <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
18
+ <span> · </span>
19
+ <a href="https://kubb.dev/" target="_blank">Documentation</a>
20
+ <span> · </span>
21
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
22
+ <span> · </span>
23
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
24
+ </h4>
25
+ </div>
26
+
27
+ ## Supporting Kubb
28
+
29
+ Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
30
+
31
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
32
+
33
+ <p align="center">
34
+ <a href="https://github.com/sponsors/stijnvanhulle">
35
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
36
+ </a>
37
+ </p>
38
+
39
+
40
+ <!-- Badges -->
41
+
42
+ [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-svelte-query?flat&colorA=18181B&colorB=f58517
43
+ [npm-version-href]: https://npmjs.com/package/@kubb/plugin-svelte-query
44
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-svelte-query?flat&colorA=18181B&colorB=f58517
45
+ [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-svelte-query
46
+ [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
47
+ [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
48
+ [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
49
+ [build-href]: https://www.npmjs.com/package/@kubb/plugin-svelte-query
50
+ [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-svelte-query?style=flat&colorA=18181B&colorB=f58517
51
+ [minified-href]: https://www.npmjs.com/package/@kubb/plugin-svelte-query
52
+ [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
53
+ [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-svelte-query
54
+
55
+ ## options query
56
+
57
+ ### v4
58
+
59
+ UseBaseQueryOptions => react-query only
60
+ UseQueryOptions => vue-query only
61
+ CreateQueryOptions => solid-query only
62
+ CreateQueryOptions => svelte-query only
63
+
64
+ ### v5
65
+
66
+ UseBaseQueryOptions => react-query only https://github.com/TanStack/query/blob/ce1305c27e7ac7988656d171d882a665a286cc6a/packages/react-query/src/types.ts#L18
67
+ QueryObserverOptions => vue-query only https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQuery.ts#L24
68
+ UseQueryOptions => solid-query only
69
+
70
+ ## result query
71
+
72
+ ### v4
73
+
74
+ UseQueryResult => react-query only
75
+ UseQueryReturnType => vue-query only
76
+ CreateQueryResult => solid-query only
77
+ CreateQueryResult => svelte-query only
78
+
79
+ ### v5
80
+
81
+ UseQueryResult => react-query only
82
+ UseQueryReturnType => vue-query only
83
+
84
+ ## queryOptions() query
85
+
86
+ ### v5
87
+
88
+ queryOptions => react-query only
89
+
90
+ ```typescript
91
+ {
92
+ query: {
93
+ types: {
94
+ options: 'UseBaseQueryOptions'
95
+ result: 'UseQueryResult'
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## options mutation
102
+
103
+ ### v4
104
+
105
+ UseMutationOptions => react-query only
106
+ VueMutationObserverOptions => vue-query only
107
+
108
+ ### v5
109
+
110
+ UseMutationOptions => react-query only
111
+ MutationObserverOptions => vue-query only
112
+
113
+ ## result mutation
114
+
115
+ ### v4
116
+
117
+ UseMutationResult => react-query only
118
+ UseMutationReturnType => vue-query only
119
+
120
+ ### v5
121
+
122
+ UseMutationResult => react-query only
123
+ UseMutationReturnType => vue-query only
@@ -0,0 +1,452 @@
1
+ 'use strict';
2
+
3
+ var chunkKRGCKSGR_cjs = require('./chunk-KRGCKSGR.cjs');
4
+ var path = require('path');
5
+ var core = require('@kubb/core');
6
+ var transformers = require('@kubb/core/transformers');
7
+ var pluginOas = require('@kubb/plugin-oas');
8
+ var pluginZod = require('@kubb/plugin-zod');
9
+ var hooks = require('@kubb/plugin-oas/hooks');
10
+ var pluginTs = require('@kubb/plugin-ts');
11
+ var react = require('@kubb/react');
12
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ var path__default = /*#__PURE__*/_interopDefault(path);
17
+
18
+ var clientGenerator = pluginOas.createReactGenerator({
19
+ name: "client",
20
+ Operation({ options, operation }) {
21
+ const {
22
+ plugin: {
23
+ options: { output }
24
+ }
25
+ } = react.useApp();
26
+ const { getSchemas, getName, getFile } = hooks.useOperationManager();
27
+ const client = {
28
+ name: getName(operation, { type: "function" }),
29
+ file: getFile(operation)
30
+ };
31
+ const type = {
32
+ file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
33
+ schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
34
+ };
35
+ const zod = {
36
+ file: getFile(operation, { pluginKey: [pluginZod.pluginZodName] }),
37
+ schemas: getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" })
38
+ };
39
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: client.file.baseName, path: client.file.path, meta: client.file.meta, banner: output?.banner, footer: output?.footer, children: [
40
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.importPath }),
41
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["RequestConfig"], path: options.importPath, isTypeOnly: true }),
42
+ options.parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
43
+ /* @__PURE__ */ jsxRuntime.jsx(
44
+ react.File.Import,
45
+ {
46
+ name: [
47
+ type.schemas.request?.name,
48
+ type.schemas.response.name,
49
+ type.schemas.pathParams?.name,
50
+ type.schemas.queryParams?.name,
51
+ type.schemas.headerParams?.name,
52
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
53
+ ].filter(Boolean),
54
+ root: client.file.path,
55
+ path: type.file.path,
56
+ isTypeOnly: true
57
+ }
58
+ ),
59
+ /* @__PURE__ */ jsxRuntime.jsx(
60
+ chunkKRGCKSGR_cjs.Client,
61
+ {
62
+ name: client.name,
63
+ baseURL: options.baseURL,
64
+ dataReturnType: options.dataReturnType,
65
+ pathParamsType: options.pathParamsType,
66
+ paramsType: options.paramsType,
67
+ typeSchemas: type.schemas,
68
+ operation,
69
+ parser: options.parser,
70
+ zodSchemas: zod.schemas
71
+ }
72
+ )
73
+ ] });
74
+ }
75
+ });
76
+ var operationsGenerator = pluginOas.createReactGenerator({
77
+ name: "client",
78
+ Operations({ operations }) {
79
+ const {
80
+ pluginManager,
81
+ plugin: {
82
+ options: { output }
83
+ }
84
+ } = react.useApp();
85
+ const name = "operations";
86
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginClientName] });
87
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: /* @__PURE__ */ jsxRuntime.jsx(chunkKRGCKSGR_cjs.Operations, { name, operations }) });
88
+ }
89
+ });
90
+ var groupedClientGenerator = pluginOas.createReactGenerator({
91
+ name: "groupedClient",
92
+ Operations({ operations }) {
93
+ const {
94
+ pluginManager,
95
+ plugin: { options }
96
+ } = react.useApp();
97
+ const { getName, getFile } = hooks.useOperationManager();
98
+ const controllers = operations.reduce(
99
+ (acc, operation) => {
100
+ if (options.group?.type === "tag") {
101
+ const tag = operation.getTags().at(0)?.name;
102
+ const name = tag ? options.group?.name?.({ group: transformers.camelCase(tag) }) : void 0;
103
+ if (!tag || !name) {
104
+ return acc;
105
+ }
106
+ const file = pluginManager.getFile({
107
+ name,
108
+ extname: ".ts",
109
+ pluginKey: [pluginClientName],
110
+ options: { tag }
111
+ });
112
+ const client = {
113
+ name: getName(operation, { type: "function" }),
114
+ file: getFile(operation)
115
+ };
116
+ const previousFile = acc.find((item) => item.file.path === file.path);
117
+ if (previousFile) {
118
+ previousFile.clients.push(client);
119
+ } else {
120
+ acc.push({ name, file, clients: [client] });
121
+ }
122
+ }
123
+ return acc;
124
+ },
125
+ []
126
+ );
127
+ return controllers.map(({ name, file, clients }) => {
128
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: options.output?.banner, footer: options.output?.footer, children: [
129
+ clients.map((client) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
130
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
131
+ ] }, file.path);
132
+ });
133
+ }
134
+ });
135
+
136
+ // ../plugin-client/src/plugin.ts
137
+ var pluginClientName = "plugin-client";
138
+ core.createPlugin((options) => {
139
+ const {
140
+ output = { path: "clients", barrelType: "named" },
141
+ group,
142
+ exclude = [],
143
+ include,
144
+ override = [],
145
+ transformers: transformers$1 = {},
146
+ dataReturnType = "data",
147
+ pathParamsType = "inline",
148
+ paramsType = "inline",
149
+ operations = false,
150
+ baseURL,
151
+ generators = [clientGenerator, group ? groupedClientGenerator : void 0, operations ? operationsGenerator : void 0].filter(Boolean),
152
+ importPath = "@kubb/plugin-client/client",
153
+ parser = "client"
154
+ } = options;
155
+ return {
156
+ name: pluginClientName,
157
+ options: {
158
+ output,
159
+ group,
160
+ parser,
161
+ dataReturnType,
162
+ importPath,
163
+ paramsType,
164
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType,
165
+ baseURL
166
+ },
167
+ pre: [pluginOas.pluginOasName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
168
+ resolvePath(baseName, pathMode, options2) {
169
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
170
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
171
+ if (options2?.tag && group?.type === "tag") {
172
+ const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
173
+ return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
174
+ }
175
+ if (mode === "single") {
176
+ return path__default.default.resolve(root, output.path);
177
+ }
178
+ return path__default.default.resolve(root, output.path, baseName);
179
+ },
180
+ resolveName(name, type) {
181
+ const resolvedName = transformers.camelCase(name, { isFile: type === "file" });
182
+ if (type) {
183
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
184
+ }
185
+ return resolvedName;
186
+ },
187
+ async buildStart() {
188
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
189
+ const oas = await swaggerPlugin.context.getOas();
190
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
191
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
192
+ const baseURL2 = await swaggerPlugin.context.getBaseURL();
193
+ const operationGenerator = new pluginOas.OperationGenerator(
194
+ baseURL2 ? {
195
+ ...this.plugin.options,
196
+ baseURL: baseURL2
197
+ } : this.plugin.options,
198
+ {
199
+ oas,
200
+ pluginManager: this.pluginManager,
201
+ plugin: this.plugin,
202
+ contentType: swaggerPlugin.context.contentType,
203
+ exclude,
204
+ include,
205
+ override,
206
+ mode
207
+ }
208
+ );
209
+ const files = await operationGenerator.build(...generators);
210
+ await this.addFile(...files);
211
+ const barrelFiles = await this.fileManager.getBarrelFiles({
212
+ type: output.barrelType ?? "named",
213
+ root,
214
+ output,
215
+ files: this.fileManager.files,
216
+ meta: {
217
+ pluginKey: this.plugin.key
218
+ },
219
+ logger: this.logger
220
+ });
221
+ await this.addFile(...barrelFiles);
222
+ }
223
+ };
224
+ });
225
+ var queryGenerator = pluginOas.createReactGenerator({
226
+ name: "svelte-query",
227
+ Operation({ options, operation }) {
228
+ const {
229
+ plugin: {
230
+ options: { output }
231
+ }
232
+ } = react.useApp();
233
+ const { getSchemas, getName, getFile } = hooks.useOperationManager();
234
+ const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
235
+ const importPath = options.query ? options.query.importPath : "@tanstack/svelte-query";
236
+ const query = {
237
+ name: getName(operation, { type: "function", prefix: "create" }),
238
+ typeName: getName(operation, { type: "type" }),
239
+ file: getFile(operation, { prefix: "create" })
240
+ };
241
+ const client = {
242
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
243
+ };
244
+ const queryOptions = {
245
+ name: getName(operation, { type: "function", suffix: "QueryOptions" })
246
+ };
247
+ const queryKey = {
248
+ name: getName(operation, { type: "const", suffix: "QueryKey" }),
249
+ typeName: getName(operation, { type: "type", suffix: "QueryKey" })
250
+ };
251
+ const type = {
252
+ file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
253
+ //todo remove type?
254
+ schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
255
+ };
256
+ const zod = {
257
+ file: getFile(operation, { pluginKey: [pluginZod.pluginZodName] }),
258
+ schemas: getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" })
259
+ };
260
+ if (!isQuery) {
261
+ return null;
262
+ }
263
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
264
+ options.parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
265
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.client.importPath }),
266
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
267
+ options.client.dataReturnType === "full" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
268
+ /* @__PURE__ */ jsxRuntime.jsx(
269
+ react.File.Import,
270
+ {
271
+ name: [
272
+ type.schemas.request?.name,
273
+ type.schemas.response.name,
274
+ type.schemas.pathParams?.name,
275
+ type.schemas.queryParams?.name,
276
+ type.schemas.headerParams?.name,
277
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
278
+ ].filter(Boolean),
279
+ root: query.file.path,
280
+ path: type.file.path,
281
+ isTypeOnly: true
282
+ }
283
+ ),
284
+ /* @__PURE__ */ jsxRuntime.jsx(
285
+ chunkKRGCKSGR_cjs.QueryKey,
286
+ {
287
+ name: queryKey.name,
288
+ typeName: queryKey.typeName,
289
+ operation,
290
+ pathParamsType: options.pathParamsType,
291
+ typeSchemas: type.schemas,
292
+ transformer: options.queryKey
293
+ }
294
+ ),
295
+ /* @__PURE__ */ jsxRuntime.jsx(
296
+ chunkKRGCKSGR_cjs.Client,
297
+ {
298
+ name: client.name,
299
+ isExportable: false,
300
+ isIndexable: false,
301
+ baseURL: options.client.baseURL,
302
+ operation,
303
+ typeSchemas: type.schemas,
304
+ zodSchemas: zod.schemas,
305
+ dataReturnType: options.client.dataReturnType,
306
+ paramsType: options.paramsType,
307
+ pathParamsType: options.pathParamsType,
308
+ parser: options.parser
309
+ }
310
+ ),
311
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["queryOptions"], path: importPath }),
312
+ /* @__PURE__ */ jsxRuntime.jsx(
313
+ chunkKRGCKSGR_cjs.QueryOptions,
314
+ {
315
+ name: queryOptions.name,
316
+ clientName: client.name,
317
+ queryKeyName: queryKey.name,
318
+ typeSchemas: type.schemas,
319
+ paramsType: options.paramsType,
320
+ pathParamsType: options.pathParamsType
321
+ }
322
+ ),
323
+ options.query && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
324
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["createQuery"], path: importPath }),
325
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["QueryKey", "CreateBaseQueryOptions", "CreateQueryResult"], path: importPath, isTypeOnly: true }),
326
+ /* @__PURE__ */ jsxRuntime.jsx(
327
+ chunkKRGCKSGR_cjs.Query,
328
+ {
329
+ name: query.name,
330
+ queryOptionsName: queryOptions.name,
331
+ typeSchemas: type.schemas,
332
+ pathParamsType: options.pathParamsType,
333
+ operation,
334
+ paramsType: options.paramsType,
335
+ dataReturnType: options.client.dataReturnType,
336
+ queryKeyName: queryKey.name,
337
+ queryKeyTypeName: queryKey.typeName
338
+ }
339
+ )
340
+ ] })
341
+ ] });
342
+ }
343
+ });
344
+ var mutationGenerator = pluginOas.createReactGenerator({
345
+ name: "svelte-query",
346
+ Operation({ options, operation }) {
347
+ const {
348
+ plugin: {
349
+ options: { output }
350
+ }
351
+ } = react.useApp();
352
+ const { getSchemas, getName, getFile } = hooks.useOperationManager();
353
+ const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
354
+ const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method);
355
+ const importPath = options.mutation ? options.mutation.importPath : "@tanstack/svelte-query";
356
+ const mutation = {
357
+ name: getName(operation, { type: "function", prefix: "create" }),
358
+ typeName: getName(operation, { type: "type" }),
359
+ file: getFile(operation, { prefix: "create" })
360
+ };
361
+ const type = {
362
+ file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
363
+ //todo remove type?
364
+ schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
365
+ };
366
+ const zod = {
367
+ file: getFile(operation, { pluginKey: [pluginZod.pluginZodName] }),
368
+ schemas: getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" })
369
+ };
370
+ const client = {
371
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
372
+ };
373
+ const mutationKey = {
374
+ name: getName(operation, { type: "const", suffix: "MutationKey" }),
375
+ typeName: getName(operation, { type: "type", suffix: "MutationKey" })
376
+ };
377
+ if (!isMutation) {
378
+ return null;
379
+ }
380
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mutation.file.baseName, path: mutation.file.path, meta: mutation.file.meta, banner: output?.banner, footer: output?.footer, children: [
381
+ options.parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zod.schemas.response.name], root: mutation.file.path, path: zod.file.path }),
382
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.client.importPath }),
383
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["RequestConfig", "ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
384
+ /* @__PURE__ */ jsxRuntime.jsx(
385
+ react.File.Import,
386
+ {
387
+ name: [
388
+ type.schemas.request?.name,
389
+ type.schemas.response.name,
390
+ type.schemas.pathParams?.name,
391
+ type.schemas.queryParams?.name,
392
+ type.schemas.headerParams?.name,
393
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
394
+ ].filter(Boolean),
395
+ root: mutation.file.path,
396
+ path: type.file.path,
397
+ isTypeOnly: true
398
+ }
399
+ ),
400
+ /* @__PURE__ */ jsxRuntime.jsx(
401
+ chunkKRGCKSGR_cjs.MutationKey,
402
+ {
403
+ name: mutationKey.name,
404
+ typeName: mutationKey.typeName,
405
+ operation,
406
+ pathParamsType: options.pathParamsType,
407
+ typeSchemas: type.schemas,
408
+ transformer: options.mutationKey
409
+ }
410
+ ),
411
+ /* @__PURE__ */ jsxRuntime.jsx(
412
+ chunkKRGCKSGR_cjs.Client,
413
+ {
414
+ name: client.name,
415
+ isExportable: false,
416
+ isIndexable: false,
417
+ baseURL: options.client.baseURL,
418
+ operation,
419
+ typeSchemas: type.schemas,
420
+ zodSchemas: zod.schemas,
421
+ dataReturnType: options.client.dataReturnType,
422
+ paramsType: options.paramsType,
423
+ pathParamsType: options.pathParamsType,
424
+ parser: options.parser
425
+ }
426
+ ),
427
+ options.mutation && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
428
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["createMutation"], path: importPath }),
429
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["CreateMutationOptions", "CreateMutationResult"], path: importPath, isTypeOnly: true }),
430
+ /* @__PURE__ */ jsxRuntime.jsx(
431
+ chunkKRGCKSGR_cjs.Mutation,
432
+ {
433
+ name: mutation.name,
434
+ clientName: client.name,
435
+ typeName: mutation.typeName,
436
+ typeSchemas: type.schemas,
437
+ operation,
438
+ dataReturnType: options.client.dataReturnType,
439
+ paramsType: options.paramsType,
440
+ pathParamsType: options.pathParamsType,
441
+ mutationKeyName: mutationKey.name
442
+ }
443
+ )
444
+ ] })
445
+ ] });
446
+ }
447
+ });
448
+
449
+ exports.mutationGenerator = mutationGenerator;
450
+ exports.queryGenerator = queryGenerator;
451
+ //# sourceMappingURL=chunk-CDRGJAED.cjs.map
452
+ //# sourceMappingURL=chunk-CDRGJAED.cjs.map