@svadmin/core 0.25.3 → 0.25.5
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/package.json +2 -2
- package/src/query-hooks.svelte.ts +23 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/core",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.5",
|
|
4
4
|
"author": "zuohuadong",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"svelte": "^5.0.0",
|
|
25
|
-
"@tanstack/svelte-query": "^6.
|
|
25
|
+
"@tanstack/svelte-query": "^6.1.29"
|
|
26
26
|
},
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
@@ -43,6 +43,20 @@ function extendQuery<Q extends object, E extends Record<string, unknown>>(
|
|
|
43
43
|
|
|
44
44
|
export type MaybeGetter<T> = T | (() => T);
|
|
45
45
|
|
|
46
|
+
function cloneQueryKeyPart<T>(value: T): T {
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
return value.map(item => cloneQueryKeyPart(item)) as T;
|
|
49
|
+
}
|
|
50
|
+
if (value && typeof value === 'object') {
|
|
51
|
+
const proto = Object.getPrototypeOf(value);
|
|
52
|
+
if (proto !== Object.prototype && proto !== null) return value;
|
|
53
|
+
return Object.fromEntries(
|
|
54
|
+
Object.entries(value as Record<string, unknown>).map(([key, entry]) => [key, cloneQueryKeyPart(entry)])
|
|
55
|
+
) as T;
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
export interface UseListOptions<TData extends BaseRecord = BaseRecord, TError = HttpError> {
|
|
47
61
|
resource?: KnownResources;
|
|
48
62
|
pagination?: Pagination;
|
|
@@ -71,15 +85,19 @@ export function useList<TData extends BaseRecord = BaseRecord, TError = HttpErro
|
|
|
71
85
|
const resource = getResource();
|
|
72
86
|
const provider = getDataProviderForResource(resource, opts.dataProviderName);
|
|
73
87
|
const queryOptions = opts.queryOptions;
|
|
88
|
+
const pagination = cloneQueryKeyPart(opts.pagination);
|
|
89
|
+
const sorters = cloneQueryKeyPart(opts.sorters);
|
|
90
|
+
const filters = cloneQueryKeyPart(opts.filters);
|
|
91
|
+
const meta = cloneQueryKeyPart(opts.meta);
|
|
74
92
|
|
|
75
93
|
return {
|
|
76
|
-
queryKey: [opts.dataProviderName, resource, 'list',
|
|
94
|
+
queryKey: [opts.dataProviderName, resource, 'list', pagination, sorters, filters, meta],
|
|
77
95
|
queryFn: async () => provider.getList<TData>({
|
|
78
96
|
resource,
|
|
79
|
-
pagination
|
|
80
|
-
sorters
|
|
81
|
-
filters
|
|
82
|
-
meta
|
|
97
|
+
pagination,
|
|
98
|
+
sorters,
|
|
99
|
+
filters,
|
|
100
|
+
meta,
|
|
83
101
|
}),
|
|
84
102
|
enabled: queryOptions?.enabled ?? true,
|
|
85
103
|
staleTime: queryOptions?.staleTime ?? adminOptions.reactQuery?.staleTime,
|