@rozenite/tanstack-query-plugin 1.5.1 → 1.7.0-rc.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +22 -0
  3. package/dist/{tanstack-query.html → devtools/tanstack-query.html} +1 -1
  4. package/dist/react-native/chunks/useTanStackQueryDevTools.require.cjs +1 -0
  5. package/dist/react-native/chunks/useTanStackQueryDevTools.require.js +862 -0
  6. package/dist/{react-native.cjs → react-native/index.cjs} +1 -1
  7. package/dist/react-native/index.d.ts +7 -0
  8. package/dist/react-native/index.js +6 -0
  9. package/dist/rozenite.json +1 -1
  10. package/package.json +27 -7
  11. package/src/react-native/agent/__tests__/tanstack-query-agent.test.ts +508 -0
  12. package/src/react-native/agent/tanstack-query-agent.ts +750 -0
  13. package/src/react-native/agent/useTanStackQueryAgentTools.ts +147 -0
  14. package/src/react-native/devtools-actions.ts +197 -0
  15. package/src/react-native/useHandleDevToolsMessages.ts +9 -104
  16. package/src/react-native/useTanStackQueryDevTools.ts +3 -0
  17. package/tsconfig.json +3 -0
  18. package/dist/react-native.d.ts +0 -1
  19. package/dist/react-native.js +0 -6
  20. package/dist/rozenite.config.d.ts +0 -7
  21. package/dist/src/react-native/useHandleDevToolsMessages.d.ts +0 -3
  22. package/dist/src/react-native/useHandleInitialData.d.ts +0 -3
  23. package/dist/src/react-native/useSyncTanStackCache.d.ts +0 -3
  24. package/dist/src/react-native/useTanStackQueryDevTools.d.ts +0 -2
  25. package/dist/src/shared/dehydrate.d.ts +0 -6
  26. package/dist/src/shared/hydrate.d.ts +0 -10
  27. package/dist/src/shared/messaging.d.ts +0 -34
  28. package/dist/src/shared/types.d.ts +0 -25
  29. package/dist/src/shared/useSyncOnlineStatus.d.ts +0 -2
  30. package/dist/src/ui/tanstack-query.d.ts +0 -1
  31. package/dist/src/ui/useHandleSyncMessages.d.ts +0 -2
  32. package/dist/src/ui/useSyncDevToolsEvents.d.ts +0 -2
  33. package/dist/src/ui/useSyncInitialData.d.ts +0 -2
  34. package/dist/useTanStackQueryDevTools.cjs +0 -1
  35. package/dist/useTanStackQueryDevTools.js +0 -312
  36. /package/dist/{assets → devtools/assets}/CXEL7IU7-DJlSmt0p.js +0 -0
  37. /package/dist/{assets → devtools/assets}/tanstack-query-_leiFatc.js +0 -0
@@ -0,0 +1,147 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import { useRozenitePluginAgentTool } from '@rozenite/agent-bridge';
4
+ import {
5
+ clearMutationCacheTool,
6
+ clearQueryCacheTool,
7
+ createTanStackQueryAgentController,
8
+ getCacheSummaryTool,
9
+ getMutationDetailsTool,
10
+ getOnlineStatusTool,
11
+ getQueryDetailsTool,
12
+ invalidateQueryTool,
13
+ listMutationsTool,
14
+ listQueriesTool,
15
+ refetchQueryTool,
16
+ removeQueryTool,
17
+ resetQueryTool,
18
+ setQueryErrorTool,
19
+ setQueryLoadingTool,
20
+ TANSTACK_QUERY_AGENT_PLUGIN_ID,
21
+ type TanStackQueryAgentMutationIdInput,
22
+ type TanStackQueryAgentOnlineStatusInput,
23
+ type TanStackQueryAgentPaginationInput,
24
+ type TanStackQueryAgentQueryHashInput,
25
+ type TanStackQueryAgentQueryToggleInput,
26
+ setOnlineStatusTool,
27
+ } from './tanstack-query-agent';
28
+
29
+ export const useTanStackQueryAgentTools = (queryClient: QueryClient) => {
30
+ const controller = useMemo(
31
+ () => createTanStackQueryAgentController(queryClient),
32
+ [queryClient]
33
+ );
34
+
35
+ useEffect(() => {
36
+ const unsubscribeQueryCache = queryClient
37
+ .getQueryCache()
38
+ .subscribe((event) => controller.handleQueryCacheEvent(event));
39
+ const unsubscribeMutationCache = queryClient
40
+ .getMutationCache()
41
+ .subscribe((event) => controller.handleMutationCacheEvent(event));
42
+
43
+ return () => {
44
+ unsubscribeQueryCache();
45
+ unsubscribeMutationCache();
46
+ };
47
+ }, [controller, queryClient]);
48
+
49
+ useRozenitePluginAgentTool({
50
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
51
+ tool: getCacheSummaryTool,
52
+ handler: () => controller.getCacheSummary(),
53
+ });
54
+
55
+ useRozenitePluginAgentTool({
56
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
57
+ tool: getOnlineStatusTool,
58
+ handler: () => controller.getOnlineStatus(),
59
+ });
60
+
61
+ useRozenitePluginAgentTool<TanStackQueryAgentOnlineStatusInput>({
62
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
63
+ tool: setOnlineStatusTool,
64
+ handler: (input: TanStackQueryAgentOnlineStatusInput) =>
65
+ controller.setOnlineStatus(input),
66
+ });
67
+
68
+ useRozenitePluginAgentTool<TanStackQueryAgentPaginationInput>({
69
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
70
+ tool: listQueriesTool,
71
+ handler: (input = {}) => controller.listQueries(input),
72
+ });
73
+
74
+ useRozenitePluginAgentTool<TanStackQueryAgentQueryHashInput>({
75
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
76
+ tool: getQueryDetailsTool,
77
+ handler: (input: TanStackQueryAgentQueryHashInput) =>
78
+ controller.getQueryDetails(input),
79
+ });
80
+
81
+ useRozenitePluginAgentTool<TanStackQueryAgentQueryHashInput>({
82
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
83
+ tool: refetchQueryTool,
84
+ handler: (input: TanStackQueryAgentQueryHashInput) =>
85
+ controller.refetchQuery(input),
86
+ });
87
+
88
+ useRozenitePluginAgentTool<TanStackQueryAgentQueryToggleInput>({
89
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
90
+ tool: setQueryLoadingTool,
91
+ handler: (input: TanStackQueryAgentQueryToggleInput) =>
92
+ controller.setQueryLoading(input),
93
+ });
94
+
95
+ useRozenitePluginAgentTool<TanStackQueryAgentQueryToggleInput>({
96
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
97
+ tool: setQueryErrorTool,
98
+ handler: (input: TanStackQueryAgentQueryToggleInput) =>
99
+ controller.setQueryError(input),
100
+ });
101
+
102
+ useRozenitePluginAgentTool<TanStackQueryAgentQueryHashInput>({
103
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
104
+ tool: invalidateQueryTool,
105
+ handler: (input: TanStackQueryAgentQueryHashInput) =>
106
+ controller.invalidateQuery(input),
107
+ });
108
+
109
+ useRozenitePluginAgentTool<TanStackQueryAgentQueryHashInput>({
110
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
111
+ tool: resetQueryTool,
112
+ handler: (input: TanStackQueryAgentQueryHashInput) =>
113
+ controller.resetQuery(input),
114
+ });
115
+
116
+ useRozenitePluginAgentTool<TanStackQueryAgentQueryHashInput>({
117
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
118
+ tool: removeQueryTool,
119
+ handler: (input: TanStackQueryAgentQueryHashInput) =>
120
+ controller.removeQuery(input),
121
+ });
122
+
123
+ useRozenitePluginAgentTool({
124
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
125
+ tool: clearQueryCacheTool,
126
+ handler: () => controller.clearQueryCache(),
127
+ });
128
+
129
+ useRozenitePluginAgentTool<TanStackQueryAgentPaginationInput>({
130
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
131
+ tool: listMutationsTool,
132
+ handler: (input = {}) => controller.listMutations(input),
133
+ });
134
+
135
+ useRozenitePluginAgentTool<TanStackQueryAgentMutationIdInput>({
136
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
137
+ tool: getMutationDetailsTool,
138
+ handler: (input: TanStackQueryAgentMutationIdInput) =>
139
+ controller.getMutationDetails(input),
140
+ });
141
+
142
+ useRozenitePluginAgentTool({
143
+ pluginId: TANSTACK_QUERY_AGENT_PLUGIN_ID,
144
+ tool: clearMutationCacheTool,
145
+ handler: () => controller.clearMutationCache(),
146
+ });
147
+ };
@@ -0,0 +1,197 @@
1
+ import { QueryClient } from '@tanstack/react-query';
2
+ import { DevToolsActionType } from '../shared/types';
3
+
4
+ type QueryScopedActionInput = {
5
+ type: Exclude<
6
+ DevToolsActionType,
7
+ 'CLEAR_MUTATION_CACHE' | 'CLEAR_QUERY_CACHE'
8
+ >;
9
+ queryHash: string;
10
+ };
11
+
12
+ type CacheScopedActionInput = {
13
+ type: 'CLEAR_MUTATION_CACHE' | 'CLEAR_QUERY_CACHE';
14
+ queryHash?: string;
15
+ };
16
+
17
+ export type TanStackQueryDevtoolsActionInput =
18
+ | QueryScopedActionInput
19
+ | CacheScopedActionInput;
20
+
21
+ const getActiveQuery = (queryClient: QueryClient, queryHash?: string) => {
22
+ if (!queryHash) {
23
+ throw new Error('queryHash is required for this TanStack Query action.');
24
+ }
25
+
26
+ const activeQuery = queryClient.getQueryCache().get(queryHash);
27
+ if (!activeQuery) {
28
+ throw new Error(`No active query found for hash: ${queryHash}`);
29
+ }
30
+
31
+ return activeQuery;
32
+ };
33
+
34
+ export const applyTanStackQueryDevtoolsAction = async (
35
+ queryClient: QueryClient,
36
+ input: TanStackQueryDevtoolsActionInput
37
+ ) => {
38
+ switch (input.type) {
39
+ case 'CLEAR_QUERY_CACHE': {
40
+ const queryCountBefore = queryClient.getQueryCache().getAll().length;
41
+ queryClient.getQueryCache().clear();
42
+ return {
43
+ applied: true,
44
+ action: input.type,
45
+ cleared: true,
46
+ queryCountBefore,
47
+ queryCountAfter: queryClient.getQueryCache().getAll().length,
48
+ };
49
+ }
50
+
51
+ case 'CLEAR_MUTATION_CACHE': {
52
+ const mutationCountBefore =
53
+ queryClient.getMutationCache().getAll().length;
54
+ queryClient.getMutationCache().clear();
55
+ return {
56
+ applied: true,
57
+ action: input.type,
58
+ cleared: true,
59
+ mutationCountBefore,
60
+ mutationCountAfter: queryClient.getMutationCache().getAll().length,
61
+ };
62
+ }
63
+
64
+ case 'TRIGGER_ERROR': {
65
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
66
+ const previousQueryOptions = activeQuery.options;
67
+ const error = new Error('Unknown error from devtools');
68
+
69
+ activeQuery.setState({
70
+ status: 'error',
71
+ error,
72
+ fetchMeta: {
73
+ ...activeQuery.state.fetchMeta,
74
+ // @ts-expect-error This does exist
75
+ __previousQueryOptions: previousQueryOptions,
76
+ },
77
+ });
78
+
79
+ return {
80
+ applied: true,
81
+ action: input.type,
82
+ queryHash: activeQuery.queryHash,
83
+ };
84
+ }
85
+
86
+ case 'RESTORE_ERROR': {
87
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
88
+ await queryClient.resetQueries(activeQuery);
89
+ return {
90
+ applied: true,
91
+ action: input.type,
92
+ queryHash: activeQuery.queryHash,
93
+ };
94
+ }
95
+
96
+ case 'TRIGGER_LOADING': {
97
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
98
+ const previousQueryOptions = activeQuery.options;
99
+
100
+ void activeQuery.fetch({
101
+ ...previousQueryOptions,
102
+ queryFn: () =>
103
+ new Promise(() => {
104
+ // Never resolve - simulates perpetual loading
105
+ }),
106
+ gcTime: -1,
107
+ });
108
+
109
+ activeQuery.setState({
110
+ data: undefined,
111
+ status: 'pending',
112
+ fetchMeta: {
113
+ ...activeQuery.state.fetchMeta,
114
+ // @ts-expect-error This does exist
115
+ __previousQueryOptions: previousQueryOptions,
116
+ },
117
+ });
118
+
119
+ return {
120
+ applied: true,
121
+ action: input.type,
122
+ queryHash: activeQuery.queryHash,
123
+ };
124
+ }
125
+
126
+ case 'RESTORE_LOADING': {
127
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
128
+ const previousState = activeQuery.state;
129
+ const previousOptions = activeQuery.state.fetchMeta
130
+ ? (
131
+ activeQuery.state.fetchMeta as unknown as {
132
+ __previousQueryOptions: unknown;
133
+ }
134
+ ).__previousQueryOptions
135
+ : null;
136
+
137
+ activeQuery.cancel({ silent: true });
138
+ activeQuery.setState({
139
+ ...previousState,
140
+ fetchStatus: 'idle',
141
+ fetchMeta: null,
142
+ });
143
+
144
+ if (previousOptions) {
145
+ void activeQuery.fetch(previousOptions);
146
+ }
147
+
148
+ return {
149
+ applied: true,
150
+ action: input.type,
151
+ queryHash: activeQuery.queryHash,
152
+ };
153
+ }
154
+
155
+ case 'RESET': {
156
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
157
+ await queryClient.resetQueries(activeQuery);
158
+ return {
159
+ applied: true,
160
+ action: input.type,
161
+ queryHash: activeQuery.queryHash,
162
+ };
163
+ }
164
+
165
+ case 'REMOVE': {
166
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
167
+ queryClient.removeQueries(activeQuery);
168
+ return {
169
+ applied: true,
170
+ action: input.type,
171
+ queryHash: activeQuery.queryHash,
172
+ };
173
+ }
174
+
175
+ case 'REFETCH': {
176
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
177
+ await activeQuery.fetch().catch(() => {
178
+ // Ignore errors from refetch in the agent/UI bridge.
179
+ });
180
+ return {
181
+ applied: true,
182
+ action: input.type,
183
+ queryHash: activeQuery.queryHash,
184
+ };
185
+ }
186
+
187
+ case 'INVALIDATE': {
188
+ const activeQuery = getActiveQuery(queryClient, input.queryHash);
189
+ await queryClient.invalidateQueries(activeQuery);
190
+ return {
191
+ applied: true,
192
+ action: input.type,
193
+ queryHash: activeQuery.queryHash,
194
+ };
195
+ }
196
+ }
197
+ };
@@ -1,6 +1,7 @@
1
1
  import { useEffect } from 'react';
2
2
  import { QueryClient } from '@tanstack/react-query';
3
3
  import { TanStackQueryPluginClient } from '../shared/messaging';
4
+ import { applyTanStackQueryDevtoolsAction } from './devtools-actions';
4
5
 
5
6
  export const useHandleDevToolsMessages = (
6
7
  queryClient: QueryClient,
@@ -14,110 +15,14 @@ export const useHandleDevToolsMessages = (
14
15
  const subscription = client.onMessage(
15
16
  'devtools-action',
16
17
  ({ type, queryHash }) => {
17
- const activeQuery = queryClient.getQueryCache().get(queryHash);
18
-
19
- if (!activeQuery) {
20
- console.warn(`No active query found for hash: ${queryHash}`);
21
- return;
22
- }
23
-
24
- switch (type) {
25
- case 'TRIGGER_ERROR': {
26
- // Code from React Query External Sync:
27
- // https://github.com/LovesWorking/react-query-external-sync/blob/main/src/react-query-external-sync/useSyncQueriesExternal.ts#L717
28
-
29
- const __previousQueryOptions = activeQuery.options;
30
- const error = new Error('Unknown error from devtools');
31
-
32
- activeQuery.setState({
33
- status: 'error',
34
- error,
35
- fetchMeta: {
36
- ...activeQuery.state.fetchMeta,
37
- // @ts-expect-error This does exist
38
- __previousQueryOptions,
39
- },
40
- });
41
- break;
42
- }
43
- case 'RESTORE_ERROR': {
44
- queryClient.resetQueries(activeQuery);
45
- break;
46
- }
47
- case 'TRIGGER_LOADING': {
48
- // Code from React Query External Sync:
49
- // https://github.com/LovesWorking/react-query-external-sync/blob/main/src/react-query-external-sync/useSyncQueriesExternal.ts#L742
50
-
51
- if (!activeQuery) return;
52
- const __previousQueryOptions = activeQuery.options;
53
- // Trigger a fetch in order to trigger suspense as well.
54
- activeQuery.fetch({
55
- ...__previousQueryOptions,
56
- queryFn: () => {
57
- return new Promise(() => {
58
- // Never resolve - simulates perpetual loading
59
- });
60
- },
61
- gcTime: -1,
62
- });
63
- activeQuery.setState({
64
- data: undefined,
65
- status: 'pending',
66
- fetchMeta: {
67
- ...activeQuery.state.fetchMeta,
68
- // @ts-expect-error This does exist
69
- __previousQueryOptions,
70
- },
71
- });
72
- break;
73
- }
74
- case 'RESTORE_LOADING': {
75
- // Code from React Query External Sync:
76
- // https://github.com/LovesWorking/tanstack-query-dev-tools-expo-plugin/blob/main/src/useSyncQueries.ts#L176
77
-
78
- const previousState = activeQuery.state;
79
- const previousOptions = activeQuery.state.fetchMeta
80
- ? (
81
- activeQuery.state.fetchMeta as unknown as {
82
- __previousQueryOptions: unknown;
83
- }
84
- ).__previousQueryOptions
85
- : null;
86
-
87
- activeQuery.cancel({ silent: true });
88
- activeQuery.setState({
89
- ...previousState,
90
- fetchStatus: 'idle',
91
- fetchMeta: null,
92
- });
93
-
94
- if (previousOptions) {
95
- activeQuery.fetch(previousOptions);
96
- }
97
- break;
98
- }
99
- case 'RESET': {
100
- queryClient.resetQueries(activeQuery);
101
- break;
102
- }
103
- case 'REMOVE': {
104
- queryClient.removeQueries(activeQuery);
105
- break;
106
- }
107
- case 'REFETCH': {
108
- activeQuery.fetch().catch(() => {
109
- // Ignore errors
110
- });
111
- break;
112
- }
113
- case 'INVALIDATE': {
114
- queryClient.invalidateQueries(activeQuery);
115
- break;
116
- }
117
- default: {
118
- console.warn(`Unknown devtools action: ${type}`);
119
- }
120
- }
18
+ void applyTanStackQueryDevtoolsAction(queryClient, { type, queryHash })
19
+ .catch((error) => {
20
+ const message =
21
+ error instanceof Error ? error.message : String(error);
22
+ console.warn(
23
+ `[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${type}": ${message}`
24
+ );
25
+ });
121
26
  }
122
27
  );
123
28
 
@@ -5,6 +5,7 @@ import { useSyncOnlineStatus } from '../shared/useSyncOnlineStatus';
5
5
  import { useHandleDevToolsMessages } from './useHandleDevToolsMessages';
6
6
  import { useSyncTanStackCache } from './useSyncTanStackCache';
7
7
  import { useHandleInitialData } from './useHandleInitialData';
8
+ import { useTanStackQueryAgentTools } from './agent/useTanStackQueryAgentTools';
8
9
 
9
10
  export const useTanStackQueryDevTools = (queryClient: QueryClient) => {
10
11
  const client = useRozeniteDevToolsClient<TanStackQueryPluginEventMap>({
@@ -18,4 +19,6 @@ export const useTanStackQueryDevTools = (queryClient: QueryClient) => {
18
19
  useSyncTanStackCache(queryClient, client);
19
20
 
20
21
  useHandleInitialData(queryClient, client);
22
+
23
+ useTanStackQueryAgentTools(queryClient);
21
24
  };
package/tsconfig.json CHANGED
@@ -19,6 +19,9 @@
19
19
  "include": ["src/**/*", "react-native.ts", "rozenite.config.ts"],
20
20
  "exclude": ["node_modules", "dist", "build"],
21
21
  "references": [
22
+ {
23
+ "path": "../agent-bridge"
24
+ },
22
25
  {
23
26
  "path": "../plugin-bridge"
24
27
  },
@@ -1 +0,0 @@
1
- export declare let useTanStackQueryDevTools: typeof import('./src/react-native/useTanStackQueryDevTools').useTanStackQueryDevTools;
@@ -1,6 +0,0 @@
1
- let e;
2
- const o = process.env.NODE_ENV !== "production", s = typeof window > "u";
3
- o && !s ? e = require("./useTanStackQueryDevTools.js").useTanStackQueryDevTools : e = () => ({ isConnected: !1 });
4
- export {
5
- e as useTanStackQueryDevTools
6
- };
@@ -1,7 +0,0 @@
1
- declare const _default: {
2
- panels: {
3
- name: string;
4
- source: string;
5
- }[];
6
- };
7
- export default _default;
@@ -1,3 +0,0 @@
1
- import { QueryClient } from '@tanstack/react-query';
2
- import { TanStackQueryPluginClient } from '../shared/messaging';
3
- export declare const useHandleDevToolsMessages: (queryClient: QueryClient, client: TanStackQueryPluginClient | null) => void;
@@ -1,3 +0,0 @@
1
- import { TanStackQueryPluginClient } from '../shared/messaging';
2
- import { QueryClient } from '@tanstack/react-query';
3
- export declare const useHandleInitialData: (queryClient: QueryClient, client: TanStackQueryPluginClient | null) => void;
@@ -1,3 +0,0 @@
1
- import { QueryClient } from '@tanstack/react-query';
2
- import { TanStackQueryPluginClient } from '../shared/messaging';
3
- export declare const useSyncTanStackCache: (queryClient: QueryClient, client: TanStackQueryPluginClient | null) => void;
@@ -1,2 +0,0 @@
1
- import { QueryClient } from '@tanstack/react-query';
2
- export declare const useTanStackQueryDevTools: (queryClient: QueryClient) => void;
@@ -1,6 +0,0 @@
1
- import { Query, Mutation, QueryClient } from '@tanstack/react-query';
2
- import { SerializableQuery, SerializableMutation, SerializableObserver, SerializableQueryClient } from './types';
3
- export declare const dehydrateObservers: (query: Query) => SerializableObserver[];
4
- export declare const dehydrateQuery: (query: Query) => SerializableQuery;
5
- export declare const dehydrateMutation: (mutation: Mutation) => SerializableMutation;
6
- export declare const dehydrateQueryClient: (queryClient: QueryClient) => SerializableQueryClient;
@@ -1,10 +0,0 @@
1
- import { QueryClient } from '@tanstack/react-query';
2
- import { SerializableQuery, SerializableMutation, SerializableQueryClient, SerializableObserver, PartialQueryState } from './types';
3
- export declare const hydrateQueryClient: (client: QueryClient, dehydratedState: SerializableQueryClient) => void;
4
- export declare const applyQueryEvent: (queryClient: QueryClient, type: "added" | "updated" | "removed" | "observerAdded" | "observerRemoved" | "observerResultsUpdated" | "observerOptionsUpdated", data: SerializableQuery | PartialQueryState, action?: string) => void;
5
- export declare const applyPartialQueryState: (queryClient: QueryClient, data: PartialQueryState) => void;
6
- export declare const applyMutationEvent: (queryClient: QueryClient, type: "added" | "updated" | "removed" | "observerAdded" | "observerRemoved" | "observerResultsUpdated" | "observerOptionsUpdated", data: SerializableMutation) => void;
7
- export declare const applyQueryObserverEvent: (queryClient: QueryClient, data: {
8
- queryHash: string;
9
- observers: SerializableObserver[];
10
- }) => void;
@@ -1,34 +0,0 @@
1
- import { RozeniteDevToolsClient } from '@rozenite/plugin-bridge';
2
- import { DevToolsActionType, SerializableQueryClient, SerializableQuery, SerializableMutation, SerializableObserver, PartialQueryState } from './types';
3
- export type TanStackQueryPluginEventMap = {
4
- 'online-status-changed': {
5
- online: boolean;
6
- };
7
- 'devtools-action': {
8
- type: DevToolsActionType;
9
- queryHash: string;
10
- };
11
- 'request-initial-data': unknown;
12
- 'sync-data': {
13
- data: SerializableQueryClient;
14
- };
15
- 'sync-query-event': {
16
- type: 'added' | 'removed';
17
- data: SerializableQuery;
18
- } | {
19
- type: 'updated';
20
- action?: string;
21
- data: SerializableQuery | PartialQueryState;
22
- } | {
23
- type: 'observerAdded' | 'observerRemoved' | 'observerOptionsUpdated';
24
- data: {
25
- queryHash: string;
26
- observers: SerializableObserver[];
27
- };
28
- };
29
- 'sync-mutation-event': {
30
- type: 'added' | 'updated' | 'removed' | 'observerAdded' | 'observerRemoved' | 'observerResultsUpdated' | 'observerOptionsUpdated';
31
- data: SerializableMutation;
32
- };
33
- };
34
- export type TanStackQueryPluginClient = RozeniteDevToolsClient<TanStackQueryPluginEventMap>;
@@ -1,25 +0,0 @@
1
- import { QueryKey, MutationState, QueryState, QueryObserverOptions, InfiniteQueryObserverOptions, MutationOptions } from '@tanstack/react-query';
2
- export type SerializableQuery = {
3
- queryHash: string;
4
- state: QueryState;
5
- queryKey: QueryKey;
6
- observers: SerializableObserver[];
7
- };
8
- export type PartialQueryState = {
9
- queryHash: string;
10
- state: Partial<QueryState>;
11
- };
12
- export type SerializableMutation = {
13
- mutationId: number;
14
- options: MutationOptions;
15
- state: MutationState;
16
- };
17
- export type SerializableObserver = {
18
- queryHash: string;
19
- options: QueryObserverOptions | InfiniteQueryObserverOptions;
20
- };
21
- export type SerializableQueryClient = {
22
- queries: SerializableQuery[];
23
- mutations: SerializableMutation[];
24
- };
25
- export type DevToolsActionType = 'REFETCH' | 'INVALIDATE' | 'RESET' | 'REMOVE' | 'TRIGGER_ERROR' | 'RESTORE_ERROR' | 'TRIGGER_LOADING' | 'RESTORE_LOADING' | 'CLEAR_MUTATION_CACHE' | 'CLEAR_QUERY_CACHE';
@@ -1,2 +0,0 @@
1
- import { TanStackQueryPluginClient } from './messaging';
2
- export declare const useSyncOnlineStatus: (client: TanStackQueryPluginClient | null) => void;
@@ -1 +0,0 @@
1
- export default function TanStackQueryPanel(): import("react/jsx-runtime").JSX.Element;
@@ -1,2 +0,0 @@
1
- import { TanStackQueryPluginClient } from '../shared/messaging';
2
- export declare const useHandleSyncMessages: (client: TanStackQueryPluginClient | null) => void;
@@ -1,2 +0,0 @@
1
- import { TanStackQueryPluginClient } from '../shared/messaging';
2
- export declare const useSyncDevToolsEvents: (client: TanStackQueryPluginClient | null) => void;
@@ -1,2 +0,0 @@
1
- import { TanStackQueryPluginClient } from '../shared/messaging';
2
- export declare const useSyncInitialData: (client: TanStackQueryPluginClient | null) => void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@rozenite/plugin-bridge"),y=require("react"),p=require("@tanstack/react-query"),q=require("fast-deep-equal"),S=e=>e&&e.__esModule?e:{default:e},g=S(q),l=e=>{y.useEffect(()=>{if(!e)return;const a=p.onlineManager.subscribe(n=>{e.send("online-status-changed",{online:n})}),c=e.onMessage("online-status-changed",({online:n})=>{p.onlineManager.setOnline(n)});return()=>{a(),c.remove()}},[e])},M=(e,a)=>{y.useEffect(()=>{if(!a)return;const c=a.onMessage("devtools-action",({type:n,queryHash:o})=>{const s=e.getQueryCache().get(o);if(!s){console.warn(`No active query found for hash: ${o}`);return}switch(n){case"TRIGGER_ERROR":{const d=s.options,t=new Error("Unknown error from devtools");s.setState({status:"error",error:t,fetchMeta:{...s.state.fetchMeta,__previousQueryOptions:d}});break}case"RESTORE_ERROR":{e.resetQueries(s);break}case"TRIGGER_LOADING":{if(!s)return;const d=s.options;s.fetch({...d,queryFn:()=>new Promise(()=>{}),gcTime:-1}),s.setState({data:void 0,status:"pending",fetchMeta:{...s.state.fetchMeta,__previousQueryOptions:d}});break}case"RESTORE_LOADING":{const d=s.state,t=s.state.fetchMeta?s.state.fetchMeta.__previousQueryOptions:null;s.cancel({silent:!0}),s.setState({...d,fetchStatus:"idle",fetchMeta:null}),t&&s.fetch(t);break}case"RESET":{e.resetQueries(s);break}case"REMOVE":{e.removeQueries(s);break}case"REFETCH":{s.fetch().catch(()=>{});break}case"INVALIDATE":{e.invalidateQueries(s);break}default:console.warn(`Unknown devtools action: ${n}`)}});return()=>{c.remove()}},[a])},f=e=>e.observers.map(a=>({queryHash:e.queryHash,options:a.options})),h=e=>{const a=f(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:a}},v=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),H=e=>({queries:e.getQueryCache().getAll().map(h),mutations:e.getMutationCache().getAll().map(v)}),R=(e,a)=>{const c=y.useRef(new Map),n=y.useMemo(()=>o=>{if(!a||o.type==="observerResultsUpdated")return;if("query"in o){const{query:t,type:u}=o;if(u==="added"||u==="removed"){u==="removed"&&c.current.delete(t.queryHash);const i=h(t);a.send("sync-query-event",{type:u,data:i});return}if(u==="updated"&&"action"in o){const i=o.action;switch(i.type){case"fetch":{const r={queryHash:t.queryHash,state:{status:t.state.status,fetchStatus:t.state.fetchStatus,fetchMeta:t.state.fetchMeta,dataUpdatedAt:t.state.dataUpdatedAt,errorUpdatedAt:t.state.errorUpdatedAt}};a.send("sync-query-event",{type:"updated",action:"fetch",data:r});break}case"success":{const r={queryHash:t.queryHash,state:{status:t.state.status,data:t.state.data,dataUpdatedAt:t.state.dataUpdatedAt,error:t.state.error,errorUpdatedAt:t.state.errorUpdatedAt,fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"success",data:r});break}case"error":{const r={queryHash:t.queryHash,state:{status:t.state.status,error:t.state.error,errorUpdatedAt:t.state.errorUpdatedAt,fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"error",data:r});break}case"setState":{const r={queryHash:t.queryHash,state:i.state};a.send("sync-query-event",{type:"updated",action:"setState",data:r});break}case"invalidate":{const r={queryHash:t.queryHash,state:{isInvalidated:t.state.isInvalidated}};a.send("sync-query-event",{type:"updated",action:"invalidate",data:r});break}case"pause":{const r={queryHash:t.queryHash,state:{fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"pause",data:r});break}case"continue":{const r={queryHash:t.queryHash,state:{fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"continue",data:r});break}default:{const r=h(t);a.send("sync-query-event",{type:u,data:r})}}return}if(u==="observerAdded"||u==="observerRemoved"||u==="observerOptionsUpdated"){const i=f(t),r=c.current.get(t.queryHash);if(u==="observerOptionsUpdated"&&r&&g.default(r,i))return;c.current.set(t.queryHash,i),a.send("sync-query-event",{type:u,data:{queryHash:t.queryHash,observers:i}});return}}const{mutation:s,type:d}=o;if(s){const t=v(s);a.send("sync-mutation-event",{type:d,data:t})}},[a]);y.useEffect(()=>{if(!a)return;const o=e.getMutationCache().subscribe(n),s=e.getQueryCache().subscribe(n);return()=>{o(),s()}},[a,e,n])},k=(e,a)=>{y.useEffect(()=>{if(!a)return;const c=a.onMessage("request-initial-data",()=>{const n=H(e);a.send("sync-data",{data:n})});return()=>{c.remove()}},[a,e])},O=e=>{const a=b.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});l(a),M(e,a),R(e,a),k(e,a)};exports.useTanStackQueryDevTools=O;