@kubb/plugin-vue-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.
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/chunk-A7SD37VK.cjs +584 -0
- package/dist/chunk-A7SD37VK.cjs.map +1 -0
- package/dist/chunk-DHJLKFYS.js +827 -0
- package/dist/chunk-DHJLKFYS.js.map +1 -0
- package/dist/chunk-J4RZRRHQ.cjs +837 -0
- package/dist/chunk-J4RZRRHQ.cjs.map +1 -0
- package/dist/chunk-O4EGNKUX.js +576 -0
- package/dist/chunk-O4EGNKUX.js.map +1 -0
- package/dist/components.cjs +36 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +150 -0
- package/dist/components.d.ts +150 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/generators.cjs +21 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +12 -0
- package/dist/generators.d.ts +12 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +134 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +127 -0
- package/dist/index.js.map +1 -0
- package/dist/types-C8LfCZUP.d.cts +389 -0
- package/dist/types-C8LfCZUP.d.ts +389 -0
- package/package.json +102 -0
- package/src/components/InfiniteQuery.tsx +190 -0
- package/src/components/InfiniteQueryOptions.tsx +185 -0
- package/src/components/Mutation.tsx +167 -0
- package/src/components/MutationKey.tsx +54 -0
- package/src/components/Query.tsx +191 -0
- package/src/components/QueryKey.tsx +91 -0
- package/src/components/QueryOptions.tsx +152 -0
- package/src/components/index.ts +7 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +53 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +53 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +45 -0
- package/src/generators/__snapshots__/findByTags.ts +53 -0
- package/src/generators/__snapshots__/findByTagsObject.ts +62 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +53 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +53 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +53 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +58 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +58 -0
- package/src/generators/__snapshots__/postAsQuery.ts +52 -0
- package/src/generators/__snapshots__/updatePetById.ts +45 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +45 -0
- package/src/generators/index.ts +3 -0
- package/src/generators/infiniteQueryGenerator.tsx +137 -0
- package/src/generators/mutationGenerator.tsx +116 -0
- package/src/generators/queryGenerator.tsx +129 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +149 -0
- package/src/types.ts +159 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { Client, Operations, QueryKey, QueryOptions, Query, MutationKey, Mutation, InfiniteQueryOptions, InfiniteQuery } from './chunk-DHJLKFYS.js';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
4
|
+
import { camelCase } from '@kubb/core/transformers';
|
|
5
|
+
import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
6
|
+
import { pluginZodName } from '@kubb/plugin-zod';
|
|
7
|
+
import { useOperationManager } from '@kubb/plugin-oas/hooks';
|
|
8
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
9
|
+
import { useApp, File, Function } from '@kubb/react';
|
|
10
|
+
import { jsxs, jsx, Fragment } from '@kubb/react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
var clientGenerator = createReactGenerator({
|
|
13
|
+
name: "client",
|
|
14
|
+
Operation({ options, operation }) {
|
|
15
|
+
const {
|
|
16
|
+
plugin: {
|
|
17
|
+
options: { output }
|
|
18
|
+
}
|
|
19
|
+
} = useApp();
|
|
20
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
21
|
+
const client = {
|
|
22
|
+
name: getName(operation, { type: "function" }),
|
|
23
|
+
file: getFile(operation)
|
|
24
|
+
};
|
|
25
|
+
const type = {
|
|
26
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
27
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
28
|
+
};
|
|
29
|
+
const zod = {
|
|
30
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
31
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
|
|
32
|
+
};
|
|
33
|
+
return /* @__PURE__ */ jsxs(File, { baseName: client.file.baseName, path: client.file.path, meta: client.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
34
|
+
/* @__PURE__ */ jsx(File.Import, { name: "client", path: options.importPath }),
|
|
35
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.importPath, isTypeOnly: true }),
|
|
36
|
+
options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
|
|
37
|
+
/* @__PURE__ */ jsx(
|
|
38
|
+
File.Import,
|
|
39
|
+
{
|
|
40
|
+
name: [
|
|
41
|
+
type.schemas.request?.name,
|
|
42
|
+
type.schemas.response.name,
|
|
43
|
+
type.schemas.pathParams?.name,
|
|
44
|
+
type.schemas.queryParams?.name,
|
|
45
|
+
type.schemas.headerParams?.name,
|
|
46
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
47
|
+
].filter(Boolean),
|
|
48
|
+
root: client.file.path,
|
|
49
|
+
path: type.file.path,
|
|
50
|
+
isTypeOnly: true
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
/* @__PURE__ */ jsx(
|
|
54
|
+
Client,
|
|
55
|
+
{
|
|
56
|
+
name: client.name,
|
|
57
|
+
baseURL: options.baseURL,
|
|
58
|
+
dataReturnType: options.dataReturnType,
|
|
59
|
+
pathParamsType: options.pathParamsType,
|
|
60
|
+
paramsType: options.paramsType,
|
|
61
|
+
typeSchemas: type.schemas,
|
|
62
|
+
operation,
|
|
63
|
+
parser: options.parser,
|
|
64
|
+
zodSchemas: zod.schemas
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
] });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
var operationsGenerator = createReactGenerator({
|
|
71
|
+
name: "client",
|
|
72
|
+
Operations({ operations }) {
|
|
73
|
+
const {
|
|
74
|
+
pluginManager,
|
|
75
|
+
plugin: {
|
|
76
|
+
options: { output }
|
|
77
|
+
}
|
|
78
|
+
} = useApp();
|
|
79
|
+
const name = "operations";
|
|
80
|
+
const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginClientName] });
|
|
81
|
+
return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: /* @__PURE__ */ jsx(Operations, { name, operations }) });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
var groupedClientGenerator = createReactGenerator({
|
|
85
|
+
name: "groupedClient",
|
|
86
|
+
Operations({ operations }) {
|
|
87
|
+
const {
|
|
88
|
+
pluginManager,
|
|
89
|
+
plugin: { options }
|
|
90
|
+
} = useApp();
|
|
91
|
+
const { getName, getFile } = useOperationManager();
|
|
92
|
+
const controllers = operations.reduce(
|
|
93
|
+
(acc, operation) => {
|
|
94
|
+
if (options.group?.type === "tag") {
|
|
95
|
+
const tag = operation.getTags().at(0)?.name;
|
|
96
|
+
const name = tag ? options.group?.name?.({ group: camelCase(tag) }) : void 0;
|
|
97
|
+
if (!tag || !name) {
|
|
98
|
+
return acc;
|
|
99
|
+
}
|
|
100
|
+
const file = pluginManager.getFile({
|
|
101
|
+
name,
|
|
102
|
+
extname: ".ts",
|
|
103
|
+
pluginKey: [pluginClientName],
|
|
104
|
+
options: { tag }
|
|
105
|
+
});
|
|
106
|
+
const client = {
|
|
107
|
+
name: getName(operation, { type: "function" }),
|
|
108
|
+
file: getFile(operation)
|
|
109
|
+
};
|
|
110
|
+
const previousFile = acc.find((item) => item.file.path === file.path);
|
|
111
|
+
if (previousFile) {
|
|
112
|
+
previousFile.clients.push(client);
|
|
113
|
+
} else {
|
|
114
|
+
acc.push({ name, file, clients: [client] });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return acc;
|
|
118
|
+
},
|
|
119
|
+
[]
|
|
120
|
+
);
|
|
121
|
+
return controllers.map(({ name, file, clients }) => {
|
|
122
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: options.output?.banner, footer: options.output?.footer, children: [
|
|
123
|
+
clients.map((client) => /* @__PURE__ */ jsx(File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
|
|
124
|
+
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
|
|
125
|
+
] }, file.path);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// ../plugin-client/src/plugin.ts
|
|
131
|
+
var pluginClientName = "plugin-client";
|
|
132
|
+
createPlugin((options) => {
|
|
133
|
+
const {
|
|
134
|
+
output = { path: "clients", barrelType: "named" },
|
|
135
|
+
group,
|
|
136
|
+
exclude = [],
|
|
137
|
+
include,
|
|
138
|
+
override = [],
|
|
139
|
+
transformers = {},
|
|
140
|
+
dataReturnType = "data",
|
|
141
|
+
pathParamsType = "inline",
|
|
142
|
+
paramsType = "inline",
|
|
143
|
+
operations = false,
|
|
144
|
+
baseURL,
|
|
145
|
+
generators = [clientGenerator, group ? groupedClientGenerator : void 0, operations ? operationsGenerator : void 0].filter(Boolean),
|
|
146
|
+
importPath = "@kubb/plugin-client/client",
|
|
147
|
+
parser = "client"
|
|
148
|
+
} = options;
|
|
149
|
+
return {
|
|
150
|
+
name: pluginClientName,
|
|
151
|
+
options: {
|
|
152
|
+
output,
|
|
153
|
+
group,
|
|
154
|
+
parser,
|
|
155
|
+
dataReturnType,
|
|
156
|
+
importPath,
|
|
157
|
+
paramsType,
|
|
158
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType,
|
|
159
|
+
baseURL
|
|
160
|
+
},
|
|
161
|
+
pre: [pluginOasName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
|
162
|
+
resolvePath(baseName, pathMode, options2) {
|
|
163
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
164
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
165
|
+
if (options2?.tag && group?.type === "tag") {
|
|
166
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
167
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
168
|
+
}
|
|
169
|
+
if (mode === "single") {
|
|
170
|
+
return path.resolve(root, output.path);
|
|
171
|
+
}
|
|
172
|
+
return path.resolve(root, output.path, baseName);
|
|
173
|
+
},
|
|
174
|
+
resolveName(name, type) {
|
|
175
|
+
const resolvedName = camelCase(name, { isFile: type === "file" });
|
|
176
|
+
if (type) {
|
|
177
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
178
|
+
}
|
|
179
|
+
return resolvedName;
|
|
180
|
+
},
|
|
181
|
+
async buildStart() {
|
|
182
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
183
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
184
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
185
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
186
|
+
const baseURL2 = await swaggerPlugin.context.getBaseURL();
|
|
187
|
+
const operationGenerator = new OperationGenerator(
|
|
188
|
+
baseURL2 ? {
|
|
189
|
+
...this.plugin.options,
|
|
190
|
+
baseURL: baseURL2
|
|
191
|
+
} : this.plugin.options,
|
|
192
|
+
{
|
|
193
|
+
oas,
|
|
194
|
+
pluginManager: this.pluginManager,
|
|
195
|
+
plugin: this.plugin,
|
|
196
|
+
contentType: swaggerPlugin.context.contentType,
|
|
197
|
+
exclude,
|
|
198
|
+
include,
|
|
199
|
+
override,
|
|
200
|
+
mode
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
const files = await operationGenerator.build(...generators);
|
|
204
|
+
await this.addFile(...files);
|
|
205
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
206
|
+
type: output.barrelType ?? "named",
|
|
207
|
+
root,
|
|
208
|
+
output,
|
|
209
|
+
files: this.fileManager.files,
|
|
210
|
+
meta: {
|
|
211
|
+
pluginKey: this.plugin.key
|
|
212
|
+
},
|
|
213
|
+
logger: this.logger
|
|
214
|
+
});
|
|
215
|
+
await this.addFile(...barrelFiles);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
});
|
|
219
|
+
var queryGenerator = createReactGenerator({
|
|
220
|
+
name: "vue-query",
|
|
221
|
+
Operation({ options, operation }) {
|
|
222
|
+
const {
|
|
223
|
+
plugin: {
|
|
224
|
+
options: { output }
|
|
225
|
+
}
|
|
226
|
+
} = useApp();
|
|
227
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
228
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
229
|
+
const importPath = options.query ? options.query.importPath : "@tanstack/vue-query";
|
|
230
|
+
const query = {
|
|
231
|
+
name: getName(operation, { type: "function", prefix: "use" }),
|
|
232
|
+
typeName: getName(operation, { type: "type" }),
|
|
233
|
+
file: getFile(operation, { prefix: "use" })
|
|
234
|
+
};
|
|
235
|
+
const client = {
|
|
236
|
+
name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
|
|
237
|
+
};
|
|
238
|
+
const queryOptions = {
|
|
239
|
+
name: getName(operation, { type: "function", suffix: "QueryOptions" })
|
|
240
|
+
};
|
|
241
|
+
const queryKey = {
|
|
242
|
+
name: getName(operation, { type: "const", suffix: "QueryKey" }),
|
|
243
|
+
typeName: getName(operation, { type: "type", suffix: "QueryKey" })
|
|
244
|
+
};
|
|
245
|
+
const type = {
|
|
246
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
247
|
+
//todo remove type?
|
|
248
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
249
|
+
};
|
|
250
|
+
const zod = {
|
|
251
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
252
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
|
|
253
|
+
};
|
|
254
|
+
if (!isQuery) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return /* @__PURE__ */ jsxs(File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
258
|
+
options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
|
|
259
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["unref"], path: "vue" }),
|
|
260
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["MaybeRef"], path: "vue", isTypeOnly: true }),
|
|
261
|
+
/* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
|
|
262
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
263
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
264
|
+
/* @__PURE__ */ jsx(
|
|
265
|
+
File.Import,
|
|
266
|
+
{
|
|
267
|
+
name: [
|
|
268
|
+
type.schemas.request?.name,
|
|
269
|
+
type.schemas.response.name,
|
|
270
|
+
type.schemas.pathParams?.name,
|
|
271
|
+
type.schemas.queryParams?.name,
|
|
272
|
+
type.schemas.headerParams?.name,
|
|
273
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
274
|
+
].filter(Boolean),
|
|
275
|
+
root: query.file.path,
|
|
276
|
+
path: type.file.path,
|
|
277
|
+
isTypeOnly: true
|
|
278
|
+
}
|
|
279
|
+
),
|
|
280
|
+
/* @__PURE__ */ jsx(
|
|
281
|
+
QueryKey,
|
|
282
|
+
{
|
|
283
|
+
name: queryKey.name,
|
|
284
|
+
typeName: queryKey.typeName,
|
|
285
|
+
operation,
|
|
286
|
+
pathParamsType: options.pathParamsType,
|
|
287
|
+
typeSchemas: type.schemas,
|
|
288
|
+
transformer: options.queryKey
|
|
289
|
+
}
|
|
290
|
+
),
|
|
291
|
+
/* @__PURE__ */ jsx(
|
|
292
|
+
Client,
|
|
293
|
+
{
|
|
294
|
+
name: client.name,
|
|
295
|
+
isExportable: false,
|
|
296
|
+
isIndexable: false,
|
|
297
|
+
baseURL: options.client.baseURL,
|
|
298
|
+
operation,
|
|
299
|
+
typeSchemas: type.schemas,
|
|
300
|
+
zodSchemas: zod.schemas,
|
|
301
|
+
dataReturnType: options.client.dataReturnType,
|
|
302
|
+
paramsType: options.paramsType,
|
|
303
|
+
pathParamsType: options.pathParamsType,
|
|
304
|
+
parser: options.parser
|
|
305
|
+
}
|
|
306
|
+
),
|
|
307
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["queryOptions"], path: importPath }),
|
|
308
|
+
/* @__PURE__ */ jsx(
|
|
309
|
+
QueryOptions,
|
|
310
|
+
{
|
|
311
|
+
name: queryOptions.name,
|
|
312
|
+
clientName: client.name,
|
|
313
|
+
queryKeyName: queryKey.name,
|
|
314
|
+
typeSchemas: type.schemas,
|
|
315
|
+
paramsType: options.paramsType,
|
|
316
|
+
pathParamsType: options.pathParamsType
|
|
317
|
+
}
|
|
318
|
+
),
|
|
319
|
+
options.query && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
320
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["useQuery"], path: importPath }),
|
|
321
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["QueryKey", "QueryObserverOptions", "UseQueryReturnType"], path: importPath, isTypeOnly: true }),
|
|
322
|
+
/* @__PURE__ */ jsx(
|
|
323
|
+
Query,
|
|
324
|
+
{
|
|
325
|
+
name: query.name,
|
|
326
|
+
queryOptionsName: queryOptions.name,
|
|
327
|
+
typeSchemas: type.schemas,
|
|
328
|
+
paramsType: options.paramsType,
|
|
329
|
+
pathParamsType: options.pathParamsType,
|
|
330
|
+
operation,
|
|
331
|
+
dataReturnType: options.client.dataReturnType,
|
|
332
|
+
queryKeyName: queryKey.name,
|
|
333
|
+
queryKeyTypeName: queryKey.typeName
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
] })
|
|
337
|
+
] });
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
var mutationGenerator = createReactGenerator({
|
|
341
|
+
name: "vue-query",
|
|
342
|
+
Operation({ options, operation }) {
|
|
343
|
+
const {
|
|
344
|
+
plugin: {
|
|
345
|
+
options: { output }
|
|
346
|
+
}
|
|
347
|
+
} = useApp();
|
|
348
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
349
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
350
|
+
const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method);
|
|
351
|
+
const importPath = options.mutation ? options.mutation.importPath : "@tanstack/vue-query";
|
|
352
|
+
const mutation = {
|
|
353
|
+
name: getName(operation, { type: "function", prefix: "use" }),
|
|
354
|
+
typeName: getName(operation, { type: "type" }),
|
|
355
|
+
file: getFile(operation, { prefix: "use" })
|
|
356
|
+
};
|
|
357
|
+
const type = {
|
|
358
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
359
|
+
//todo remove type?
|
|
360
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
361
|
+
};
|
|
362
|
+
const zod = {
|
|
363
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
364
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
|
|
365
|
+
};
|
|
366
|
+
const client = {
|
|
367
|
+
name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
|
|
368
|
+
};
|
|
369
|
+
const mutationKey = {
|
|
370
|
+
name: getName(operation, { type: "const", suffix: "MutationKey" }),
|
|
371
|
+
typeName: getName(operation, { type: "type", suffix: "MutationKey" })
|
|
372
|
+
};
|
|
373
|
+
if (!isMutation) {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
return /* @__PURE__ */ jsxs(File, { baseName: mutation.file.baseName, path: mutation.file.path, meta: mutation.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
377
|
+
options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: mutation.file.path, path: zod.file.path }),
|
|
378
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["MaybeRef"], path: "vue", isTypeOnly: true }),
|
|
379
|
+
/* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
|
|
380
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig", "ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
381
|
+
/* @__PURE__ */ jsx(
|
|
382
|
+
File.Import,
|
|
383
|
+
{
|
|
384
|
+
name: [
|
|
385
|
+
type.schemas.request?.name,
|
|
386
|
+
type.schemas.response.name,
|
|
387
|
+
type.schemas.pathParams?.name,
|
|
388
|
+
type.schemas.queryParams?.name,
|
|
389
|
+
type.schemas.headerParams?.name,
|
|
390
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
391
|
+
].filter(Boolean),
|
|
392
|
+
root: mutation.file.path,
|
|
393
|
+
path: type.file.path,
|
|
394
|
+
isTypeOnly: true
|
|
395
|
+
}
|
|
396
|
+
),
|
|
397
|
+
/* @__PURE__ */ jsx(
|
|
398
|
+
MutationKey,
|
|
399
|
+
{
|
|
400
|
+
name: mutationKey.name,
|
|
401
|
+
typeName: mutationKey.typeName,
|
|
402
|
+
operation,
|
|
403
|
+
pathParamsType: options.pathParamsType,
|
|
404
|
+
typeSchemas: type.schemas,
|
|
405
|
+
transformer: options.mutationKey
|
|
406
|
+
}
|
|
407
|
+
),
|
|
408
|
+
/* @__PURE__ */ jsx(
|
|
409
|
+
Client,
|
|
410
|
+
{
|
|
411
|
+
name: client.name,
|
|
412
|
+
isExportable: false,
|
|
413
|
+
isIndexable: false,
|
|
414
|
+
baseURL: options.client.baseURL,
|
|
415
|
+
operation,
|
|
416
|
+
typeSchemas: type.schemas,
|
|
417
|
+
zodSchemas: zod.schemas,
|
|
418
|
+
dataReturnType: options.client.dataReturnType,
|
|
419
|
+
paramsType: options.paramsType,
|
|
420
|
+
pathParamsType: options.pathParamsType,
|
|
421
|
+
parser: options.parser
|
|
422
|
+
}
|
|
423
|
+
),
|
|
424
|
+
options.mutation && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
425
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["useMutation"], path: importPath }),
|
|
426
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["MutationObserverOptions"], path: importPath, isTypeOnly: true }),
|
|
427
|
+
/* @__PURE__ */ jsx(
|
|
428
|
+
Mutation,
|
|
429
|
+
{
|
|
430
|
+
name: mutation.name,
|
|
431
|
+
clientName: client.name,
|
|
432
|
+
typeName: mutation.typeName,
|
|
433
|
+
typeSchemas: type.schemas,
|
|
434
|
+
operation,
|
|
435
|
+
dataReturnType: options.client.dataReturnType,
|
|
436
|
+
paramsType: options.paramsType,
|
|
437
|
+
pathParamsType: options.pathParamsType,
|
|
438
|
+
mutationKeyName: mutationKey.name
|
|
439
|
+
}
|
|
440
|
+
)
|
|
441
|
+
] })
|
|
442
|
+
] });
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
var infiniteQueryGenerator = createReactGenerator({
|
|
446
|
+
name: "vue-infinite-query",
|
|
447
|
+
Operation({ options, operation }) {
|
|
448
|
+
const {
|
|
449
|
+
plugin: {
|
|
450
|
+
options: { output }
|
|
451
|
+
}
|
|
452
|
+
} = useApp();
|
|
453
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
454
|
+
const isQuery = typeof options.query === "boolean" ? options.query : !!options.query.methods?.some((method) => operation.method === method);
|
|
455
|
+
const isInfinite = isQuery && !!options.infinite;
|
|
456
|
+
const importPath = options.query ? options.query.importPath : "@tanstack/vue-query";
|
|
457
|
+
const query = {
|
|
458
|
+
name: getName(operation, { type: "function", prefix: "use", suffix: "infinite" }),
|
|
459
|
+
typeName: getName(operation, { type: "type" }),
|
|
460
|
+
file: getFile(operation, { prefix: "use", suffix: "infinite" })
|
|
461
|
+
};
|
|
462
|
+
const client = {
|
|
463
|
+
name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
|
|
464
|
+
};
|
|
465
|
+
const queryOptions = {
|
|
466
|
+
name: getName(operation, { type: "function", suffix: "InfiniteQueryOptions" })
|
|
467
|
+
};
|
|
468
|
+
const queryKey = {
|
|
469
|
+
name: getName(operation, { type: "const", suffix: "InfiniteQueryKey" }),
|
|
470
|
+
typeName: getName(operation, { type: "type", suffix: "InfiniteQueryKey" })
|
|
471
|
+
};
|
|
472
|
+
const type = {
|
|
473
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
474
|
+
//todo remove type?
|
|
475
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
476
|
+
};
|
|
477
|
+
const zod = {
|
|
478
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
479
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
|
|
480
|
+
};
|
|
481
|
+
if (!isQuery || !isInfinite) {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
return /* @__PURE__ */ jsxs(File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
485
|
+
options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
|
|
486
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["unref"], path: "vue" }),
|
|
487
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["MaybeRef"], path: "vue", isTypeOnly: true }),
|
|
488
|
+
/* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
|
|
489
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
490
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
|
|
491
|
+
/* @__PURE__ */ jsx(
|
|
492
|
+
File.Import,
|
|
493
|
+
{
|
|
494
|
+
name: [
|
|
495
|
+
type.schemas.request?.name,
|
|
496
|
+
type.schemas.response.name,
|
|
497
|
+
type.schemas.pathParams?.name,
|
|
498
|
+
type.schemas.queryParams?.name,
|
|
499
|
+
type.schemas.headerParams?.name,
|
|
500
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
501
|
+
].filter(Boolean),
|
|
502
|
+
root: query.file.path,
|
|
503
|
+
path: type.file.path,
|
|
504
|
+
isTypeOnly: true
|
|
505
|
+
}
|
|
506
|
+
),
|
|
507
|
+
/* @__PURE__ */ jsx(
|
|
508
|
+
QueryKey,
|
|
509
|
+
{
|
|
510
|
+
name: queryKey.name,
|
|
511
|
+
typeName: queryKey.typeName,
|
|
512
|
+
operation,
|
|
513
|
+
pathParamsType: options.pathParamsType,
|
|
514
|
+
typeSchemas: type.schemas,
|
|
515
|
+
transformer: options.queryKey
|
|
516
|
+
}
|
|
517
|
+
),
|
|
518
|
+
/* @__PURE__ */ jsx(
|
|
519
|
+
Client,
|
|
520
|
+
{
|
|
521
|
+
name: client.name,
|
|
522
|
+
isExportable: false,
|
|
523
|
+
isIndexable: false,
|
|
524
|
+
baseURL: options.client.baseURL,
|
|
525
|
+
operation,
|
|
526
|
+
typeSchemas: type.schemas,
|
|
527
|
+
zodSchemas: zod.schemas,
|
|
528
|
+
dataReturnType: options.client.dataReturnType,
|
|
529
|
+
paramsType: options.paramsType,
|
|
530
|
+
pathParamsType: options.pathParamsType,
|
|
531
|
+
parser: options.parser
|
|
532
|
+
}
|
|
533
|
+
),
|
|
534
|
+
options.infinite && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
535
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["infiniteQueryOptions"], path: importPath }),
|
|
536
|
+
/* @__PURE__ */ jsx(
|
|
537
|
+
InfiniteQueryOptions,
|
|
538
|
+
{
|
|
539
|
+
name: queryOptions.name,
|
|
540
|
+
clientName: client.name,
|
|
541
|
+
queryKeyName: queryKey.name,
|
|
542
|
+
typeSchemas: type.schemas,
|
|
543
|
+
paramsType: options.paramsType,
|
|
544
|
+
pathParamsType: options.pathParamsType,
|
|
545
|
+
dataReturnType: options.client.dataReturnType,
|
|
546
|
+
cursorParam: options.infinite.cursorParam,
|
|
547
|
+
initialPageParam: options.infinite.initialPageParam,
|
|
548
|
+
queryParam: options.infinite.queryParam
|
|
549
|
+
}
|
|
550
|
+
)
|
|
551
|
+
] }),
|
|
552
|
+
options.infinite && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
553
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["useInfiniteQuery"], path: importPath }),
|
|
554
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["QueryKey", "InfiniteQueryObserverOptions", "UseInfiniteQueryReturnType"], path: importPath, isTypeOnly: true }),
|
|
555
|
+
/* @__PURE__ */ jsx(
|
|
556
|
+
InfiniteQuery,
|
|
557
|
+
{
|
|
558
|
+
name: query.name,
|
|
559
|
+
queryOptionsName: queryOptions.name,
|
|
560
|
+
typeSchemas: type.schemas,
|
|
561
|
+
paramsType: options.paramsType,
|
|
562
|
+
pathParamsType: options.pathParamsType,
|
|
563
|
+
operation,
|
|
564
|
+
dataReturnType: options.client.dataReturnType,
|
|
565
|
+
queryKeyName: queryKey.name,
|
|
566
|
+
queryKeyTypeName: queryKey.typeName
|
|
567
|
+
}
|
|
568
|
+
)
|
|
569
|
+
] })
|
|
570
|
+
] });
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
export { infiniteQueryGenerator, mutationGenerator, queryGenerator };
|
|
575
|
+
//# sourceMappingURL=chunk-O4EGNKUX.js.map
|
|
576
|
+
//# sourceMappingURL=chunk-O4EGNKUX.js.map
|