@rozenite/tanstack-query-plugin 1.0.0-alpha.0 → 1.0.0-alpha.10
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/README.md +2 -2
- package/dist/assets/CXEL7IU7-BTFA0aeQ.js +1172 -0
- package/dist/assets/tanstack-query-DWTo8DT_.js +48 -0
- package/dist/react-native.cjs +1 -1
- package/dist/react-native.d.ts +1 -5
- package/dist/react-native.js +3 -86
- package/dist/rozenite.config.d.ts +7 -0
- package/dist/rozenite.json +1 -1
- package/dist/src/react-native/useHandleDevToolsMessages.d.ts +3 -0
- package/dist/src/react-native/useHandleInitialData.d.ts +3 -0
- package/dist/src/react-native/useSyncTanStackCache.d.ts +3 -0
- package/dist/src/react-native/useTanStackQueryDevTools.d.ts +2 -0
- package/dist/src/shared/dehydrate.d.ts +6 -0
- package/dist/src/shared/hydrate.d.ts +10 -0
- package/dist/src/shared/messaging.d.ts +34 -0
- package/dist/src/shared/types.d.ts +25 -0
- package/dist/src/shared/useSyncOnlineStatus.d.ts +2 -0
- package/dist/src/ui/tanstack-query.d.ts +1 -0
- package/dist/src/ui/useHandleSyncMessages.d.ts +2 -0
- package/dist/src/ui/useSyncDevToolsEvents.d.ts +2 -0
- package/dist/src/ui/useSyncInitialData.d.ts +2 -0
- package/dist/tanstack-query.html +1 -1
- package/dist/useTanstackQueryDevTools.cjs +1 -0
- package/dist/useTanstackQueryDevTools.js +312 -0
- package/package.json +14 -9
- package/project.json +12 -0
- package/react-native.ts +2 -2
- package/src/react-native/useHandleDevToolsMessages.ts +119 -0
- package/src/react-native/useHandleInitialData.ts +24 -0
- package/src/react-native/useSyncTanStackCache.ts +246 -0
- package/src/react-native/useTanstackQueryDevTools.ts +21 -0
- package/src/shared/dehydrate.ts +42 -0
- package/src/shared/hydrate.ts +250 -0
- package/src/shared/messaging.ts +54 -0
- package/src/shared/types.ts +48 -0
- package/src/shared/useSyncOnlineStatus.ts +29 -0
- package/src/ui/tanstack-query.tsx +21 -184
- package/src/ui/useHandleSyncMessages.ts +66 -0
- package/src/ui/useSyncDevToolsEvents.ts +55 -0
- package/src/ui/useSyncInitialData.ts +14 -0
- package/tsconfig.json +13 -6
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/assets/tanstack-query-CXp_Psxe.js +0 -48
- package/src/react-native/useTanStackQueryDevTools.ts +0 -214
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { useRozeniteDevToolsClient } from '@rozenite/plugin-bridge';
|
|
2
|
-
import type { QueryCacheNotifyEvent, MutationCacheNotifyEvent, QueryClient, Query, Mutation } from '@tanstack/react-query';
|
|
3
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
type DevToolsActionType =
|
|
6
|
-
| 'REFETCH'
|
|
7
|
-
| 'INVALIDATE'
|
|
8
|
-
| 'RESET'
|
|
9
|
-
| 'REMOVE'
|
|
10
|
-
| 'TRIGGER_ERROR'
|
|
11
|
-
| 'RESTORE_ERROR'
|
|
12
|
-
| 'TRIGGER_LOADING'
|
|
13
|
-
| 'RESTORE_LOADING'
|
|
14
|
-
| 'CLEAR_MUTATION_CACHE'
|
|
15
|
-
| 'CLEAR_QUERY_CACHE';
|
|
16
|
-
|
|
17
|
-
interface DevToolsEventDetail {
|
|
18
|
-
type: DevToolsActionType;
|
|
19
|
-
queryHash?: string;
|
|
20
|
-
mutationId?: number;
|
|
21
|
-
metadata?: Record<string, unknown>;
|
|
22
|
-
requestId?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type DevToolsEventMap = {
|
|
26
|
-
"DEVTOOLS_TO_DEVICE": DevToolsEventDetail;
|
|
27
|
-
"DEVICE_TO_DEVTOOLS": QueryCacheNotifyEvent | MutationCacheNotifyEvent;
|
|
28
|
-
"DEVICE_TO_DEVTOOLS_ACK": { requestId: string; success: boolean };
|
|
29
|
-
"DEVICE_TO_DEVTOOLS_INITIAL_DATA": { queries: Query[]; mutations: Mutation[] };
|
|
30
|
-
"DEVTOOLS_TO_DEVICE_INITIAL_DATA_REQUEST": unknown;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const useTanStackQueryDevTools = (queryClient: QueryClient) => {
|
|
34
|
-
const client = useRozeniteDevToolsClient<DevToolsEventMap>({
|
|
35
|
-
pluginId: '@rozenite/tanstack-query-plugin',
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (!client) return;
|
|
40
|
-
|
|
41
|
-
const subscription = client.onMessage("DEVTOOLS_TO_DEVICE_INITIAL_DATA_REQUEST", () => {
|
|
42
|
-
client.send("DEVICE_TO_DEVTOOLS_INITIAL_DATA", {
|
|
43
|
-
queries: queryClient.getQueryCache().getAll(),
|
|
44
|
-
mutations: queryClient.getMutationCache().getAll(),
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return () => subscription.remove();
|
|
49
|
-
}, [client, queryClient]);
|
|
50
|
-
|
|
51
|
-
// Track pending DevTools requests that are waiting for acknowledgment
|
|
52
|
-
const pendingDevToolsRequests = useRef<Set<string>>(new Set());
|
|
53
|
-
|
|
54
|
-
const handleEvent = useCallback((event: DevToolsEventDetail) => {
|
|
55
|
-
const getQuery = (hash: string): Query | undefined => {
|
|
56
|
-
return queryClient.getQueryCache().getAll().find(q => q.queryHash === hash);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const onEvent = (event: DevToolsEventDetail): void => {
|
|
60
|
-
const { type, queryHash, metadata, requestId } = event;
|
|
61
|
-
|
|
62
|
-
if (type === 'REFETCH' && queryHash) {
|
|
63
|
-
getQuery(queryHash)?.fetch();
|
|
64
|
-
if (requestId) {
|
|
65
|
-
pendingDevToolsRequests.current.add(requestId);
|
|
66
|
-
// Acknowledge immediately after the fetch is initiated
|
|
67
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
68
|
-
pendingDevToolsRequests.current.delete(requestId);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (type === 'INVALIDATE' && queryHash) {
|
|
72
|
-
const query = getQuery(queryHash);
|
|
73
|
-
if (query) {
|
|
74
|
-
queryClient.invalidateQueries({ queryKey: query.queryKey });
|
|
75
|
-
}
|
|
76
|
-
if (requestId) {
|
|
77
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (type === 'RESET' && queryHash) {
|
|
81
|
-
const query = getQuery(queryHash);
|
|
82
|
-
if (query) {
|
|
83
|
-
queryClient.resetQueries({ queryKey: query.queryKey });
|
|
84
|
-
}
|
|
85
|
-
if (requestId) {
|
|
86
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (type === 'REMOVE' && queryHash) {
|
|
90
|
-
const query = getQuery(queryHash);
|
|
91
|
-
if (query) {
|
|
92
|
-
queryClient.removeQueries({ queryKey: query.queryKey });
|
|
93
|
-
}
|
|
94
|
-
if (requestId) {
|
|
95
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (type === 'TRIGGER_LOADING' && queryHash) {
|
|
99
|
-
const query = getQuery(queryHash);
|
|
100
|
-
|
|
101
|
-
if (query) {
|
|
102
|
-
// Set state to loading/pending (simulate fetch in progress)
|
|
103
|
-
query.setState({
|
|
104
|
-
...query.state,
|
|
105
|
-
fetchStatus: 'fetching',
|
|
106
|
-
status: 'pending',
|
|
107
|
-
error: null,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
if (requestId) {
|
|
111
|
-
pendingDevToolsRequests.current.add(requestId);
|
|
112
|
-
// Acknowledge immediately after the state change is applied
|
|
113
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
114
|
-
pendingDevToolsRequests.current.delete(requestId);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (type === 'RESTORE_LOADING' && queryHash) {
|
|
119
|
-
const query = getQuery(queryHash);
|
|
120
|
-
if (query) {
|
|
121
|
-
// Set state to idle/success (simulate fetch complete)
|
|
122
|
-
query.setState({
|
|
123
|
-
...query.state,
|
|
124
|
-
fetchStatus: 'idle',
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
if (requestId) {
|
|
128
|
-
pendingDevToolsRequests.current.add(requestId);
|
|
129
|
-
// Acknowledge immediately after the state change is applied
|
|
130
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
131
|
-
pendingDevToolsRequests.current.delete(requestId);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (type === 'TRIGGER_ERROR' && queryHash) {
|
|
136
|
-
const query = getQuery(queryHash);
|
|
137
|
-
if (query) {
|
|
138
|
-
query.setState({
|
|
139
|
-
...query.state,
|
|
140
|
-
fetchStatus: 'idle',
|
|
141
|
-
status: 'error',
|
|
142
|
-
error: metadata?.error as Error || new Error('Forced error via devtools'),
|
|
143
|
-
errorUpdateCount: (query.state.errorUpdateCount ?? 0) + 1,
|
|
144
|
-
errorUpdatedAt: Date.now(),
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
if (requestId) {
|
|
148
|
-
pendingDevToolsRequests.current.add(requestId);
|
|
149
|
-
// Acknowledge immediately after the state change is applied
|
|
150
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
151
|
-
pendingDevToolsRequests.current.delete(requestId);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (type === 'RESTORE_ERROR' && queryHash) {
|
|
156
|
-
const query = getQuery(queryHash);
|
|
157
|
-
if (query) {
|
|
158
|
-
queryClient.resetQueries({ queryKey: query.queryKey });
|
|
159
|
-
}
|
|
160
|
-
if (requestId) {
|
|
161
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (type === 'CLEAR_MUTATION_CACHE') {
|
|
165
|
-
queryClient.getMutationCache().clear();
|
|
166
|
-
if (requestId) {
|
|
167
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (type === 'CLEAR_QUERY_CACHE') {
|
|
171
|
-
queryClient.clear();
|
|
172
|
-
if (requestId) {
|
|
173
|
-
client?.send("DEVICE_TO_DEVTOOLS_ACK", { requestId, success: true });
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
onEvent(event);
|
|
179
|
-
}, [queryClient, client]);
|
|
180
|
-
|
|
181
|
-
useEffect(() => {
|
|
182
|
-
if (!client) return;
|
|
183
|
-
|
|
184
|
-
const subscription = client.onMessage("DEVTOOLS_TO_DEVICE", handleEvent);
|
|
185
|
-
return () => subscription.remove();
|
|
186
|
-
}, [handleEvent, client]);
|
|
187
|
-
|
|
188
|
-
useEffect(() => {
|
|
189
|
-
if (!client) return;
|
|
190
|
-
|
|
191
|
-
return queryClient.getQueryCache().subscribe((event) => {
|
|
192
|
-
// Don't send events for queries that have pending DevTools requests
|
|
193
|
-
if (pendingDevToolsRequests.current.size > 0) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
client.send("DEVICE_TO_DEVTOOLS", event);
|
|
198
|
-
});
|
|
199
|
-
}, [client, queryClient]);
|
|
200
|
-
|
|
201
|
-
// Subscribe to mutation cache events
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
if (!client) return;
|
|
204
|
-
|
|
205
|
-
return queryClient.getMutationCache().subscribe((event) => {
|
|
206
|
-
// Don't send events for mutations that have pending DevTools requests
|
|
207
|
-
if (pendingDevToolsRequests.current.size > 0) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
client.send("DEVICE_TO_DEVTOOLS", event);
|
|
212
|
-
});
|
|
213
|
-
}, [client, queryClient]);
|
|
214
|
-
}
|