@refinedev/core 4.7.2 → 4.8.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/CHANGELOG.md +33 -0
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/auditLog/useLogList/index.d.ts +11 -5
- package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
- package/dist/hooks/data/useCustom.d.ts +6 -5
- package/dist/hooks/data/useCustom.d.ts.map +1 -1
- package/dist/hooks/data/useInfiniteList.d.ts +6 -5
- package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.ts +6 -5
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/data/useMany.d.ts +6 -5
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts +6 -5
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/form/useForm.d.ts +6 -6
- package/dist/hooks/form/useForm.d.ts.map +1 -1
- package/dist/hooks/show/useShow.d.ts +9 -4
- package/dist/hooks/show/useShow.d.ts.map +1 -1
- package/dist/hooks/useSelect/index.d.ts +19 -6
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/hooks/useTable/index.d.ts +3 -3
- package/dist/hooks/useTable/index.d.ts.map +1 -1
- package/dist/iife/index.js +5 -5
- package/dist/iife/index.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/auditLog/useLogList/index.ts +17 -7
- package/src/hooks/data/useCustom.ts +25 -11
- package/src/hooks/data/useInfiniteList.ts +23 -11
- package/src/hooks/data/useList.ts +20 -9
- package/src/hooks/data/useMany.ts +35 -8
- package/src/hooks/data/useOne.ts +21 -8
- package/src/hooks/form/useForm.ts +18 -8
- package/src/hooks/show/useShow.ts +22 -6
- package/src/hooks/useSelect/index.ts +35 -9
- package/src/hooks/useTable/index.ts +19 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -7,34 +7,44 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import { AuditLogContext } from "@contexts/auditLog";
|
|
9
9
|
import { queryKeys } from "@definitions/helpers";
|
|
10
|
-
import { HttpError,
|
|
10
|
+
import { HttpError, MetaQuery } from "../../../interfaces";
|
|
11
11
|
|
|
12
|
-
export type UseLogProps<
|
|
12
|
+
export type UseLogProps<TQueryFnData, TError, TData> = {
|
|
13
13
|
resource: string;
|
|
14
14
|
action?: string;
|
|
15
15
|
meta?: Record<number | string, any>;
|
|
16
16
|
author?: Record<number | string, any>;
|
|
17
|
-
queryOptions?: UseQueryOptions<
|
|
18
|
-
metaData?:
|
|
17
|
+
queryOptions?: UseQueryOptions<TQueryFnData, TError, TData>;
|
|
18
|
+
metaData?: MetaQuery;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* useLogList is used to get and filter audit logs.
|
|
23
|
+
*
|
|
23
24
|
* @see {@link https://refine.dev/docs/core/hooks/audit-log/useLogList} for more details.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam TQueryFnData - Result data returned by the query function.
|
|
27
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
28
|
+
* @typeParam TData - Result data returned by the `select` function. Defaults to `TQueryFnData`
|
|
29
|
+
*
|
|
24
30
|
*/
|
|
25
|
-
export const useLogList = <
|
|
31
|
+
export const useLogList = <
|
|
32
|
+
TQueryFnData = any,
|
|
33
|
+
TError extends HttpError = HttpError,
|
|
34
|
+
TData = TQueryFnData,
|
|
35
|
+
>({
|
|
26
36
|
resource,
|
|
27
37
|
action,
|
|
28
38
|
meta,
|
|
29
39
|
author,
|
|
30
40
|
metaData,
|
|
31
41
|
queryOptions,
|
|
32
|
-
}: UseLogProps<
|
|
42
|
+
}: UseLogProps<TQueryFnData, TError, TData>): UseQueryResult<TData> => {
|
|
33
43
|
const { get } = useContext(AuditLogContext);
|
|
34
44
|
|
|
35
45
|
const queryKey = queryKeys(resource, undefined, metaData);
|
|
36
46
|
|
|
37
|
-
const queryResponse = useQuery<
|
|
47
|
+
const queryResponse = useQuery<TQueryFnData, TError, TData>(
|
|
38
48
|
queryKey.logList(meta),
|
|
39
49
|
() =>
|
|
40
50
|
get?.({
|
|
@@ -34,7 +34,7 @@ interface UseCustomConfig<TQuery, TPayload> {
|
|
|
34
34
|
headers?: {};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export type UseCustomProps<
|
|
37
|
+
export type UseCustomProps<TQueryFnData, TError, TQuery, TPayload, TData> = {
|
|
38
38
|
/**
|
|
39
39
|
* request's URL
|
|
40
40
|
*/
|
|
@@ -50,7 +50,11 @@ export type UseCustomProps<TData, TError, TQuery, TPayload> = {
|
|
|
50
50
|
/**
|
|
51
51
|
* react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options"
|
|
52
52
|
*/
|
|
53
|
-
queryOptions?: UseQueryOptions<
|
|
53
|
+
queryOptions?: UseQueryOptions<
|
|
54
|
+
CustomResponse<TQueryFnData>,
|
|
55
|
+
TError,
|
|
56
|
+
CustomResponse<TData>
|
|
57
|
+
>;
|
|
54
58
|
/**
|
|
55
59
|
* meta data for `dataProvider`
|
|
56
60
|
*/
|
|
@@ -77,17 +81,20 @@ export type UseCustomProps<TData, TError, TQuery, TPayload> = {
|
|
|
77
81
|
*
|
|
78
82
|
* @see {@link https://refine.dev/docs/core/hooks/data/useCustom} for more details.
|
|
79
83
|
*
|
|
80
|
-
* @typeParam
|
|
81
|
-
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/core/interfaceReferences#httperror `HttpError`}
|
|
84
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
85
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
82
86
|
* @typeParam TQuery - Values for query params
|
|
83
87
|
* @typeParam TPayload - Values for params
|
|
88
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
84
89
|
*
|
|
85
90
|
*/
|
|
91
|
+
|
|
86
92
|
export const useCustom = <
|
|
87
|
-
|
|
93
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
88
94
|
TError extends HttpError = HttpError,
|
|
89
95
|
TQuery = unknown,
|
|
90
96
|
TPayload = unknown,
|
|
97
|
+
TData extends BaseRecord = TQueryFnData,
|
|
91
98
|
>({
|
|
92
99
|
url,
|
|
93
100
|
method,
|
|
@@ -98,10 +105,13 @@ export const useCustom = <
|
|
|
98
105
|
meta,
|
|
99
106
|
metaData,
|
|
100
107
|
dataProviderName,
|
|
101
|
-
}: UseCustomProps<
|
|
102
|
-
|
|
103
|
-
TError
|
|
104
|
-
|
|
108
|
+
}: UseCustomProps<
|
|
109
|
+
TQueryFnData,
|
|
110
|
+
TError,
|
|
111
|
+
TQuery,
|
|
112
|
+
TPayload,
|
|
113
|
+
TData
|
|
114
|
+
>): QueryObserverResult<CustomResponse<TData>, TError> => {
|
|
105
115
|
const dataProvider = useDataProvider();
|
|
106
116
|
|
|
107
117
|
const { custom } = dataProvider(dataProviderName);
|
|
@@ -113,7 +123,11 @@ export const useCustom = <
|
|
|
113
123
|
const handleNotification = useHandleNotification();
|
|
114
124
|
|
|
115
125
|
if (custom) {
|
|
116
|
-
const queryResponse = useQuery<
|
|
126
|
+
const queryResponse = useQuery<
|
|
127
|
+
CustomResponse<TQueryFnData>,
|
|
128
|
+
TError,
|
|
129
|
+
CustomResponse<TData>
|
|
130
|
+
>({
|
|
117
131
|
queryKey: [
|
|
118
132
|
dataProviderName,
|
|
119
133
|
"custom",
|
|
@@ -122,7 +136,7 @@ export const useCustom = <
|
|
|
122
136
|
{ ...config, ...(pickNotDeprecated(meta, metaData) || {}) },
|
|
123
137
|
],
|
|
124
138
|
queryFn: ({ queryKey, pageParam, signal }) =>
|
|
125
|
-
custom<
|
|
139
|
+
custom<TQueryFnData>({
|
|
126
140
|
url,
|
|
127
141
|
method,
|
|
128
142
|
...config,
|
|
@@ -80,7 +80,7 @@ type BaseInfiniteListProps = {
|
|
|
80
80
|
dataProviderName?: string;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
export type UseInfiniteListProps<
|
|
83
|
+
export type UseInfiniteListProps<TQueryFnData, TError, TData> = {
|
|
84
84
|
/**
|
|
85
85
|
* Resource name for API data interactions
|
|
86
86
|
*/
|
|
@@ -88,7 +88,11 @@ export type UseInfiniteListProps<TData, TError> = {
|
|
|
88
88
|
/**
|
|
89
89
|
* Tanstack Query's [useInfiniteQuery](https://tanstack.com/query/v4/docs/react/reference/useInfiniteQuery) options
|
|
90
90
|
*/
|
|
91
|
-
queryOptions?: UseInfiniteQueryOptions<
|
|
91
|
+
queryOptions?: UseInfiniteQueryOptions<
|
|
92
|
+
GetListResponse<TQueryFnData>,
|
|
93
|
+
TError,
|
|
94
|
+
GetListResponse<TData>
|
|
95
|
+
>;
|
|
92
96
|
} & BaseInfiniteListProps &
|
|
93
97
|
SuccessErrorNotification<
|
|
94
98
|
InfiniteData<GetListResponse<TData>>,
|
|
@@ -104,13 +108,16 @@ export type UseInfiniteListProps<TData, TError> = {
|
|
|
104
108
|
*
|
|
105
109
|
* @see {@link https://refine.dev/docs/core/hooks/data/useInfiniteList} for more details.
|
|
106
110
|
*
|
|
107
|
-
* @typeParam
|
|
108
|
-
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/core/interfaceReferences#httperror `HttpError`}
|
|
111
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
112
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
113
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
109
114
|
*
|
|
110
115
|
*/
|
|
116
|
+
|
|
111
117
|
export const useInfiniteList = <
|
|
112
|
-
|
|
118
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
113
119
|
TError extends HttpError = HttpError,
|
|
120
|
+
TData extends BaseRecord = TQueryFnData,
|
|
114
121
|
>({
|
|
115
122
|
resource,
|
|
116
123
|
config,
|
|
@@ -127,10 +134,11 @@ export const useInfiniteList = <
|
|
|
127
134
|
onLiveEvent,
|
|
128
135
|
liveParams,
|
|
129
136
|
dataProviderName,
|
|
130
|
-
}: UseInfiniteListProps<
|
|
131
|
-
|
|
132
|
-
TError
|
|
133
|
-
|
|
137
|
+
}: UseInfiniteListProps<
|
|
138
|
+
TQueryFnData,
|
|
139
|
+
TError,
|
|
140
|
+
TData
|
|
141
|
+
>): InfiniteQueryObserverResult<GetListResponse<TData>, TError> => {
|
|
134
142
|
const { resources } = useResource();
|
|
135
143
|
const dataProvider = useDataProvider();
|
|
136
144
|
const translate = useTranslate();
|
|
@@ -203,7 +211,11 @@ export const useInfiniteList = <
|
|
|
203
211
|
onLiveEvent,
|
|
204
212
|
});
|
|
205
213
|
|
|
206
|
-
const queryResponse = useInfiniteQuery<
|
|
214
|
+
const queryResponse = useInfiniteQuery<
|
|
215
|
+
GetListResponse<TQueryFnData>,
|
|
216
|
+
TError,
|
|
217
|
+
GetListResponse<TData>
|
|
218
|
+
>(
|
|
207
219
|
queryKey.list({
|
|
208
220
|
filters: prefferedFilters,
|
|
209
221
|
hasPagination: isServerPagination,
|
|
@@ -223,7 +235,7 @@ export const useInfiniteList = <
|
|
|
223
235
|
current: pageParam,
|
|
224
236
|
};
|
|
225
237
|
|
|
226
|
-
return getList<
|
|
238
|
+
return getList<TQueryFnData>({
|
|
227
239
|
resource,
|
|
228
240
|
pagination: paginationProperties,
|
|
229
241
|
hasPagination: isServerPagination,
|
|
@@ -77,7 +77,7 @@ export type BaseListProps = {
|
|
|
77
77
|
dataProviderName?: string;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
export type UseListProps<
|
|
80
|
+
export type UseListProps<TQueryFnData, TError, TData> = {
|
|
81
81
|
/**
|
|
82
82
|
* Resource name for API data interactions
|
|
83
83
|
*/
|
|
@@ -86,7 +86,11 @@ export type UseListProps<TData, TError> = {
|
|
|
86
86
|
/**
|
|
87
87
|
* Tanstack Query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
|
|
88
88
|
*/
|
|
89
|
-
queryOptions?: UseQueryOptions<
|
|
89
|
+
queryOptions?: UseQueryOptions<
|
|
90
|
+
GetListResponse<TQueryFnData>,
|
|
91
|
+
TError,
|
|
92
|
+
GetListResponse<TData>
|
|
93
|
+
>;
|
|
90
94
|
} & BaseListProps &
|
|
91
95
|
SuccessErrorNotification<
|
|
92
96
|
GetListResponse<TData>,
|
|
@@ -102,13 +106,16 @@ export type UseListProps<TData, TError> = {
|
|
|
102
106
|
*
|
|
103
107
|
* @see {@link https://refine.dev/docs/core/hooks/data/useList} for more details.
|
|
104
108
|
*
|
|
105
|
-
* @typeParam
|
|
106
|
-
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/core/interfaceReferences#httperror `HttpError`}
|
|
109
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
110
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
111
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
107
112
|
*
|
|
108
113
|
*/
|
|
114
|
+
|
|
109
115
|
export const useList = <
|
|
110
|
-
|
|
116
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
111
117
|
TError extends HttpError = HttpError,
|
|
118
|
+
TData extends BaseRecord = TQueryFnData,
|
|
112
119
|
>({
|
|
113
120
|
resource,
|
|
114
121
|
config,
|
|
@@ -125,7 +132,7 @@ export const useList = <
|
|
|
125
132
|
onLiveEvent,
|
|
126
133
|
liveParams,
|
|
127
134
|
dataProviderName,
|
|
128
|
-
}: UseListProps<
|
|
135
|
+
}: UseListProps<TQueryFnData, TError, TData>): QueryObserverResult<
|
|
129
136
|
GetListResponse<TData>,
|
|
130
137
|
TError
|
|
131
138
|
> => {
|
|
@@ -201,7 +208,11 @@ export const useList = <
|
|
|
201
208
|
onLiveEvent,
|
|
202
209
|
});
|
|
203
210
|
|
|
204
|
-
const queryResponse = useQuery<
|
|
211
|
+
const queryResponse = useQuery<
|
|
212
|
+
GetListResponse<TQueryFnData>,
|
|
213
|
+
TError,
|
|
214
|
+
GetListResponse<TData>
|
|
215
|
+
>(
|
|
205
216
|
queryKey.list({
|
|
206
217
|
filters: prefferedFilters,
|
|
207
218
|
hasPagination: isServerPagination,
|
|
@@ -216,7 +227,7 @@ export const useList = <
|
|
|
216
227
|
}),
|
|
217
228
|
}),
|
|
218
229
|
({ queryKey, pageParam, signal }) => {
|
|
219
|
-
return getList<
|
|
230
|
+
return getList<TQueryFnData>({
|
|
220
231
|
resource: resource!,
|
|
221
232
|
pagination: prefferedPagination,
|
|
222
233
|
hasPagination: isServerPagination,
|
|
@@ -267,7 +278,7 @@ export const useList = <
|
|
|
267
278
|
return queryOptions?.select?.(data);
|
|
268
279
|
}
|
|
269
280
|
|
|
270
|
-
return data
|
|
281
|
+
return data as unknown as GetListResponse<TData>;
|
|
271
282
|
},
|
|
272
283
|
onSuccess: (data) => {
|
|
273
284
|
queryOptions?.onSuccess?.(data);
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
useActiveAuthProvider,
|
|
30
30
|
} from "@definitions/helpers";
|
|
31
31
|
|
|
32
|
-
export type UseManyProps<
|
|
32
|
+
export type UseManyProps<TQueryFnData, TError, TData> = {
|
|
33
33
|
/**
|
|
34
34
|
* Resource name for API data interactions
|
|
35
35
|
*/
|
|
@@ -42,7 +42,11 @@ export type UseManyProps<TData, TError> = {
|
|
|
42
42
|
/**
|
|
43
43
|
* react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
|
|
44
44
|
*/
|
|
45
|
-
queryOptions?: UseQueryOptions<
|
|
45
|
+
queryOptions?: UseQueryOptions<
|
|
46
|
+
GetManyResponse<TQueryFnData>,
|
|
47
|
+
TError,
|
|
48
|
+
GetManyResponse<TData>
|
|
49
|
+
>;
|
|
46
50
|
/**
|
|
47
51
|
* Metadata query for `dataProvider`,
|
|
48
52
|
*/
|
|
@@ -67,13 +71,16 @@ export type UseManyProps<TData, TError> = {
|
|
|
67
71
|
*
|
|
68
72
|
* @see {@link https://refine.dev/docs/core/hooks/data/useMany} for more details.
|
|
69
73
|
*
|
|
70
|
-
* @typeParam
|
|
71
|
-
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/core/interfaceReferences#httperror `HttpError`}
|
|
74
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
75
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
76
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
72
77
|
*
|
|
73
78
|
*/
|
|
79
|
+
|
|
74
80
|
export const useMany = <
|
|
75
|
-
|
|
81
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
76
82
|
TError extends HttpError = HttpError,
|
|
83
|
+
TData extends BaseRecord = TQueryFnData,
|
|
77
84
|
>({
|
|
78
85
|
resource,
|
|
79
86
|
ids,
|
|
@@ -86,7 +93,7 @@ export const useMany = <
|
|
|
86
93
|
onLiveEvent,
|
|
87
94
|
liveParams,
|
|
88
95
|
dataProviderName,
|
|
89
|
-
}: UseManyProps<
|
|
96
|
+
}: UseManyProps<TQueryFnData, TError, TData>): QueryObserverResult<
|
|
90
97
|
GetManyResponse<TData>
|
|
91
98
|
> => {
|
|
92
99
|
const { resources } = useResource();
|
|
@@ -128,13 +135,25 @@ export const useMany = <
|
|
|
128
135
|
onLiveEvent,
|
|
129
136
|
});
|
|
130
137
|
|
|
131
|
-
const queryResponse = useQuery<
|
|
138
|
+
const queryResponse = useQuery<
|
|
139
|
+
GetManyResponse<TQueryFnData>,
|
|
140
|
+
TError,
|
|
141
|
+
GetManyResponse<TData>
|
|
142
|
+
>(
|
|
132
143
|
queryKey.many(ids),
|
|
133
144
|
({ queryKey, pageParam, signal }) => {
|
|
134
145
|
if (getMany) {
|
|
135
146
|
return getMany({
|
|
136
147
|
resource,
|
|
137
148
|
ids,
|
|
149
|
+
meta: {
|
|
150
|
+
...(pickNotDeprecated(meta, metaData) || {}),
|
|
151
|
+
queryContext: {
|
|
152
|
+
queryKey,
|
|
153
|
+
pageParam,
|
|
154
|
+
signal,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
138
157
|
metaData: {
|
|
139
158
|
...(pickNotDeprecated(meta, metaData) || {}),
|
|
140
159
|
queryContext: {
|
|
@@ -147,9 +166,17 @@ export const useMany = <
|
|
|
147
166
|
} else {
|
|
148
167
|
return handleMultiple(
|
|
149
168
|
ids.map((id) =>
|
|
150
|
-
getOne<
|
|
169
|
+
getOne<TQueryFnData>({
|
|
151
170
|
resource,
|
|
152
171
|
id,
|
|
172
|
+
meta: {
|
|
173
|
+
...(pickNotDeprecated(meta, metaData) || {}),
|
|
174
|
+
queryContext: {
|
|
175
|
+
queryKey,
|
|
176
|
+
pageParam,
|
|
177
|
+
signal,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
153
180
|
metaData: {
|
|
154
181
|
...(pickNotDeprecated(meta, metaData) || {}),
|
|
155
182
|
queryContext: {
|
package/src/hooks/data/useOne.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
useActiveAuthProvider,
|
|
30
30
|
} from "@definitions";
|
|
31
31
|
|
|
32
|
-
export type UseOneProps<
|
|
32
|
+
export type UseOneProps<TQueryFnData, TError, TData> = {
|
|
33
33
|
/**
|
|
34
34
|
* Resource name for API data interactions
|
|
35
35
|
*/
|
|
@@ -42,7 +42,11 @@ export type UseOneProps<TData, TError> = {
|
|
|
42
42
|
/**
|
|
43
43
|
* react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
|
|
44
44
|
*/
|
|
45
|
-
queryOptions?: UseQueryOptions<
|
|
45
|
+
queryOptions?: UseQueryOptions<
|
|
46
|
+
GetOneResponse<TQueryFnData>,
|
|
47
|
+
TError,
|
|
48
|
+
GetOneResponse<TData>
|
|
49
|
+
>;
|
|
46
50
|
/**
|
|
47
51
|
* Metadata query for `dataProvider`,
|
|
48
52
|
*/
|
|
@@ -71,13 +75,16 @@ export type UseOneProps<TData, TError> = {
|
|
|
71
75
|
*
|
|
72
76
|
* @see {@link https://refine.dev/docs/core/hooks/data/useOne} for more details.
|
|
73
77
|
*
|
|
74
|
-
* @typeParam
|
|
75
|
-
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-
|
|
78
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
79
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
80
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
76
81
|
*
|
|
77
82
|
*/
|
|
83
|
+
|
|
78
84
|
export const useOne = <
|
|
79
|
-
|
|
85
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
80
86
|
TError extends HttpError = HttpError,
|
|
87
|
+
TData extends BaseRecord = TQueryFnData,
|
|
81
88
|
>({
|
|
82
89
|
resource,
|
|
83
90
|
id,
|
|
@@ -90,7 +97,9 @@ export const useOne = <
|
|
|
90
97
|
onLiveEvent,
|
|
91
98
|
liveParams,
|
|
92
99
|
dataProviderName,
|
|
93
|
-
}: UseOneProps<
|
|
100
|
+
}: UseOneProps<TQueryFnData, TError, TData>): QueryObserverResult<
|
|
101
|
+
GetOneResponse<TData>
|
|
102
|
+
> => {
|
|
94
103
|
const { resources } = useResource();
|
|
95
104
|
const dataProvider = useDataProvider();
|
|
96
105
|
const queryKey = queryKeys(
|
|
@@ -130,10 +139,14 @@ export const useOne = <
|
|
|
130
139
|
onLiveEvent,
|
|
131
140
|
});
|
|
132
141
|
|
|
133
|
-
const queryResponse = useQuery<
|
|
142
|
+
const queryResponse = useQuery<
|
|
143
|
+
GetOneResponse<TQueryFnData>,
|
|
144
|
+
TError,
|
|
145
|
+
GetOneResponse<TData>
|
|
146
|
+
>(
|
|
134
147
|
queryKey.detail(id),
|
|
135
148
|
({ queryKey, pageParam, signal }) =>
|
|
136
|
-
getOne<
|
|
149
|
+
getOne<TQueryFnData>({
|
|
137
150
|
resource: resource!,
|
|
138
151
|
id: id!,
|
|
139
152
|
meta: {
|
|
@@ -56,6 +56,7 @@ type ActionFormProps<
|
|
|
56
56
|
TData extends BaseRecord = BaseRecord,
|
|
57
57
|
TError extends HttpError = HttpError,
|
|
58
58
|
TVariables = {},
|
|
59
|
+
TSelectData extends BaseRecord = TData,
|
|
59
60
|
> = {
|
|
60
61
|
/**
|
|
61
62
|
* Resource name for API data interactions
|
|
@@ -121,7 +122,11 @@ type ActionFormProps<
|
|
|
121
122
|
/**
|
|
122
123
|
* react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options of useOne hook used while in edit mode.
|
|
123
124
|
*/
|
|
124
|
-
queryOptions?: UseQueryOptions<
|
|
125
|
+
queryOptions?: UseQueryOptions<
|
|
126
|
+
GetOneResponse<TData>,
|
|
127
|
+
TError,
|
|
128
|
+
GetOneResponse<TSelectData>
|
|
129
|
+
>;
|
|
125
130
|
/**
|
|
126
131
|
* react-query's [useMutation](https://tanstack.com/query/v4/docs/reference/useMutation) options of useCreate hook used while submitting in create and clone modes.
|
|
127
132
|
*/
|
|
@@ -150,17 +155,20 @@ export type UseFormProps<
|
|
|
150
155
|
TData extends BaseRecord = BaseRecord,
|
|
151
156
|
TError extends HttpError = HttpError,
|
|
152
157
|
TVariables = {},
|
|
153
|
-
|
|
158
|
+
TSelectData extends BaseRecord = TData,
|
|
159
|
+
> = ActionFormProps<TData, TError, TVariables, TSelectData> &
|
|
160
|
+
ActionParams &
|
|
161
|
+
LiveModeProps;
|
|
154
162
|
|
|
155
163
|
export type UseFormReturnType<
|
|
156
164
|
TData extends BaseRecord = BaseRecord,
|
|
157
165
|
TError extends HttpError = HttpError,
|
|
158
166
|
TVariables = {},
|
|
167
|
+
TSelectData extends BaseRecord = TData,
|
|
159
168
|
> = {
|
|
160
169
|
id?: BaseKey;
|
|
161
170
|
setId: Dispatch<SetStateAction<BaseKey | undefined>>;
|
|
162
|
-
|
|
163
|
-
queryResult?: QueryObserverResult<GetOneResponse<TData>>;
|
|
171
|
+
queryResult?: QueryObserverResult<GetOneResponse<TSelectData>>;
|
|
164
172
|
mutationResult:
|
|
165
173
|
| UseUpdateReturnType<TData, TError, TVariables>
|
|
166
174
|
| UseCreateReturnType<TData, TError, TVariables>;
|
|
@@ -190,6 +198,7 @@ export const useForm = <
|
|
|
190
198
|
TData extends BaseRecord = BaseRecord,
|
|
191
199
|
TError extends HttpError = HttpError,
|
|
192
200
|
TVariables = {},
|
|
201
|
+
TSelectData extends BaseRecord = TData,
|
|
193
202
|
>({
|
|
194
203
|
resource: resourceFromProps,
|
|
195
204
|
action: actionFromProps,
|
|
@@ -211,11 +220,12 @@ export const useForm = <
|
|
|
211
220
|
queryOptions,
|
|
212
221
|
createMutationOptions,
|
|
213
222
|
updateMutationOptions,
|
|
214
|
-
}: UseFormProps<
|
|
223
|
+
}: UseFormProps<
|
|
215
224
|
TData,
|
|
216
225
|
TError,
|
|
217
|
-
TVariables
|
|
218
|
-
|
|
226
|
+
TVariables,
|
|
227
|
+
TSelectData
|
|
228
|
+
> = {}): UseFormReturnType<TData, TError, TVariables, TSelectData> => {
|
|
219
229
|
const { options } = useRefineContext();
|
|
220
230
|
const { resources } = useResource();
|
|
221
231
|
const routerType = useRouterType();
|
|
@@ -349,7 +359,7 @@ export const useForm = <
|
|
|
349
359
|
|
|
350
360
|
const enableQuery = id !== undefined && (isEdit || isClone);
|
|
351
361
|
|
|
352
|
-
const queryResult = useOne<TData>({
|
|
362
|
+
const queryResult = useOne<TData, TError, TSelectData>({
|
|
353
363
|
resource: resource?.name,
|
|
354
364
|
id: id ?? "",
|
|
355
365
|
queryOptions: {
|
|
@@ -29,8 +29,9 @@ export type useShowReturnType<TData extends BaseRecord = BaseRecord> = {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export type useShowProps<
|
|
32
|
-
|
|
32
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
33
33
|
TError extends HttpError = HttpError,
|
|
34
|
+
TData extends BaseRecord = TQueryFnData,
|
|
34
35
|
> = {
|
|
35
36
|
/**
|
|
36
37
|
* Resource name for API data interactions
|
|
@@ -45,7 +46,11 @@ export type useShowProps<
|
|
|
45
46
|
/**
|
|
46
47
|
* react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
|
|
47
48
|
*/
|
|
48
|
-
queryOptions?: UseQueryOptions<
|
|
49
|
+
queryOptions?: UseQueryOptions<
|
|
50
|
+
GetOneResponse<TQueryFnData>,
|
|
51
|
+
TError,
|
|
52
|
+
GetOneResponse<TData>
|
|
53
|
+
>;
|
|
49
54
|
/**
|
|
50
55
|
* Additional meta data to pass to the data provider's `getOne`
|
|
51
56
|
*/
|
|
@@ -70,13 +75,20 @@ export type useShowProps<
|
|
|
70
75
|
/**
|
|
71
76
|
* `useShow` hook allows you to fetch the desired record.
|
|
72
77
|
* It uses `getOne` method as query function from the dataProvider that is
|
|
73
|
-
* passed to {@link https://refine.dev/docs/api-
|
|
78
|
+
* passed to {@link https://refine.dev/docs/api-reference/core/components/refine-config/ `<Refine>`}.
|
|
74
79
|
*
|
|
75
80
|
* @see {@link https://refine.dev/docs/core/hooks/show/useShow} for more details.
|
|
81
|
+
*
|
|
82
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
83
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
84
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
85
|
+
*
|
|
76
86
|
*/
|
|
87
|
+
|
|
77
88
|
export const useShow = <
|
|
78
|
-
|
|
89
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
79
90
|
TError extends HttpError = HttpError,
|
|
91
|
+
TData extends BaseRecord = TQueryFnData,
|
|
80
92
|
>({
|
|
81
93
|
resource: resourceFromProp,
|
|
82
94
|
id,
|
|
@@ -88,7 +100,11 @@ export const useShow = <
|
|
|
88
100
|
onLiveEvent,
|
|
89
101
|
dataProviderName,
|
|
90
102
|
queryOptions,
|
|
91
|
-
}: useShowProps<
|
|
103
|
+
}: useShowProps<
|
|
104
|
+
TQueryFnData,
|
|
105
|
+
TError,
|
|
106
|
+
TData
|
|
107
|
+
> = {}): useShowReturnType<TData> => {
|
|
92
108
|
const routerType = useRouterType();
|
|
93
109
|
const { resources } = useResource();
|
|
94
110
|
const { useParams } = useRouterContext();
|
|
@@ -170,7 +186,7 @@ export const useShow = <
|
|
|
170
186
|
`See https://refine.dev/docs/api-reference/core/hooks/show/useShow/#resource`,
|
|
171
187
|
);
|
|
172
188
|
|
|
173
|
-
const queryResult = useOne<
|
|
189
|
+
const queryResult = useOne<TQueryFnData, TError, TData>({
|
|
174
190
|
resource: resource?.name,
|
|
175
191
|
id: showId ?? "",
|
|
176
192
|
queryOptions: {
|