@kubb/plugin-react-query 3.0.0-alpha.10 → 3.0.0-alpha.12
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/dist/chunk-AGLJPONA.cjs +1423 -0
- package/dist/chunk-AGLJPONA.cjs.map +1 -0
- package/dist/{chunk-ZYTZV43V.js → chunk-I7X4HNDR.js} +228 -285
- package/dist/chunk-I7X4HNDR.js.map +1 -0
- package/dist/components.cjs +23 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +2 -12
- package/dist/components.js.map +1 -1
- package/dist/{index-5kpkk-7M.d.cts → index-BzoLlZve.d.cts} +0 -8
- package/dist/{index-5kpkk-7M.d.ts → index-BzoLlZve.d.ts} +0 -8
- package/dist/index.cjs +52 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -26
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +3 -3
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +2 -2
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +3 -3
- package/src/__snapshots__/queryOptions/getPetById.ts +3 -3
- package/src/components/Mutation.tsx +4 -20
- package/src/components/Query.tsx +3 -4
- package/src/components/QueryImports.tsx +2 -2
- package/src/components/QueryOptions.tsx +5 -15
- package/src/components/SchemaType.tsx +17 -2
- package/src/components/__snapshots__/gen/showPetById.ts +1 -1
- package/dist/chunk-7ZODZVKP.cjs +0 -1470
- package/dist/chunk-7ZODZVKP.cjs.map +0 -1
- package/dist/chunk-ZYTZV43V.js.map +0 -1
|
@@ -0,0 +1,1423 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var transformers2 = require('@kubb/core/transformers');
|
|
4
|
+
var utils = require('@kubb/core/utils');
|
|
5
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
6
|
+
var utils$1 = require('@kubb/plugin-oas/utils');
|
|
7
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
8
|
+
var react = require('@kubb/react');
|
|
9
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
10
|
+
var oas = require('@kubb/oas');
|
|
11
|
+
var core = require('@kubb/core');
|
|
12
|
+
var pluginZod = require('@kubb/plugin-zod');
|
|
13
|
+
|
|
14
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
|
|
16
|
+
var transformers2__default = /*#__PURE__*/_interopDefault(transformers2);
|
|
17
|
+
|
|
18
|
+
// src/components/Mutation.tsx
|
|
19
|
+
function SchemaType() {
|
|
20
|
+
const {
|
|
21
|
+
plugin: {
|
|
22
|
+
options: { dataReturnType }
|
|
23
|
+
}
|
|
24
|
+
} = react.useApp();
|
|
25
|
+
const { getSchemas, getName, getFile } = hooks.useOperationManager();
|
|
26
|
+
const operation = hooks.useOperation();
|
|
27
|
+
const file = getFile(operation);
|
|
28
|
+
const fileType = getFile(operation, { pluginKey: [pluginTs.pluginTsName] });
|
|
29
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
30
|
+
const [TData, TError, TRequest, TPathParams, TQueryParams, THeaderParams, TResponse] = [
|
|
31
|
+
schemas.response.name,
|
|
32
|
+
schemas.errors?.map((item) => item.name).join(" | ") || "never",
|
|
33
|
+
schemas.request?.name || "never",
|
|
34
|
+
schemas.pathParams?.name || "never",
|
|
35
|
+
schemas.queryParams?.name || "never",
|
|
36
|
+
schemas.headerParams?.name || "never",
|
|
37
|
+
schemas.response.name
|
|
38
|
+
];
|
|
39
|
+
const factoryName = getName(operation, { type: "type" });
|
|
40
|
+
const clientType = `${factoryName}Client`;
|
|
41
|
+
const isFormData = operation.getContentType() === "multipart/form-data";
|
|
42
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
43
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
react.File.Import,
|
|
45
|
+
{
|
|
46
|
+
name: [
|
|
47
|
+
schemas.request?.name,
|
|
48
|
+
schemas.response.name,
|
|
49
|
+
schemas.pathParams?.name,
|
|
50
|
+
schemas.queryParams?.name,
|
|
51
|
+
schemas.headerParams?.name,
|
|
52
|
+
...schemas.errors?.map((error) => error.name) || []
|
|
53
|
+
].filter(Boolean),
|
|
54
|
+
root: file.path,
|
|
55
|
+
path: fileType.path,
|
|
56
|
+
isTypeOnly: true
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: clientType, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: clientType, children: `typeof client<${TResponse}, ${TError}, ${isFormData ? "FormData" : TRequest}>` }) }),
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: factoryName, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: factoryName, children: `
|
|
61
|
+
{
|
|
62
|
+
data: ${TData}
|
|
63
|
+
error: ${TError}
|
|
64
|
+
request: ${isFormData ? "FormData" : TRequest}
|
|
65
|
+
pathParams: ${TPathParams}
|
|
66
|
+
queryParams: ${TQueryParams}
|
|
67
|
+
headerParams: ${THeaderParams}
|
|
68
|
+
response: ${dataReturnType === "data" ? TData : `Awaited<ReturnType<${clientType}>>`}
|
|
69
|
+
client: {
|
|
70
|
+
parameters: Partial<Parameters<${clientType}>[0]>
|
|
71
|
+
return: Awaited<ReturnType<${clientType}>>
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
` }) })
|
|
75
|
+
] });
|
|
76
|
+
}
|
|
77
|
+
function Template({ name, params, mutateParams, JSDoc, client, hook, dataReturnType }) {
|
|
78
|
+
const isFormData = client.contentType === "multipart/form-data";
|
|
79
|
+
const headers = [
|
|
80
|
+
client.contentType !== "application/json" ? `'Content-Type': '${client.contentType}'` : void 0,
|
|
81
|
+
client.withHeaders ? "...headers" : void 0
|
|
82
|
+
].filter(Boolean).join(", ");
|
|
83
|
+
const clientOptions = [
|
|
84
|
+
`method: "${client.method}"`,
|
|
85
|
+
`url: ${client.path.template}`,
|
|
86
|
+
client.withQueryParams ? "params" : void 0,
|
|
87
|
+
client.withData && !isFormData ? "data" : void 0,
|
|
88
|
+
client.withData && isFormData ? "data: formData" : void 0,
|
|
89
|
+
headers.length ? `headers: { ${headers}, ...clientOptions.headers }` : void 0,
|
|
90
|
+
"...clientOptions"
|
|
91
|
+
].filter(Boolean);
|
|
92
|
+
const resolvedClientOptions = `${transformers2__default.default.createIndent(4)}${clientOptions.join(`,
|
|
93
|
+
${transformers2__default.default.createIndent(4)}`)}`;
|
|
94
|
+
const formData = isFormData ? `
|
|
95
|
+
const formData = new FormData()
|
|
96
|
+
if(data) {
|
|
97
|
+
Object.keys(data).forEach((key) => {
|
|
98
|
+
const value = data[key];
|
|
99
|
+
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
100
|
+
formData.append(key, value);
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
` : void 0;
|
|
105
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { export: true, name, params, JSDoc, children: `
|
|
106
|
+
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
107
|
+
|
|
108
|
+
return ${hook.name}({
|
|
109
|
+
mutationFn: async(${mutateParams}) => {
|
|
110
|
+
${hook.children || ""}
|
|
111
|
+
${formData || ""}
|
|
112
|
+
const res = await client<${client.generics}>({
|
|
113
|
+
${resolvedClientOptions}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
return ${dataReturnType === "data" ? "res.data" : "res"}
|
|
117
|
+
},
|
|
118
|
+
...mutationOptions
|
|
119
|
+
})` }) });
|
|
120
|
+
}
|
|
121
|
+
function RootTemplate({ children }) {
|
|
122
|
+
const {
|
|
123
|
+
plugin: {
|
|
124
|
+
options: {
|
|
125
|
+
client: { importPath },
|
|
126
|
+
mutate
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} = react.useApp();
|
|
130
|
+
const { getFile } = hooks.useOperationManager();
|
|
131
|
+
const operation = hooks.useOperation();
|
|
132
|
+
const file = getFile(operation);
|
|
133
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
134
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: importPath }),
|
|
135
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
136
|
+
react.File.Import,
|
|
137
|
+
{
|
|
138
|
+
name: ["UseMutationOptions"],
|
|
139
|
+
path: typeof mutate !== "boolean" && mutate.importPath ? mutate.importPath : "@tanstack/react-query",
|
|
140
|
+
isTypeOnly: true
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["useMutation"], path: typeof mutate !== "boolean" && mutate.importPath ? mutate.importPath : "@tanstack/react-query" }),
|
|
144
|
+
children
|
|
145
|
+
] });
|
|
146
|
+
}
|
|
147
|
+
var defaultTemplates = { default: Template, root: RootTemplate };
|
|
148
|
+
function Mutation({ Template: Template6 = defaultTemplates.default }) {
|
|
149
|
+
const {
|
|
150
|
+
plugin: {
|
|
151
|
+
options: { dataReturnType, mutate }
|
|
152
|
+
}
|
|
153
|
+
} = react.useApp();
|
|
154
|
+
const operation = hooks.useOperation();
|
|
155
|
+
const { getSchemas, getName } = hooks.useOperationManager();
|
|
156
|
+
const name = getName(operation, { type: "function" });
|
|
157
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
158
|
+
const contentType = operation.getContentType();
|
|
159
|
+
const params = new utils.FunctionParams();
|
|
160
|
+
const mutateParams = new utils.FunctionParams();
|
|
161
|
+
const factoryName = getName(operation, { type: "type" });
|
|
162
|
+
const requestType = mutate && mutate.variablesType === "mutate" ? utils.FunctionParams.toObject([
|
|
163
|
+
...utils$1.getASTParams(schemas.pathParams, { typed: true }),
|
|
164
|
+
{
|
|
165
|
+
name: "params",
|
|
166
|
+
type: `${factoryName}['queryParams']`,
|
|
167
|
+
enabled: !!schemas.queryParams?.name,
|
|
168
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: "headers",
|
|
172
|
+
type: `${factoryName}['headerParams']`,
|
|
173
|
+
enabled: !!schemas.headerParams?.name,
|
|
174
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "data",
|
|
178
|
+
type: `${factoryName}['request']`,
|
|
179
|
+
enabled: !!schemas.request?.name,
|
|
180
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
181
|
+
}
|
|
182
|
+
])?.type : schemas.request?.name ? `${factoryName}['request']` : "never";
|
|
183
|
+
const client = {
|
|
184
|
+
method: operation.method,
|
|
185
|
+
path: new utils.URLPath(operation.path),
|
|
186
|
+
generics: [`${factoryName}["data"]`, `${factoryName}["error"]`, requestType ? `${factoryName}["request"]` : "void"].join(", "),
|
|
187
|
+
withQueryParams: !!schemas.queryParams?.name,
|
|
188
|
+
withData: !!schemas.request?.name,
|
|
189
|
+
withPathParams: !!schemas.pathParams?.name,
|
|
190
|
+
withHeaders: !!schemas.headerParams?.name,
|
|
191
|
+
contentType
|
|
192
|
+
};
|
|
193
|
+
const hook = {
|
|
194
|
+
name: "useMutation",
|
|
195
|
+
generics: [`${factoryName}['response']`, `${factoryName}["error"]`, requestType ? `${requestType}` : "void"].join(", ")
|
|
196
|
+
};
|
|
197
|
+
const resultGenerics = [
|
|
198
|
+
`${factoryName}["response"]`,
|
|
199
|
+
`${factoryName}["error"]`,
|
|
200
|
+
mutate && mutate?.variablesType === "mutate" ? requestType : `${factoryName}["request"]`
|
|
201
|
+
];
|
|
202
|
+
if (mutate && mutate?.variablesType === "mutate") {
|
|
203
|
+
params.add([
|
|
204
|
+
{
|
|
205
|
+
name: "options",
|
|
206
|
+
type: `{
|
|
207
|
+
mutation?: UseMutationOptions<${resultGenerics.join(", ")}>,
|
|
208
|
+
client?: ${factoryName}['client']['parameters']
|
|
209
|
+
}`,
|
|
210
|
+
default: "{}"
|
|
211
|
+
}
|
|
212
|
+
]);
|
|
213
|
+
mutateParams.add([
|
|
214
|
+
[
|
|
215
|
+
...utils$1.getASTParams(schemas.pathParams, { typed: false }),
|
|
216
|
+
{
|
|
217
|
+
name: "params",
|
|
218
|
+
enabled: client.withQueryParams,
|
|
219
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
name: "headers",
|
|
223
|
+
enabled: client.withHeaders,
|
|
224
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "data",
|
|
228
|
+
enabled: !!schemas.request?.name,
|
|
229
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
]);
|
|
233
|
+
} else {
|
|
234
|
+
params.add([
|
|
235
|
+
...utils$1.getASTParams(schemas.pathParams, { typed: true }),
|
|
236
|
+
{
|
|
237
|
+
name: "params",
|
|
238
|
+
type: `${factoryName}['queryParams']`,
|
|
239
|
+
enabled: client.withQueryParams,
|
|
240
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: "headers",
|
|
244
|
+
type: `${factoryName}['headerParams']`,
|
|
245
|
+
enabled: client.withHeaders,
|
|
246
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "options",
|
|
250
|
+
type: `{
|
|
251
|
+
mutation?: UseMutationOptions<${resultGenerics.join(", ")}>,
|
|
252
|
+
client?: ${factoryName}['client']['parameters']
|
|
253
|
+
}`,
|
|
254
|
+
default: "{}"
|
|
255
|
+
}
|
|
256
|
+
]);
|
|
257
|
+
mutateParams.add([
|
|
258
|
+
{
|
|
259
|
+
name: "data",
|
|
260
|
+
enabled: !!schemas.request?.name,
|
|
261
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
262
|
+
}
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
265
|
+
if (!mutate) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
269
|
+
Template6,
|
|
270
|
+
{
|
|
271
|
+
name,
|
|
272
|
+
JSDoc: { comments: utils$1.getComments(operation) },
|
|
273
|
+
client,
|
|
274
|
+
hook,
|
|
275
|
+
params: params.toString(),
|
|
276
|
+
mutateParams: mutateParams.toString(),
|
|
277
|
+
dataReturnType
|
|
278
|
+
}
|
|
279
|
+
) });
|
|
280
|
+
}
|
|
281
|
+
Mutation.File = function({ ...props }) {
|
|
282
|
+
const templates = { ...defaultTemplates, ...props.templates };
|
|
283
|
+
const Template6 = templates.default;
|
|
284
|
+
const RootTemplate2 = templates.root;
|
|
285
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RootTemplate2, { children: [
|
|
286
|
+
/* @__PURE__ */ jsxRuntime.jsx(SchemaType, {}),
|
|
287
|
+
/* @__PURE__ */ jsxRuntime.jsx(Mutation, { Template: Template6 })
|
|
288
|
+
] });
|
|
289
|
+
};
|
|
290
|
+
Mutation.templates = defaultTemplates;
|
|
291
|
+
var reactQueryDepRegex = /@tanstack\/(react|solid|vue|svelte)-query/;
|
|
292
|
+
function getImportNames() {
|
|
293
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
294
|
+
return {
|
|
295
|
+
mutation: {
|
|
296
|
+
react: {
|
|
297
|
+
path: "@tanstack/react-query",
|
|
298
|
+
hookName: "useMutation",
|
|
299
|
+
optionsType: "UseMutationOptions",
|
|
300
|
+
resultType: "UseMutationResult"
|
|
301
|
+
},
|
|
302
|
+
solid: {
|
|
303
|
+
path: "@tanstack/solid-query",
|
|
304
|
+
hookName: "createMutation",
|
|
305
|
+
optionsType: "CreateMutationOptions",
|
|
306
|
+
resultType: "CreateMutationResult"
|
|
307
|
+
},
|
|
308
|
+
svelte: {
|
|
309
|
+
path: "@tanstack/svelte-query",
|
|
310
|
+
hookName: "createMutation",
|
|
311
|
+
optionsType: "CreateMutationOptions",
|
|
312
|
+
resultType: "CreateMutationResult"
|
|
313
|
+
},
|
|
314
|
+
vue: {
|
|
315
|
+
path: "@tanstack/vue-query",
|
|
316
|
+
hookName: "useMutation",
|
|
317
|
+
optionsType: isV5 ? "UseMutationOptions" : "VueMutationObserverOptions",
|
|
318
|
+
resultType: "UseMutationReturnType"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
query: {
|
|
322
|
+
react: {
|
|
323
|
+
path: "@tanstack/react-query",
|
|
324
|
+
hookName: "useQuery",
|
|
325
|
+
optionsType: isV5 ? "QueryObserverOptions" : "UseBaseQueryOptions",
|
|
326
|
+
resultType: "UseQueryResult"
|
|
327
|
+
},
|
|
328
|
+
solid: {
|
|
329
|
+
path: "@tanstack/solid-query",
|
|
330
|
+
hookName: "createQuery",
|
|
331
|
+
optionsType: "CreateBaseQueryOptions",
|
|
332
|
+
resultType: "CreateQueryResult"
|
|
333
|
+
},
|
|
334
|
+
svelte: {
|
|
335
|
+
path: "@tanstack/svelte-query",
|
|
336
|
+
hookName: "createQuery",
|
|
337
|
+
optionsType: "CreateBaseQueryOptions",
|
|
338
|
+
resultType: "CreateQueryResult"
|
|
339
|
+
},
|
|
340
|
+
vue: {
|
|
341
|
+
path: "@tanstack/vue-query",
|
|
342
|
+
hookName: "useQuery",
|
|
343
|
+
optionsType: isV5 ? "QueryObserverOptions" : "VueQueryObserverOptions",
|
|
344
|
+
resultType: isV5 ? "UseQueryReturnType" : "UseQueryReturnType"
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
queryInfinite: {
|
|
348
|
+
react: {
|
|
349
|
+
path: "@tanstack/react-query",
|
|
350
|
+
hookName: "useInfiniteQuery",
|
|
351
|
+
optionsType: isV5 ? "InfiniteQueryObserverOptions" : "UseInfiniteQueryOptions",
|
|
352
|
+
resultType: "UseInfiniteQueryResult"
|
|
353
|
+
},
|
|
354
|
+
solid: {
|
|
355
|
+
path: "@tanstack/solid-query",
|
|
356
|
+
hookName: "createInfiniteQuery",
|
|
357
|
+
optionsType: "CreateInfiniteQueryOptions",
|
|
358
|
+
resultType: "CreateInfiniteQueryResult"
|
|
359
|
+
},
|
|
360
|
+
svelte: {
|
|
361
|
+
path: "@tanstack/svelte-query",
|
|
362
|
+
hookName: "createInfiniteQuery",
|
|
363
|
+
optionsType: "CreateInfiniteQueryOptions",
|
|
364
|
+
resultType: "CreateInfiniteQueryResult"
|
|
365
|
+
},
|
|
366
|
+
vue: {
|
|
367
|
+
path: "@tanstack/vue-query",
|
|
368
|
+
hookName: "useInfiniteQuery",
|
|
369
|
+
optionsType: isV5 ? "UseInfiniteQueryOptions" : "VueInfiniteQueryObserverOptions",
|
|
370
|
+
resultType: isV5 ? "UseInfiniteQueryReturnType" : "VueInfiniteQueryObserverOptions"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
querySuspense: {
|
|
374
|
+
react: {
|
|
375
|
+
path: "@tanstack/react-query",
|
|
376
|
+
hookName: "useSuspenseQuery",
|
|
377
|
+
optionsType: "UseSuspenseQueryOptions",
|
|
378
|
+
resultType: "UseSuspenseQueryResult"
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function Template2({ path, hookPath = path, isInfinite, hookName, queryOptions, optionsType, resultType }) {
|
|
384
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
385
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [optionsType, resultType], path, isTypeOnly: true }),
|
|
386
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [hookName], path: hookPath }),
|
|
387
|
+
queryOptions && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [queryOptions].filter(Boolean), path }),
|
|
388
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["QueryKey", isInfinite ? "InfiniteData" : void 0].filter(Boolean), path, isTypeOnly: true })
|
|
389
|
+
] });
|
|
390
|
+
}
|
|
391
|
+
var defaultTemplates2 = {
|
|
392
|
+
get react() {
|
|
393
|
+
return function({ context, hookPath, ...rest }) {
|
|
394
|
+
const importNames = getImportNames();
|
|
395
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
396
|
+
const { isInfinite, isSuspense } = context;
|
|
397
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
398
|
+
Template2,
|
|
399
|
+
{
|
|
400
|
+
isInfinite,
|
|
401
|
+
...isSuspense ? importNames.querySuspense.react : isInfinite ? importNames.queryInfinite.react : importNames.query.react,
|
|
402
|
+
queryOptions: isV5 ? isInfinite ? "infiniteQueryOptions" : "queryOptions" : void 0,
|
|
403
|
+
hookPath,
|
|
404
|
+
...rest
|
|
405
|
+
}
|
|
406
|
+
);
|
|
407
|
+
};
|
|
408
|
+
},
|
|
409
|
+
get solid() {
|
|
410
|
+
return function({ context, hookPath, ...rest }) {
|
|
411
|
+
const importNames = getImportNames();
|
|
412
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
413
|
+
const { isInfinite } = context;
|
|
414
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
415
|
+
Template2,
|
|
416
|
+
{
|
|
417
|
+
isInfinite,
|
|
418
|
+
...isInfinite ? importNames.queryInfinite.solid : importNames.query.solid,
|
|
419
|
+
queryOptions: isV5 ? isInfinite ? "infiniteQueryOptions" : "queryOptions" : void 0,
|
|
420
|
+
hookPath,
|
|
421
|
+
...rest
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
};
|
|
425
|
+
},
|
|
426
|
+
get svelte() {
|
|
427
|
+
return function({ context, hookPath, ...rest }) {
|
|
428
|
+
const importNames = getImportNames();
|
|
429
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
430
|
+
const { isInfinite } = context;
|
|
431
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
432
|
+
Template2,
|
|
433
|
+
{
|
|
434
|
+
isInfinite,
|
|
435
|
+
...isInfinite ? importNames.queryInfinite.svelte : importNames.query.svelte,
|
|
436
|
+
queryOptions: isV5 ? isInfinite ? "infiniteQueryOptions" : "queryOptions" : void 0,
|
|
437
|
+
hookPath,
|
|
438
|
+
...rest
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
};
|
|
442
|
+
},
|
|
443
|
+
get vue() {
|
|
444
|
+
return function({ context, hookPath, ...rest }) {
|
|
445
|
+
const importNames = getImportNames();
|
|
446
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
447
|
+
const { isInfinite } = context;
|
|
448
|
+
const path = "@tanstack/vue-query";
|
|
449
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
450
|
+
isV5 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
451
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
452
|
+
Template2,
|
|
453
|
+
{
|
|
454
|
+
isInfinite,
|
|
455
|
+
...isInfinite ? importNames.queryInfinite.vue : importNames.query.vue,
|
|
456
|
+
queryOptions: isInfinite ? "infiniteQueryOptions" : "queryOptions",
|
|
457
|
+
hookPath,
|
|
458
|
+
...rest
|
|
459
|
+
}
|
|
460
|
+
),
|
|
461
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["QueryObserverOptions"], path, isTypeOnly: true })
|
|
462
|
+
] }),
|
|
463
|
+
!isV5 && isInfinite && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
464
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [importNames.queryInfinite.vue.resultType], path, isTypeOnly: true }),
|
|
465
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [importNames.queryInfinite.vue.optionsType], path: "@tanstack/vue-query/build/lib/types", isTypeOnly: true }),
|
|
466
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [importNames.queryInfinite.vue.hookName], path })
|
|
467
|
+
] }),
|
|
468
|
+
!isV5 && !isInfinite && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
469
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [importNames.query.vue.resultType], path, isTypeOnly: true }),
|
|
470
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [importNames.query.vue.optionsType], path: "@tanstack/vue-query/build/lib/types", isTypeOnly: true }),
|
|
471
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [importNames.query.vue.hookName], path })
|
|
472
|
+
] }),
|
|
473
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["unref"], path: "vue" }),
|
|
474
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["MaybeRef"], path: "vue", isTypeOnly: true }),
|
|
475
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["QueryKey"], path, isTypeOnly: true })
|
|
476
|
+
] });
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
function QueryImports({ hookPath, isInfinite, isSuspense, Template: Template6 = defaultTemplates2.react }) {
|
|
481
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
482
|
+
Template6,
|
|
483
|
+
{
|
|
484
|
+
hookPath,
|
|
485
|
+
context: {
|
|
486
|
+
isInfinite,
|
|
487
|
+
isSuspense
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
QueryImports.templates = defaultTemplates2;
|
|
493
|
+
function Template3({ name, typeName, params, generics, returnType, JSDoc, keys }) {
|
|
494
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
495
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function.Arrow, { name, export: true, generics, params, returnType, singleLine: true, JSDoc, children: `[${keys}] as const` }) }),
|
|
496
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: typeName, export: true, children: `ReturnType<typeof ${name}>` }) })
|
|
497
|
+
] });
|
|
498
|
+
}
|
|
499
|
+
var defaultTemplates3 = {
|
|
500
|
+
get react() {
|
|
501
|
+
return function(props) {
|
|
502
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { ...props });
|
|
503
|
+
};
|
|
504
|
+
},
|
|
505
|
+
get solid() {
|
|
506
|
+
return function(props) {
|
|
507
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { ...props });
|
|
508
|
+
};
|
|
509
|
+
},
|
|
510
|
+
get svelte() {
|
|
511
|
+
return function(props) {
|
|
512
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { ...props });
|
|
513
|
+
};
|
|
514
|
+
},
|
|
515
|
+
get vue() {
|
|
516
|
+
return function({ context, ...rest }) {
|
|
517
|
+
const { factory } = context;
|
|
518
|
+
const {
|
|
519
|
+
plugin: {
|
|
520
|
+
options: { pathParamsType, query }
|
|
521
|
+
}
|
|
522
|
+
} = react.useApp();
|
|
523
|
+
const { getSchemas } = hooks.useOperationManager();
|
|
524
|
+
const operation = hooks.useOperation();
|
|
525
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
526
|
+
const path = new utils.URLPath(operation.path);
|
|
527
|
+
const params = new utils.FunctionParams();
|
|
528
|
+
const withQueryParams = !!schemas.queryParams?.name;
|
|
529
|
+
const withRequest = !!schemas.request?.name;
|
|
530
|
+
params.add([
|
|
531
|
+
...pathParamsType === "object" ? [
|
|
532
|
+
utils$1.getASTParams(schemas.pathParams, {
|
|
533
|
+
typed: true,
|
|
534
|
+
override: (item) => ({
|
|
535
|
+
...item,
|
|
536
|
+
type: `MaybeRef<${item.type}>`
|
|
537
|
+
})
|
|
538
|
+
})
|
|
539
|
+
] : utils$1.getASTParams(schemas.pathParams, {
|
|
540
|
+
typed: true,
|
|
541
|
+
override: (item) => ({
|
|
542
|
+
...item,
|
|
543
|
+
type: `MaybeRef<${item.type}>`
|
|
544
|
+
})
|
|
545
|
+
}),
|
|
546
|
+
{
|
|
547
|
+
name: "params",
|
|
548
|
+
type: `MaybeRef<${`${factory.name}["queryParams"]`}>`,
|
|
549
|
+
enabled: withQueryParams,
|
|
550
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
name: "request",
|
|
554
|
+
type: `MaybeRef<${`${factory.name}["request"]`}>`,
|
|
555
|
+
enabled: withRequest,
|
|
556
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
557
|
+
}
|
|
558
|
+
]);
|
|
559
|
+
const keys = [
|
|
560
|
+
path.toObject({
|
|
561
|
+
type: "path",
|
|
562
|
+
stringify: true,
|
|
563
|
+
replacer: (pathParam) => `unref(${pathParam})`
|
|
564
|
+
}),
|
|
565
|
+
withQueryParams ? "...(params ? [params] : [])" : void 0,
|
|
566
|
+
withRequest ? "...(request ? [request] : [])" : void 0
|
|
567
|
+
].filter(Boolean);
|
|
568
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { ...rest, params: params.toString(), keys: keys.join(", ") });
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
function QueryKey({ name, typeName, factory, keysFn, Template: Template6 = defaultTemplates3.react }) {
|
|
573
|
+
const {
|
|
574
|
+
plugin: {
|
|
575
|
+
options: { pathParamsType }
|
|
576
|
+
}
|
|
577
|
+
} = react.useApp();
|
|
578
|
+
const { getSchemas } = hooks.useOperationManager();
|
|
579
|
+
const operation = hooks.useOperation();
|
|
580
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
581
|
+
const path = new utils.URLPath(operation.path);
|
|
582
|
+
const params = new utils.FunctionParams();
|
|
583
|
+
const withQueryParams = !!schemas.queryParams?.name;
|
|
584
|
+
const withRequest = !!schemas.request?.name;
|
|
585
|
+
params.add([
|
|
586
|
+
...pathParamsType === "object" ? [utils$1.getASTParams(schemas.pathParams, { typed: true })] : utils$1.getASTParams(schemas.pathParams, { typed: true }),
|
|
587
|
+
{
|
|
588
|
+
name: "params",
|
|
589
|
+
type: `${factory.name}["queryParams"]`,
|
|
590
|
+
enabled: withQueryParams,
|
|
591
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
name: "data",
|
|
595
|
+
type: `${factory.name}["request"]`,
|
|
596
|
+
enabled: withRequest,
|
|
597
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
598
|
+
}
|
|
599
|
+
]);
|
|
600
|
+
const keys = [
|
|
601
|
+
path.toObject({
|
|
602
|
+
type: "path",
|
|
603
|
+
stringify: true
|
|
604
|
+
}),
|
|
605
|
+
withQueryParams ? "...(params ? [params] : [])" : void 0,
|
|
606
|
+
withRequest ? "...(data ? [data] : [])" : void 0
|
|
607
|
+
].filter(Boolean);
|
|
608
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template6, { typeName, name, params: params.toString(), keys: keysFn(keys).join(", "), context: { factory } });
|
|
609
|
+
}
|
|
610
|
+
QueryKey.templates = defaultTemplates3;
|
|
611
|
+
function Template4({ name, params, JSDoc, hook, client, infinite, dataReturnType, parser }) {
|
|
612
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
613
|
+
const isFormData = client.contentType === "multipart/form-data";
|
|
614
|
+
const headers = [
|
|
615
|
+
client.contentType !== "application/json" ? `'Content-Type': '${client.contentType}'` : void 0,
|
|
616
|
+
client.withHeaders ? "...headers" : void 0
|
|
617
|
+
].filter(Boolean).join(", ");
|
|
618
|
+
const clientOptions = [
|
|
619
|
+
`method: "${client.method}"`,
|
|
620
|
+
`url: ${client.path.template}`,
|
|
621
|
+
client.withQueryParams && !infinite ? "params" : void 0,
|
|
622
|
+
client.withData && !isFormData ? "data" : void 0,
|
|
623
|
+
client.withData && isFormData ? "data: formData" : void 0,
|
|
624
|
+
headers.length ? `headers: { ${headers}, ...options.headers }` : void 0,
|
|
625
|
+
"...options",
|
|
626
|
+
client.withQueryParams && !!infinite ? `params: {
|
|
627
|
+
...params,
|
|
628
|
+
['${infinite.queryParam}']: pageParam,
|
|
629
|
+
...(options.params || {}),
|
|
630
|
+
}` : void 0
|
|
631
|
+
].filter(Boolean);
|
|
632
|
+
const queryOptions = [
|
|
633
|
+
isV5 && !!infinite ? `initialPageParam: ${infinite.initialPageParam}` : void 0,
|
|
634
|
+
isV5 && !!infinite && !!infinite.cursorParam ? `getNextPageParam: (lastPage) => lastPage['${infinite.cursorParam}']` : void 0,
|
|
635
|
+
isV5 && !!infinite && !!infinite.cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${infinite.cursorParam}']` : void 0,
|
|
636
|
+
isV5 && !!infinite && !infinite.cursorParam && dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : void 0,
|
|
637
|
+
isV5 && !!infinite && !infinite.cursorParam && dataReturnType === "data" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1" : void 0,
|
|
638
|
+
isV5 && !!infinite && !infinite.cursorParam ? "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1" : void 0
|
|
639
|
+
].filter(Boolean);
|
|
640
|
+
const resolvedClientOptions = `${transformers2__default.default.createIndent(4)}${clientOptions.join(`,
|
|
641
|
+
${transformers2__default.default.createIndent(4)}`)}`;
|
|
642
|
+
const resolvedQueryOptions = `${transformers2__default.default.createIndent(4)}${queryOptions.join(`,
|
|
643
|
+
${transformers2__default.default.createIndent(4)}`)}`;
|
|
644
|
+
let returnRes = parser ? `return ${parser}(res.data)` : "return res.data";
|
|
645
|
+
if (dataReturnType === "full") {
|
|
646
|
+
returnRes = parser ? `return {...res, data: ${parser}(res.data)}` : "return res";
|
|
647
|
+
}
|
|
648
|
+
const formData = isFormData ? `
|
|
649
|
+
const formData = new FormData()
|
|
650
|
+
if(data) {
|
|
651
|
+
Object.keys(data).forEach((key) => {
|
|
652
|
+
const value = data[key];
|
|
653
|
+
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
654
|
+
formData.append(key, value);
|
|
655
|
+
}
|
|
656
|
+
})
|
|
657
|
+
}
|
|
658
|
+
` : void 0;
|
|
659
|
+
if (infinite) {
|
|
660
|
+
if (isV5) {
|
|
661
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params, JSDoc, children: `
|
|
662
|
+
const queryKey = ${hook.queryKey}
|
|
663
|
+
|
|
664
|
+
return infiniteQueryOptions({
|
|
665
|
+
queryKey,
|
|
666
|
+
queryFn: async ({ pageParam }) => {
|
|
667
|
+
${hook.children || ""}
|
|
668
|
+
${formData || ""}
|
|
669
|
+
const res = await client<${client.generics}>({
|
|
670
|
+
${resolvedClientOptions}
|
|
671
|
+
})
|
|
672
|
+
|
|
673
|
+
${returnRes}
|
|
674
|
+
},
|
|
675
|
+
${resolvedQueryOptions}
|
|
676
|
+
})
|
|
677
|
+
|
|
678
|
+
` }) });
|
|
679
|
+
}
|
|
680
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params, JSDoc, children: `
|
|
681
|
+
const queryKey = ${hook.queryKey}
|
|
682
|
+
|
|
683
|
+
return {
|
|
684
|
+
queryKey,
|
|
685
|
+
queryFn: async ({ pageParam }) => {
|
|
686
|
+
${hook.children || ""}
|
|
687
|
+
${formData || ""}
|
|
688
|
+
const res = await client<${client.generics}>({
|
|
689
|
+
${resolvedClientOptions}
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
${returnRes}
|
|
693
|
+
},
|
|
694
|
+
${resolvedQueryOptions}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
` }) });
|
|
698
|
+
}
|
|
699
|
+
if (isV5) {
|
|
700
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params, JSDoc, children: `
|
|
701
|
+
const queryKey = ${hook.queryKey}
|
|
702
|
+
|
|
703
|
+
return queryOptions({
|
|
704
|
+
queryKey,
|
|
705
|
+
queryFn: async () => {
|
|
706
|
+
${hook.children || ""}
|
|
707
|
+
${formData || ""}
|
|
708
|
+
const res = await client<${client.generics}>({
|
|
709
|
+
${resolvedClientOptions}
|
|
710
|
+
})
|
|
711
|
+
|
|
712
|
+
${returnRes}
|
|
713
|
+
},
|
|
714
|
+
${resolvedQueryOptions}
|
|
715
|
+
})
|
|
716
|
+
|
|
717
|
+
` }) });
|
|
718
|
+
}
|
|
719
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params, JSDoc, children: `
|
|
720
|
+
const queryKey = ${hook.queryKey}
|
|
721
|
+
|
|
722
|
+
return {
|
|
723
|
+
queryKey,
|
|
724
|
+
queryFn: async () => {
|
|
725
|
+
${hook.children || ""}
|
|
726
|
+
${formData || ""}
|
|
727
|
+
const res = await client<${client.generics}>({
|
|
728
|
+
${resolvedClientOptions}
|
|
729
|
+
})
|
|
730
|
+
|
|
731
|
+
${returnRes}
|
|
732
|
+
},
|
|
733
|
+
${resolvedQueryOptions}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
` }) });
|
|
737
|
+
}
|
|
738
|
+
var defaultTemplates4 = {
|
|
739
|
+
get react() {
|
|
740
|
+
return function(props) {
|
|
741
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template4, { ...props });
|
|
742
|
+
};
|
|
743
|
+
},
|
|
744
|
+
get solid() {
|
|
745
|
+
return function(props) {
|
|
746
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template4, { ...props });
|
|
747
|
+
};
|
|
748
|
+
},
|
|
749
|
+
get svelte() {
|
|
750
|
+
return function(props) {
|
|
751
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template4, { ...props });
|
|
752
|
+
};
|
|
753
|
+
},
|
|
754
|
+
get vue() {
|
|
755
|
+
return function({ client, context, ...rest }) {
|
|
756
|
+
const { factory, queryKey } = context;
|
|
757
|
+
const {
|
|
758
|
+
plugin: {
|
|
759
|
+
options: { pathParamsType }
|
|
760
|
+
}
|
|
761
|
+
} = react.useApp();
|
|
762
|
+
const { getSchemas } = hooks.useOperationManager();
|
|
763
|
+
const operation = hooks.useOperation();
|
|
764
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
765
|
+
const params = new utils.FunctionParams();
|
|
766
|
+
const queryKeyParams = new utils.FunctionParams();
|
|
767
|
+
params.add([
|
|
768
|
+
...pathParamsType === "object" ? [
|
|
769
|
+
utils$1.getASTParams(schemas.pathParams, {
|
|
770
|
+
typed: true,
|
|
771
|
+
override: (item) => ({
|
|
772
|
+
...item,
|
|
773
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0,
|
|
774
|
+
type: `MaybeRef<${item.type}>`
|
|
775
|
+
})
|
|
776
|
+
})
|
|
777
|
+
] : utils$1.getASTParams(schemas.pathParams, {
|
|
778
|
+
typed: true,
|
|
779
|
+
override: (item) => ({
|
|
780
|
+
...item,
|
|
781
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0,
|
|
782
|
+
type: `MaybeRef<${item.type}>`
|
|
783
|
+
})
|
|
784
|
+
}),
|
|
785
|
+
{
|
|
786
|
+
name: "refParams",
|
|
787
|
+
type: `MaybeRef<${schemas.queryParams?.name}>`,
|
|
788
|
+
enabled: client.withQueryParams,
|
|
789
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
name: "refHeaders",
|
|
793
|
+
type: `MaybeRef<${schemas.headerParams?.name}>`,
|
|
794
|
+
enabled: client.withHeaders,
|
|
795
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
name: "refData",
|
|
799
|
+
type: `MaybeRef<${schemas.request?.name}>`,
|
|
800
|
+
enabled: client.withData,
|
|
801
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
name: "options",
|
|
805
|
+
type: `${factory.name}['client']['parameters']`,
|
|
806
|
+
default: "{}"
|
|
807
|
+
}
|
|
808
|
+
]);
|
|
809
|
+
queryKeyParams.add([
|
|
810
|
+
...pathParamsType === "object" ? [
|
|
811
|
+
utils$1.getASTParams(schemas.pathParams, {
|
|
812
|
+
override: (item) => ({
|
|
813
|
+
...item,
|
|
814
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0
|
|
815
|
+
})
|
|
816
|
+
})
|
|
817
|
+
] : utils$1.getASTParams(schemas.pathParams, {
|
|
818
|
+
override: (item) => ({
|
|
819
|
+
...item,
|
|
820
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0
|
|
821
|
+
})
|
|
822
|
+
}),
|
|
823
|
+
{
|
|
824
|
+
name: "refParams",
|
|
825
|
+
enabled: client.withQueryParams,
|
|
826
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
name: "refData",
|
|
830
|
+
enabled: client.withData,
|
|
831
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
832
|
+
}
|
|
833
|
+
]);
|
|
834
|
+
const unrefs = params.items.filter((item) => item.enabled).map((item) => {
|
|
835
|
+
return item.name ? `const ${transformers2__default.default.camelCase(item.name.replace("ref", ""))} = unref(${item.name})` : void 0;
|
|
836
|
+
}).join("\n");
|
|
837
|
+
const hook = {
|
|
838
|
+
queryKey: `${queryKey}(${queryKeyParams.toString()})`,
|
|
839
|
+
children: unrefs
|
|
840
|
+
};
|
|
841
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template4, { ...rest, params: params.toString(), hook, client });
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
function QueryOptions({ factory, infinite, suspense, resultType, dataReturnType, Template: Template6 = defaultTemplates4.react }) {
|
|
846
|
+
const {
|
|
847
|
+
pluginManager,
|
|
848
|
+
plugin: {
|
|
849
|
+
key: pluginKey,
|
|
850
|
+
options: { parser, pathParamsType, queryOptions }
|
|
851
|
+
}
|
|
852
|
+
} = react.useApp();
|
|
853
|
+
const { getSchemas } = hooks.useOperationManager();
|
|
854
|
+
const operation = hooks.useOperation();
|
|
855
|
+
const contentType = operation.getContentType();
|
|
856
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
857
|
+
const zodSchemas = getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" });
|
|
858
|
+
const queryKey = pluginManager.resolveName({
|
|
859
|
+
name: [factory.name, infinite ? "Infinite" : void 0, suspense ? "Suspense" : void 0, "QueryKey"].filter(Boolean).join(""),
|
|
860
|
+
pluginKey
|
|
861
|
+
});
|
|
862
|
+
const queryOptionsName = pluginManager.resolveName({
|
|
863
|
+
name: [factory.name, infinite ? "Infinite" : void 0, suspense ? "Suspense" : void 0, "QueryOptions"].filter(Boolean).join(""),
|
|
864
|
+
pluginKey
|
|
865
|
+
});
|
|
866
|
+
const generics = new utils.FunctionParams();
|
|
867
|
+
const params = new utils.FunctionParams();
|
|
868
|
+
const queryKeyParams = new utils.FunctionParams();
|
|
869
|
+
const clientGenerics = [`${factory.name}['data']`, `${factory.name}['error']`];
|
|
870
|
+
suspense ? [`${factory.name}['response']`, `${factory.name}["error"]`, "TData"] : [`${factory.name}['response']`, `${factory.name}["error"]`, "TData", "TQueryData"];
|
|
871
|
+
const client = {
|
|
872
|
+
withQueryParams: !!schemas.queryParams?.name,
|
|
873
|
+
withData: !!schemas.request?.name,
|
|
874
|
+
withPathParams: !!schemas.pathParams?.name,
|
|
875
|
+
withHeaders: !!schemas.headerParams?.name,
|
|
876
|
+
method: operation.method,
|
|
877
|
+
path: new utils.URLPath(operation.path),
|
|
878
|
+
generics: clientGenerics.toString(),
|
|
879
|
+
contentType
|
|
880
|
+
};
|
|
881
|
+
generics.add([
|
|
882
|
+
{ type: "TData", default: `${factory.name}["response"]` },
|
|
883
|
+
suspense ? void 0 : { type: "TQueryData", default: `${factory.name}["response"]` }
|
|
884
|
+
]);
|
|
885
|
+
params.add([
|
|
886
|
+
...pathParamsType === "object" ? [utils$1.getASTParams(schemas.pathParams, { typed: true })] : utils$1.getASTParams(schemas.pathParams, { typed: true }),
|
|
887
|
+
{
|
|
888
|
+
name: "params",
|
|
889
|
+
type: `${factory.name}['queryParams']`,
|
|
890
|
+
enabled: client.withQueryParams,
|
|
891
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
name: "headers",
|
|
895
|
+
type: `${factory.name}['headerParams']`,
|
|
896
|
+
enabled: client.withHeaders,
|
|
897
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
name: "data",
|
|
901
|
+
type: `${factory.name}['request']`,
|
|
902
|
+
enabled: client.withData,
|
|
903
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
name: "options",
|
|
907
|
+
type: `${factory.name}['client']['parameters']`,
|
|
908
|
+
default: "{}"
|
|
909
|
+
}
|
|
910
|
+
]);
|
|
911
|
+
queryKeyParams.add([
|
|
912
|
+
...pathParamsType === "object" ? [utils$1.getASTParams(schemas.pathParams)] : utils$1.getASTParams(schemas.pathParams),
|
|
913
|
+
{
|
|
914
|
+
name: "params",
|
|
915
|
+
enabled: client.withQueryParams,
|
|
916
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
917
|
+
},
|
|
918
|
+
{
|
|
919
|
+
name: "data",
|
|
920
|
+
enabled: client.withData,
|
|
921
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
922
|
+
}
|
|
923
|
+
]);
|
|
924
|
+
const hook = {
|
|
925
|
+
queryKey: `${queryKey}(${queryKeyParams.toString()})`
|
|
926
|
+
};
|
|
927
|
+
if (!queryOptions) {
|
|
928
|
+
return null;
|
|
929
|
+
}
|
|
930
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
931
|
+
Template6,
|
|
932
|
+
{
|
|
933
|
+
name: queryOptionsName,
|
|
934
|
+
params: params.toString(),
|
|
935
|
+
client,
|
|
936
|
+
hook,
|
|
937
|
+
infinite,
|
|
938
|
+
dataReturnType,
|
|
939
|
+
parser: parser === "zod" ? `${zodSchemas.response.name}.parse` : void 0,
|
|
940
|
+
context: {
|
|
941
|
+
factory,
|
|
942
|
+
queryKey
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
QueryOptions.templates = defaultTemplates4;
|
|
948
|
+
function Template5({ name, generics, returnType, params, JSDoc, hook, infinite }) {
|
|
949
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
950
|
+
const resolvedReturnType = `${returnType} & { queryKey: TQueryKey }`;
|
|
951
|
+
if (isV5) {
|
|
952
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, generics, returnType: resolvedReturnType, params, JSDoc, children: `
|
|
953
|
+
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
|
|
954
|
+
const queryKey = queryOptions?.queryKey ?? ${hook.queryKey}
|
|
955
|
+
|
|
956
|
+
const query = ${hook.name}({
|
|
957
|
+
...${hook.queryOptions} as unknown as ${infinite ? "InfiniteQueryObserverOptions" : "QueryObserverOptions"},
|
|
958
|
+
queryKey,
|
|
959
|
+
...queryOptions as unknown as ${infinite ? 'Omit<InfiniteQueryObserverOptions, "queryKey">' : 'Omit<QueryObserverOptions, "queryKey">'}
|
|
960
|
+
}) as ${resolvedReturnType}
|
|
961
|
+
|
|
962
|
+
query.queryKey = queryKey as TQueryKey
|
|
963
|
+
|
|
964
|
+
return query
|
|
965
|
+
|
|
966
|
+
` }) });
|
|
967
|
+
}
|
|
968
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, generics, returnType: resolvedReturnType, params, JSDoc, children: `
|
|
969
|
+
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
|
|
970
|
+
const queryKey = queryOptions?.queryKey ?? ${hook.queryKey}
|
|
971
|
+
|
|
972
|
+
const query = ${hook.name}<${hook.generics}>({
|
|
973
|
+
...${hook.queryOptions},
|
|
974
|
+
queryKey,
|
|
975
|
+
...queryOptions
|
|
976
|
+
}) as ${resolvedReturnType}
|
|
977
|
+
|
|
978
|
+
query.queryKey = queryKey as TQueryKey
|
|
979
|
+
|
|
980
|
+
return query
|
|
981
|
+
|
|
982
|
+
` }) });
|
|
983
|
+
}
|
|
984
|
+
var defaultTemplates5 = {
|
|
985
|
+
get react() {
|
|
986
|
+
return function(props) {
|
|
987
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template5, { ...props });
|
|
988
|
+
};
|
|
989
|
+
},
|
|
990
|
+
get solid() {
|
|
991
|
+
return function(props) {
|
|
992
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template5, { ...props });
|
|
993
|
+
};
|
|
994
|
+
},
|
|
995
|
+
get svelte() {
|
|
996
|
+
return function(props) {
|
|
997
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template5, { ...props });
|
|
998
|
+
};
|
|
999
|
+
},
|
|
1000
|
+
get vue() {
|
|
1001
|
+
return function({ context, hook, ...rest }) {
|
|
1002
|
+
const { factory, queryKey } = context;
|
|
1003
|
+
const {
|
|
1004
|
+
pluginManager,
|
|
1005
|
+
plugin: {
|
|
1006
|
+
key: pluginKey,
|
|
1007
|
+
options: { pathParamsType }
|
|
1008
|
+
}
|
|
1009
|
+
} = react.useApp();
|
|
1010
|
+
const operation = hooks.useOperation();
|
|
1011
|
+
const { getSchemas } = hooks.useOperationManager();
|
|
1012
|
+
const importNames = getImportNames();
|
|
1013
|
+
const queryOptions = pluginManager.resolveName({
|
|
1014
|
+
name: `${factory.name}QueryOptions`,
|
|
1015
|
+
pluginKey
|
|
1016
|
+
});
|
|
1017
|
+
const hookName = rest.infinite ? importNames.queryInfinite.vue.hookName : importNames.query.vue.hookName;
|
|
1018
|
+
const resultType = rest.infinite ? importNames.queryInfinite.vue.resultType : importNames.query.vue.resultType;
|
|
1019
|
+
const optionsType = rest.infinite ? importNames.queryInfinite.vue.optionsType : importNames.query.vue.optionsType;
|
|
1020
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
1021
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
1022
|
+
const params = new utils.FunctionParams();
|
|
1023
|
+
const queryParams = new utils.FunctionParams();
|
|
1024
|
+
const queryKeyParams = new utils.FunctionParams();
|
|
1025
|
+
const client = {
|
|
1026
|
+
withQueryParams: !!schemas.queryParams?.name,
|
|
1027
|
+
withData: !!schemas.request?.name,
|
|
1028
|
+
withPathParams: !!schemas.pathParams?.name,
|
|
1029
|
+
withHeaders: !!schemas.headerParams?.name
|
|
1030
|
+
};
|
|
1031
|
+
const resultGenerics = ["TData", `${factory.name}['error']`];
|
|
1032
|
+
const queryOptionsOverrideGenerics = [`${factory.name}['response']`, `${factory.name}['error']`, "TData", "TQueryKey"];
|
|
1033
|
+
const queryOptionsGenerics = ["TData", "TQueryData"];
|
|
1034
|
+
params.add([
|
|
1035
|
+
...pathParamsType === "object" ? [
|
|
1036
|
+
utils$1.getASTParams(schemas.pathParams, {
|
|
1037
|
+
typed: true,
|
|
1038
|
+
override: (item) => ({
|
|
1039
|
+
...item,
|
|
1040
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0
|
|
1041
|
+
})
|
|
1042
|
+
})
|
|
1043
|
+
] : utils$1.getASTParams(schemas.pathParams, {
|
|
1044
|
+
typed: true,
|
|
1045
|
+
override: (item) => ({
|
|
1046
|
+
...item,
|
|
1047
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0
|
|
1048
|
+
})
|
|
1049
|
+
}),
|
|
1050
|
+
{
|
|
1051
|
+
name: "refParams",
|
|
1052
|
+
type: `MaybeRef<${schemas.queryParams?.name}>`,
|
|
1053
|
+
enabled: client.withQueryParams,
|
|
1054
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
name: "refHeaders",
|
|
1058
|
+
type: `MaybeRef<${schemas.headerParams?.name}>`,
|
|
1059
|
+
enabled: client.withHeaders,
|
|
1060
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
name: "refData",
|
|
1064
|
+
type: `MaybeRef<${schemas.request?.name}>`,
|
|
1065
|
+
enabled: client.withData,
|
|
1066
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
name: "options",
|
|
1070
|
+
type: `{
|
|
1071
|
+
query?: Partial<${optionsType}<${queryOptionsOverrideGenerics.join(", ")}>>,
|
|
1072
|
+
client?: ${factory.name}['client']['parameters']
|
|
1073
|
+
}`,
|
|
1074
|
+
default: "{}"
|
|
1075
|
+
}
|
|
1076
|
+
]);
|
|
1077
|
+
queryParams.add([
|
|
1078
|
+
...utils$1.getASTParams(schemas.pathParams, {
|
|
1079
|
+
typed: false,
|
|
1080
|
+
override: (item) => ({
|
|
1081
|
+
...item,
|
|
1082
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0
|
|
1083
|
+
})
|
|
1084
|
+
}),
|
|
1085
|
+
{
|
|
1086
|
+
name: "refParams",
|
|
1087
|
+
enabled: client.withQueryParams,
|
|
1088
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
name: "refHeaders",
|
|
1092
|
+
enabled: client.withHeaders,
|
|
1093
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
name: "clientOptions",
|
|
1097
|
+
required: false
|
|
1098
|
+
}
|
|
1099
|
+
]);
|
|
1100
|
+
queryKeyParams.add([
|
|
1101
|
+
...pathParamsType === "object" ? [
|
|
1102
|
+
utils$1.getASTParams(schemas.pathParams, {
|
|
1103
|
+
override: (item) => ({
|
|
1104
|
+
...item,
|
|
1105
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0
|
|
1106
|
+
})
|
|
1107
|
+
})
|
|
1108
|
+
] : utils$1.getASTParams(schemas.pathParams, {
|
|
1109
|
+
override: (item) => ({
|
|
1110
|
+
...item,
|
|
1111
|
+
name: item.name ? `ref${transformers2__default.default.pascalCase(item.name)}` : void 0
|
|
1112
|
+
})
|
|
1113
|
+
}),
|
|
1114
|
+
{
|
|
1115
|
+
name: "refParams",
|
|
1116
|
+
enabled: client.withQueryParams,
|
|
1117
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
name: "refData",
|
|
1121
|
+
enabled: client.withData,
|
|
1122
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
1123
|
+
}
|
|
1124
|
+
]);
|
|
1125
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1126
|
+
Template5,
|
|
1127
|
+
{
|
|
1128
|
+
...rest,
|
|
1129
|
+
params: params.toString(),
|
|
1130
|
+
returnType: `${resultType}<${resultGenerics.join(", ")}>`,
|
|
1131
|
+
hook: {
|
|
1132
|
+
...hook,
|
|
1133
|
+
name: hookName,
|
|
1134
|
+
queryOptions: isV5 ? `${queryOptions}(${queryParams.toString()})` : `${queryOptions}<${queryOptionsGenerics.join(", ")}>(${queryParams.toString()})`,
|
|
1135
|
+
queryKey: `${queryKey}(${queryKeyParams.toString()})`
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
);
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
function Query({
|
|
1143
|
+
factory,
|
|
1144
|
+
optionsType,
|
|
1145
|
+
hookName,
|
|
1146
|
+
resultType,
|
|
1147
|
+
Template: Template6 = defaultTemplates5.react,
|
|
1148
|
+
QueryKeyTemplate = QueryKey.templates.react,
|
|
1149
|
+
QueryOptionsTemplate = QueryOptions.templates.react,
|
|
1150
|
+
...props
|
|
1151
|
+
}) {
|
|
1152
|
+
const {
|
|
1153
|
+
pluginManager,
|
|
1154
|
+
plugin: {
|
|
1155
|
+
key: pluginKey,
|
|
1156
|
+
options: { dataReturnType, pathParamsType }
|
|
1157
|
+
}
|
|
1158
|
+
} = react.useApp();
|
|
1159
|
+
const operation = hooks.useOperation();
|
|
1160
|
+
const { getSchemas, getName } = hooks.useOperationManager();
|
|
1161
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
1162
|
+
const name = getName(operation, { type: "function" });
|
|
1163
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
1164
|
+
const queryKey = pluginManager.resolveName({
|
|
1165
|
+
name: [factory.name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0, "QueryKey"].filter(Boolean).join(""),
|
|
1166
|
+
pluginKey
|
|
1167
|
+
});
|
|
1168
|
+
const queryKeyType = pluginManager.resolveName({
|
|
1169
|
+
name: [factory.name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0, "QueryKey"].filter(Boolean).join(""),
|
|
1170
|
+
type: "type",
|
|
1171
|
+
pluginKey
|
|
1172
|
+
});
|
|
1173
|
+
const queryOptions = pluginManager.resolveName({
|
|
1174
|
+
name: [factory.name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0, "QueryOptions"].filter(Boolean).join(""),
|
|
1175
|
+
pluginKey
|
|
1176
|
+
});
|
|
1177
|
+
const generics = new utils.FunctionParams();
|
|
1178
|
+
const params = new utils.FunctionParams();
|
|
1179
|
+
const queryParams = new utils.FunctionParams();
|
|
1180
|
+
const queryKeyParams = new utils.FunctionParams();
|
|
1181
|
+
const client = {
|
|
1182
|
+
method: operation.method,
|
|
1183
|
+
path: new utils.URLPath(operation.path),
|
|
1184
|
+
withQueryParams: !!schemas.queryParams?.name,
|
|
1185
|
+
withData: !!schemas.request?.name,
|
|
1186
|
+
withPathParams: !!schemas.pathParams?.name,
|
|
1187
|
+
withHeaders: !!schemas.headerParams?.name
|
|
1188
|
+
};
|
|
1189
|
+
generics.add([
|
|
1190
|
+
{
|
|
1191
|
+
type: "TData",
|
|
1192
|
+
default: props.infinite ? `InfiniteData<${factory.name}["response"]>` : `${factory.name}["response"]`
|
|
1193
|
+
},
|
|
1194
|
+
props.suspense ? void 0 : { type: "TQueryData", default: `${factory.name}["response"]` },
|
|
1195
|
+
{ type: "TQueryKey extends QueryKey", default: queryKeyType }
|
|
1196
|
+
]);
|
|
1197
|
+
const resultGenerics = ["TData", `${factory.name}['error']`];
|
|
1198
|
+
const queryOptionsOverrideGenerics = props.suspense ? [`${factory.name}['response']`, `${factory.name}['error']`, "TData", "TQueryKey"] : [`${factory.name}['response']`, `${factory.name}['error']`, "TData", "TQueryData", "TQueryKey"];
|
|
1199
|
+
const queryOptionsGenerics = props.suspense ? ["TData"] : ["TData", "TQueryData"];
|
|
1200
|
+
params.add([
|
|
1201
|
+
...pathParamsType === "object" ? [utils$1.getASTParams(schemas.pathParams, { typed: true })] : utils$1.getASTParams(schemas.pathParams, { typed: true }),
|
|
1202
|
+
{
|
|
1203
|
+
name: "params",
|
|
1204
|
+
type: `${factory.name}['queryParams']`,
|
|
1205
|
+
enabled: client.withQueryParams,
|
|
1206
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
name: "headers",
|
|
1210
|
+
type: `${factory.name}['headerParams']`,
|
|
1211
|
+
enabled: client.withHeaders,
|
|
1212
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
1213
|
+
},
|
|
1214
|
+
{
|
|
1215
|
+
name: "data",
|
|
1216
|
+
type: `${factory.name}['request']`,
|
|
1217
|
+
enabled: client.withData,
|
|
1218
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
1219
|
+
},
|
|
1220
|
+
{
|
|
1221
|
+
name: "options",
|
|
1222
|
+
type: `{
|
|
1223
|
+
query?: Partial<${optionsType}<${queryOptionsOverrideGenerics.join(", ")}>>,
|
|
1224
|
+
client?: ${factory.name}['client']['parameters']
|
|
1225
|
+
}`,
|
|
1226
|
+
default: "{}"
|
|
1227
|
+
}
|
|
1228
|
+
]);
|
|
1229
|
+
queryParams.add([
|
|
1230
|
+
...pathParamsType === "object" ? [utils$1.getASTParams(schemas.pathParams)] : utils$1.getASTParams(schemas.pathParams),
|
|
1231
|
+
{
|
|
1232
|
+
name: "params",
|
|
1233
|
+
enabled: client.withQueryParams,
|
|
1234
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
name: "headers",
|
|
1238
|
+
enabled: client.withHeaders,
|
|
1239
|
+
required: oas.isRequired(schemas.headerParams?.schema)
|
|
1240
|
+
},
|
|
1241
|
+
{
|
|
1242
|
+
name: "data",
|
|
1243
|
+
enabled: client.withData,
|
|
1244
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
name: "clientOptions",
|
|
1248
|
+
required: false
|
|
1249
|
+
}
|
|
1250
|
+
]);
|
|
1251
|
+
queryKeyParams.add([
|
|
1252
|
+
...pathParamsType === "object" ? [utils$1.getASTParams(schemas.pathParams)] : utils$1.getASTParams(schemas.pathParams),
|
|
1253
|
+
{
|
|
1254
|
+
name: "params",
|
|
1255
|
+
enabled: client.withQueryParams,
|
|
1256
|
+
required: oas.isRequired(schemas.queryParams?.schema)
|
|
1257
|
+
},
|
|
1258
|
+
{
|
|
1259
|
+
name: "data",
|
|
1260
|
+
enabled: client.withData,
|
|
1261
|
+
required: oas.isRequired(schemas.request?.schema)
|
|
1262
|
+
}
|
|
1263
|
+
]);
|
|
1264
|
+
const hook = {
|
|
1265
|
+
name: hookName,
|
|
1266
|
+
generics: [isV5 ? "any" : `${factory.name}['data']`, `${factory.name}['error']`, "TData", "any"].join(", "),
|
|
1267
|
+
queryOptions: isV5 ? `${queryOptions}(${queryParams.toString()})` : `${queryOptions}<${queryOptionsGenerics.join(", ")}>(${queryParams.toString()})`,
|
|
1268
|
+
queryKey: `${queryKey}(${queryKeyParams.toString()})`
|
|
1269
|
+
};
|
|
1270
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1271
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1272
|
+
QueryKey,
|
|
1273
|
+
{
|
|
1274
|
+
keysFn: props.query ? props.query.queryKey : (keys) => keys,
|
|
1275
|
+
Template: QueryKeyTemplate,
|
|
1276
|
+
factory,
|
|
1277
|
+
name: queryKey,
|
|
1278
|
+
typeName: queryKeyType
|
|
1279
|
+
}
|
|
1280
|
+
),
|
|
1281
|
+
props.queryOptions && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1282
|
+
QueryOptions,
|
|
1283
|
+
{
|
|
1284
|
+
Template: QueryOptionsTemplate,
|
|
1285
|
+
factory,
|
|
1286
|
+
resultType: optionsType,
|
|
1287
|
+
dataReturnType,
|
|
1288
|
+
infinite: props.infinite,
|
|
1289
|
+
suspense: props.suspense
|
|
1290
|
+
}
|
|
1291
|
+
),
|
|
1292
|
+
props.query && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1293
|
+
Template6,
|
|
1294
|
+
{
|
|
1295
|
+
name: [name, props.infinite ? "Infinite" : void 0, props.suspense ? "Suspense" : void 0].filter(Boolean).join(""),
|
|
1296
|
+
generics: generics.toString(),
|
|
1297
|
+
JSDoc: { comments: utils$1.getComments(operation) },
|
|
1298
|
+
params: params.toString(),
|
|
1299
|
+
returnType: `${resultType}<${resultGenerics.join(", ")}>`,
|
|
1300
|
+
hook,
|
|
1301
|
+
infinite: props.infinite,
|
|
1302
|
+
context: {
|
|
1303
|
+
factory,
|
|
1304
|
+
queryKey
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
)
|
|
1308
|
+
] });
|
|
1309
|
+
}
|
|
1310
|
+
Query.File = function({ templates }) {
|
|
1311
|
+
const {
|
|
1312
|
+
plugin: {
|
|
1313
|
+
options: {
|
|
1314
|
+
client: { importPath },
|
|
1315
|
+
infinite,
|
|
1316
|
+
suspense,
|
|
1317
|
+
query,
|
|
1318
|
+
queryOptions,
|
|
1319
|
+
parser
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
} = react.useApp();
|
|
1323
|
+
const { getSchemas, getFile, getName } = hooks.useOperationManager();
|
|
1324
|
+
const operation = hooks.useOperation();
|
|
1325
|
+
const schemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
|
|
1326
|
+
const zodSchemas = getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" });
|
|
1327
|
+
const file = getFile(operation);
|
|
1328
|
+
const fileType = getFile(operation, { pluginKey: [pluginTs.pluginTsName] });
|
|
1329
|
+
const fileZodSchemas = getFile(operation, {
|
|
1330
|
+
pluginKey: [pluginZod.pluginZodName]
|
|
1331
|
+
});
|
|
1332
|
+
const factoryName = getName(operation, { type: "type" });
|
|
1333
|
+
const importNames = getImportNames();
|
|
1334
|
+
const isV5 = new core.PackageManager().isValidSync(reactQueryDepRegex, ">=5");
|
|
1335
|
+
const Template6 = templates?.query["react"] || defaultTemplates5["react"];
|
|
1336
|
+
const QueryOptionsTemplate = templates?.queryOptions["react"] || QueryOptions.templates["react"];
|
|
1337
|
+
const QueryKeyTemplate = templates?.queryKey["react"] || QueryKey.templates["react"];
|
|
1338
|
+
const Import = templates?.queryImports["react"] || QueryImports.templates["react"];
|
|
1339
|
+
const factory = {
|
|
1340
|
+
name: factoryName
|
|
1341
|
+
};
|
|
1342
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
1343
|
+
parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zodSchemas.response?.name], root: file.path, path: fileZodSchemas.path }),
|
|
1344
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: importPath }),
|
|
1345
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1346
|
+
react.File.Import,
|
|
1347
|
+
{
|
|
1348
|
+
name: [
|
|
1349
|
+
schemas.request?.name,
|
|
1350
|
+
schemas.response.name,
|
|
1351
|
+
schemas.pathParams?.name,
|
|
1352
|
+
schemas.queryParams?.name,
|
|
1353
|
+
schemas.headerParams?.name,
|
|
1354
|
+
...schemas.errors?.map((error) => error.name) || []
|
|
1355
|
+
].filter(Boolean),
|
|
1356
|
+
root: file.path,
|
|
1357
|
+
path: fileType.path,
|
|
1358
|
+
isTypeOnly: true
|
|
1359
|
+
}
|
|
1360
|
+
),
|
|
1361
|
+
/* @__PURE__ */ jsxRuntime.jsx(QueryImports, { hookPath: typeof query !== "boolean" ? query.importPath : void 0, Template: Import, isInfinite: false, isSuspense: false }),
|
|
1362
|
+
!!infinite && /* @__PURE__ */ jsxRuntime.jsx(QueryImports, { hookPath: typeof query !== "boolean" ? query.importPath : void 0, Template: Import, isInfinite: true, isSuspense: false }),
|
|
1363
|
+
!!suspense && isV5 && /* @__PURE__ */ jsxRuntime.jsx(QueryImports, { hookPath: typeof query !== "boolean" ? query.importPath : void 0, Template: Import, isInfinite: false, isSuspense: true }),
|
|
1364
|
+
/* @__PURE__ */ jsxRuntime.jsx(SchemaType, {}),
|
|
1365
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1366
|
+
Query,
|
|
1367
|
+
{
|
|
1368
|
+
factory,
|
|
1369
|
+
Template: Template6,
|
|
1370
|
+
QueryKeyTemplate,
|
|
1371
|
+
QueryOptionsTemplate,
|
|
1372
|
+
infinite: false,
|
|
1373
|
+
suspense: false,
|
|
1374
|
+
query,
|
|
1375
|
+
queryOptions,
|
|
1376
|
+
hookName: importNames.query["react"].hookName,
|
|
1377
|
+
resultType: importNames.query["react"].resultType,
|
|
1378
|
+
optionsType: importNames.query["react"].optionsType
|
|
1379
|
+
}
|
|
1380
|
+
),
|
|
1381
|
+
!!infinite && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1382
|
+
Query,
|
|
1383
|
+
{
|
|
1384
|
+
factory,
|
|
1385
|
+
Template: Template6,
|
|
1386
|
+
QueryKeyTemplate,
|
|
1387
|
+
QueryOptionsTemplate,
|
|
1388
|
+
infinite,
|
|
1389
|
+
suspense: false,
|
|
1390
|
+
query,
|
|
1391
|
+
queryOptions,
|
|
1392
|
+
hookName: importNames.queryInfinite["react"].hookName,
|
|
1393
|
+
resultType: importNames.queryInfinite["react"].resultType,
|
|
1394
|
+
optionsType: importNames.queryInfinite["react"].optionsType
|
|
1395
|
+
}
|
|
1396
|
+
),
|
|
1397
|
+
!!suspense && isV5 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1398
|
+
Query,
|
|
1399
|
+
{
|
|
1400
|
+
factory,
|
|
1401
|
+
Template: Template6,
|
|
1402
|
+
QueryKeyTemplate,
|
|
1403
|
+
QueryOptionsTemplate,
|
|
1404
|
+
infinite: false,
|
|
1405
|
+
suspense,
|
|
1406
|
+
query,
|
|
1407
|
+
queryOptions,
|
|
1408
|
+
hookName: importNames.querySuspense["react"].hookName,
|
|
1409
|
+
resultType: importNames.querySuspense["react"].resultType,
|
|
1410
|
+
optionsType: importNames.querySuspense["react"].optionsType
|
|
1411
|
+
}
|
|
1412
|
+
)
|
|
1413
|
+
] });
|
|
1414
|
+
};
|
|
1415
|
+
Query.templates = defaultTemplates5;
|
|
1416
|
+
|
|
1417
|
+
exports.Mutation = Mutation;
|
|
1418
|
+
exports.Query = Query;
|
|
1419
|
+
exports.QueryImports = QueryImports;
|
|
1420
|
+
exports.QueryKey = QueryKey;
|
|
1421
|
+
exports.QueryOptions = QueryOptions;
|
|
1422
|
+
//# sourceMappingURL=chunk-AGLJPONA.cjs.map
|
|
1423
|
+
//# sourceMappingURL=chunk-AGLJPONA.cjs.map
|