@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
|
@@ -1,177 +1,12 @@
|
|
|
1
|
-
import { File, Function, FunctionParams, Type } from "@kubb/react";
|
|
2
1
|
import { isOptional } from "@kubb/oas";
|
|
3
|
-
import { Client } from "@kubb/plugin-client/components";
|
|
4
2
|
import { getComments, getPathParams } from "@kubb/plugin-oas/utils";
|
|
3
|
+
import { File, Function, FunctionParams, Type } from "@kubb/react";
|
|
5
4
|
import { URLPath } from "@kubb/core/utils";
|
|
6
5
|
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
6
|
+
import { Client } from "@kubb/plugin-client/components";
|
|
7
7
|
|
|
8
|
-
//#region src/components/MutationKey.tsx
|
|
9
|
-
function getParams$7({}) {
|
|
10
|
-
return FunctionParams.factory({});
|
|
11
|
-
}
|
|
12
|
-
const getTransformer$1 = ({ operation, casing }) => {
|
|
13
|
-
return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
|
|
14
|
-
};
|
|
15
|
-
function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer$1 }) {
|
|
16
|
-
const params = getParams$7({
|
|
17
|
-
pathParamsType,
|
|
18
|
-
typeSchemas
|
|
19
|
-
});
|
|
20
|
-
const keys = transformer({
|
|
21
|
-
operation,
|
|
22
|
-
schemas: typeSchemas,
|
|
23
|
-
casing: paramsCasing
|
|
24
|
-
});
|
|
25
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
26
|
-
name,
|
|
27
|
-
isExportable: true,
|
|
28
|
-
isIndexable: true,
|
|
29
|
-
children: /* @__PURE__ */ jsx(Function.Arrow, {
|
|
30
|
-
name,
|
|
31
|
-
export: true,
|
|
32
|
-
params: params.toConstructor(),
|
|
33
|
-
singleLine: true,
|
|
34
|
-
children: `[${keys.join(", ")}] as const`
|
|
35
|
-
})
|
|
36
|
-
}), /* @__PURE__ */ jsx(File.Source, {
|
|
37
|
-
name: typeName,
|
|
38
|
-
isExportable: true,
|
|
39
|
-
isIndexable: true,
|
|
40
|
-
isTypeOnly: true,
|
|
41
|
-
children: /* @__PURE__ */ jsx(Type, {
|
|
42
|
-
name: typeName,
|
|
43
|
-
export: true,
|
|
44
|
-
children: `ReturnType<typeof ${name}>`
|
|
45
|
-
})
|
|
46
|
-
})] });
|
|
47
|
-
}
|
|
48
|
-
MutationKey.getParams = getParams$7;
|
|
49
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/components/Mutation.tsx
|
|
53
|
-
function getParams$6({ paramsCasing, dataReturnType, typeSchemas }) {
|
|
54
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
55
|
-
const TRequest = FunctionParams.factory({
|
|
56
|
-
...getPathParams(typeSchemas.pathParams, {
|
|
57
|
-
typed: true,
|
|
58
|
-
casing: paramsCasing
|
|
59
|
-
}),
|
|
60
|
-
data: typeSchemas.request?.name ? {
|
|
61
|
-
type: typeSchemas.request?.name,
|
|
62
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
63
|
-
} : void 0,
|
|
64
|
-
params: typeSchemas.queryParams?.name ? {
|
|
65
|
-
type: typeSchemas.queryParams?.name,
|
|
66
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
67
|
-
} : void 0,
|
|
68
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
69
|
-
type: typeSchemas.headerParams?.name,
|
|
70
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
71
|
-
} : void 0
|
|
72
|
-
}).toConstructor();
|
|
73
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
74
|
-
const generics = [
|
|
75
|
-
TData,
|
|
76
|
-
TError,
|
|
77
|
-
TRequest ? `{${TRequest}}` : "void",
|
|
78
|
-
"TContext"
|
|
79
|
-
].join(", ");
|
|
80
|
-
return FunctionParams.factory({ options: {
|
|
81
|
-
type: `
|
|
82
|
-
{
|
|
83
|
-
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
84
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
|
|
85
|
-
}
|
|
86
|
-
`,
|
|
87
|
-
default: "{}"
|
|
88
|
-
} });
|
|
89
|
-
}
|
|
90
|
-
function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }) {
|
|
91
|
-
const mutationKeyParams = MutationKey.getParams({
|
|
92
|
-
pathParamsType,
|
|
93
|
-
typeSchemas
|
|
94
|
-
});
|
|
95
|
-
const params = getParams$6({
|
|
96
|
-
paramsCasing,
|
|
97
|
-
pathParamsType,
|
|
98
|
-
dataReturnType,
|
|
99
|
-
typeSchemas
|
|
100
|
-
});
|
|
101
|
-
const clientParams = Client.getParams({
|
|
102
|
-
paramsCasing,
|
|
103
|
-
paramsType,
|
|
104
|
-
typeSchemas,
|
|
105
|
-
pathParamsType,
|
|
106
|
-
isConfigurable: true
|
|
107
|
-
});
|
|
108
|
-
const mutationParams = FunctionParams.factory({
|
|
109
|
-
...getPathParams(typeSchemas.pathParams, {
|
|
110
|
-
typed: true,
|
|
111
|
-
casing: paramsCasing
|
|
112
|
-
}),
|
|
113
|
-
data: typeSchemas.request?.name ? {
|
|
114
|
-
type: typeSchemas.request?.name,
|
|
115
|
-
optional: isOptional(typeSchemas.request?.schema)
|
|
116
|
-
} : void 0,
|
|
117
|
-
params: typeSchemas.queryParams?.name ? {
|
|
118
|
-
type: typeSchemas.queryParams?.name,
|
|
119
|
-
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
120
|
-
} : void 0,
|
|
121
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
122
|
-
type: typeSchemas.headerParams?.name,
|
|
123
|
-
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
124
|
-
} : void 0
|
|
125
|
-
});
|
|
126
|
-
const dataParams = FunctionParams.factory({ data: {
|
|
127
|
-
mode: "object",
|
|
128
|
-
children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
|
|
129
|
-
if (value) acc[key] = {
|
|
130
|
-
...value,
|
|
131
|
-
type: void 0
|
|
132
|
-
};
|
|
133
|
-
return acc;
|
|
134
|
-
}, {})
|
|
135
|
-
} });
|
|
136
|
-
const TRequest = mutationParams.toConstructor();
|
|
137
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
138
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
139
|
-
const generics = [
|
|
140
|
-
TData,
|
|
141
|
-
TError,
|
|
142
|
-
TRequest ? `{${TRequest}}` : "void",
|
|
143
|
-
"TContext"
|
|
144
|
-
].join(", ");
|
|
145
|
-
return /* @__PURE__ */ jsx(File.Source, {
|
|
146
|
-
name,
|
|
147
|
-
isExportable: true,
|
|
148
|
-
isIndexable: true,
|
|
149
|
-
children: /* @__PURE__ */ jsx(Function, {
|
|
150
|
-
name,
|
|
151
|
-
export: true,
|
|
152
|
-
params: params.toConstructor(),
|
|
153
|
-
JSDoc: { comments: getComments(operation) },
|
|
154
|
-
generics: ["TContext"],
|
|
155
|
-
children: `
|
|
156
|
-
const { mutation = {}, client: config = {} } = options ?? {}
|
|
157
|
-
const { client: queryClient, ...mutationOptions } = mutation;
|
|
158
|
-
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
159
|
-
|
|
160
|
-
return useMutation<${generics}>({
|
|
161
|
-
mutationFn: async(${dataParams.toConstructor()}) => {
|
|
162
|
-
return ${clientName}(${clientParams.toCall()})
|
|
163
|
-
},
|
|
164
|
-
mutationKey,
|
|
165
|
-
...mutationOptions
|
|
166
|
-
}, queryClient)
|
|
167
|
-
`
|
|
168
|
-
})
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
//#endregion
|
|
173
8
|
//#region src/components/QueryKey.tsx
|
|
174
|
-
function getParams$
|
|
9
|
+
function getParams$8({ pathParamsType, paramsCasing, typeSchemas }) {
|
|
175
10
|
return FunctionParams.factory({
|
|
176
11
|
pathParams: {
|
|
177
12
|
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
@@ -190,7 +25,7 @@ function getParams$5({ pathParamsType, paramsCasing, typeSchemas }) {
|
|
|
190
25
|
} : void 0
|
|
191
26
|
});
|
|
192
27
|
}
|
|
193
|
-
const getTransformer = ({ operation, schemas, casing }) => {
|
|
28
|
+
const getTransformer$1 = ({ operation, schemas, casing }) => {
|
|
194
29
|
return [
|
|
195
30
|
new URLPath(operation.path, { casing }).toObject({
|
|
196
31
|
type: "path",
|
|
@@ -200,8 +35,8 @@ const getTransformer = ({ operation, schemas, casing }) => {
|
|
|
200
35
|
schemas.request?.name ? "...(data ? [data] : [])" : void 0
|
|
201
36
|
].filter(Boolean);
|
|
202
37
|
};
|
|
203
|
-
function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }) {
|
|
204
|
-
const params = getParams$
|
|
38
|
+
function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer$1 }) {
|
|
39
|
+
const params = getParams$8({
|
|
205
40
|
pathParamsType,
|
|
206
41
|
typeSchemas,
|
|
207
42
|
paramsCasing
|
|
@@ -234,12 +69,12 @@ function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation,
|
|
|
234
69
|
})
|
|
235
70
|
})] });
|
|
236
71
|
}
|
|
237
|
-
QueryKey.getParams = getParams$
|
|
238
|
-
QueryKey.getTransformer = getTransformer;
|
|
72
|
+
QueryKey.getParams = getParams$8;
|
|
73
|
+
QueryKey.getTransformer = getTransformer$1;
|
|
239
74
|
|
|
240
75
|
//#endregion
|
|
241
76
|
//#region src/components/QueryOptions.tsx
|
|
242
|
-
function getParams$
|
|
77
|
+
function getParams$7({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
243
78
|
if (paramsType === "object") return FunctionParams.factory({
|
|
244
79
|
data: {
|
|
245
80
|
mode: "object",
|
|
@@ -295,7 +130,7 @@ function getParams$4({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
|
295
130
|
});
|
|
296
131
|
}
|
|
297
132
|
function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
298
|
-
const params = getParams$
|
|
133
|
+
const params = getParams$7({
|
|
299
134
|
paramsType,
|
|
300
135
|
paramsCasing,
|
|
301
136
|
pathParamsType,
|
|
@@ -339,13 +174,11 @@ function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCas
|
|
|
339
174
|
})
|
|
340
175
|
});
|
|
341
176
|
}
|
|
342
|
-
QueryOptions.getParams = getParams$
|
|
177
|
+
QueryOptions.getParams = getParams$7;
|
|
343
178
|
|
|
344
179
|
//#endregion
|
|
345
|
-
//#region src/components/
|
|
346
|
-
function getParams$
|
|
347
|
-
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
348
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
180
|
+
//#region src/components/InfiniteQuery.tsx
|
|
181
|
+
function getParams$6({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }) {
|
|
349
182
|
if (paramsType === "object") return FunctionParams.factory({
|
|
350
183
|
data: {
|
|
351
184
|
mode: "object",
|
|
@@ -371,13 +204,7 @@ function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
371
204
|
options: {
|
|
372
205
|
type: `
|
|
373
206
|
{
|
|
374
|
-
query?: Partial<
|
|
375
|
-
TData,
|
|
376
|
-
TError,
|
|
377
|
-
"TData",
|
|
378
|
-
"TQueryData",
|
|
379
|
-
"TQueryKey"
|
|
380
|
-
].join(", ")}>> & { client?: QueryClient },
|
|
207
|
+
query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
381
208
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
382
209
|
}
|
|
383
210
|
`,
|
|
@@ -408,13 +235,7 @@ function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
408
235
|
options: {
|
|
409
236
|
type: `
|
|
410
237
|
{
|
|
411
|
-
query?: Partial<
|
|
412
|
-
TData,
|
|
413
|
-
TError,
|
|
414
|
-
"TData",
|
|
415
|
-
"TQueryData",
|
|
416
|
-
"TQueryKey"
|
|
417
|
-
].join(", ")}>> & { client?: QueryClient },
|
|
238
|
+
query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
418
239
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
419
240
|
}
|
|
420
241
|
`,
|
|
@@ -422,13 +243,17 @@ function getParams$3({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
422
243
|
}
|
|
423
244
|
});
|
|
424
245
|
}
|
|
425
|
-
function
|
|
426
|
-
const
|
|
427
|
-
const
|
|
246
|
+
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, queryParam }) {
|
|
247
|
+
const responseType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
248
|
+
const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
249
|
+
const pageParamType = (queryParam && typeSchemas.queryParams?.name ? `NonNullable<${typeSchemas.queryParams?.name}['${queryParam}']>` : void 0) ?? "number";
|
|
250
|
+
const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
428
251
|
const generics = [
|
|
429
|
-
`
|
|
430
|
-
`
|
|
431
|
-
|
|
252
|
+
`TQueryFnData = ${responseType}`,
|
|
253
|
+
`TError = ${errorType}`,
|
|
254
|
+
"TData = InfiniteData<TQueryFnData>",
|
|
255
|
+
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
256
|
+
`TPageParam = ${pageParamType}`
|
|
432
257
|
];
|
|
433
258
|
const queryKeyParams = QueryKey.getParams({
|
|
434
259
|
pathParamsType,
|
|
@@ -441,12 +266,12 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
441
266
|
typeSchemas,
|
|
442
267
|
paramsCasing
|
|
443
268
|
});
|
|
444
|
-
const params = getParams$
|
|
269
|
+
const params = getParams$6({
|
|
445
270
|
paramsCasing,
|
|
446
271
|
paramsType,
|
|
447
272
|
pathParamsType,
|
|
448
|
-
|
|
449
|
-
|
|
273
|
+
typeSchemas,
|
|
274
|
+
pageParamGeneric: "TPageParam"
|
|
450
275
|
});
|
|
451
276
|
const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
|
|
452
277
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
@@ -464,11 +289,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
464
289
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
465
290
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
466
291
|
|
|
467
|
-
const query =
|
|
292
|
+
const query = useInfiniteQuery({
|
|
468
293
|
...${queryOptions},
|
|
469
294
|
queryKey,
|
|
470
295
|
...queryOptions
|
|
471
|
-
} as unknown as
|
|
296
|
+
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
472
297
|
|
|
473
298
|
query.queryKey = queryKey as TQueryKey
|
|
474
299
|
|
|
@@ -477,11 +302,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
477
302
|
})
|
|
478
303
|
});
|
|
479
304
|
}
|
|
480
|
-
|
|
305
|
+
InfiniteQuery.getParams = getParams$6;
|
|
481
306
|
|
|
482
307
|
//#endregion
|
|
483
308
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
484
|
-
function getParams$
|
|
309
|
+
function getParams$5({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
485
310
|
if (paramsType === "object") return FunctionParams.factory({
|
|
486
311
|
data: {
|
|
487
312
|
mode: "object",
|
|
@@ -537,9 +362,10 @@ function getParams$2({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
|
537
362
|
});
|
|
538
363
|
}
|
|
539
364
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, typeSchemas, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
540
|
-
const
|
|
541
|
-
const
|
|
542
|
-
const
|
|
365
|
+
const queryFnDataType = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
366
|
+
const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
367
|
+
const pageParamType = queryParam && typeSchemas.queryParams?.name ? `NonNullable<${typeSchemas.queryParams?.name}['${queryParam}']>` : "number";
|
|
368
|
+
const params = getParams$5({
|
|
543
369
|
paramsType,
|
|
544
370
|
paramsCasing,
|
|
545
371
|
pathParamsType,
|
|
@@ -582,7 +408,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
582
408
|
params: params.toConstructor(),
|
|
583
409
|
children: `
|
|
584
410
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
585
|
-
return infiniteQueryOptions<${
|
|
411
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
586
412
|
${enabledText}
|
|
587
413
|
queryKey,
|
|
588
414
|
queryFn: async ({ signal, pageParam }) => {
|
|
@@ -605,7 +431,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
605
431
|
params: params.toConstructor(),
|
|
606
432
|
children: `
|
|
607
433
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
608
|
-
return infiniteQueryOptions<${
|
|
434
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
609
435
|
${enabledText}
|
|
610
436
|
queryKey,
|
|
611
437
|
queryFn: async ({ signal }) => {
|
|
@@ -618,10 +444,232 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
618
444
|
})
|
|
619
445
|
});
|
|
620
446
|
}
|
|
621
|
-
InfiniteQueryOptions.getParams = getParams$
|
|
447
|
+
InfiniteQueryOptions.getParams = getParams$5;
|
|
622
448
|
|
|
623
449
|
//#endregion
|
|
624
|
-
//#region src/components/
|
|
450
|
+
//#region src/components/MutationKey.tsx
|
|
451
|
+
function getParams$4({}) {
|
|
452
|
+
return FunctionParams.factory({});
|
|
453
|
+
}
|
|
454
|
+
const getTransformer = ({ operation, casing }) => {
|
|
455
|
+
return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
|
|
456
|
+
};
|
|
457
|
+
function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }) {
|
|
458
|
+
const params = getParams$4({
|
|
459
|
+
pathParamsType,
|
|
460
|
+
typeSchemas
|
|
461
|
+
});
|
|
462
|
+
const keys = transformer({
|
|
463
|
+
operation,
|
|
464
|
+
schemas: typeSchemas,
|
|
465
|
+
casing: paramsCasing
|
|
466
|
+
});
|
|
467
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
468
|
+
name,
|
|
469
|
+
isExportable: true,
|
|
470
|
+
isIndexable: true,
|
|
471
|
+
children: /* @__PURE__ */ jsx(Function.Arrow, {
|
|
472
|
+
name,
|
|
473
|
+
export: true,
|
|
474
|
+
params: params.toConstructor(),
|
|
475
|
+
singleLine: true,
|
|
476
|
+
children: `[${keys.join(", ")}] as const`
|
|
477
|
+
})
|
|
478
|
+
}), /* @__PURE__ */ jsx(File.Source, {
|
|
479
|
+
name: typeName,
|
|
480
|
+
isExportable: true,
|
|
481
|
+
isIndexable: true,
|
|
482
|
+
isTypeOnly: true,
|
|
483
|
+
children: /* @__PURE__ */ jsx(Type, {
|
|
484
|
+
name: typeName,
|
|
485
|
+
export: true,
|
|
486
|
+
children: `ReturnType<typeof ${name}>`
|
|
487
|
+
})
|
|
488
|
+
})] });
|
|
489
|
+
}
|
|
490
|
+
MutationKey.getParams = getParams$4;
|
|
491
|
+
MutationKey.getTransformer = getTransformer;
|
|
492
|
+
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/components/MutationOptions.tsx
|
|
495
|
+
function getParams$3({ typeSchemas }) {
|
|
496
|
+
return FunctionParams.factory({ config: {
|
|
497
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
|
|
498
|
+
default: "{}"
|
|
499
|
+
} });
|
|
500
|
+
}
|
|
501
|
+
function MutationOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
502
|
+
const params = getParams$3({ typeSchemas });
|
|
503
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
504
|
+
const TError = typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error";
|
|
505
|
+
const clientParams = Client.getParams({
|
|
506
|
+
typeSchemas,
|
|
507
|
+
paramsCasing,
|
|
508
|
+
paramsType,
|
|
509
|
+
pathParamsType,
|
|
510
|
+
isConfigurable: true
|
|
511
|
+
});
|
|
512
|
+
const mutationKeyParams = MutationKey.getParams({
|
|
513
|
+
pathParamsType,
|
|
514
|
+
typeSchemas
|
|
515
|
+
});
|
|
516
|
+
const mutationParams = FunctionParams.factory({
|
|
517
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
518
|
+
typed: true,
|
|
519
|
+
casing: paramsCasing
|
|
520
|
+
}),
|
|
521
|
+
data: typeSchemas.request?.name ? {
|
|
522
|
+
type: typeSchemas.request?.name,
|
|
523
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
524
|
+
} : void 0,
|
|
525
|
+
params: typeSchemas.queryParams?.name ? {
|
|
526
|
+
type: typeSchemas.queryParams?.name,
|
|
527
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
528
|
+
} : void 0,
|
|
529
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
530
|
+
type: typeSchemas.headerParams?.name,
|
|
531
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
532
|
+
} : void 0
|
|
533
|
+
});
|
|
534
|
+
const dataParams = FunctionParams.factory({ data: {
|
|
535
|
+
mode: "object",
|
|
536
|
+
children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
|
|
537
|
+
if (value) acc[key] = {
|
|
538
|
+
...value,
|
|
539
|
+
type: void 0
|
|
540
|
+
};
|
|
541
|
+
return acc;
|
|
542
|
+
}, {})
|
|
543
|
+
} });
|
|
544
|
+
const TRequest = mutationParams.toConstructor();
|
|
545
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
546
|
+
name,
|
|
547
|
+
isExportable: true,
|
|
548
|
+
isIndexable: true,
|
|
549
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
550
|
+
name,
|
|
551
|
+
export: true,
|
|
552
|
+
params: params.toConstructor(),
|
|
553
|
+
children: `
|
|
554
|
+
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
555
|
+
return mutationOptions<${TData}, ResponseErrorConfig<${TError}>, ${TRequest ? `{${TRequest}}` : "void"}, typeof mutationKey>({
|
|
556
|
+
mutationKey,
|
|
557
|
+
mutationFn: async(${dataParams.toConstructor()}) => {
|
|
558
|
+
return ${clientName}(${clientParams.toCall()})
|
|
559
|
+
},
|
|
560
|
+
})
|
|
561
|
+
`
|
|
562
|
+
})
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
MutationOptions.getParams = getParams$3;
|
|
566
|
+
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region src/components/Mutation.tsx
|
|
569
|
+
function getParams$2({ paramsCasing, dataReturnType, typeSchemas }) {
|
|
570
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
571
|
+
const TRequest = FunctionParams.factory({
|
|
572
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
573
|
+
typed: true,
|
|
574
|
+
casing: paramsCasing
|
|
575
|
+
}),
|
|
576
|
+
data: typeSchemas.request?.name ? {
|
|
577
|
+
type: typeSchemas.request?.name,
|
|
578
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
579
|
+
} : void 0,
|
|
580
|
+
params: typeSchemas.queryParams?.name ? {
|
|
581
|
+
type: typeSchemas.queryParams?.name,
|
|
582
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
583
|
+
} : void 0,
|
|
584
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
585
|
+
type: typeSchemas.headerParams?.name,
|
|
586
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
587
|
+
} : void 0
|
|
588
|
+
}).toConstructor();
|
|
589
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
590
|
+
const generics = [
|
|
591
|
+
TData,
|
|
592
|
+
TError,
|
|
593
|
+
TRequest ? `{${TRequest}}` : "void",
|
|
594
|
+
"TContext"
|
|
595
|
+
].join(", ");
|
|
596
|
+
return FunctionParams.factory({ options: {
|
|
597
|
+
type: `
|
|
598
|
+
{
|
|
599
|
+
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
600
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
|
|
601
|
+
}
|
|
602
|
+
`,
|
|
603
|
+
default: "{}"
|
|
604
|
+
} });
|
|
605
|
+
}
|
|
606
|
+
function Mutation({ name, mutationOptionsName, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }) {
|
|
607
|
+
const mutationKeyParams = MutationKey.getParams({
|
|
608
|
+
pathParamsType,
|
|
609
|
+
typeSchemas
|
|
610
|
+
});
|
|
611
|
+
const params = getParams$2({
|
|
612
|
+
paramsCasing,
|
|
613
|
+
pathParamsType,
|
|
614
|
+
dataReturnType,
|
|
615
|
+
typeSchemas
|
|
616
|
+
});
|
|
617
|
+
const mutationParams = FunctionParams.factory({
|
|
618
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
619
|
+
typed: true,
|
|
620
|
+
casing: paramsCasing
|
|
621
|
+
}),
|
|
622
|
+
data: typeSchemas.request?.name ? {
|
|
623
|
+
type: typeSchemas.request?.name,
|
|
624
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
625
|
+
} : void 0,
|
|
626
|
+
params: typeSchemas.queryParams?.name ? {
|
|
627
|
+
type: typeSchemas.queryParams?.name,
|
|
628
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
629
|
+
} : void 0,
|
|
630
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
631
|
+
type: typeSchemas.headerParams?.name,
|
|
632
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
633
|
+
} : void 0
|
|
634
|
+
});
|
|
635
|
+
const mutationOptionsParams = MutationOptions.getParams({ typeSchemas });
|
|
636
|
+
const TRequest = mutationParams.toConstructor();
|
|
637
|
+
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
638
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
639
|
+
const returnType = `UseMutationOptions<${[
|
|
640
|
+
TData,
|
|
641
|
+
TError,
|
|
642
|
+
TRequest ? `{${TRequest}}` : "void",
|
|
643
|
+
"TContext"
|
|
644
|
+
].join(", ")}>`;
|
|
645
|
+
const mutationOptions = `${mutationOptionsName}(${mutationOptionsParams.toCall()})`;
|
|
646
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
647
|
+
name,
|
|
648
|
+
isExportable: true,
|
|
649
|
+
isIndexable: true,
|
|
650
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
651
|
+
name,
|
|
652
|
+
export: true,
|
|
653
|
+
params: params.toConstructor(),
|
|
654
|
+
JSDoc: { comments: getComments(operation) },
|
|
655
|
+
generics: ["TContext"],
|
|
656
|
+
children: `
|
|
657
|
+
const { mutation = {}, client: config = {} } = options ?? {}
|
|
658
|
+
const { client: queryClient, ...mutationOptions } = mutation;
|
|
659
|
+
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
660
|
+
|
|
661
|
+
return useMutation({
|
|
662
|
+
...${mutationOptions},
|
|
663
|
+
mutationKey,
|
|
664
|
+
...mutationOptions
|
|
665
|
+
} as unknown as UseMutationOptions, queryClient) as ${returnType}
|
|
666
|
+
`
|
|
667
|
+
})
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region src/components/Query.tsx
|
|
625
673
|
function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
|
|
626
674
|
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
627
675
|
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
@@ -650,12 +698,12 @@ function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
650
698
|
options: {
|
|
651
699
|
type: `
|
|
652
700
|
{
|
|
653
|
-
query?: Partial<
|
|
701
|
+
query?: Partial<QueryObserverOptions<${[
|
|
654
702
|
TData,
|
|
655
703
|
TError,
|
|
704
|
+
"TData",
|
|
656
705
|
"TQueryData",
|
|
657
|
-
"TQueryKey"
|
|
658
|
-
"TQueryData"
|
|
706
|
+
"TQueryKey"
|
|
659
707
|
].join(", ")}>> & { client?: QueryClient },
|
|
660
708
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
661
709
|
}
|
|
@@ -687,12 +735,12 @@ function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
687
735
|
options: {
|
|
688
736
|
type: `
|
|
689
737
|
{
|
|
690
|
-
query?: Partial<
|
|
738
|
+
query?: Partial<QueryObserverOptions<${[
|
|
691
739
|
TData,
|
|
692
740
|
TError,
|
|
741
|
+
"TData",
|
|
693
742
|
"TQueryData",
|
|
694
|
-
"TQueryKey"
|
|
695
|
-
"TQueryData"
|
|
743
|
+
"TQueryKey"
|
|
696
744
|
].join(", ")}>> & { client?: QueryClient },
|
|
697
745
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
|
|
698
746
|
}
|
|
@@ -701,11 +749,11 @@ function getParams$1({ paramsType, paramsCasing, pathParamsType, dataReturnType,
|
|
|
701
749
|
}
|
|
702
750
|
});
|
|
703
751
|
}
|
|
704
|
-
function
|
|
752
|
+
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation }) {
|
|
705
753
|
const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
|
|
706
|
-
const returnType = `
|
|
754
|
+
const returnType = `UseQueryResult<${["TData", `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`].join(", ")}> & { queryKey: TQueryKey }`;
|
|
707
755
|
const generics = [
|
|
708
|
-
`TData =
|
|
756
|
+
`TData = ${TData}`,
|
|
709
757
|
`TQueryData = ${TData}`,
|
|
710
758
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
711
759
|
];
|
|
@@ -743,11 +791,11 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
743
791
|
const { client: queryClient, ...queryOptions } = queryConfig
|
|
744
792
|
const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
745
793
|
|
|
746
|
-
const query =
|
|
794
|
+
const query = useQuery({
|
|
747
795
|
...${queryOptions},
|
|
748
796
|
queryKey,
|
|
749
797
|
...queryOptions
|
|
750
|
-
} as unknown as
|
|
798
|
+
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
751
799
|
|
|
752
800
|
query.queryKey = queryKey as TQueryKey
|
|
753
801
|
|
|
@@ -756,7 +804,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
756
804
|
})
|
|
757
805
|
});
|
|
758
806
|
}
|
|
759
|
-
|
|
807
|
+
Query.getParams = getParams$1;
|
|
760
808
|
|
|
761
809
|
//#endregion
|
|
762
810
|
//#region src/components/SuspenseQuery.tsx
|
|
@@ -898,5 +946,5 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
898
946
|
SuspenseQuery.getParams = getParams;
|
|
899
947
|
|
|
900
948
|
//#endregion
|
|
901
|
-
export { InfiniteQuery, InfiniteQueryOptions, Mutation, MutationKey, Query, QueryKey, QueryOptions, SuspenseQuery };
|
|
902
|
-
//# sourceMappingURL=components-
|
|
949
|
+
export { InfiniteQuery, InfiniteQueryOptions, Mutation, MutationKey, MutationOptions, Query, QueryKey, QueryOptions, SuspenseQuery };
|
|
950
|
+
//# sourceMappingURL=components-Dz_s6t75.js.map
|