@kubb/plugin-react-query 4.0.0 → 4.1.0
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-DzT-kLe8.cjs → components-DkiO4xNZ.cjs} +283 -229
- package/dist/components-DkiO4xNZ.cjs.map +1 -0
- package/dist/{components-C51l7G1u.js → components-Dz_s6t75.js} +276 -228
- package/dist/components-Dz_s6t75.js.map +1 -0
- package/dist/components.cjs +2 -1
- package/dist/components.d.cts +136 -106
- package/dist/components.d.ts +136 -106
- package/dist/components.js +2 -2
- package/dist/{generators-Bko771xm.cjs → generators-BiW_MevM.cjs} +27 -9
- package/dist/generators-BiW_MevM.cjs.map +1 -0
- package/dist/{generators-B3xZ2QoY.js → generators-ByqomtgH.js} +25 -7
- package/dist/generators-ByqomtgH.js.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/package.json +9 -10
- package/src/components/InfiniteQuery.tsx +21 -14
- package/src/components/InfiniteQueryOptions.tsx +19 -7
- package/src/components/Mutation.tsx +12 -40
- package/src/components/MutationOptions.tsx +113 -0
- package/src/components/index.ts +4 -3
- package/src/generators/__snapshots__/clientPostImportPath.ts +25 -12
- package/src/generators/__snapshots__/findInfiniteByTags.ts +14 -8
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +14 -8
- package/src/generators/__snapshots__/updatePetById.ts +25 -12
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +25 -12
- package/src/generators/infiniteQueryGenerator.tsx +1 -0
- package/src/generators/mutationGenerator.tsx +18 -2
- package/dist/components-C51l7G1u.js.map +0 -1
- package/dist/components-DzT-kLe8.cjs.map +0 -1
- package/dist/generators-B3xZ2QoY.js.map +0 -1
- package/dist/generators-Bko771xm.cjs.map +0 -1
|
@@ -21,186 +21,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
-
let __kubb_react = require("@kubb/react");
|
|
25
|
-
__kubb_react = __toESM(__kubb_react);
|
|
26
24
|
let __kubb_oas = require("@kubb/oas");
|
|
27
25
|
__kubb_oas = __toESM(__kubb_oas);
|
|
28
|
-
let __kubb_plugin_client_components = require("@kubb/plugin-client/components");
|
|
29
|
-
__kubb_plugin_client_components = __toESM(__kubb_plugin_client_components);
|
|
30
26
|
let __kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
31
27
|
__kubb_plugin_oas_utils = __toESM(__kubb_plugin_oas_utils);
|
|
28
|
+
let __kubb_react = require("@kubb/react");
|
|
29
|
+
__kubb_react = __toESM(__kubb_react);
|
|
32
30
|
let __kubb_core_utils = require("@kubb/core/utils");
|
|
33
31
|
__kubb_core_utils = __toESM(__kubb_core_utils);
|
|
34
32
|
let __kubb_react_jsx_runtime = require("@kubb/react/jsx-runtime");
|
|
35
33
|
__kubb_react_jsx_runtime = __toESM(__kubb_react_jsx_runtime);
|
|
34
|
+
let __kubb_plugin_client_components = require("@kubb/plugin-client/components");
|
|
35
|
+
__kubb_plugin_client_components = __toESM(__kubb_plugin_client_components);
|
|
36
36
|
|
|
37
|
-
//#region src/components/MutationKey.tsx
|
|
38
|
-
function getParams$7({}) {
|
|
39
|
-
return __kubb_react.FunctionParams.factory({});
|
|
40
|
-
}
|
|
41
|
-
const getTransformer$1 = ({ operation, casing }) => {
|
|
42
|
-
return [`{ url: '${new __kubb_core_utils.URLPath(operation.path, { casing }).toURLPath()}' }`];
|
|
43
|
-
};
|
|
44
|
-
function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer$1 }) {
|
|
45
|
-
const params = getParams$7({
|
|
46
|
-
pathParamsType,
|
|
47
|
-
typeSchemas
|
|
48
|
-
});
|
|
49
|
-
const keys = transformer({
|
|
50
|
-
operation,
|
|
51
|
-
schemas: typeSchemas,
|
|
52
|
-
casing: paramsCasing
|
|
53
|
-
});
|
|
54
|
-
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
55
|
-
name,
|
|
56
|
-
isExportable: true,
|
|
57
|
-
isIndexable: true,
|
|
58
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function.Arrow, {
|
|
59
|
-
name,
|
|
60
|
-
export: true,
|
|
61
|
-
params: params.toConstructor(),
|
|
62
|
-
singleLine: true,
|
|
63
|
-
children: `[${keys.join(", ")}] as const`
|
|
64
|
-
})
|
|
65
|
-
}), /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
66
|
-
name: typeName,
|
|
67
|
-
isExportable: true,
|
|
68
|
-
isIndexable: true,
|
|
69
|
-
isTypeOnly: true,
|
|
70
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Type, {
|
|
71
|
-
name: typeName,
|
|
72
|
-
export: true,
|
|
73
|
-
children: `ReturnType<typeof ${name}>`
|
|
74
|
-
})
|
|
75
|
-
})] });
|
|
76
|
-
}
|
|
77
|
-
MutationKey.getParams = getParams$7;
|
|
78
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/components/Mutation.tsx
|
|
82
|
-
function getParams$6({ paramsCasing, dataReturnType, typeSchemas }) {
|
|
83
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
84
|
-
const TRequest = __kubb_react.FunctionParams.factory({
|
|
85
|
-
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
86
|
-
typed: true,
|
|
87
|
-
casing: paramsCasing
|
|
88
|
-
}),
|
|
89
|
-
data: typeSchemas.request?.name ? {
|
|
90
|
-
type: typeSchemas.request?.name,
|
|
91
|
-
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
92
|
-
} : void 0,
|
|
93
|
-
params: typeSchemas.queryParams?.name ? {
|
|
94
|
-
type: typeSchemas.queryParams?.name,
|
|
95
|
-
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
96
|
-
} : void 0,
|
|
97
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
98
|
-
type: typeSchemas.headerParams?.name,
|
|
99
|
-
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
100
|
-
} : void 0
|
|
101
|
-
}).toConstructor();
|
|
102
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
103
|
-
const generics = [
|
|
104
|
-
TData,
|
|
105
|
-
TError,
|
|
106
|
-
TRequest ? `{${TRequest}}` : "void",
|
|
107
|
-
"TContext"
|
|
108
|
-
].join(", ");
|
|
109
|
-
return __kubb_react.FunctionParams.factory({ options: {
|
|
110
|
-
type: `
|
|
111
|
-
{
|
|
112
|
-
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
113
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
|
|
114
|
-
}
|
|
115
|
-
`,
|
|
116
|
-
default: "{}"
|
|
117
|
-
} });
|
|
118
|
-
}
|
|
119
|
-
function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }) {
|
|
120
|
-
const mutationKeyParams = MutationKey.getParams({
|
|
121
|
-
pathParamsType,
|
|
122
|
-
typeSchemas
|
|
123
|
-
});
|
|
124
|
-
const params = getParams$6({
|
|
125
|
-
paramsCasing,
|
|
126
|
-
pathParamsType,
|
|
127
|
-
dataReturnType,
|
|
128
|
-
typeSchemas
|
|
129
|
-
});
|
|
130
|
-
const clientParams = __kubb_plugin_client_components.Client.getParams({
|
|
131
|
-
paramsCasing,
|
|
132
|
-
paramsType,
|
|
133
|
-
typeSchemas,
|
|
134
|
-
pathParamsType,
|
|
135
|
-
isConfigurable: true
|
|
136
|
-
});
|
|
137
|
-
const mutationParams = __kubb_react.FunctionParams.factory({
|
|
138
|
-
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
139
|
-
typed: true,
|
|
140
|
-
casing: paramsCasing
|
|
141
|
-
}),
|
|
142
|
-
data: typeSchemas.request?.name ? {
|
|
143
|
-
type: typeSchemas.request?.name,
|
|
144
|
-
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
145
|
-
} : void 0,
|
|
146
|
-
params: typeSchemas.queryParams?.name ? {
|
|
147
|
-
type: typeSchemas.queryParams?.name,
|
|
148
|
-
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
149
|
-
} : void 0,
|
|
150
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
151
|
-
type: typeSchemas.headerParams?.name,
|
|
152
|
-
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
153
|
-
} : void 0
|
|
154
|
-
});
|
|
155
|
-
const dataParams = __kubb_react.FunctionParams.factory({ data: {
|
|
156
|
-
mode: "object",
|
|
157
|
-
children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
|
|
158
|
-
if (value) acc[key] = {
|
|
159
|
-
...value,
|
|
160
|
-
type: void 0
|
|
161
|
-
};
|
|
162
|
-
return acc;
|
|
163
|
-
}, {})
|
|
164
|
-
} });
|
|
165
|
-
const TRequest = mutationParams.toConstructor();
|
|
166
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
167
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
168
|
-
const generics = [
|
|
169
|
-
TData,
|
|
170
|
-
TError,
|
|
171
|
-
TRequest ? `{${TRequest}}` : "void",
|
|
172
|
-
"TContext"
|
|
173
|
-
].join(", ");
|
|
174
|
-
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
175
|
-
name,
|
|
176
|
-
isExportable: true,
|
|
177
|
-
isIndexable: true,
|
|
178
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
179
|
-
name,
|
|
180
|
-
export: true,
|
|
181
|
-
params: params.toConstructor(),
|
|
182
|
-
JSDoc: { comments: (0, __kubb_plugin_oas_utils.getComments)(operation) },
|
|
183
|
-
generics: ["TContext"],
|
|
184
|
-
children: `
|
|
185
|
-
const { mutation = {}, client: config = {} } = options ?? {}
|
|
186
|
-
const { client: queryClient, ...mutationOptions } = mutation;
|
|
187
|
-
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
188
|
-
|
|
189
|
-
return useMutation<${generics}>({
|
|
190
|
-
mutationFn: async(${dataParams.toConstructor()}) => {
|
|
191
|
-
return ${clientName}(${clientParams.toCall()})
|
|
192
|
-
},
|
|
193
|
-
mutationKey,
|
|
194
|
-
...mutationOptions
|
|
195
|
-
}, queryClient)
|
|
196
|
-
`
|
|
197
|
-
})
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
//#endregion
|
|
202
37
|
//#region src/components/QueryKey.tsx
|
|
203
|
-
function getParams$
|
|
38
|
+
function getParams$8({ pathParamsType, paramsCasing, typeSchemas }) {
|
|
204
39
|
return __kubb_react.FunctionParams.factory({
|
|
205
40
|
pathParams: {
|
|
206
41
|
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
@@ -219,7 +54,7 @@ function getParams$5({ pathParamsType, paramsCasing, typeSchemas }) {
|
|
|
219
54
|
} : void 0
|
|
220
55
|
});
|
|
221
56
|
}
|
|
222
|
-
const getTransformer = ({ operation, schemas, casing }) => {
|
|
57
|
+
const getTransformer$1 = ({ operation, schemas, casing }) => {
|
|
223
58
|
return [
|
|
224
59
|
new __kubb_core_utils.URLPath(operation.path, { casing }).toObject({
|
|
225
60
|
type: "path",
|
|
@@ -229,8 +64,8 @@ const getTransformer = ({ operation, schemas, casing }) => {
|
|
|
229
64
|
schemas.request?.name ? "...(data ? [data] : [])" : void 0
|
|
230
65
|
].filter(Boolean);
|
|
231
66
|
};
|
|
232
|
-
function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }) {
|
|
233
|
-
const params = getParams$
|
|
67
|
+
function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer$1 }) {
|
|
68
|
+
const params = getParams$8({
|
|
234
69
|
pathParamsType,
|
|
235
70
|
typeSchemas,
|
|
236
71
|
paramsCasing
|
|
@@ -263,12 +98,12 @@ function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation,
|
|
|
263
98
|
})
|
|
264
99
|
})] });
|
|
265
100
|
}
|
|
266
|
-
QueryKey.getParams = getParams$
|
|
267
|
-
QueryKey.getTransformer = getTransformer;
|
|
101
|
+
QueryKey.getParams = getParams$8;
|
|
102
|
+
QueryKey.getTransformer = getTransformer$1;
|
|
268
103
|
|
|
269
104
|
//#endregion
|
|
270
105
|
//#region src/components/QueryOptions.tsx
|
|
271
|
-
function getParams$
|
|
106
|
+
function getParams$7({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
272
107
|
if (paramsType === "object") return __kubb_react.FunctionParams.factory({
|
|
273
108
|
data: {
|
|
274
109
|
mode: "object",
|
|
@@ -324,7 +159,7 @@ function getParams$4({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
|
324
159
|
});
|
|
325
160
|
}
|
|
326
161
|
function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
327
|
-
const params = getParams$
|
|
162
|
+
const params = getParams$7({
|
|
328
163
|
paramsType,
|
|
329
164
|
paramsCasing,
|
|
330
165
|
pathParamsType,
|
|
@@ -368,13 +203,11 @@ function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCas
|
|
|
368
203
|
})
|
|
369
204
|
});
|
|
370
205
|
}
|
|
371
|
-
QueryOptions.getParams = getParams$
|
|
206
|
+
QueryOptions.getParams = getParams$7;
|
|
372
207
|
|
|
373
208
|
//#endregion
|
|
374
|
-
//#region src/components/
|
|
375
|
-
function getParams$
|
|
376
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
377
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
209
|
+
//#region src/components/InfiniteQuery.tsx
|
|
210
|
+
function getParams$6({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }) {
|
|
378
211
|
if (paramsType === "object") return __kubb_react.FunctionParams.factory({
|
|
379
212
|
data: {
|
|
380
213
|
mode: "object",
|
|
@@ -400,13 +233,7 @@ function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
400
233
|
options: {
|
|
401
234
|
type: `
|
|
402
235
|
{
|
|
403
|
-
query?: Partial<
|
|
404
|
-
TData,
|
|
405
|
-
TError,
|
|
406
|
-
"TData",
|
|
407
|
-
"TQueryData",
|
|
408
|
-
"TQueryKey"
|
|
409
|
-
].join(", ")}>> & { client?: QueryClient },
|
|
236
|
+
query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
410
237
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
411
238
|
}
|
|
412
239
|
`,
|
|
@@ -437,13 +264,7 @@ function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
437
264
|
options: {
|
|
438
265
|
type: `
|
|
439
266
|
{
|
|
440
|
-
query?: Partial<
|
|
441
|
-
TData,
|
|
442
|
-
TError,
|
|
443
|
-
"TData",
|
|
444
|
-
"TQueryData",
|
|
445
|
-
"TQueryKey"
|
|
446
|
-
].join(", ")}>> & { client?: QueryClient },
|
|
267
|
+
query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
447
268
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
448
269
|
}
|
|
449
270
|
`,
|
|
@@ -451,13 +272,17 @@ function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
451
272
|
}
|
|
452
273
|
});
|
|
453
274
|
}
|
|
454
|
-
function
|
|
455
|
-
const
|
|
456
|
-
const
|
|
275
|
+
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, queryParam }) {
|
|
276
|
+
const responseType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
277
|
+
const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
278
|
+
const pageParamType = (queryParam && typeSchemas.queryParams?.name ? `NonNullable<${typeSchemas.queryParams?.name}['${queryParam}']>` : void 0) ?? "number";
|
|
279
|
+
const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
457
280
|
const generics = [
|
|
458
|
-
`
|
|
459
|
-
`
|
|
460
|
-
|
|
281
|
+
`TQueryFnData = ${responseType}`,
|
|
282
|
+
`TError = ${errorType}`,
|
|
283
|
+
"TData = InfiniteData<TQueryFnData>",
|
|
284
|
+
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
285
|
+
`TPageParam = ${pageParamType}`
|
|
461
286
|
];
|
|
462
287
|
const queryKeyParams = QueryKey.getParams({
|
|
463
288
|
pathParamsType,
|
|
@@ -470,12 +295,12 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
470
295
|
typeSchemas,
|
|
471
296
|
paramsCasing
|
|
472
297
|
});
|
|
473
|
-
const params = getParams$
|
|
298
|
+
const params = getParams$6({
|
|
474
299
|
paramsCasing,
|
|
475
300
|
paramsType,
|
|
476
301
|
pathParamsType,
|
|
477
|
-
|
|
478
|
-
|
|
302
|
+
typeSchemas,
|
|
303
|
+
pageParamGeneric: "TPageParam"
|
|
479
304
|
});
|
|
480
305
|
const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
|
|
481
306
|
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
@@ -493,11 +318,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
493
318
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
494
319
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
495
320
|
|
|
496
|
-
const query =
|
|
321
|
+
const query = useInfiniteQuery({
|
|
497
322
|
...${queryOptions},
|
|
498
323
|
queryKey,
|
|
499
324
|
...queryOptions
|
|
500
|
-
} as unknown as
|
|
325
|
+
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
501
326
|
|
|
502
327
|
query.queryKey = queryKey as TQueryKey
|
|
503
328
|
|
|
@@ -506,11 +331,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
506
331
|
})
|
|
507
332
|
});
|
|
508
333
|
}
|
|
509
|
-
|
|
334
|
+
InfiniteQuery.getParams = getParams$6;
|
|
510
335
|
|
|
511
336
|
//#endregion
|
|
512
337
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
513
|
-
function getParams$
|
|
338
|
+
function getParams$5({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
514
339
|
if (paramsType === "object") return __kubb_react.FunctionParams.factory({
|
|
515
340
|
data: {
|
|
516
341
|
mode: "object",
|
|
@@ -566,9 +391,10 @@ function getParams$2({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
|
566
391
|
});
|
|
567
392
|
}
|
|
568
393
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, typeSchemas, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
569
|
-
const
|
|
570
|
-
const
|
|
571
|
-
const
|
|
394
|
+
const queryFnDataType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
395
|
+
const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
396
|
+
const pageParamType = queryParam && typeSchemas.queryParams?.name ? `NonNullable<${typeSchemas.queryParams?.name}['${queryParam}']>` : "number";
|
|
397
|
+
const params = getParams$5({
|
|
572
398
|
paramsType,
|
|
573
399
|
paramsCasing,
|
|
574
400
|
pathParamsType,
|
|
@@ -611,7 +437,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
611
437
|
params: params.toConstructor(),
|
|
612
438
|
children: `
|
|
613
439
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
614
|
-
return infiniteQueryOptions<${
|
|
440
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
615
441
|
${enabledText}
|
|
616
442
|
queryKey,
|
|
617
443
|
queryFn: async ({ signal, pageParam }) => {
|
|
@@ -634,7 +460,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
634
460
|
params: params.toConstructor(),
|
|
635
461
|
children: `
|
|
636
462
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
637
|
-
return infiniteQueryOptions<${
|
|
463
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
638
464
|
${enabledText}
|
|
639
465
|
queryKey,
|
|
640
466
|
queryFn: async ({ signal }) => {
|
|
@@ -647,10 +473,232 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
647
473
|
})
|
|
648
474
|
});
|
|
649
475
|
}
|
|
650
|
-
InfiniteQueryOptions.getParams = getParams$
|
|
476
|
+
InfiniteQueryOptions.getParams = getParams$5;
|
|
651
477
|
|
|
652
478
|
//#endregion
|
|
653
|
-
//#region src/components/
|
|
479
|
+
//#region src/components/MutationKey.tsx
|
|
480
|
+
function getParams$4({}) {
|
|
481
|
+
return __kubb_react.FunctionParams.factory({});
|
|
482
|
+
}
|
|
483
|
+
const getTransformer = ({ operation, casing }) => {
|
|
484
|
+
return [`{ url: '${new __kubb_core_utils.URLPath(operation.path, { casing }).toURLPath()}' }`];
|
|
485
|
+
};
|
|
486
|
+
function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }) {
|
|
487
|
+
const params = getParams$4({
|
|
488
|
+
pathParamsType,
|
|
489
|
+
typeSchemas
|
|
490
|
+
});
|
|
491
|
+
const keys = transformer({
|
|
492
|
+
operation,
|
|
493
|
+
schemas: typeSchemas,
|
|
494
|
+
casing: paramsCasing
|
|
495
|
+
});
|
|
496
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
497
|
+
name,
|
|
498
|
+
isExportable: true,
|
|
499
|
+
isIndexable: true,
|
|
500
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function.Arrow, {
|
|
501
|
+
name,
|
|
502
|
+
export: true,
|
|
503
|
+
params: params.toConstructor(),
|
|
504
|
+
singleLine: true,
|
|
505
|
+
children: `[${keys.join(", ")}] as const`
|
|
506
|
+
})
|
|
507
|
+
}), /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
508
|
+
name: typeName,
|
|
509
|
+
isExportable: true,
|
|
510
|
+
isIndexable: true,
|
|
511
|
+
isTypeOnly: true,
|
|
512
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Type, {
|
|
513
|
+
name: typeName,
|
|
514
|
+
export: true,
|
|
515
|
+
children: `ReturnType<typeof ${name}>`
|
|
516
|
+
})
|
|
517
|
+
})] });
|
|
518
|
+
}
|
|
519
|
+
MutationKey.getParams = getParams$4;
|
|
520
|
+
MutationKey.getTransformer = getTransformer;
|
|
521
|
+
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/components/MutationOptions.tsx
|
|
524
|
+
function getParams$3({ typeSchemas }) {
|
|
525
|
+
return __kubb_react.FunctionParams.factory({ config: {
|
|
526
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
527
|
+
default: "{}"
|
|
528
|
+
} });
|
|
529
|
+
}
|
|
530
|
+
function MutationOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
531
|
+
const params = getParams$3({ typeSchemas });
|
|
532
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
533
|
+
const TError = typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error";
|
|
534
|
+
const clientParams = __kubb_plugin_client_components.Client.getParams({
|
|
535
|
+
typeSchemas,
|
|
536
|
+
paramsCasing,
|
|
537
|
+
paramsType,
|
|
538
|
+
pathParamsType,
|
|
539
|
+
isConfigurable: true
|
|
540
|
+
});
|
|
541
|
+
const mutationKeyParams = MutationKey.getParams({
|
|
542
|
+
pathParamsType,
|
|
543
|
+
typeSchemas
|
|
544
|
+
});
|
|
545
|
+
const mutationParams = __kubb_react.FunctionParams.factory({
|
|
546
|
+
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
547
|
+
typed: true,
|
|
548
|
+
casing: paramsCasing
|
|
549
|
+
}),
|
|
550
|
+
data: typeSchemas.request?.name ? {
|
|
551
|
+
type: typeSchemas.request?.name,
|
|
552
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
553
|
+
} : void 0,
|
|
554
|
+
params: typeSchemas.queryParams?.name ? {
|
|
555
|
+
type: typeSchemas.queryParams?.name,
|
|
556
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
557
|
+
} : void 0,
|
|
558
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
559
|
+
type: typeSchemas.headerParams?.name,
|
|
560
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
561
|
+
} : void 0
|
|
562
|
+
});
|
|
563
|
+
const dataParams = __kubb_react.FunctionParams.factory({ data: {
|
|
564
|
+
mode: "object",
|
|
565
|
+
children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
|
|
566
|
+
if (value) acc[key] = {
|
|
567
|
+
...value,
|
|
568
|
+
type: void 0
|
|
569
|
+
};
|
|
570
|
+
return acc;
|
|
571
|
+
}, {})
|
|
572
|
+
} });
|
|
573
|
+
const TRequest = mutationParams.toConstructor();
|
|
574
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
575
|
+
name,
|
|
576
|
+
isExportable: true,
|
|
577
|
+
isIndexable: true,
|
|
578
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
579
|
+
name,
|
|
580
|
+
export: true,
|
|
581
|
+
params: params.toConstructor(),
|
|
582
|
+
children: `
|
|
583
|
+
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
584
|
+
return mutationOptions<${TData}, ResponseErrorConfig<${TError}>, ${TRequest ? `{${TRequest}}` : "void"}, typeof mutationKey>({
|
|
585
|
+
mutationKey,
|
|
586
|
+
mutationFn: async(${dataParams.toConstructor()}) => {
|
|
587
|
+
return ${clientName}(${clientParams.toCall()})
|
|
588
|
+
},
|
|
589
|
+
})
|
|
590
|
+
`
|
|
591
|
+
})
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
MutationOptions.getParams = getParams$3;
|
|
595
|
+
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region src/components/Mutation.tsx
|
|
598
|
+
function getParams$2({ paramsCasing, dataReturnType, typeSchemas }) {
|
|
599
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
600
|
+
const TRequest = __kubb_react.FunctionParams.factory({
|
|
601
|
+
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
602
|
+
typed: true,
|
|
603
|
+
casing: paramsCasing
|
|
604
|
+
}),
|
|
605
|
+
data: typeSchemas.request?.name ? {
|
|
606
|
+
type: typeSchemas.request?.name,
|
|
607
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
608
|
+
} : void 0,
|
|
609
|
+
params: typeSchemas.queryParams?.name ? {
|
|
610
|
+
type: typeSchemas.queryParams?.name,
|
|
611
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
612
|
+
} : void 0,
|
|
613
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
614
|
+
type: typeSchemas.headerParams?.name,
|
|
615
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
616
|
+
} : void 0
|
|
617
|
+
}).toConstructor();
|
|
618
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
619
|
+
const generics = [
|
|
620
|
+
TData,
|
|
621
|
+
TError,
|
|
622
|
+
TRequest ? `{${TRequest}}` : "void",
|
|
623
|
+
"TContext"
|
|
624
|
+
].join(", ");
|
|
625
|
+
return __kubb_react.FunctionParams.factory({ options: {
|
|
626
|
+
type: `
|
|
627
|
+
{
|
|
628
|
+
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
629
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
|
|
630
|
+
}
|
|
631
|
+
`,
|
|
632
|
+
default: "{}"
|
|
633
|
+
} });
|
|
634
|
+
}
|
|
635
|
+
function Mutation({ name, mutationOptionsName, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }) {
|
|
636
|
+
const mutationKeyParams = MutationKey.getParams({
|
|
637
|
+
pathParamsType,
|
|
638
|
+
typeSchemas
|
|
639
|
+
});
|
|
640
|
+
const params = getParams$2({
|
|
641
|
+
paramsCasing,
|
|
642
|
+
pathParamsType,
|
|
643
|
+
dataReturnType,
|
|
644
|
+
typeSchemas
|
|
645
|
+
});
|
|
646
|
+
const mutationParams = __kubb_react.FunctionParams.factory({
|
|
647
|
+
...(0, __kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
648
|
+
typed: true,
|
|
649
|
+
casing: paramsCasing
|
|
650
|
+
}),
|
|
651
|
+
data: typeSchemas.request?.name ? {
|
|
652
|
+
type: typeSchemas.request?.name,
|
|
653
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
654
|
+
} : void 0,
|
|
655
|
+
params: typeSchemas.queryParams?.name ? {
|
|
656
|
+
type: typeSchemas.queryParams?.name,
|
|
657
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
658
|
+
} : void 0,
|
|
659
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
660
|
+
type: typeSchemas.headerParams?.name,
|
|
661
|
+
optional: (0, __kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
662
|
+
} : void 0
|
|
663
|
+
});
|
|
664
|
+
const mutationOptionsParams = MutationOptions.getParams({ typeSchemas });
|
|
665
|
+
const TRequest = mutationParams.toConstructor();
|
|
666
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
667
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
668
|
+
const returnType = `UseMutationOptions<${[
|
|
669
|
+
TData,
|
|
670
|
+
TError,
|
|
671
|
+
TRequest ? `{${TRequest}}` : "void",
|
|
672
|
+
"TContext"
|
|
673
|
+
].join(", ")}>`;
|
|
674
|
+
const mutationOptions = `${mutationOptionsName}(${mutationOptionsParams.toCall()})`;
|
|
675
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
|
|
676
|
+
name,
|
|
677
|
+
isExportable: true,
|
|
678
|
+
isIndexable: true,
|
|
679
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Function, {
|
|
680
|
+
name,
|
|
681
|
+
export: true,
|
|
682
|
+
params: params.toConstructor(),
|
|
683
|
+
JSDoc: { comments: (0, __kubb_plugin_oas_utils.getComments)(operation) },
|
|
684
|
+
generics: ["TContext"],
|
|
685
|
+
children: `
|
|
686
|
+
const { mutation = {}, client: config = {} } = options ?? {}
|
|
687
|
+
const { client: queryClient, ...mutationOptions } = mutation;
|
|
688
|
+
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
689
|
+
|
|
690
|
+
return useMutation({
|
|
691
|
+
...${mutationOptions},
|
|
692
|
+
mutationKey,
|
|
693
|
+
...mutationOptions
|
|
694
|
+
} as unknown as UseMutationOptions, queryClient) as ${returnType}
|
|
695
|
+
`
|
|
696
|
+
})
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/components/Query.tsx
|
|
654
702
|
function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
|
|
655
703
|
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
656
704
|
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
@@ -679,12 +727,12 @@ function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
679
727
|
options: {
|
|
680
728
|
type: `
|
|
681
729
|
{
|
|
682
|
-
query?: Partial<
|
|
730
|
+
query?: Partial<QueryObserverOptions<${[
|
|
683
731
|
TData,
|
|
684
732
|
TError,
|
|
733
|
+
"TData",
|
|
685
734
|
"TQueryData",
|
|
686
|
-
"TQueryKey"
|
|
687
|
-
"TQueryData"
|
|
735
|
+
"TQueryKey"
|
|
688
736
|
].join(", ")}>> & { client?: QueryClient },
|
|
689
737
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
690
738
|
}
|
|
@@ -716,12 +764,12 @@ function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
716
764
|
options: {
|
|
717
765
|
type: `
|
|
718
766
|
{
|
|
719
|
-
query?: Partial<
|
|
767
|
+
query?: Partial<QueryObserverOptions<${[
|
|
720
768
|
TData,
|
|
721
769
|
TError,
|
|
770
|
+
"TData",
|
|
722
771
|
"TQueryData",
|
|
723
|
-
"TQueryKey"
|
|
724
|
-
"TQueryData"
|
|
772
|
+
"TQueryKey"
|
|
725
773
|
].join(", ")}>> & { client?: QueryClient },
|
|
726
774
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
727
775
|
}
|
|
@@ -730,11 +778,11 @@ function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
730
778
|
}
|
|
731
779
|
});
|
|
732
780
|
}
|
|
733
|
-
function
|
|
781
|
+
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation }) {
|
|
734
782
|
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
735
|
-
const returnType = `
|
|
783
|
+
const returnType = `UseQueryResult<${["TData", `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`].join(", ")}> & { queryKey: TQueryKey }`;
|
|
736
784
|
const generics = [
|
|
737
|
-
`TData =
|
|
785
|
+
`TData = ${TData}`,
|
|
738
786
|
`TQueryData = ${TData}`,
|
|
739
787
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
740
788
|
];
|
|
@@ -772,11 +820,11 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
772
820
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
773
821
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
774
822
|
|
|
775
|
-
const query =
|
|
823
|
+
const query = useQuery({
|
|
776
824
|
...${queryOptions},
|
|
777
825
|
queryKey,
|
|
778
826
|
...queryOptions
|
|
779
|
-
} as unknown as
|
|
827
|
+
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
780
828
|
|
|
781
829
|
query.queryKey = queryKey as TQueryKey
|
|
782
830
|
|
|
@@ -785,7 +833,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
785
833
|
})
|
|
786
834
|
});
|
|
787
835
|
}
|
|
788
|
-
|
|
836
|
+
Query.getParams = getParams$1;
|
|
789
837
|
|
|
790
838
|
//#endregion
|
|
791
839
|
//#region src/components/SuspenseQuery.tsx
|
|
@@ -951,6 +999,12 @@ Object.defineProperty(exports, 'MutationKey', {
|
|
|
951
999
|
return MutationKey;
|
|
952
1000
|
}
|
|
953
1001
|
});
|
|
1002
|
+
Object.defineProperty(exports, 'MutationOptions', {
|
|
1003
|
+
enumerable: true,
|
|
1004
|
+
get: function () {
|
|
1005
|
+
return MutationOptions;
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
954
1008
|
Object.defineProperty(exports, 'Query', {
|
|
955
1009
|
enumerable: true,
|
|
956
1010
|
get: function () {
|
|
@@ -981,4 +1035,4 @@ Object.defineProperty(exports, '__toESM', {
|
|
|
981
1035
|
return __toESM;
|
|
982
1036
|
}
|
|
983
1037
|
});
|
|
984
|
-
//# sourceMappingURL=components-
|
|
1038
|
+
//# sourceMappingURL=components-DkiO4xNZ.cjs.map
|