@buoy-gg/react-query 2.1.16 → 3.0.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/lib/commonjs/index.js +12 -0
- package/lib/commonjs/preset.js +23 -0
- package/lib/commonjs/react-query/sync/dehydrate.js +56 -0
- package/lib/commonjs/react-query/sync/reactQuerySyncAdapter.js +132 -0
- package/lib/module/index.js +4 -0
- package/lib/module/preset.js +23 -0
- package/lib/module/react-query/sync/dehydrate.js +52 -0
- package/lib/module/react-query/sync/reactQuerySyncAdapter.js +127 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/preset.d.ts.map +1 -1
- package/lib/typescript/react-query/sync/dehydrate.d.ts +30 -0
- package/lib/typescript/react-query/sync/dehydrate.d.ts.map +1 -0
- package/lib/typescript/react-query/sync/reactQuerySyncAdapter.d.ts +34 -0
- package/lib/typescript/react-query/sync/reactQuerySyncAdapter.d.ts.map +1 -0
- package/package.json +3 -3
package/lib/commonjs/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var _exportNames = {
|
|
|
11
11
|
setQueryClient: true,
|
|
12
12
|
disconnectQueryClient: true,
|
|
13
13
|
reactQueryEventStore: true,
|
|
14
|
+
createReactQuerySyncAdapter: true,
|
|
14
15
|
ReactQueryModal: true,
|
|
15
16
|
ReactQueryModalHeader: true,
|
|
16
17
|
QueryBrowserModal: true,
|
|
@@ -316,6 +317,12 @@ Object.defineProperty(exports, "WifiToggle", {
|
|
|
316
317
|
return _WifiToggle.WifiToggle;
|
|
317
318
|
}
|
|
318
319
|
});
|
|
320
|
+
Object.defineProperty(exports, "createReactQuerySyncAdapter", {
|
|
321
|
+
enumerable: true,
|
|
322
|
+
get: function () {
|
|
323
|
+
return _reactQuerySyncAdapter.createReactQuerySyncAdapter;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
319
326
|
Object.defineProperty(exports, "createReactQueryTool", {
|
|
320
327
|
enumerable: true,
|
|
321
328
|
get: function () {
|
|
@@ -504,6 +511,7 @@ Object.defineProperty(exports, "wifiTogglePreset", {
|
|
|
504
511
|
});
|
|
505
512
|
var _preset = require("./preset");
|
|
506
513
|
var _reactQueryEventStore = require("./react-query/stores/reactQueryEventStore");
|
|
514
|
+
var _reactQuerySyncAdapter = require("./react-query/sync/reactQuerySyncAdapter");
|
|
507
515
|
var _ReactQueryModal = require("./react-query/components/modals/ReactQueryModal");
|
|
508
516
|
var _ReactQueryModalHeader = require("./react-query/components/modals/ReactQueryModalHeader");
|
|
509
517
|
var _QueryBrowserModal = require("./react-query/components/modals/QueryBrowserModal");
|
|
@@ -655,6 +663,10 @@ try {
|
|
|
655
663
|
// QUERY CLIENT CONNECTION (Required for users to connect their QueryClient)
|
|
656
664
|
// =============================================================================
|
|
657
665
|
|
|
666
|
+
// =============================================================================
|
|
667
|
+
// EXTERNAL SYNC (Adapter factory for @buoy-gg/external-sync's useExternalSync)
|
|
668
|
+
// =============================================================================
|
|
669
|
+
|
|
658
670
|
// =============================================================================
|
|
659
671
|
// COMPONENTS (For custom UI implementations)
|
|
660
672
|
// =============================================================================
|
package/lib/commonjs/preset.js
CHANGED
|
@@ -41,6 +41,29 @@ const saveWifiState = async enabled => {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Restore the persisted WiFi state into onlineManager on app load.
|
|
46
|
+
*
|
|
47
|
+
* The toggle is rendered as a `toggle-only` tool whose state lives in
|
|
48
|
+
* `onlineManager`, not in a mounted React component. The `useWifiState` hook
|
|
49
|
+
* only restores when its component (the modal) mounts, so without this the
|
|
50
|
+
* persisted offline state is lost on reload and defaults back to online.
|
|
51
|
+
* Running this at module load ensures the saved state is applied eagerly.
|
|
52
|
+
*/
|
|
53
|
+
const restoreWifiState = async () => {
|
|
54
|
+
try {
|
|
55
|
+
const savedState = await _sharedUi.persistentStorage.getItem(_sharedUi.devToolsStorageKeys.settings.wifiEnabled());
|
|
56
|
+
if (savedState !== null) {
|
|
57
|
+
_reactQuery.onlineManager.setOnline(savedState === "true");
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
// Failed to restore WiFi state
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Eagerly restore persisted WiFi state on import so offline mode survives reloads.
|
|
65
|
+
restoreWifiState();
|
|
66
|
+
|
|
44
67
|
/**
|
|
45
68
|
* WiFi icon component - uses hooks to subscribe to onlineManager changes.
|
|
46
69
|
*
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dehydrateQueryClient = dehydrateQueryClient;
|
|
7
|
+
/**
|
|
8
|
+
* Dehydration for external sync — ported from buoy-desktop's
|
|
9
|
+
* react-query-external-sync/hydration.ts so the desktop dashboard can
|
|
10
|
+
* hydrate an identical mirror of the device's QueryClient.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function dehydrateQueryClient(client) {
|
|
14
|
+
const mutations = client.getMutationCache().getAll().map(mutation => dehydrateMutation(mutation));
|
|
15
|
+
const queries = client.getQueryCache().getAll().map(query => dehydrateQuery(query));
|
|
16
|
+
return {
|
|
17
|
+
mutations,
|
|
18
|
+
queries
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function dehydrateMutation(mutation) {
|
|
22
|
+
return {
|
|
23
|
+
mutationId: mutation.mutationId,
|
|
24
|
+
mutationKey: mutation.options.mutationKey,
|
|
25
|
+
state: mutation.state,
|
|
26
|
+
...(mutation.options.scope && {
|
|
27
|
+
scope: mutation.options.scope
|
|
28
|
+
}),
|
|
29
|
+
...(mutation.meta && {
|
|
30
|
+
meta: mutation.meta
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function dehydrateQuery(query) {
|
|
35
|
+
const observerStates = query.observers.map(observer => ({
|
|
36
|
+
queryHash: query.queryHash,
|
|
37
|
+
options: observer.options,
|
|
38
|
+
// Remove queryFn from observer options so the dashboard can't accidentally
|
|
39
|
+
// run device fetch functions (they aren't serializable anyway)
|
|
40
|
+
queryFn: undefined
|
|
41
|
+
}));
|
|
42
|
+
return {
|
|
43
|
+
state: {
|
|
44
|
+
...query.state,
|
|
45
|
+
...(query.state.data !== undefined && {
|
|
46
|
+
data: query.state.data
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
queryKey: query.queryKey,
|
|
50
|
+
queryHash: query.queryHash,
|
|
51
|
+
...(query.meta && {
|
|
52
|
+
meta: query.meta
|
|
53
|
+
}),
|
|
54
|
+
observers: observerStates
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createReactQuerySyncAdapter = createReactQuerySyncAdapter;
|
|
7
|
+
var _reactQuery = require("@tanstack/react-query");
|
|
8
|
+
var _dehydrate = require("./dehydrate");
|
|
9
|
+
/**
|
|
10
|
+
* Sync adapter for the React Query tool, consumed by @buoy-gg/external-sync's
|
|
11
|
+
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
12
|
+
* this package doesn't need a dependency on it).
|
|
13
|
+
*
|
|
14
|
+
* Action handlers are ported from buoy-desktop's react-query-external-sync
|
|
15
|
+
* (useSyncQueries.ts) so the dashboard keeps identical behavior, including
|
|
16
|
+
* the trigger/restore loading and error simulations used by the TanStack
|
|
17
|
+
* devtools UI.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function createReactQuerySyncAdapter(queryClient) {
|
|
21
|
+
const getQuery = params => {
|
|
22
|
+
const {
|
|
23
|
+
queryHash
|
|
24
|
+
} = params;
|
|
25
|
+
const query = queryClient.getQueryCache().get(queryHash);
|
|
26
|
+
if (!query) {
|
|
27
|
+
throw new Error(`Query with hash "${queryHash}" not found`);
|
|
28
|
+
}
|
|
29
|
+
return query;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
version: 1,
|
|
33
|
+
getSnapshot: () => ({
|
|
34
|
+
dehydratedState: (0, _dehydrate.dehydrateQueryClient)(queryClient),
|
|
35
|
+
isOnlineManagerOnline: _reactQuery.onlineManager.isOnline()
|
|
36
|
+
}),
|
|
37
|
+
subscribe: onChange => {
|
|
38
|
+
const unsubQueries = queryClient.getQueryCache().subscribe(onChange);
|
|
39
|
+
const unsubMutations = queryClient.getMutationCache().subscribe(onChange);
|
|
40
|
+
const unsubOnline = _reactQuery.onlineManager.subscribe(onChange);
|
|
41
|
+
return () => {
|
|
42
|
+
unsubQueries();
|
|
43
|
+
unsubMutations();
|
|
44
|
+
unsubOnline();
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
actions: {
|
|
48
|
+
refetch: params => {
|
|
49
|
+
const query = getQuery(params);
|
|
50
|
+
// Swallow fetch rejections — the resulting error state syncs anyway
|
|
51
|
+
return query.fetch().catch(() => undefined);
|
|
52
|
+
},
|
|
53
|
+
invalidate: params => queryClient.invalidateQueries(getQuery(params)),
|
|
54
|
+
reset: params => queryClient.resetQueries(getQuery(params)),
|
|
55
|
+
remove: params => {
|
|
56
|
+
queryClient.removeQueries(getQuery(params));
|
|
57
|
+
},
|
|
58
|
+
setQueryData: params => {
|
|
59
|
+
const {
|
|
60
|
+
queryKey,
|
|
61
|
+
data
|
|
62
|
+
} = params;
|
|
63
|
+
queryClient.setQueryData(queryKey, data, {
|
|
64
|
+
updatedAt: Date.now()
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
triggerError: params => {
|
|
68
|
+
const query = getQuery(params);
|
|
69
|
+
const __previousQueryOptions = query.options;
|
|
70
|
+
query.setState({
|
|
71
|
+
status: "error",
|
|
72
|
+
error: new Error("Unknown error from devtools"),
|
|
73
|
+
fetchMeta: {
|
|
74
|
+
...query.state.fetchMeta,
|
|
75
|
+
// @ts-expect-error This does exist
|
|
76
|
+
__previousQueryOptions
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
restoreError: params => queryClient.resetQueries(getQuery(params)),
|
|
81
|
+
triggerLoading: params => {
|
|
82
|
+
const query = getQuery(params);
|
|
83
|
+
const __previousQueryOptions = query.options;
|
|
84
|
+
// Trigger a fetch in order to trigger suspense as well
|
|
85
|
+
query.fetch({
|
|
86
|
+
...__previousQueryOptions,
|
|
87
|
+
queryFn: () => new Promise(() => {
|
|
88
|
+
// Never resolve — simulates perpetual loading
|
|
89
|
+
}),
|
|
90
|
+
gcTime: -1
|
|
91
|
+
}).catch(() => undefined);
|
|
92
|
+
query.setState({
|
|
93
|
+
data: undefined,
|
|
94
|
+
status: "pending",
|
|
95
|
+
fetchMeta: {
|
|
96
|
+
...query.state.fetchMeta,
|
|
97
|
+
// @ts-expect-error This does exist
|
|
98
|
+
__previousQueryOptions
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
restoreLoading: params => {
|
|
103
|
+
const query = getQuery(params);
|
|
104
|
+
const previousState = query.state;
|
|
105
|
+
const previousOptions = query.state.fetchMeta ? query.state.fetchMeta.__previousQueryOptions : null;
|
|
106
|
+
query.cancel({
|
|
107
|
+
silent: true
|
|
108
|
+
});
|
|
109
|
+
query.setState({
|
|
110
|
+
...previousState,
|
|
111
|
+
fetchStatus: "idle",
|
|
112
|
+
fetchMeta: null
|
|
113
|
+
});
|
|
114
|
+
if (previousOptions) {
|
|
115
|
+
query.fetch(previousOptions).catch(() => undefined);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
clearQueryCache: () => {
|
|
119
|
+
queryClient.getQueryCache().clear();
|
|
120
|
+
},
|
|
121
|
+
clearMutationCache: () => {
|
|
122
|
+
queryClient.getMutationCache().clear();
|
|
123
|
+
},
|
|
124
|
+
setOnline: params => {
|
|
125
|
+
const {
|
|
126
|
+
online
|
|
127
|
+
} = params;
|
|
128
|
+
_reactQuery.onlineManager.setOnline(online);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
package/lib/module/index.js
CHANGED
|
@@ -27,6 +27,10 @@ export { reactQueryToolPreset, createReactQueryTool, wifiTogglePreset, createWif
|
|
|
27
27
|
// =============================================================================
|
|
28
28
|
export { setQueryClient, disconnectQueryClient } from "./react-query/stores/reactQueryEventStore";
|
|
29
29
|
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// EXTERNAL SYNC (Adapter factory for @buoy-gg/external-sync's useExternalSync)
|
|
32
|
+
// =============================================================================
|
|
33
|
+
export { createReactQuerySyncAdapter } from "./react-query/sync/reactQuerySyncAdapter";
|
|
30
34
|
// =============================================================================
|
|
31
35
|
// COMPONENTS (For custom UI implementations)
|
|
32
36
|
// =============================================================================
|
package/lib/module/preset.js
CHANGED
|
@@ -34,6 +34,29 @@ const saveWifiState = async enabled => {
|
|
|
34
34
|
// Failed to save WiFi state
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Restore the persisted WiFi state into onlineManager on app load.
|
|
40
|
+
*
|
|
41
|
+
* The toggle is rendered as a `toggle-only` tool whose state lives in
|
|
42
|
+
* `onlineManager`, not in a mounted React component. The `useWifiState` hook
|
|
43
|
+
* only restores when its component (the modal) mounts, so without this the
|
|
44
|
+
* persisted offline state is lost on reload and defaults back to online.
|
|
45
|
+
* Running this at module load ensures the saved state is applied eagerly.
|
|
46
|
+
*/
|
|
47
|
+
const restoreWifiState = async () => {
|
|
48
|
+
try {
|
|
49
|
+
const savedState = await persistentStorage.getItem(devToolsStorageKeys.settings.wifiEnabled());
|
|
50
|
+
if (savedState !== null) {
|
|
51
|
+
onlineManager.setOnline(savedState === "true");
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
// Failed to restore WiFi state
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Eagerly restore persisted WiFi state on import so offline mode survives reloads.
|
|
59
|
+
restoreWifiState();
|
|
37
60
|
import { useState, useEffect } from "react";
|
|
38
61
|
|
|
39
62
|
/**
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
export function dehydrateQueryClient(client) {
|
|
10
|
+
const mutations = client.getMutationCache().getAll().map(mutation => dehydrateMutation(mutation));
|
|
11
|
+
const queries = client.getQueryCache().getAll().map(query => dehydrateQuery(query));
|
|
12
|
+
return {
|
|
13
|
+
mutations,
|
|
14
|
+
queries
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function dehydrateMutation(mutation) {
|
|
18
|
+
return {
|
|
19
|
+
mutationId: mutation.mutationId,
|
|
20
|
+
mutationKey: mutation.options.mutationKey,
|
|
21
|
+
state: mutation.state,
|
|
22
|
+
...(mutation.options.scope && {
|
|
23
|
+
scope: mutation.options.scope
|
|
24
|
+
}),
|
|
25
|
+
...(mutation.meta && {
|
|
26
|
+
meta: mutation.meta
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function dehydrateQuery(query) {
|
|
31
|
+
const observerStates = query.observers.map(observer => ({
|
|
32
|
+
queryHash: query.queryHash,
|
|
33
|
+
options: observer.options,
|
|
34
|
+
// Remove queryFn from observer options so the dashboard can't accidentally
|
|
35
|
+
// run device fetch functions (they aren't serializable anyway)
|
|
36
|
+
queryFn: undefined
|
|
37
|
+
}));
|
|
38
|
+
return {
|
|
39
|
+
state: {
|
|
40
|
+
...query.state,
|
|
41
|
+
...(query.state.data !== undefined && {
|
|
42
|
+
data: query.state.data
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
queryKey: query.queryKey,
|
|
46
|
+
queryHash: query.queryHash,
|
|
47
|
+
...(query.meta && {
|
|
48
|
+
meta: query.meta
|
|
49
|
+
}),
|
|
50
|
+
observers: observerStates
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sync adapter for the React Query tool, consumed by @buoy-gg/external-sync's
|
|
5
|
+
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
6
|
+
* this package doesn't need a dependency on it).
|
|
7
|
+
*
|
|
8
|
+
* Action handlers are ported from buoy-desktop's react-query-external-sync
|
|
9
|
+
* (useSyncQueries.ts) so the dashboard keeps identical behavior, including
|
|
10
|
+
* the trigger/restore loading and error simulations used by the TanStack
|
|
11
|
+
* devtools UI.
|
|
12
|
+
*/
|
|
13
|
+
import { onlineManager } from "@tanstack/react-query";
|
|
14
|
+
import { dehydrateQueryClient } from "./dehydrate";
|
|
15
|
+
export function createReactQuerySyncAdapter(queryClient) {
|
|
16
|
+
const getQuery = params => {
|
|
17
|
+
const {
|
|
18
|
+
queryHash
|
|
19
|
+
} = params;
|
|
20
|
+
const query = queryClient.getQueryCache().get(queryHash);
|
|
21
|
+
if (!query) {
|
|
22
|
+
throw new Error(`Query with hash "${queryHash}" not found`);
|
|
23
|
+
}
|
|
24
|
+
return query;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
version: 1,
|
|
28
|
+
getSnapshot: () => ({
|
|
29
|
+
dehydratedState: dehydrateQueryClient(queryClient),
|
|
30
|
+
isOnlineManagerOnline: onlineManager.isOnline()
|
|
31
|
+
}),
|
|
32
|
+
subscribe: onChange => {
|
|
33
|
+
const unsubQueries = queryClient.getQueryCache().subscribe(onChange);
|
|
34
|
+
const unsubMutations = queryClient.getMutationCache().subscribe(onChange);
|
|
35
|
+
const unsubOnline = onlineManager.subscribe(onChange);
|
|
36
|
+
return () => {
|
|
37
|
+
unsubQueries();
|
|
38
|
+
unsubMutations();
|
|
39
|
+
unsubOnline();
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
actions: {
|
|
43
|
+
refetch: params => {
|
|
44
|
+
const query = getQuery(params);
|
|
45
|
+
// Swallow fetch rejections — the resulting error state syncs anyway
|
|
46
|
+
return query.fetch().catch(() => undefined);
|
|
47
|
+
},
|
|
48
|
+
invalidate: params => queryClient.invalidateQueries(getQuery(params)),
|
|
49
|
+
reset: params => queryClient.resetQueries(getQuery(params)),
|
|
50
|
+
remove: params => {
|
|
51
|
+
queryClient.removeQueries(getQuery(params));
|
|
52
|
+
},
|
|
53
|
+
setQueryData: params => {
|
|
54
|
+
const {
|
|
55
|
+
queryKey,
|
|
56
|
+
data
|
|
57
|
+
} = params;
|
|
58
|
+
queryClient.setQueryData(queryKey, data, {
|
|
59
|
+
updatedAt: Date.now()
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
triggerError: params => {
|
|
63
|
+
const query = getQuery(params);
|
|
64
|
+
const __previousQueryOptions = query.options;
|
|
65
|
+
query.setState({
|
|
66
|
+
status: "error",
|
|
67
|
+
error: new Error("Unknown error from devtools"),
|
|
68
|
+
fetchMeta: {
|
|
69
|
+
...query.state.fetchMeta,
|
|
70
|
+
// @ts-expect-error This does exist
|
|
71
|
+
__previousQueryOptions
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
restoreError: params => queryClient.resetQueries(getQuery(params)),
|
|
76
|
+
triggerLoading: params => {
|
|
77
|
+
const query = getQuery(params);
|
|
78
|
+
const __previousQueryOptions = query.options;
|
|
79
|
+
// Trigger a fetch in order to trigger suspense as well
|
|
80
|
+
query.fetch({
|
|
81
|
+
...__previousQueryOptions,
|
|
82
|
+
queryFn: () => new Promise(() => {
|
|
83
|
+
// Never resolve — simulates perpetual loading
|
|
84
|
+
}),
|
|
85
|
+
gcTime: -1
|
|
86
|
+
}).catch(() => undefined);
|
|
87
|
+
query.setState({
|
|
88
|
+
data: undefined,
|
|
89
|
+
status: "pending",
|
|
90
|
+
fetchMeta: {
|
|
91
|
+
...query.state.fetchMeta,
|
|
92
|
+
// @ts-expect-error This does exist
|
|
93
|
+
__previousQueryOptions
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
restoreLoading: params => {
|
|
98
|
+
const query = getQuery(params);
|
|
99
|
+
const previousState = query.state;
|
|
100
|
+
const previousOptions = query.state.fetchMeta ? query.state.fetchMeta.__previousQueryOptions : null;
|
|
101
|
+
query.cancel({
|
|
102
|
+
silent: true
|
|
103
|
+
});
|
|
104
|
+
query.setState({
|
|
105
|
+
...previousState,
|
|
106
|
+
fetchStatus: "idle",
|
|
107
|
+
fetchMeta: null
|
|
108
|
+
});
|
|
109
|
+
if (previousOptions) {
|
|
110
|
+
query.fetch(previousOptions).catch(() => undefined);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
clearQueryCache: () => {
|
|
114
|
+
queryClient.getQueryCache().clear();
|
|
115
|
+
},
|
|
116
|
+
clearMutationCache: () => {
|
|
117
|
+
queryClient.getMutationCache().clear();
|
|
118
|
+
},
|
|
119
|
+
setOnline: params => {
|
|
120
|
+
const {
|
|
121
|
+
online
|
|
122
|
+
} = params;
|
|
123
|
+
onlineManager.setOnline(online);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { reactQueryToolPreset, createReactQueryTool, wifiTogglePreset, createWifiToggleTool, } from "./preset";
|
|
11
11
|
export { setQueryClient, disconnectQueryClient, type ReactQueryEvent, type ReactQueryEventType, } from "./react-query/stores/reactQueryEventStore";
|
|
12
|
+
export { createReactQuerySyncAdapter } from "./react-query/sync/reactQuerySyncAdapter";
|
|
13
|
+
export type { DehydratedState, DehydratedQuery, DehydratedMutation, ObserverState, } from "./react-query/sync/dehydrate";
|
|
12
14
|
export { ReactQueryModal } from "./react-query/components/modals/ReactQueryModal";
|
|
13
15
|
export { ReactQueryModalHeader } from "./react-query/components/modals/ReactQueryModalHeader";
|
|
14
16
|
export { QueryBrowserModal } from "./react-query/components/modals/QueryBrowserModal";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAKlB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAKlB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,2CAA2C,CAAC;AAKnD,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AACvF,YAAY,EACV,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,aAAa,GACd,MAAM,8BAA8B,CAAC;AAOtC,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE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AO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAK1D,gBAAgB;AAChB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../src/preset.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;
|
|
1
|
+
{"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../src/preset.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AA+C3F;;;;;;;;;;;;;GAaG;AACH,iBAAS,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,+BAY3C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB;;;;;qBAKd;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;;;;;CAKlC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACvC;;;;;qBAMoB;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;;;;;EASpC;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;CAc5B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;;;;;qBAWmC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;;;;;EA6BnD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dehydration for external sync — ported from buoy-desktop's
|
|
3
|
+
* react-query-external-sync/hydration.ts so the desktop dashboard can
|
|
4
|
+
* hydrate an identical mirror of the device's QueryClient.
|
|
5
|
+
*/
|
|
6
|
+
import type { DefaultError, MutationKey, MutationMeta, MutationScope, MutationState, QueryClient, QueryKey, QueryMeta, QueryObserverOptions, QueryState } from "@tanstack/react-query";
|
|
7
|
+
export interface DehydratedState {
|
|
8
|
+
mutations: DehydratedMutation[];
|
|
9
|
+
queries: DehydratedQuery[];
|
|
10
|
+
}
|
|
11
|
+
export interface DehydratedMutation {
|
|
12
|
+
mutationId: number;
|
|
13
|
+
mutationKey?: MutationKey;
|
|
14
|
+
state: MutationState;
|
|
15
|
+
meta?: MutationMeta;
|
|
16
|
+
scope?: MutationScope;
|
|
17
|
+
}
|
|
18
|
+
export interface DehydratedQuery {
|
|
19
|
+
queryHash: string;
|
|
20
|
+
queryKey: QueryKey;
|
|
21
|
+
state: QueryState;
|
|
22
|
+
meta?: QueryMeta;
|
|
23
|
+
observers: ObserverState[];
|
|
24
|
+
}
|
|
25
|
+
export interface ObserverState<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
|
|
26
|
+
queryHash: string;
|
|
27
|
+
options: QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>;
|
|
28
|
+
}
|
|
29
|
+
export declare function dehydrateQueryClient(client: QueryClient): DehydratedState;
|
|
30
|
+
//# sourceMappingURL=dehydrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dehydrate.d.ts","sourceRoot":"","sources":["../../../../src/react-query/sync/dehydrate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,YAAY,EAEZ,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EAEb,WAAW,EAEX,QAAQ,EACR,SAAS,EACT,oBAAoB,EACpB,UAAU,EACX,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa,CAC5B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,UAAU,GAAG,YAAY,EACzB,SAAS,SAAS,QAAQ,GAAG,QAAQ;IAErC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,oBAAoB,CAC3B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,CACV,CAAC;CACH;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,eAAe,CAYzE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync adapter for the React Query tool, consumed by @buoy-gg/external-sync's
|
|
3
|
+
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
4
|
+
* this package doesn't need a dependency on it).
|
|
5
|
+
*
|
|
6
|
+
* Action handlers are ported from buoy-desktop's react-query-external-sync
|
|
7
|
+
* (useSyncQueries.ts) so the dashboard keeps identical behavior, including
|
|
8
|
+
* the trigger/restore loading and error simulations used by the TanStack
|
|
9
|
+
* devtools UI.
|
|
10
|
+
*/
|
|
11
|
+
import { type QueryClient } from "@tanstack/react-query";
|
|
12
|
+
export declare function createReactQuerySyncAdapter(queryClient: QueryClient): {
|
|
13
|
+
version: number;
|
|
14
|
+
getSnapshot: () => {
|
|
15
|
+
dehydratedState: import("./dehydrate").DehydratedState;
|
|
16
|
+
isOnlineManagerOnline: boolean;
|
|
17
|
+
};
|
|
18
|
+
subscribe: (onChange: () => void) => () => void;
|
|
19
|
+
actions: {
|
|
20
|
+
refetch: (params: unknown) => Promise<unknown>;
|
|
21
|
+
invalidate: (params: unknown) => Promise<void>;
|
|
22
|
+
reset: (params: unknown) => Promise<void>;
|
|
23
|
+
remove: (params: unknown) => void;
|
|
24
|
+
setQueryData: (params: unknown) => void;
|
|
25
|
+
triggerError: (params: unknown) => void;
|
|
26
|
+
restoreError: (params: unknown) => Promise<void>;
|
|
27
|
+
triggerLoading: (params: unknown) => void;
|
|
28
|
+
restoreLoading: (params: unknown) => void;
|
|
29
|
+
clearQueryCache: () => void;
|
|
30
|
+
clearMutationCache: () => void;
|
|
31
|
+
setOnline: (params: unknown) => void;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=reactQuerySyncAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactQuerySyncAdapter.d.ts","sourceRoot":"","sources":["../../../../src/react-query/sync/reactQuerySyncAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAiB,KAAK,WAAW,EAAiB,MAAM,uBAAuB,CAAC;AAgBvF,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW;;;;;;0BAgB1C,MAAM,IAAI;;0BAaZ,OAAO;6BAKJ,OAAO;wBAEZ,OAAO;yBACN,OAAO;+BAGD,OAAO;+BAIP,OAAO;+BAaP,OAAO;iCAEL,OAAO;iCAwBP,OAAO;;;4BA4BZ,OAAO;;EAMhC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/react-query",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "react-query package",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
],
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@buoy-gg/
|
|
30
|
-
"@buoy-gg/
|
|
29
|
+
"@buoy-gg/floating-tools-core": "3.0.0",
|
|
30
|
+
"@buoy-gg/shared-ui": "3.0.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@tanstack/react-query": ">=5.0.0",
|