@buoy-gg/react-query 7.0.41 → 7.0.42
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 +11 -73
- package/lib/commonjs/checkPeer.js +1 -8
- package/lib/commonjs/checkPeer.web.js +1 -3
- package/lib/commonjs/index.js +1 -657
- package/lib/commonjs/preset.js +1 -243
- package/lib/commonjs/react-query/components/DataEditorMode.js +1 -317
- package/lib/commonjs/react-query/components/FilterStatusBadge.js +1 -55
- package/lib/commonjs/react-query/components/MutationBrowserMode.js +1 -52
- package/lib/commonjs/react-query/components/MutationEditorMode.js +1 -276
- package/lib/commonjs/react-query/components/QueryBrowserMode.js +1 -99
- package/lib/commonjs/react-query/components/QueryDebugInfo.js +1 -107
- package/lib/commonjs/react-query/components/QueryFilterViewV3.js +1 -224
- package/lib/commonjs/react-query/components/QuerySelector.js +1 -209
- package/lib/commonjs/react-query/components/ReactQueryDevToolsModal.js +1 -91
- package/lib/commonjs/react-query/components/ReactQuerySection.js +1 -47
- package/lib/commonjs/react-query/components/ReactQueryTracker.js +1 -38
- package/lib/commonjs/react-query/components/WifiToggle.js +1 -51
- package/lib/commonjs/react-query/components/modals/DataEditorModal.js +1 -103
- package/lib/commonjs/react-query/components/modals/MutationBrowserFooter.js +1 -61
- package/lib/commonjs/react-query/components/modals/MutationBrowserModal.js +1 -164
- package/lib/commonjs/react-query/components/modals/MutationEditorModal.js +1 -106
- package/lib/commonjs/react-query/components/modals/QueryBrowserFooter.js +1 -56
- package/lib/commonjs/react-query/components/modals/QueryBrowserModal.js +1 -254
- package/lib/commonjs/react-query/components/modals/ReactQueryModal.js +1 -83
- package/lib/commonjs/react-query/components/modals/ReactQueryModalHeader.js +1 -194
- package/lib/commonjs/react-query/components/modals/SwipeIndicator.js +1 -204
- package/lib/commonjs/react-query/components/query-browser/ActionButton.js +1 -100
- package/lib/commonjs/react-query/components/query-browser/ClearCacheButton.js +1 -53
- package/lib/commonjs/react-query/components/query-browser/Explorer.js +1 -75
- package/lib/commonjs/react-query/components/query-browser/MutationButton.js +1 -190
- package/lib/commonjs/react-query/components/query-browser/MutationDetails.js +1 -124
- package/lib/commonjs/react-query/components/query-browser/MutationDetailsChips.js +1 -68
- package/lib/commonjs/react-query/components/query-browser/MutationInformation.js +1 -118
- package/lib/commonjs/react-query/components/query-browser/MutationStatusCount.js +1 -84
- package/lib/commonjs/react-query/components/query-browser/MutationsList.js +1 -220
- package/lib/commonjs/react-query/components/query-browser/NetworkToggleButton.js +1 -54
- package/lib/commonjs/react-query/components/query-browser/QueryActions.js +1 -124
- package/lib/commonjs/react-query/components/query-browser/QueryBrowser.js +1 -181
- package/lib/commonjs/react-query/components/query-browser/QueryDetails.js +1 -141
- package/lib/commonjs/react-query/components/query-browser/QueryDetailsChip.js +1 -78
- package/lib/commonjs/react-query/components/query-browser/QueryInformation.js +1 -95
- package/lib/commonjs/react-query/components/query-browser/QueryRow.js +1 -96
- package/lib/commonjs/react-query/components/query-browser/QueryStatus.js +1 -167
- package/lib/commonjs/react-query/components/query-browser/QueryStatusCount.js +1 -100
- package/lib/commonjs/react-query/components/query-browser/StorageStatusCount.js +1 -61
- package/lib/commonjs/react-query/components/query-browser/index.js +1 -170
- package/lib/commonjs/react-query/components/query-browser/svgs.js +1 -72
- package/lib/commonjs/react-query/hooks/useActionButtons.js +1 -51
- package/lib/commonjs/react-query/hooks/useAllMutations.js +1 -85
- package/lib/commonjs/react-query/hooks/useAllQueries.js +1 -117
- package/lib/commonjs/react-query/hooks/useModalManager.js +1 -178
- package/lib/commonjs/react-query/hooks/useModalPersistence.js +1 -71
- package/lib/commonjs/react-query/hooks/useMutationActionButtons.js +1 -21
- package/lib/commonjs/react-query/hooks/useQueryStatusCounts.js +1 -114
- package/lib/commonjs/react-query/hooks/useReactQueryState.js +1 -24
- package/lib/commonjs/react-query/hooks/useSelectedMutation.js +1 -30
- package/lib/commonjs/react-query/hooks/useSelectedQuery.js +1 -96
- package/lib/commonjs/react-query/hooks/useStorageQueryCounts.js +1 -28
- package/lib/commonjs/react-query/hooks/useWifiState.js +1 -67
- package/lib/commonjs/react-query/stores/reactQueryEventStore.js +1 -302
- package/lib/commonjs/react-query/sync/dehydrate.js +1 -166
- package/lib/commonjs/react-query/sync/reactQuerySyncAdapter.js +1 -593
- package/lib/commonjs/react-query/sync/snapshotProvider.js +1 -289
- package/lib/commonjs/react-query/sync/useReactQuerySyncAdapter.js +1 -34
- package/lib/commonjs/react-query/types/types.js +1 -14
- package/lib/commonjs/react-query/utils/actions/deleteItem.js +1 -23
- package/lib/commonjs/react-query/utils/actions/emitDevToolsEvent.js +1 -40
- package/lib/commonjs/react-query/utils/actions/invalidate.js +1 -15
- package/lib/commonjs/react-query/utils/actions/refetch.js +1 -17
- package/lib/commonjs/react-query/utils/actions/remove.js +1 -15
- package/lib/commonjs/react-query/utils/actions/reset.js +1 -17
- package/lib/commonjs/react-query/utils/actions/triggerError.js +1 -33
- package/lib/commonjs/react-query/utils/actions/triggerLoading.js +1 -54
- package/lib/commonjs/react-query/utils/deleteNestedDataByPath.js +1 -56
- package/lib/commonjs/react-query/utils/getQueryStatusColor.js +1 -16
- package/lib/commonjs/react-query/utils/getQueryStatusLabel.js +1 -23
- package/lib/commonjs/react-query/utils/getStorageQueryCounts.js +1 -35
- package/lib/commonjs/react-query/utils/modalStorageOperations.js +1 -127
- package/lib/commonjs/react-query/utils/storageQueryUtils.js +1 -149
- package/lib/commonjs/react-query/utils/testIDs.js +1 -61
- package/lib/commonjs/react-query/utils/updateNestedDataByPath.js +1 -61
- package/lib/module/checkPeer.js +1 -8
- package/lib/module/checkPeer.web.js +1 -3
- package/lib/module/index.js +1 -130
- package/lib/module/preset.js +1 -239
- package/lib/module/react-query/components/DataEditorMode.js +1 -311
- package/lib/module/react-query/components/FilterStatusBadge.js +1 -51
- package/lib/module/react-query/components/MutationBrowserMode.js +1 -47
- package/lib/module/react-query/components/MutationEditorMode.js +1 -270
- package/lib/module/react-query/components/QueryBrowserMode.js +1 -94
- package/lib/module/react-query/components/QueryDebugInfo.js +1 -104
- package/lib/module/react-query/components/QueryFilterViewV3.js +1 -221
- package/lib/module/react-query/components/QuerySelector.js +1 -205
- package/lib/module/react-query/components/ReactQueryDevToolsModal.js +1 -87
- package/lib/module/react-query/components/ReactQuerySection.js +1 -43
- package/lib/module/react-query/components/ReactQueryTracker.js +1 -35
- package/lib/module/react-query/components/WifiToggle.js +1 -48
- package/lib/module/react-query/components/modals/DataEditorModal.js +1 -99
- package/lib/module/react-query/components/modals/MutationBrowserFooter.js +1 -56
- package/lib/module/react-query/components/modals/MutationBrowserModal.js +1 -161
- package/lib/module/react-query/components/modals/MutationEditorModal.js +1 -102
- package/lib/module/react-query/components/modals/QueryBrowserFooter.js +1 -51
- package/lib/module/react-query/components/modals/QueryBrowserModal.js +1 -250
- package/lib/module/react-query/components/modals/ReactQueryModal.js +1 -79
- package/lib/module/react-query/components/modals/ReactQueryModalHeader.js +1 -190
- package/lib/module/react-query/components/modals/SwipeIndicator.js +1 -201
- package/lib/module/react-query/components/query-browser/ActionButton.js +1 -96
- package/lib/module/react-query/components/query-browser/ClearCacheButton.js +1 -49
- package/lib/module/react-query/components/query-browser/Explorer.js +1 -70
- package/lib/module/react-query/components/query-browser/MutationButton.js +1 -186
- package/lib/module/react-query/components/query-browser/MutationDetails.js +1 -119
- package/lib/module/react-query/components/query-browser/MutationDetailsChips.js +1 -64
- package/lib/module/react-query/components/query-browser/MutationInformation.js +1 -113
- package/lib/module/react-query/components/query-browser/MutationStatusCount.js +1 -79
- package/lib/module/react-query/components/query-browser/MutationsList.js +1 -215
- package/lib/module/react-query/components/query-browser/NetworkToggleButton.js +1 -50
- package/lib/module/react-query/components/query-browser/QueryActions.js +1 -119
- package/lib/module/react-query/components/query-browser/QueryBrowser.js +1 -176
- package/lib/module/react-query/components/query-browser/QueryDetails.js +1 -136
- package/lib/module/react-query/components/query-browser/QueryDetailsChip.js +1 -74
- package/lib/module/react-query/components/query-browser/QueryInformation.js +1 -90
- package/lib/module/react-query/components/query-browser/QueryRow.js +1 -92
- package/lib/module/react-query/components/query-browser/QueryStatus.js +1 -163
- package/lib/module/react-query/components/query-browser/QueryStatusCount.js +1 -95
- package/lib/module/react-query/components/query-browser/StorageStatusCount.js +1 -56
- package/lib/module/react-query/components/query-browser/index.js +1 -22
- package/lib/module/react-query/components/query-browser/svgs.js +1 -64
- package/lib/module/react-query/hooks/useActionButtons.js +1 -46
- package/lib/module/react-query/hooks/useAllMutations.js +1 -82
- package/lib/module/react-query/hooks/useAllQueries.js +1 -114
- package/lib/module/react-query/hooks/useModalManager.js +1 -175
- package/lib/module/react-query/hooks/useModalPersistence.js +1 -67
- package/lib/module/react-query/hooks/useMutationActionButtons.js +1 -17
- package/lib/module/react-query/hooks/useQueryStatusCounts.js +1 -112
- package/lib/module/react-query/hooks/useReactQueryState.js +1 -20
- package/lib/module/react-query/hooks/useSelectedMutation.js +1 -27
- package/lib/module/react-query/hooks/useSelectedQuery.js +1 -92
- package/lib/module/react-query/hooks/useStorageQueryCounts.js +1 -25
- package/lib/module/react-query/hooks/useWifiState.js +1 -64
- package/lib/module/react-query/stores/reactQueryEventStore.js +1 -293
- package/lib/module/react-query/sync/dehydrate.js +1 -156
- package/lib/module/react-query/sync/reactQuerySyncAdapter.js +1 -589
- package/lib/module/react-query/sync/snapshotProvider.js +1 -284
- package/lib/module/react-query/sync/useReactQuerySyncAdapter.js +1 -31
- package/lib/module/react-query/types/types.js +1 -10
- package/lib/module/react-query/utils/actions/deleteItem.js +1 -19
- package/lib/module/react-query/utils/actions/emitDevToolsEvent.js +1 -36
- package/lib/module/react-query/utils/actions/invalidate.js +1 -11
- package/lib/module/react-query/utils/actions/refetch.js +1 -13
- package/lib/module/react-query/utils/actions/remove.js +1 -11
- package/lib/module/react-query/utils/actions/reset.js +1 -13
- package/lib/module/react-query/utils/actions/triggerError.js +1 -29
- package/lib/module/react-query/utils/actions/triggerLoading.js +1 -50
- package/lib/module/react-query/utils/deleteNestedDataByPath.js +1 -51
- package/lib/module/react-query/utils/getQueryStatusColor.js +1 -12
- package/lib/module/react-query/utils/getQueryStatusLabel.js +1 -19
- package/lib/module/react-query/utils/getStorageQueryCounts.js +1 -31
- package/lib/module/react-query/utils/modalStorageOperations.js +1 -117
- package/lib/module/react-query/utils/storageQueryUtils.js +1 -140
- package/lib/module/react-query/utils/testIDs.js +1 -54
- package/lib/module/react-query/utils/updateNestedDataByPath.js +1 -56
- package/lib/web/index.mjs +3 -4
- package/package.json +3 -3
- package/lib/typescript/checkPeer.d.ts.map +0 -1
- package/lib/typescript/checkPeer.web.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/react-query/components/DataEditorMode.d.ts.map +0 -1
- package/lib/typescript/react-query/components/FilterStatusBadge.d.ts.map +0 -1
- package/lib/typescript/react-query/components/MutationBrowserMode.d.ts.map +0 -1
- package/lib/typescript/react-query/components/MutationEditorMode.d.ts.map +0 -1
- package/lib/typescript/react-query/components/QueryBrowserMode.d.ts.map +0 -1
- package/lib/typescript/react-query/components/QueryDebugInfo.d.ts.map +0 -1
- package/lib/typescript/react-query/components/QueryFilterViewV3.d.ts.map +0 -1
- package/lib/typescript/react-query/components/QuerySelector.d.ts.map +0 -1
- package/lib/typescript/react-query/components/ReactQueryDevToolsModal.d.ts.map +0 -1
- package/lib/typescript/react-query/components/ReactQuerySection.d.ts.map +0 -1
- package/lib/typescript/react-query/components/ReactQueryTracker.d.ts.map +0 -1
- package/lib/typescript/react-query/components/WifiToggle.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/DataEditorModal.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/MutationBrowserFooter.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/MutationBrowserModal.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/MutationEditorModal.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/QueryBrowserFooter.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/QueryBrowserModal.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/ReactQueryModal.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/ReactQueryModalHeader.d.ts.map +0 -1
- package/lib/typescript/react-query/components/modals/SwipeIndicator.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/ActionButton.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/ClearCacheButton.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/Explorer.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/MutationButton.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/MutationDetails.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/MutationDetailsChips.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/MutationInformation.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/MutationStatusCount.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/MutationsList.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/NetworkToggleButton.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryActions.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryBrowser.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryDetails.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryDetailsChip.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryInformation.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryRow.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryStatus.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/QueryStatusCount.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/StorageStatusCount.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/index.d.ts.map +0 -1
- package/lib/typescript/react-query/components/query-browser/svgs.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useActionButtons.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useAllMutations.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useAllQueries.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useModalManager.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useModalPersistence.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useMutationActionButtons.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useQueryStatusCounts.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useReactQueryState.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useSelectedMutation.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useSelectedQuery.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useStorageQueryCounts.d.ts.map +0 -1
- package/lib/typescript/react-query/hooks/useWifiState.d.ts.map +0 -1
- package/lib/typescript/react-query/stores/reactQueryEventStore.d.ts.map +0 -1
- package/lib/typescript/react-query/sync/dehydrate.d.ts.map +0 -1
- package/lib/typescript/react-query/sync/reactQuerySyncAdapter.d.ts.map +0 -1
- package/lib/typescript/react-query/sync/snapshotProvider.d.ts.map +0 -1
- package/lib/typescript/react-query/sync/useReactQuerySyncAdapter.d.ts.map +0 -1
- package/lib/typescript/react-query/types/types.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/deleteItem.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/emitDevToolsEvent.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/invalidate.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/refetch.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/remove.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/reset.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/triggerError.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/actions/triggerLoading.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/deleteNestedDataByPath.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/getQueryStatusColor.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/getQueryStatusLabel.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/getStorageQueryCounts.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/modalStorageOperations.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/storageQueryUtils.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/testIDs.d.ts.map +0 -1
- package/lib/typescript/react-query/utils/updateNestedDataByPath.d.ts.map +0 -1
|
@@ -1,64 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useState, useRef } from "react";
|
|
4
|
-
import { onlineManager } from "@tanstack/react-query";
|
|
5
|
-
import { devToolsStorageKeys, persistentStorage } from "@buoy-gg/shared-ui";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Synchronizes a local Wi-Fi toggle with React Query's `onlineManager`, persisting the selection
|
|
9
|
-
* so developers can simulate offline mode across reloads.
|
|
10
|
-
*/
|
|
11
|
-
export function useWifiState() {
|
|
12
|
-
const [isOnline, setIsOnline] = useState(() => onlineManager.isOnline());
|
|
13
|
-
const hasLoadedPersistedState = useRef(false);
|
|
14
|
-
|
|
15
|
-
// Load persisted WiFi state on mount
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (hasLoadedPersistedState.current) return;
|
|
18
|
-
const loadPersistedState = async () => {
|
|
19
|
-
try {
|
|
20
|
-
const savedState = await persistentStorage.getItem(devToolsStorageKeys.settings.wifiEnabled());
|
|
21
|
-
if (savedState !== null) {
|
|
22
|
-
const isEnabled = savedState === "true";
|
|
23
|
-
setIsOnline(isEnabled);
|
|
24
|
-
onlineManager.setOnline(isEnabled);
|
|
25
|
-
}
|
|
26
|
-
hasLoadedPersistedState.current = true;
|
|
27
|
-
} catch (error) {
|
|
28
|
-
// Failed to load WiFi state
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
loadPersistedState();
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
|
-
// Save WiFi state when it changes
|
|
35
|
-
const saveWifiState = async enabled => {
|
|
36
|
-
try {
|
|
37
|
-
await persistentStorage.setItem(devToolsStorageKeys.settings.wifiEnabled(), enabled.toString());
|
|
38
|
-
} catch (error) {
|
|
39
|
-
// Failed to save WiFi state
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const handleWifiToggle = () => {
|
|
43
|
-
const newOnlineState = !isOnline;
|
|
44
|
-
setIsOnline(newOnlineState);
|
|
45
|
-
onlineManager.setOnline(newOnlineState);
|
|
46
|
-
saveWifiState(newOnlineState);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Listen to online manager changes to keep state in sync
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
const unsubscribe = onlineManager.subscribe(online => {
|
|
52
|
-
setIsOnline(online);
|
|
53
|
-
// Only save if we've already loaded the persisted state to avoid overwriting on mount
|
|
54
|
-
if (hasLoadedPersistedState.current) {
|
|
55
|
-
saveWifiState(online);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return unsubscribe;
|
|
59
|
-
}, []);
|
|
60
|
-
return {
|
|
61
|
-
isOnline,
|
|
62
|
-
handleWifiToggle
|
|
63
|
-
};
|
|
64
|
-
}
|
|
1
|
+
"use strict";import{useEffect as c,useState as d,useRef as S}from"react";import{onlineManager as s}from"@tanstack/react-query";import{devToolsStorageKeys as u,persistentStorage as f}from"@buoy-gg/shared-ui";export function useWifiState(){const[i,n]=d(()=>s.isOnline());const r=S(false);c(()=>{if(r.current)return;const t=async()=>{try{const e=await f.getItem(u.settings.wifiEnabled());if(e!==null){const o=e==="true";n(o);s.setOnline(o)}r.current=true}catch(e){}};t()},[]);const a=async t=>{try{await f.setItem(u.settings.wifiEnabled(),t.toString())}catch(e){}};const l=()=>{const t=!i;n(t);s.setOnline(t);a(t)};c(()=>{const t=s.subscribe(e=>{n(e);if(r.current){a(e)}});return t},[]);return{isOnline:i,handleWifiToggle:l}}
|
|
@@ -1,293 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* React Query Event Store
|
|
5
|
-
*
|
|
6
|
-
* Bridges React Query's cache subscription system to a simple pub/sub pattern
|
|
7
|
-
* that can be consumed by the unified Events DevTools.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* 1. In your app, call setQueryClient(queryClient) to connect
|
|
11
|
-
* 2. The store will emit events for query/mutation state changes
|
|
12
|
-
* 3. The Events DevTools subscribes to these events
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { ChangeLog } from "@buoy-gg/shared-ui";
|
|
16
|
-
import { isStorageQuery } from "../utils/storageQueryUtils";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* React Query event types for the unified timeline
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Unified React Query event for the timeline
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
let eventIdCounter = 0;
|
|
27
|
-
function generateEventId() {
|
|
28
|
-
return `rq-${Date.now()}-${++eventIdCounter}`;
|
|
29
|
-
}
|
|
30
|
-
class ReactQueryEventStore extends ChangeLog {
|
|
31
|
-
queryClient = null;
|
|
32
|
-
queryUnsubscribe = null;
|
|
33
|
-
mutationUnsubscribe = null;
|
|
34
|
-
constructor() {
|
|
35
|
-
super({
|
|
36
|
-
max: 200
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Track fetch start times for duration calculation
|
|
41
|
-
fetchStartTimes = new Map();
|
|
42
|
-
mutationStartTimes = new Map();
|
|
43
|
-
|
|
44
|
-
// Track last known states to detect transitions
|
|
45
|
-
lastQueryStates = new Map();
|
|
46
|
-
lastMutationStates = new Map();
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Connect a QueryClient to the store
|
|
50
|
-
* Call this in your app after creating the QueryClient
|
|
51
|
-
*/
|
|
52
|
-
setQueryClient(queryClient) {
|
|
53
|
-
// Cleanup previous connection
|
|
54
|
-
this.disconnect();
|
|
55
|
-
this.queryClient = queryClient;
|
|
56
|
-
|
|
57
|
-
// Subscribe to query cache
|
|
58
|
-
this.queryUnsubscribe = queryClient.getQueryCache().subscribe(event => {
|
|
59
|
-
if (event.type === "updated" && event.query) {
|
|
60
|
-
this.handleQueryUpdate(event.query);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Subscribe to mutation cache
|
|
65
|
-
this.mutationUnsubscribe = queryClient.getMutationCache().subscribe(event => {
|
|
66
|
-
if (event.type === "updated" && event.mutation) {
|
|
67
|
-
this.handleMutationUpdate(event.mutation);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Disconnect from the QueryClient
|
|
74
|
-
*/
|
|
75
|
-
disconnect() {
|
|
76
|
-
if (this.queryUnsubscribe) {
|
|
77
|
-
this.queryUnsubscribe();
|
|
78
|
-
this.queryUnsubscribe = null;
|
|
79
|
-
}
|
|
80
|
-
if (this.mutationUnsubscribe) {
|
|
81
|
-
this.mutationUnsubscribe();
|
|
82
|
-
this.mutationUnsubscribe = null;
|
|
83
|
-
}
|
|
84
|
-
this.queryClient = null;
|
|
85
|
-
this.lastQueryStates.clear();
|
|
86
|
-
this.lastMutationStates.clear();
|
|
87
|
-
this.fetchStartTimes.clear();
|
|
88
|
-
this.mutationStartTimes.clear();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Handle query state updates and emit appropriate events
|
|
93
|
-
*/
|
|
94
|
-
handleQueryUpdate(query) {
|
|
95
|
-
// Skip storage queries (internal to the devtools)
|
|
96
|
-
if (isStorageQuery(query.queryKey)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const queryHash = query.queryHash;
|
|
100
|
-
const currentState = {
|
|
101
|
-
fetchStatus: query.state.fetchStatus,
|
|
102
|
-
status: query.state.status
|
|
103
|
-
};
|
|
104
|
-
const lastState = this.lastQueryStates.get(queryHash);
|
|
105
|
-
|
|
106
|
-
// Detect state transitions
|
|
107
|
-
if (!lastState) {
|
|
108
|
-
// New query - if it's fetching, emit fetch start
|
|
109
|
-
if (currentState.fetchStatus === "fetching") {
|
|
110
|
-
this.fetchStartTimes.set(queryHash, Date.now());
|
|
111
|
-
this.addEvent({
|
|
112
|
-
id: generateEventId(),
|
|
113
|
-
type: "query-fetch-start",
|
|
114
|
-
timestamp: Date.now(),
|
|
115
|
-
queryKey: query.queryKey,
|
|
116
|
-
queryHash,
|
|
117
|
-
query
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
// Existing query - check for transitions
|
|
122
|
-
const wasFetching = lastState.fetchStatus === "fetching";
|
|
123
|
-
const isFetching = currentState.fetchStatus === "fetching";
|
|
124
|
-
|
|
125
|
-
// Started fetching
|
|
126
|
-
if (!wasFetching && isFetching) {
|
|
127
|
-
this.fetchStartTimes.set(queryHash, Date.now());
|
|
128
|
-
this.addEvent({
|
|
129
|
-
id: generateEventId(),
|
|
130
|
-
type: "query-fetch-start",
|
|
131
|
-
timestamp: Date.now(),
|
|
132
|
-
queryKey: query.queryKey,
|
|
133
|
-
queryHash,
|
|
134
|
-
query
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Finished fetching
|
|
139
|
-
if (wasFetching && !isFetching) {
|
|
140
|
-
const startTime = this.fetchStartTimes.get(queryHash);
|
|
141
|
-
const duration = startTime ? Date.now() - startTime : undefined;
|
|
142
|
-
this.fetchStartTimes.delete(queryHash);
|
|
143
|
-
if (currentState.status === "error") {
|
|
144
|
-
this.addEvent({
|
|
145
|
-
id: generateEventId(),
|
|
146
|
-
type: "query-fetch-error",
|
|
147
|
-
timestamp: Date.now(),
|
|
148
|
-
queryKey: query.queryKey,
|
|
149
|
-
queryHash,
|
|
150
|
-
queryError: query.state.error,
|
|
151
|
-
duration,
|
|
152
|
-
query
|
|
153
|
-
});
|
|
154
|
-
} else {
|
|
155
|
-
this.addEvent({
|
|
156
|
-
id: generateEventId(),
|
|
157
|
-
type: "query-fetch-success",
|
|
158
|
-
timestamp: Date.now(),
|
|
159
|
-
queryKey: query.queryKey,
|
|
160
|
-
queryHash,
|
|
161
|
-
queryData: query.state.data,
|
|
162
|
-
duration,
|
|
163
|
-
query
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Query was invalidated
|
|
169
|
-
if (!lastState.status && query.state.isInvalidated) {
|
|
170
|
-
this.addEvent({
|
|
171
|
-
id: generateEventId(),
|
|
172
|
-
type: "query-invalidated",
|
|
173
|
-
timestamp: Date.now(),
|
|
174
|
-
queryKey: query.queryKey,
|
|
175
|
-
queryHash,
|
|
176
|
-
query
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Update last known state
|
|
182
|
-
this.lastQueryStates.set(queryHash, currentState);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Handle mutation state updates and emit appropriate events
|
|
187
|
-
*/
|
|
188
|
-
handleMutationUpdate(mutation) {
|
|
189
|
-
const mutationId = mutation.mutationId;
|
|
190
|
-
const currentStatus = mutation.state.status;
|
|
191
|
-
const lastStatus = this.lastMutationStates.get(mutationId);
|
|
192
|
-
if (lastStatus !== currentStatus) {
|
|
193
|
-
// Status changed
|
|
194
|
-
if (currentStatus === "pending" && lastStatus !== "pending") {
|
|
195
|
-
// Mutation started
|
|
196
|
-
this.mutationStartTimes.set(mutationId, Date.now());
|
|
197
|
-
this.addEvent({
|
|
198
|
-
id: generateEventId(),
|
|
199
|
-
type: "mutation-start",
|
|
200
|
-
timestamp: Date.now(),
|
|
201
|
-
mutationId,
|
|
202
|
-
mutationKey: mutation.options.mutationKey,
|
|
203
|
-
mutationVariables: mutation.state.variables,
|
|
204
|
-
mutation
|
|
205
|
-
});
|
|
206
|
-
} else if (currentStatus === "success" && lastStatus === "pending") {
|
|
207
|
-
// Mutation succeeded
|
|
208
|
-
const startTime = this.mutationStartTimes.get(mutationId);
|
|
209
|
-
const duration = startTime ? Date.now() - startTime : undefined;
|
|
210
|
-
this.mutationStartTimes.delete(mutationId);
|
|
211
|
-
this.addEvent({
|
|
212
|
-
id: generateEventId(),
|
|
213
|
-
type: "mutation-success",
|
|
214
|
-
timestamp: Date.now(),
|
|
215
|
-
mutationId,
|
|
216
|
-
mutationKey: mutation.options.mutationKey,
|
|
217
|
-
mutationVariables: mutation.state.variables,
|
|
218
|
-
mutationData: mutation.state.data,
|
|
219
|
-
duration,
|
|
220
|
-
mutation
|
|
221
|
-
});
|
|
222
|
-
} else if (currentStatus === "error" && lastStatus === "pending") {
|
|
223
|
-
// Mutation failed
|
|
224
|
-
const startTime = this.mutationStartTimes.get(mutationId);
|
|
225
|
-
const duration = startTime ? Date.now() - startTime : undefined;
|
|
226
|
-
this.mutationStartTimes.delete(mutationId);
|
|
227
|
-
this.addEvent({
|
|
228
|
-
id: generateEventId(),
|
|
229
|
-
type: "mutation-error",
|
|
230
|
-
timestamp: Date.now(),
|
|
231
|
-
mutationId,
|
|
232
|
-
mutationKey: mutation.options.mutationKey,
|
|
233
|
-
mutationVariables: mutation.state.variables,
|
|
234
|
-
mutationError: mutation.state.error,
|
|
235
|
-
duration,
|
|
236
|
-
mutation
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Update last known status
|
|
242
|
-
this.lastMutationStates.set(mutationId, currentStatus);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Add an event to the store
|
|
247
|
-
*/
|
|
248
|
-
addEvent(event) {
|
|
249
|
-
this.record(event);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Get all events
|
|
254
|
-
*/
|
|
255
|
-
getEvents() {
|
|
256
|
-
return this.items;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Subscribe to event changes
|
|
261
|
-
*/
|
|
262
|
-
subscribe(listener) {
|
|
263
|
-
const unsubscribe = super.subscribe(listener);
|
|
264
|
-
// Immediately call with current events
|
|
265
|
-
listener(this.items);
|
|
266
|
-
return unsubscribe;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Clear all events
|
|
271
|
-
*/
|
|
272
|
-
clearEvents() {
|
|
273
|
-
this.clear();
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Check if connected to a QueryClient
|
|
278
|
-
*/
|
|
279
|
-
isConnected() {
|
|
280
|
-
return this.queryClient !== null;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// Singleton instance
|
|
285
|
-
export const reactQueryEventStore = new ReactQueryEventStore();
|
|
286
|
-
|
|
287
|
-
// Convenience exports
|
|
288
|
-
export const setQueryClient = queryClient => reactQueryEventStore.setQueryClient(queryClient);
|
|
289
|
-
export const disconnectQueryClient = () => reactQueryEventStore.disconnect();
|
|
290
|
-
export const getReactQueryEvents = () => reactQueryEventStore.getEvents();
|
|
291
|
-
export const subscribeToReactQueryEvents = listener => reactQueryEventStore.subscribe(listener);
|
|
292
|
-
export const clearReactQueryEvents = () => reactQueryEventStore.clearEvents();
|
|
293
|
-
export const isReactQueryConnected = () => reactQueryEventStore.isConnected();
|
|
1
|
+
"use strict";import{ChangeLog as d}from"@buoy-gg/shared-ui";import{isStorageQuery as h}from"../utils/storageQueryUtils";let l=0;function n(){return`rq-${Date.now()}-${++l}`}class y extends d{queryClient=null;queryUnsubscribe=null;mutationUnsubscribe=null;constructor(){super({max:200})}fetchStartTimes=new Map;mutationStartTimes=new Map;lastQueryStates=new Map;lastMutationStates=new Map;setQueryClient(t){this.disconnect();this.queryClient=t;this.queryUnsubscribe=t.getQueryCache().subscribe(e=>{if(e.type==="updated"&&e.query){this.handleQueryUpdate(e.query)}});this.mutationUnsubscribe=t.getMutationCache().subscribe(e=>{if(e.type==="updated"&&e.mutation){this.handleMutationUpdate(e.mutation)}})}disconnect(){if(this.queryUnsubscribe){this.queryUnsubscribe();this.queryUnsubscribe=null}if(this.mutationUnsubscribe){this.mutationUnsubscribe();this.mutationUnsubscribe=null}this.queryClient=null;this.lastQueryStates.clear();this.lastMutationStates.clear();this.fetchStartTimes.clear();this.mutationStartTimes.clear()}handleQueryUpdate(t){if(h(t.queryKey)){return}const e=t.queryHash;const s={fetchStatus:t.state.fetchStatus,status:t.state.status};const a=this.lastQueryStates.get(e);if(!a){if(s.fetchStatus==="fetching"){this.fetchStartTimes.set(e,Date.now());this.addEvent({id:n(),type:"query-fetch-start",timestamp:Date.now(),queryKey:t.queryKey,queryHash:e,query:t})}}else{const i=a.fetchStatus==="fetching";const r=s.fetchStatus==="fetching";if(!i&&r){this.fetchStartTimes.set(e,Date.now());this.addEvent({id:n(),type:"query-fetch-start",timestamp:Date.now(),queryKey:t.queryKey,queryHash:e,query:t})}if(i&&!r){const o=this.fetchStartTimes.get(e);const c=o?Date.now()-o:void 0;this.fetchStartTimes.delete(e);if(s.status==="error"){this.addEvent({id:n(),type:"query-fetch-error",timestamp:Date.now(),queryKey:t.queryKey,queryHash:e,queryError:t.state.error,duration:c,query:t})}else{this.addEvent({id:n(),type:"query-fetch-success",timestamp:Date.now(),queryKey:t.queryKey,queryHash:e,queryData:t.state.data,duration:c,query:t})}}if(!a.status&&t.state.isInvalidated){this.addEvent({id:n(),type:"query-invalidated",timestamp:Date.now(),queryKey:t.queryKey,queryHash:e,query:t})}}this.lastQueryStates.set(e,s)}handleMutationUpdate(t){const e=t.mutationId;const s=t.state.status;const a=this.lastMutationStates.get(e);if(a!==s){if(s==="pending"&&a!=="pending"){this.mutationStartTimes.set(e,Date.now());this.addEvent({id:n(),type:"mutation-start",timestamp:Date.now(),mutationId:e,mutationKey:t.options.mutationKey,mutationVariables:t.state.variables,mutation:t})}else if(s==="success"&&a==="pending"){const i=this.mutationStartTimes.get(e);const r=i?Date.now()-i:void 0;this.mutationStartTimes.delete(e);this.addEvent({id:n(),type:"mutation-success",timestamp:Date.now(),mutationId:e,mutationKey:t.options.mutationKey,mutationVariables:t.state.variables,mutationData:t.state.data,duration:r,mutation:t})}else if(s==="error"&&a==="pending"){const i=this.mutationStartTimes.get(e);const r=i?Date.now()-i:void 0;this.mutationStartTimes.delete(e);this.addEvent({id:n(),type:"mutation-error",timestamp:Date.now(),mutationId:e,mutationKey:t.options.mutationKey,mutationVariables:t.state.variables,mutationError:t.state.error,duration:r,mutation:t})}}this.lastMutationStates.set(e,s)}addEvent(t){this.record(t)}getEvents(){return this.items}subscribe(t){const e=super.subscribe(t);t(this.items);return e}clearEvents(){this.clear()}isConnected(){return this.queryClient!==null}}export const reactQueryEventStore=new y;export const setQueryClient=u=>reactQueryEventStore.setQueryClient(u);export const disconnectQueryClient=()=>reactQueryEventStore.disconnect();export const getReactQueryEvents=()=>reactQueryEventStore.getEvents();export const subscribeToReactQueryEvents=u=>reactQueryEventStore.subscribe(u);export const clearReactQueryEvents=()=>reactQueryEventStore.clearEvents();export const isReactQueryConnected=()=>reactQueryEventStore.isConnected();
|
|
@@ -1,156 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Dehydration for external sync — ported from buoy-desktop's
|
|
5
|
-
* react-query-external-sync/hydration.ts so the desktop dashboard can
|
|
6
|
-
* hydrate an identical mirror of the device's QueryClient.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { isJsonSerializable, isOverWireBudget } from "@buoy-gg/shared-ui";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Sentinel used in WIRE-FORM snapshots in place of oversized query/mutation
|
|
13
|
-
* data. Same hazard as redux/zustand: a single cached payload can exceed the
|
|
14
|
-
* 2MB emit budget (dashboard goes stale) or freeze JSON.stringify. Dashboards
|
|
15
|
-
* fetch the real value via `getQueryData`.
|
|
16
|
-
*/
|
|
17
|
-
export const DATA_ON_DEVICE = Object.freeze({
|
|
18
|
-
__buoyDataOnDevice: true,
|
|
19
|
-
note: "Query data stays on the device — fetched on demand via getQueryData."
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
/** Sentinel when JSON.stringify throws (circular refs, bigint, …). */
|
|
23
|
-
export const UNSERIALIZABLE_DATA = Object.freeze({
|
|
24
|
-
__buoyUnserializable: true,
|
|
25
|
-
note: "Query data is not JSON-serializable (circular or bigint) and stayed on the device."
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
/** Keep small payloads inline; strip anything over this (same as network bodies). */
|
|
29
|
-
export const SNAPSHOT_DATA_INLINE_LIMIT = 16 * 1024;
|
|
30
|
-
export const MAX_QUERY_DETAIL_BYTES = 8 * 1024 * 1024;
|
|
31
|
-
export function isDataOnDeviceMarker(value) {
|
|
32
|
-
return !!value && typeof value === "object" && value.__buoyDataOnDevice === true;
|
|
33
|
-
}
|
|
34
|
-
export function isUnserializableMarker(value) {
|
|
35
|
-
return !!value && typeof value === "object" && value.__buoyUnserializable === true;
|
|
36
|
-
}
|
|
37
|
-
export function isWireDataMarker(value) {
|
|
38
|
-
return isDataOnDeviceMarker(value) || isUnserializableMarker(value);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Replace unserializable / oversized values with a wire marker. */
|
|
42
|
-
export function toWireData(value) {
|
|
43
|
-
if (value === undefined) return undefined;
|
|
44
|
-
if (!isOverWireBudget(value, SNAPSHOT_DATA_INLINE_LIMIT)) return value;
|
|
45
|
-
// Distinguish "too big to send" from "cannot be sent at all" — the dashboard
|
|
46
|
-
// offers a fetch for the first and must not for the second.
|
|
47
|
-
return isJsonSerializable(value) ? DATA_ON_DEVICE : UNSERIALIZABLE_DATA;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Query/mutation `error` (and `fetchFailureReason` / `failureReason`) often
|
|
52
|
-
* hold the live Axios/fetch error: `request` points at XHR (cyclic),
|
|
53
|
-
* `response.data` is the same fat body we already stripped from `state.data`.
|
|
54
|
-
* Spreading `query.state` left that copy on the wire after capping data.
|
|
55
|
-
* The dashboard only reads `error.message`.
|
|
56
|
-
*/
|
|
57
|
-
export function toWireError(value) {
|
|
58
|
-
if (value == null) return value;
|
|
59
|
-
if (typeof value === "object") {
|
|
60
|
-
const err = value;
|
|
61
|
-
const name = typeof err.name === "string" ? err.name : undefined;
|
|
62
|
-
const message = typeof err.message === "string" ? err.message : undefined;
|
|
63
|
-
if (name !== undefined || message !== undefined) {
|
|
64
|
-
return toWireData({
|
|
65
|
-
...(name !== undefined ? {
|
|
66
|
-
name
|
|
67
|
-
} : {}),
|
|
68
|
-
...(message !== undefined ? {
|
|
69
|
-
message
|
|
70
|
-
} : {})
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return toWireData(value);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Cap an on-demand detail payload (action result, not the per-tick snapshot). */
|
|
78
|
-
export function capQueryDetail(value) {
|
|
79
|
-
if (!isOverWireBudget(value, MAX_QUERY_DETAIL_BYTES)) return value;
|
|
80
|
-
if (!isJsonSerializable(value)) return UNSERIALIZABLE_DATA;
|
|
81
|
-
return {
|
|
82
|
-
__buoyTruncated: true,
|
|
83
|
-
note: `Exceeds the ${MAX_QUERY_DETAIL_BYTES / (1024 * 1024)}MB detail limit — inspect it on-device.`
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
export function dehydrateQueryClient(client) {
|
|
87
|
-
const mutations = client.getMutationCache().getAll().map(mutation => dehydrateMutation(mutation));
|
|
88
|
-
const queries = client.getQueryCache().getAll().map(query => dehydrateQuery(query));
|
|
89
|
-
return {
|
|
90
|
-
mutations,
|
|
91
|
-
queries
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function dehydrateMutation(mutation) {
|
|
95
|
-
const state = mutation.state;
|
|
96
|
-
return {
|
|
97
|
-
mutationId: mutation.mutationId,
|
|
98
|
-
mutationKey: mutation.options.mutationKey,
|
|
99
|
-
state: {
|
|
100
|
-
...state,
|
|
101
|
-
data: toWireData(state.data),
|
|
102
|
-
variables: toWireData(state.variables),
|
|
103
|
-
error: toWireError(state.error),
|
|
104
|
-
failureReason: toWireError(state.failureReason)
|
|
105
|
-
},
|
|
106
|
-
...(mutation.options.scope && {
|
|
107
|
-
scope: mutation.options.scope
|
|
108
|
-
}),
|
|
109
|
-
...(mutation.meta && {
|
|
110
|
-
meta: toWireData(mutation.meta)
|
|
111
|
-
})
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function toWireObserverOptions(options) {
|
|
115
|
-
// queryFn / select / persister are functions. initialData and
|
|
116
|
-
// placeholderData are often the SAME fat tree as state.data (apps seed
|
|
117
|
-
// the cache with it). Capping state.data still left those copies on the
|
|
118
|
-
// wire and dropped the Query panel.
|
|
119
|
-
const {
|
|
120
|
-
queryFn: _queryFn,
|
|
121
|
-
select: _select,
|
|
122
|
-
persister: _persister,
|
|
123
|
-
initialData: _initialData,
|
|
124
|
-
placeholderData: _placeholderData,
|
|
125
|
-
...light
|
|
126
|
-
} = options;
|
|
127
|
-
return {
|
|
128
|
-
...light,
|
|
129
|
-
queryFn: undefined,
|
|
130
|
-
...(options.meta ? {
|
|
131
|
-
meta: toWireData(options.meta)
|
|
132
|
-
} : {})
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function dehydrateQuery(query) {
|
|
136
|
-
const observerStates = query.observers.map(observer => ({
|
|
137
|
-
queryHash: query.queryHash,
|
|
138
|
-
options: toWireObserverOptions(observer.options)
|
|
139
|
-
}));
|
|
140
|
-
return {
|
|
141
|
-
state: {
|
|
142
|
-
...query.state,
|
|
143
|
-
...(query.state.data !== undefined && {
|
|
144
|
-
data: toWireData(query.state.data)
|
|
145
|
-
}),
|
|
146
|
-
error: toWireError(query.state.error),
|
|
147
|
-
fetchFailureReason: toWireError(query.state.fetchFailureReason)
|
|
148
|
-
},
|
|
149
|
-
queryKey: query.queryKey,
|
|
150
|
-
queryHash: query.queryHash,
|
|
151
|
-
...(query.meta && {
|
|
152
|
-
meta: toWireData(query.meta)
|
|
153
|
-
}),
|
|
154
|
-
observers: observerStates
|
|
155
|
-
};
|
|
156
|
-
}
|
|
1
|
+
"use strict";import{isJsonSerializable as a,isOverWireBudget as i}from"@buoy-gg/shared-ui";export const DATA_ON_DEVICE=Object.freeze({__buoyDataOnDevice:true,note:"Query data stays on the device \u2014 fetched on demand via getQueryData."});export const UNSERIALIZABLE_DATA=Object.freeze({__buoyUnserializable:true,note:"Query data is not JSON-serializable (circular or bigint) and stayed on the device."});export const SNAPSHOT_DATA_INLINE_LIMIT=16*1024;export const MAX_QUERY_DETAIL_BYTES=8*1024*1024;export function isDataOnDeviceMarker(e){return!!e&&typeof e==="object"&&e.__buoyDataOnDevice===true}export function isUnserializableMarker(e){return!!e&&typeof e==="object"&&e.__buoyUnserializable===true}export function isWireDataMarker(e){return isDataOnDeviceMarker(e)||isUnserializableMarker(e)}export function toWireData(e){if(e===void 0)return void 0;if(!i(e,SNAPSHOT_DATA_INLINE_LIMIT))return e;return a(e)?DATA_ON_DEVICE:UNSERIALIZABLE_DATA}export function toWireError(e){if(e==null)return e;if(typeof e==="object"){const t=e;const r=typeof t.name==="string"?t.name:void 0;const n=typeof t.message==="string"?t.message:void 0;if(r!==void 0||n!==void 0){return toWireData({...r!==void 0?{name:r}:{},...n!==void 0?{message:n}:{}})}}return toWireData(e)}export function capQueryDetail(e){if(!i(e,MAX_QUERY_DETAIL_BYTES))return e;if(!a(e))return UNSERIALIZABLE_DATA;return{__buoyTruncated:true,note:`Exceeds the ${MAX_QUERY_DETAIL_BYTES/(1024*1024)}MB detail limit \u2014 inspect it on-device.`}}export function dehydrateQueryClient(e){const t=e.getMutationCache().getAll().map(n=>s(n));const r=e.getQueryCache().getAll().map(n=>d(n));return{mutations:t,queries:r}}function s(e){const t=e.state;return{mutationId:e.mutationId,mutationKey:e.options.mutationKey,state:{...t,data:toWireData(t.data),variables:toWireData(t.variables),error:toWireError(t.error),failureReason:toWireError(t.failureReason)},...e.options.scope&&{scope:e.options.scope},...e.meta&&{meta:toWireData(e.meta)}}}function c(e){const{queryFn:t,select:r,persister:n,initialData:u,placeholderData:f,...o}=e;return{...o,queryFn:void 0,...e.meta?{meta:toWireData(e.meta)}:{}}}function d(e){const t=e.observers.map(r=>({queryHash:e.queryHash,options:c(r.options)}));return{state:{...e.state,...e.state.data!==void 0&&{data:toWireData(e.state.data)},error:toWireError(e.state.error),fetchFailureReason:toWireError(e.state.fetchFailureReason)},queryKey:e.queryKey,queryHash:e.queryHash,...e.meta&&{meta:toWireData(e.meta)},observers:t}}
|