@kubb/plugin-react-query 3.16.2 → 3.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components-CuByb-hX.js +903 -0
- package/dist/components-CuByb-hX.js.map +1 -0
- package/dist/components-DHfUELJ3.cjs +979 -0
- package/dist/components-DHfUELJ3.cjs.map +1 -0
- package/dist/components.cjs +10 -40
- package/dist/components.d.cts +306 -146
- package/dist/components.d.ts +306 -146
- package/dist/components.js +3 -3
- package/dist/generators-CNHKYwqU.js +722 -0
- package/dist/generators-CNHKYwqU.js.map +1 -0
- package/dist/generators-kx0B_Nkc.cjs +745 -0
- package/dist/{chunk-2LUZUNTA.js.map → generators-kx0B_Nkc.cjs.map} +1 -1
- package/dist/generators.cjs +6 -24
- package/dist/generators.d.cts +14 -13
- package/dist/generators.d.ts +14 -13
- package/dist/generators.js +4 -4
- package/dist/index.cjs +120 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +120 -139
- package/dist/index.js.map +1 -1
- package/dist/types-5X0s8utE.d.cts +1391 -0
- package/dist/types-BTEmPwHJ.d.ts +1391 -0
- package/package.json +23 -28
- package/dist/chunk-2LUZUNTA.js +0 -588
- package/dist/chunk-7VVTPMRL.cjs +0 -788
- package/dist/chunk-7VVTPMRL.cjs.map +0 -1
- package/dist/chunk-LT467H44.js +0 -779
- package/dist/chunk-LT467H44.js.map +0 -1
- package/dist/chunk-PIAL3C5M.cjs +0 -593
- package/dist/chunk-PIAL3C5M.cjs.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-BdjqYAq1.d.cts +0 -170
- package/dist/types-BdjqYAq1.d.ts +0 -170
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
const require_components = require('./components-DHfUELJ3.cjs');
|
|
2
|
+
const __kubb_plugin_oas = require_components.__toESM(require("@kubb/plugin-oas"));
|
|
3
|
+
const __kubb_plugin_ts = require_components.__toESM(require("@kubb/plugin-ts"));
|
|
4
|
+
const __kubb_plugin_zod = require_components.__toESM(require("@kubb/plugin-zod"));
|
|
5
|
+
const __kubb_react = require_components.__toESM(require("@kubb/react"));
|
|
6
|
+
const __kubb_plugin_client_components = require_components.__toESM(require("@kubb/plugin-client/components"));
|
|
7
|
+
const __kubb_plugin_oas_utils = require_components.__toESM(require("@kubb/plugin-oas/utils"));
|
|
8
|
+
const __kubb_react_jsx_runtime = require_components.__toESM(require("@kubb/react/jsx-runtime"));
|
|
9
|
+
const __kubb_plugin_client = require_components.__toESM(require("@kubb/plugin-client"));
|
|
10
|
+
const __kubb_plugin_oas_hooks = require_components.__toESM(require("@kubb/plugin-oas/hooks"));
|
|
11
|
+
const remeda = require_components.__toESM(require("remeda"));
|
|
12
|
+
|
|
13
|
+
//#region src/generators/queryGenerator.tsx
|
|
14
|
+
const queryGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
15
|
+
name: "react-query",
|
|
16
|
+
Operation({ options, operation }) {
|
|
17
|
+
const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
|
|
18
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
19
|
+
const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
20
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
21
|
+
const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
22
|
+
const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
|
|
23
|
+
const query = {
|
|
24
|
+
name: getName(operation, {
|
|
25
|
+
type: "function",
|
|
26
|
+
prefix: "use"
|
|
27
|
+
}),
|
|
28
|
+
typeName: getName(operation, { type: "type" }),
|
|
29
|
+
file: getFile(operation, { prefix: "use" })
|
|
30
|
+
};
|
|
31
|
+
const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
|
|
32
|
+
const client = {
|
|
33
|
+
name: hasClientPlugin ? getName(operation, {
|
|
34
|
+
type: "function",
|
|
35
|
+
pluginKey: [__kubb_plugin_client.pluginClientName]
|
|
36
|
+
}) : getName(operation, { type: "function" }),
|
|
37
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
|
|
38
|
+
};
|
|
39
|
+
const queryOptions = { name: getName(operation, {
|
|
40
|
+
type: "function",
|
|
41
|
+
suffix: "QueryOptions"
|
|
42
|
+
}) };
|
|
43
|
+
const queryKey = {
|
|
44
|
+
name: getName(operation, {
|
|
45
|
+
type: "const",
|
|
46
|
+
suffix: "QueryKey"
|
|
47
|
+
}),
|
|
48
|
+
typeName: getName(operation, {
|
|
49
|
+
type: "type",
|
|
50
|
+
suffix: "QueryKey"
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
const type = {
|
|
54
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
|
|
55
|
+
schemas: getSchemas(operation, {
|
|
56
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName],
|
|
57
|
+
type: "type"
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
const zod = {
|
|
61
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
|
|
62
|
+
schemas: getSchemas(operation, {
|
|
63
|
+
pluginKey: [__kubb_plugin_zod.pluginZodName],
|
|
64
|
+
type: "function"
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
if (!isQuery || isMutation) return null;
|
|
68
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
69
|
+
baseName: query.file.baseName,
|
|
70
|
+
path: query.file.path,
|
|
71
|
+
meta: query.file.meta,
|
|
72
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
73
|
+
oas,
|
|
74
|
+
output,
|
|
75
|
+
config: pluginManager.config
|
|
76
|
+
}),
|
|
77
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
78
|
+
oas,
|
|
79
|
+
output
|
|
80
|
+
}),
|
|
81
|
+
children: [
|
|
82
|
+
options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
83
|
+
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
|
|
84
|
+
root: query.file.path,
|
|
85
|
+
path: zod.file.path
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
88
|
+
name: "fetch",
|
|
89
|
+
path: options.client.importPath
|
|
90
|
+
}),
|
|
91
|
+
hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
92
|
+
name: [client.name],
|
|
93
|
+
root: query.file.path,
|
|
94
|
+
path: client.file.path
|
|
95
|
+
}),
|
|
96
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
97
|
+
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
98
|
+
path: options.client.importPath,
|
|
99
|
+
isTypeOnly: true
|
|
100
|
+
}),
|
|
101
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
102
|
+
name: ["ResponseConfig"],
|
|
103
|
+
path: options.client.importPath,
|
|
104
|
+
isTypeOnly: true
|
|
105
|
+
}),
|
|
106
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
107
|
+
name: [
|
|
108
|
+
type.schemas.request?.name,
|
|
109
|
+
type.schemas.response.name,
|
|
110
|
+
type.schemas.pathParams?.name,
|
|
111
|
+
type.schemas.queryParams?.name,
|
|
112
|
+
type.schemas.headerParams?.name,
|
|
113
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
114
|
+
].filter(Boolean),
|
|
115
|
+
root: query.file.path,
|
|
116
|
+
path: type.file.path,
|
|
117
|
+
isTypeOnly: true
|
|
118
|
+
}),
|
|
119
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryKey, {
|
|
120
|
+
name: queryKey.name,
|
|
121
|
+
typeName: queryKey.typeName,
|
|
122
|
+
operation,
|
|
123
|
+
pathParamsType: options.pathParamsType,
|
|
124
|
+
typeSchemas: type.schemas,
|
|
125
|
+
paramsCasing: options.paramsCasing,
|
|
126
|
+
transformer: options.queryKey
|
|
127
|
+
}),
|
|
128
|
+
!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
|
|
129
|
+
name: client.name,
|
|
130
|
+
baseURL: options.client.baseURL,
|
|
131
|
+
operation,
|
|
132
|
+
typeSchemas: type.schemas,
|
|
133
|
+
zodSchemas: zod.schemas,
|
|
134
|
+
dataReturnType: options.client.dataReturnType,
|
|
135
|
+
paramsType: options.paramsType,
|
|
136
|
+
paramsCasing: options.paramsCasing,
|
|
137
|
+
pathParamsType: options.pathParamsType,
|
|
138
|
+
parser: options.parser
|
|
139
|
+
}),
|
|
140
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
141
|
+
name: ["queryOptions"],
|
|
142
|
+
path: importPath
|
|
143
|
+
}),
|
|
144
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryOptions, {
|
|
145
|
+
name: queryOptions.name,
|
|
146
|
+
clientName: client.name,
|
|
147
|
+
queryKeyName: queryKey.name,
|
|
148
|
+
typeSchemas: type.schemas,
|
|
149
|
+
paramsCasing: options.paramsCasing,
|
|
150
|
+
paramsType: options.paramsType,
|
|
151
|
+
pathParamsType: options.pathParamsType,
|
|
152
|
+
dataReturnType: options.client.dataReturnType
|
|
153
|
+
}),
|
|
154
|
+
options.query && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
155
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
156
|
+
name: ["useQuery"],
|
|
157
|
+
path: importPath
|
|
158
|
+
}),
|
|
159
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
160
|
+
name: [
|
|
161
|
+
"QueryKey",
|
|
162
|
+
"QueryClient",
|
|
163
|
+
"QueryObserverOptions",
|
|
164
|
+
"UseQueryResult",
|
|
165
|
+
"QueryClient"
|
|
166
|
+
],
|
|
167
|
+
path: importPath,
|
|
168
|
+
isTypeOnly: true
|
|
169
|
+
}),
|
|
170
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Query, {
|
|
171
|
+
name: query.name,
|
|
172
|
+
queryOptionsName: queryOptions.name,
|
|
173
|
+
typeSchemas: type.schemas,
|
|
174
|
+
paramsCasing: options.paramsCasing,
|
|
175
|
+
paramsType: options.paramsType,
|
|
176
|
+
pathParamsType: options.pathParamsType,
|
|
177
|
+
operation,
|
|
178
|
+
dataReturnType: options.client.dataReturnType,
|
|
179
|
+
queryKeyName: queryKey.name,
|
|
180
|
+
queryKeyTypeName: queryKey.typeName
|
|
181
|
+
})
|
|
182
|
+
] })
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/generators/mutationGenerator.tsx
|
|
190
|
+
const mutationGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
191
|
+
name: "react-query",
|
|
192
|
+
Operation({ options, operation }) {
|
|
193
|
+
const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
|
|
194
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
195
|
+
const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
196
|
+
const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method);
|
|
197
|
+
const isMutation = !isQuery && (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
198
|
+
const importPath = options.mutation ? options.mutation.importPath : "@tanstack/react-query";
|
|
199
|
+
const mutation = {
|
|
200
|
+
name: getName(operation, {
|
|
201
|
+
type: "function",
|
|
202
|
+
prefix: "use"
|
|
203
|
+
}),
|
|
204
|
+
typeName: getName(operation, { type: "type" }),
|
|
205
|
+
file: getFile(operation, { prefix: "use" })
|
|
206
|
+
};
|
|
207
|
+
const type = {
|
|
208
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
|
|
209
|
+
schemas: getSchemas(operation, {
|
|
210
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName],
|
|
211
|
+
type: "type"
|
|
212
|
+
})
|
|
213
|
+
};
|
|
214
|
+
const zod = {
|
|
215
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
|
|
216
|
+
schemas: getSchemas(operation, {
|
|
217
|
+
pluginKey: [__kubb_plugin_zod.pluginZodName],
|
|
218
|
+
type: "function"
|
|
219
|
+
})
|
|
220
|
+
};
|
|
221
|
+
const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
|
|
222
|
+
const client = {
|
|
223
|
+
name: hasClientPlugin ? getName(operation, {
|
|
224
|
+
type: "function",
|
|
225
|
+
pluginKey: [__kubb_plugin_client.pluginClientName]
|
|
226
|
+
}) : getName(operation, { type: "function" }),
|
|
227
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
|
|
228
|
+
};
|
|
229
|
+
const mutationKey = {
|
|
230
|
+
name: getName(operation, {
|
|
231
|
+
type: "const",
|
|
232
|
+
suffix: "MutationKey"
|
|
233
|
+
}),
|
|
234
|
+
typeName: getName(operation, {
|
|
235
|
+
type: "type",
|
|
236
|
+
suffix: "MutationKey"
|
|
237
|
+
})
|
|
238
|
+
};
|
|
239
|
+
if (!isMutation) return null;
|
|
240
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
241
|
+
baseName: mutation.file.baseName,
|
|
242
|
+
path: mutation.file.path,
|
|
243
|
+
meta: mutation.file.meta,
|
|
244
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
245
|
+
oas,
|
|
246
|
+
output,
|
|
247
|
+
config: pluginManager.config
|
|
248
|
+
}),
|
|
249
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
250
|
+
oas,
|
|
251
|
+
output
|
|
252
|
+
}),
|
|
253
|
+
children: [
|
|
254
|
+
options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
255
|
+
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
|
|
256
|
+
root: mutation.file.path,
|
|
257
|
+
path: zod.file.path
|
|
258
|
+
}),
|
|
259
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
260
|
+
name: "fetch",
|
|
261
|
+
path: options.client.importPath
|
|
262
|
+
}),
|
|
263
|
+
!!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
264
|
+
name: [client.name],
|
|
265
|
+
root: mutation.file.path,
|
|
266
|
+
path: client.file.path
|
|
267
|
+
}),
|
|
268
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
269
|
+
name: [
|
|
270
|
+
"RequestConfig",
|
|
271
|
+
"ResponseConfig",
|
|
272
|
+
"ResponseErrorConfig"
|
|
273
|
+
],
|
|
274
|
+
path: options.client.importPath,
|
|
275
|
+
isTypeOnly: true
|
|
276
|
+
}),
|
|
277
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
278
|
+
name: [
|
|
279
|
+
type.schemas.request?.name,
|
|
280
|
+
type.schemas.response.name,
|
|
281
|
+
type.schemas.pathParams?.name,
|
|
282
|
+
type.schemas.queryParams?.name,
|
|
283
|
+
type.schemas.headerParams?.name,
|
|
284
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
285
|
+
].filter(Boolean),
|
|
286
|
+
root: mutation.file.path,
|
|
287
|
+
path: type.file.path,
|
|
288
|
+
isTypeOnly: true
|
|
289
|
+
}),
|
|
290
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.MutationKey, {
|
|
291
|
+
name: mutationKey.name,
|
|
292
|
+
typeName: mutationKey.typeName,
|
|
293
|
+
operation,
|
|
294
|
+
pathParamsType: options.pathParamsType,
|
|
295
|
+
typeSchemas: type.schemas,
|
|
296
|
+
paramsCasing: options.paramsCasing,
|
|
297
|
+
transformer: options.mutationKey
|
|
298
|
+
}),
|
|
299
|
+
!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
|
|
300
|
+
name: client.name,
|
|
301
|
+
baseURL: options.client.baseURL,
|
|
302
|
+
operation,
|
|
303
|
+
typeSchemas: type.schemas,
|
|
304
|
+
zodSchemas: zod.schemas,
|
|
305
|
+
dataReturnType: options.client.dataReturnType,
|
|
306
|
+
paramsCasing: options.paramsCasing,
|
|
307
|
+
paramsType: options.paramsType,
|
|
308
|
+
pathParamsType: options.pathParamsType,
|
|
309
|
+
parser: options.parser
|
|
310
|
+
}),
|
|
311
|
+
options.mutation && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
312
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
313
|
+
name: ["useMutation"],
|
|
314
|
+
path: importPath
|
|
315
|
+
}),
|
|
316
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
317
|
+
name: ["UseMutationOptions", "QueryClient"],
|
|
318
|
+
path: importPath,
|
|
319
|
+
isTypeOnly: true
|
|
320
|
+
}),
|
|
321
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Mutation, {
|
|
322
|
+
name: mutation.name,
|
|
323
|
+
clientName: client.name,
|
|
324
|
+
typeName: mutation.typeName,
|
|
325
|
+
typeSchemas: type.schemas,
|
|
326
|
+
operation,
|
|
327
|
+
dataReturnType: options.client.dataReturnType,
|
|
328
|
+
paramsCasing: options.paramsCasing,
|
|
329
|
+
paramsType: options.paramsType,
|
|
330
|
+
pathParamsType: options.pathParamsType,
|
|
331
|
+
mutationKeyName: mutationKey.name
|
|
332
|
+
})
|
|
333
|
+
] })
|
|
334
|
+
]
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/generators/infiniteQueryGenerator.tsx
|
|
341
|
+
const infiniteQueryGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
342
|
+
name: "react-infinite-query",
|
|
343
|
+
Operation({ options, operation }) {
|
|
344
|
+
const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
|
|
345
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
346
|
+
const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
347
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
348
|
+
const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
349
|
+
const isInfinite = !!options.infinite;
|
|
350
|
+
const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
|
|
351
|
+
const query = {
|
|
352
|
+
name: getName(operation, {
|
|
353
|
+
type: "function",
|
|
354
|
+
prefix: "use",
|
|
355
|
+
suffix: "infinite"
|
|
356
|
+
}),
|
|
357
|
+
typeName: getName(operation, { type: "type" }),
|
|
358
|
+
file: getFile(operation, {
|
|
359
|
+
prefix: "use",
|
|
360
|
+
suffix: "infinite"
|
|
361
|
+
})
|
|
362
|
+
};
|
|
363
|
+
const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
|
|
364
|
+
const client = {
|
|
365
|
+
name: hasClientPlugin ? getName(operation, {
|
|
366
|
+
type: "function",
|
|
367
|
+
pluginKey: [__kubb_plugin_client.pluginClientName]
|
|
368
|
+
}) : getName(operation, {
|
|
369
|
+
type: "function",
|
|
370
|
+
suffix: "infinite"
|
|
371
|
+
}),
|
|
372
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
|
|
373
|
+
};
|
|
374
|
+
const queryOptions = { name: getName(operation, {
|
|
375
|
+
type: "function",
|
|
376
|
+
suffix: "InfiniteQueryOptions"
|
|
377
|
+
}) };
|
|
378
|
+
const queryKey = {
|
|
379
|
+
name: getName(operation, {
|
|
380
|
+
type: "const",
|
|
381
|
+
suffix: "InfiniteQueryKey"
|
|
382
|
+
}),
|
|
383
|
+
typeName: getName(operation, {
|
|
384
|
+
type: "type",
|
|
385
|
+
suffix: "InfiniteQueryKey"
|
|
386
|
+
})
|
|
387
|
+
};
|
|
388
|
+
const type = {
|
|
389
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
|
|
390
|
+
schemas: getSchemas(operation, {
|
|
391
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName],
|
|
392
|
+
type: "type"
|
|
393
|
+
})
|
|
394
|
+
};
|
|
395
|
+
const zod = {
|
|
396
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
|
|
397
|
+
schemas: getSchemas(operation, {
|
|
398
|
+
pluginKey: [__kubb_plugin_zod.pluginZodName],
|
|
399
|
+
type: "function"
|
|
400
|
+
})
|
|
401
|
+
};
|
|
402
|
+
if (!isQuery || isMutation || !isInfinite) return null;
|
|
403
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
404
|
+
baseName: query.file.baseName,
|
|
405
|
+
path: query.file.path,
|
|
406
|
+
meta: query.file.meta,
|
|
407
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
408
|
+
oas,
|
|
409
|
+
output,
|
|
410
|
+
config: pluginManager.config
|
|
411
|
+
}),
|
|
412
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
413
|
+
oas,
|
|
414
|
+
output
|
|
415
|
+
}),
|
|
416
|
+
children: [
|
|
417
|
+
options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
418
|
+
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
|
|
419
|
+
root: query.file.path,
|
|
420
|
+
path: zod.file.path
|
|
421
|
+
}),
|
|
422
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
423
|
+
name: "fetch",
|
|
424
|
+
path: options.client.importPath
|
|
425
|
+
}),
|
|
426
|
+
hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
427
|
+
name: [client.name],
|
|
428
|
+
root: query.file.path,
|
|
429
|
+
path: client.file.path
|
|
430
|
+
}),
|
|
431
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
432
|
+
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
433
|
+
path: options.client.importPath,
|
|
434
|
+
isTypeOnly: true
|
|
435
|
+
}),
|
|
436
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
437
|
+
name: ["ResponseConfig"],
|
|
438
|
+
path: options.client.importPath,
|
|
439
|
+
isTypeOnly: true
|
|
440
|
+
}),
|
|
441
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
442
|
+
name: [
|
|
443
|
+
type.schemas.request?.name,
|
|
444
|
+
type.schemas.response.name,
|
|
445
|
+
type.schemas.pathParams?.name,
|
|
446
|
+
type.schemas.queryParams?.name,
|
|
447
|
+
type.schemas.headerParams?.name,
|
|
448
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
449
|
+
].filter(Boolean),
|
|
450
|
+
root: query.file.path,
|
|
451
|
+
path: type.file.path,
|
|
452
|
+
isTypeOnly: true
|
|
453
|
+
}),
|
|
454
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryKey, {
|
|
455
|
+
name: queryKey.name,
|
|
456
|
+
typeName: queryKey.typeName,
|
|
457
|
+
operation,
|
|
458
|
+
paramsCasing: options.paramsCasing,
|
|
459
|
+
pathParamsType: options.pathParamsType,
|
|
460
|
+
typeSchemas: type.schemas,
|
|
461
|
+
transformer: options.queryKey
|
|
462
|
+
}),
|
|
463
|
+
!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
|
|
464
|
+
name: client.name,
|
|
465
|
+
baseURL: options.client.baseURL,
|
|
466
|
+
operation,
|
|
467
|
+
typeSchemas: type.schemas,
|
|
468
|
+
zodSchemas: zod.schemas,
|
|
469
|
+
dataReturnType: options.client.dataReturnType,
|
|
470
|
+
paramsCasing: options.paramsCasing,
|
|
471
|
+
paramsType: options.paramsType,
|
|
472
|
+
pathParamsType: options.pathParamsType,
|
|
473
|
+
parser: options.parser
|
|
474
|
+
}),
|
|
475
|
+
options.infinite && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
476
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
477
|
+
name: ["InfiniteData"],
|
|
478
|
+
isTypeOnly: true,
|
|
479
|
+
path: importPath
|
|
480
|
+
}),
|
|
481
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
482
|
+
name: ["infiniteQueryOptions"],
|
|
483
|
+
path: importPath
|
|
484
|
+
}),
|
|
485
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.InfiniteQueryOptions, {
|
|
486
|
+
name: queryOptions.name,
|
|
487
|
+
clientName: client.name,
|
|
488
|
+
queryKeyName: queryKey.name,
|
|
489
|
+
typeSchemas: type.schemas,
|
|
490
|
+
paramsCasing: options.paramsCasing,
|
|
491
|
+
paramsType: options.paramsType,
|
|
492
|
+
pathParamsType: options.pathParamsType,
|
|
493
|
+
dataReturnType: options.client.dataReturnType,
|
|
494
|
+
cursorParam: options.infinite.cursorParam,
|
|
495
|
+
initialPageParam: options.infinite.initialPageParam,
|
|
496
|
+
queryParam: options.infinite.queryParam
|
|
497
|
+
})
|
|
498
|
+
] }),
|
|
499
|
+
options.infinite && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
500
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
501
|
+
name: ["useInfiniteQuery"],
|
|
502
|
+
path: importPath
|
|
503
|
+
}),
|
|
504
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
505
|
+
name: [
|
|
506
|
+
"QueryKey",
|
|
507
|
+
"QueryClient",
|
|
508
|
+
"InfiniteQueryObserverOptions",
|
|
509
|
+
"UseInfiniteQueryResult"
|
|
510
|
+
],
|
|
511
|
+
path: importPath,
|
|
512
|
+
isTypeOnly: true
|
|
513
|
+
}),
|
|
514
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.InfiniteQuery, {
|
|
515
|
+
name: query.name,
|
|
516
|
+
queryOptionsName: queryOptions.name,
|
|
517
|
+
typeSchemas: type.schemas,
|
|
518
|
+
paramsCasing: options.paramsCasing,
|
|
519
|
+
paramsType: options.paramsType,
|
|
520
|
+
pathParamsType: options.pathParamsType,
|
|
521
|
+
operation,
|
|
522
|
+
dataReturnType: options.client.dataReturnType,
|
|
523
|
+
queryKeyName: queryKey.name,
|
|
524
|
+
queryKeyTypeName: queryKey.typeName
|
|
525
|
+
})
|
|
526
|
+
] })
|
|
527
|
+
]
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/generators/suspenseQueryGenerator.tsx
|
|
534
|
+
const suspenseQueryGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
535
|
+
name: "react-suspense-query",
|
|
536
|
+
Operation({ options, operation }) {
|
|
537
|
+
const { plugin: { options: { output } }, pluginManager } = (0, __kubb_react.useApp)();
|
|
538
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
539
|
+
const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
540
|
+
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
|
|
541
|
+
const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
542
|
+
const isSuspense = !!options.suspense;
|
|
543
|
+
const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
|
|
544
|
+
const query = {
|
|
545
|
+
name: getName(operation, {
|
|
546
|
+
type: "function",
|
|
547
|
+
prefix: "use",
|
|
548
|
+
suffix: "suspense"
|
|
549
|
+
}),
|
|
550
|
+
typeName: getName(operation, { type: "type" }),
|
|
551
|
+
file: getFile(operation, {
|
|
552
|
+
prefix: "use",
|
|
553
|
+
suffix: "suspense"
|
|
554
|
+
})
|
|
555
|
+
};
|
|
556
|
+
const hasClientPlugin = !!pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
|
|
557
|
+
const client = {
|
|
558
|
+
name: hasClientPlugin ? getName(operation, {
|
|
559
|
+
type: "function",
|
|
560
|
+
pluginKey: [__kubb_plugin_client.pluginClientName]
|
|
561
|
+
}) : getName(operation, {
|
|
562
|
+
type: "function",
|
|
563
|
+
suffix: "suspense"
|
|
564
|
+
}),
|
|
565
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_client.pluginClientName] })
|
|
566
|
+
};
|
|
567
|
+
const queryOptions = { name: getName(operation, {
|
|
568
|
+
type: "function",
|
|
569
|
+
suffix: "SuspenseQueryOptions"
|
|
570
|
+
}) };
|
|
571
|
+
const queryKey = {
|
|
572
|
+
name: getName(operation, {
|
|
573
|
+
type: "const",
|
|
574
|
+
suffix: "SuspenseQueryKey"
|
|
575
|
+
}),
|
|
576
|
+
typeName: getName(operation, {
|
|
577
|
+
type: "type",
|
|
578
|
+
suffix: "SuspenseQueryKey"
|
|
579
|
+
})
|
|
580
|
+
};
|
|
581
|
+
const type = {
|
|
582
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_ts.pluginTsName] }),
|
|
583
|
+
schemas: getSchemas(operation, {
|
|
584
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName],
|
|
585
|
+
type: "type"
|
|
586
|
+
})
|
|
587
|
+
};
|
|
588
|
+
const zod = {
|
|
589
|
+
file: getFile(operation, { pluginKey: [__kubb_plugin_zod.pluginZodName] }),
|
|
590
|
+
schemas: getSchemas(operation, {
|
|
591
|
+
pluginKey: [__kubb_plugin_zod.pluginZodName],
|
|
592
|
+
type: "function"
|
|
593
|
+
})
|
|
594
|
+
};
|
|
595
|
+
if (!isQuery || isMutation || !isSuspense) return null;
|
|
596
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
597
|
+
baseName: query.file.baseName,
|
|
598
|
+
path: query.file.path,
|
|
599
|
+
meta: query.file.meta,
|
|
600
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
601
|
+
oas,
|
|
602
|
+
output,
|
|
603
|
+
config: pluginManager.config
|
|
604
|
+
}),
|
|
605
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
606
|
+
oas,
|
|
607
|
+
output
|
|
608
|
+
}),
|
|
609
|
+
children: [
|
|
610
|
+
options.parser === "zod" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
611
|
+
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
|
|
612
|
+
root: query.file.path,
|
|
613
|
+
path: zod.file.path
|
|
614
|
+
}),
|
|
615
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
616
|
+
name: "fetch",
|
|
617
|
+
path: options.client.importPath
|
|
618
|
+
}),
|
|
619
|
+
hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
620
|
+
name: [client.name],
|
|
621
|
+
root: query.file.path,
|
|
622
|
+
path: client.file.path
|
|
623
|
+
}),
|
|
624
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
625
|
+
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
626
|
+
path: options.client.importPath,
|
|
627
|
+
isTypeOnly: true
|
|
628
|
+
}),
|
|
629
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
630
|
+
name: ["ResponseConfig"],
|
|
631
|
+
path: options.client.importPath,
|
|
632
|
+
isTypeOnly: true
|
|
633
|
+
}),
|
|
634
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
635
|
+
name: [
|
|
636
|
+
type.schemas.request?.name,
|
|
637
|
+
type.schemas.response.name,
|
|
638
|
+
type.schemas.pathParams?.name,
|
|
639
|
+
type.schemas.queryParams?.name,
|
|
640
|
+
type.schemas.headerParams?.name,
|
|
641
|
+
...type.schemas.statusCodes?.map((item) => item.name) || []
|
|
642
|
+
].filter(Boolean),
|
|
643
|
+
root: query.file.path,
|
|
644
|
+
path: type.file.path,
|
|
645
|
+
isTypeOnly: true
|
|
646
|
+
}),
|
|
647
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryKey, {
|
|
648
|
+
name: queryKey.name,
|
|
649
|
+
typeName: queryKey.typeName,
|
|
650
|
+
operation,
|
|
651
|
+
paramsCasing: options.paramsCasing,
|
|
652
|
+
pathParamsType: options.pathParamsType,
|
|
653
|
+
typeSchemas: type.schemas,
|
|
654
|
+
transformer: options.queryKey
|
|
655
|
+
}),
|
|
656
|
+
!hasClientPlugin && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_plugin_client_components.Client, {
|
|
657
|
+
name: client.name,
|
|
658
|
+
baseURL: options.client.baseURL,
|
|
659
|
+
operation,
|
|
660
|
+
typeSchemas: type.schemas,
|
|
661
|
+
zodSchemas: zod.schemas,
|
|
662
|
+
dataReturnType: options.client.dataReturnType,
|
|
663
|
+
paramsCasing: options.paramsCasing,
|
|
664
|
+
paramsType: options.paramsType,
|
|
665
|
+
pathParamsType: options.pathParamsType,
|
|
666
|
+
parser: options.parser
|
|
667
|
+
}),
|
|
668
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
669
|
+
name: ["queryOptions"],
|
|
670
|
+
path: importPath
|
|
671
|
+
}),
|
|
672
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.QueryOptions, {
|
|
673
|
+
name: queryOptions.name,
|
|
674
|
+
clientName: client.name,
|
|
675
|
+
queryKeyName: queryKey.name,
|
|
676
|
+
typeSchemas: type.schemas,
|
|
677
|
+
paramsCasing: options.paramsCasing,
|
|
678
|
+
paramsType: options.paramsType,
|
|
679
|
+
pathParamsType: options.pathParamsType,
|
|
680
|
+
dataReturnType: options.client.dataReturnType
|
|
681
|
+
}),
|
|
682
|
+
options.suspense && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
|
|
683
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
684
|
+
name: ["useSuspenseQuery"],
|
|
685
|
+
path: importPath
|
|
686
|
+
}),
|
|
687
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
688
|
+
name: [
|
|
689
|
+
"QueryKey",
|
|
690
|
+
"QueryClient",
|
|
691
|
+
"UseSuspenseQueryOptions",
|
|
692
|
+
"UseSuspenseQueryResult"
|
|
693
|
+
],
|
|
694
|
+
path: importPath,
|
|
695
|
+
isTypeOnly: true
|
|
696
|
+
}),
|
|
697
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
698
|
+
name: ["ResponseConfig"],
|
|
699
|
+
path: options.client.importPath,
|
|
700
|
+
isTypeOnly: true
|
|
701
|
+
}),
|
|
702
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.SuspenseQuery, {
|
|
703
|
+
name: query.name,
|
|
704
|
+
queryOptionsName: queryOptions.name,
|
|
705
|
+
typeSchemas: type.schemas,
|
|
706
|
+
paramsType: options.paramsType,
|
|
707
|
+
paramsCasing: options.paramsCasing,
|
|
708
|
+
pathParamsType: options.pathParamsType,
|
|
709
|
+
operation,
|
|
710
|
+
dataReturnType: options.client.dataReturnType,
|
|
711
|
+
queryKeyName: queryKey.name,
|
|
712
|
+
queryKeyTypeName: queryKey.typeName
|
|
713
|
+
})
|
|
714
|
+
] })
|
|
715
|
+
]
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
//#endregion
|
|
721
|
+
Object.defineProperty(exports, 'infiniteQueryGenerator', {
|
|
722
|
+
enumerable: true,
|
|
723
|
+
get: function () {
|
|
724
|
+
return infiniteQueryGenerator;
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
Object.defineProperty(exports, 'mutationGenerator', {
|
|
728
|
+
enumerable: true,
|
|
729
|
+
get: function () {
|
|
730
|
+
return mutationGenerator;
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
Object.defineProperty(exports, 'queryGenerator', {
|
|
734
|
+
enumerable: true,
|
|
735
|
+
get: function () {
|
|
736
|
+
return queryGenerator;
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
Object.defineProperty(exports, 'suspenseQueryGenerator', {
|
|
740
|
+
enumerable: true,
|
|
741
|
+
get: function () {
|
|
742
|
+
return suspenseQueryGenerator;
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
//# sourceMappingURL=generators-kx0B_Nkc.cjs.map
|