@rozenite/tanstack-query-plugin 2.1.0 → 2.3.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/CHANGELOG.md +24 -0
- package/dist/devtools/assets/{CXEL7IU7-BWccRGN3.js → CXEL7IU7-D2MCp9XC.js} +1 -1
- package/dist/devtools/assets/{tanstack-query-CbF_imft.js → tanstack-query-Bk8rHBM2.js} +12 -12
- package/dist/devtools/tanstack-query.html +1 -1
- package/dist/react-native/cjs/package.json +3 -0
- package/dist/react-native/cjs/react-native.js +12 -0
- package/dist/react-native/cjs/src/react-native/agent/tanstack-query-agent.js +376 -0
- package/dist/react-native/cjs/src/react-native/agent/useTanStackQueryAgentTools.js +98 -0
- package/dist/react-native/cjs/src/react-native/devtools-actions.js +161 -0
- package/dist/react-native/cjs/src/react-native/useHandleDevToolsMessages.js +26 -0
- package/dist/react-native/cjs/src/react-native/useHandleInitialData.js +26 -0
- package/dist/react-native/cjs/src/react-native/useSyncTanStackCache.js +203 -0
- package/dist/react-native/cjs/src/react-native/useTanStackQueryDevTools.js +20 -0
- package/dist/react-native/cjs/src/shared/agent-tools.js +197 -0
- package/dist/react-native/cjs/src/shared/dehydrate.js +35 -0
- package/dist/react-native/cjs/src/shared/messaging.js +2 -0
- package/dist/react-native/cjs/src/shared/types.js +2 -0
- package/dist/react-native/cjs/src/shared/useSyncOnlineStatus.js +23 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/react-native.d.ts +1 -0
- package/dist/react-native/react-native.js +10 -0
- package/dist/{sdk/index.d.ts → react-native/src/react-native/agent/tanstack-query-agent.d.ts} +2105 -1939
- package/dist/react-native/src/react-native/agent/tanstack-query-agent.js +370 -0
- package/dist/react-native/src/react-native/agent/useTanStackQueryAgentTools.d.ts +2 -0
- package/dist/react-native/src/react-native/agent/useTanStackQueryAgentTools.js +94 -0
- package/dist/react-native/src/react-native/devtools-actions.d.ts +115 -0
- package/dist/react-native/src/react-native/devtools-actions.js +157 -0
- package/dist/react-native/src/react-native/useHandleDevToolsMessages.d.ts +3 -0
- package/dist/react-native/src/react-native/useHandleDevToolsMessages.js +22 -0
- package/dist/react-native/src/react-native/useHandleInitialData.d.ts +3 -0
- package/dist/react-native/src/react-native/useHandleInitialData.js +22 -0
- package/dist/react-native/src/react-native/useSyncTanStackCache.d.ts +3 -0
- package/dist/react-native/src/react-native/useSyncTanStackCache.js +196 -0
- package/dist/react-native/src/react-native/useTanStackQueryDevTools.d.ts +2 -0
- package/dist/react-native/src/react-native/useTanStackQueryDevTools.js +16 -0
- package/dist/react-native/src/shared/agent-tools.d.ts +967 -0
- package/dist/react-native/src/shared/agent-tools.js +194 -0
- package/dist/react-native/src/shared/dehydrate.d.ts +6 -0
- package/dist/react-native/src/shared/dehydrate.js +28 -0
- package/dist/react-native/src/shared/messaging.d.ts +44 -0
- package/dist/react-native/src/shared/messaging.js +1 -0
- package/dist/react-native/src/shared/types.d.ts +25 -0
- package/dist/react-native/src/shared/types.js +1 -0
- package/dist/react-native/src/shared/useSyncOnlineStatus.d.ts +2 -0
- package/dist/react-native/src/shared/useSyncOnlineStatus.js +19 -0
- package/dist/rozenite.json +1 -1
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/sdk.d.ts +812 -0
- package/dist/sdk/sdk.js +8 -0
- package/dist/sdk/src/react-native/devtools-actions.d.ts +115 -0
- package/dist/sdk/src/react-native/devtools-actions.js +161 -0
- package/dist/sdk/src/shared/agent-tools.d.ts +967 -0
- package/dist/sdk/src/shared/agent-tools.js +197 -0
- package/dist/sdk/src/shared/types.d.ts +25 -0
- package/dist/sdk/src/shared/types.js +2 -0
- package/package.json +18 -18
- package/react-native.ts +8 -1
- package/rozenite.config.ts +1 -0
- package/src/__tests__/release-bundle.test.ts +32 -0
- package/tsconfig.json +1 -3
- package/dist/react-native/chunks/useTanStackQueryDevTools.require.cjs +0 -1
- package/dist/react-native/chunks/useTanStackQueryDevTools.require.js +0 -895
- package/dist/react-native/index.cjs +0 -1
- package/dist/react-native/index.d.ts +0 -7
- package/dist/react-native/index.js +0 -6
- package/dist/sdk/index.cjs +0 -1
- package/dist/sdk/index.js +0 -199
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<script>
|
|
23
23
|
var __ROZENITE_PANEL__ = true;
|
|
24
24
|
</script>
|
|
25
|
-
<script type="module" crossorigin src="../devtools/assets/tanstack-query-
|
|
25
|
+
<script type="module" crossorigin src="../devtools/assets/tanstack-query-Bk8rHBM2.js"></script>
|
|
26
26
|
</head>
|
|
27
27
|
<body>
|
|
28
28
|
<div id="root"></div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTanStackQueryDevTools = void 0;
|
|
4
|
+
const isDev = process.env.NODE_ENV !== 'production';
|
|
5
|
+
const isServer = typeof window === 'undefined' && typeof lynx === 'undefined';
|
|
6
|
+
if (isDev && !isServer) {
|
|
7
|
+
exports.useTanStackQueryDevTools =
|
|
8
|
+
require('./src/react-native/useTanStackQueryDevTools').useTanStackQueryDevTools;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
exports.useTanStackQueryDevTools = () => ({ isConnected: false });
|
|
12
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTanStackQueryAgentController = exports.buildTanStackQueryCacheSummary = exports.TANSTACK_QUERY_AGENT_TOOLS = exports.clearMutationCacheTool = exports.getMutationDetailsTool = exports.listMutationsTool = exports.clearQueryCacheTool = exports.removeQueryTool = exports.resetQueryTool = exports.invalidateQueryTool = exports.setQueryErrorTool = exports.setQueryLoadingTool = exports.refetchQueryTool = exports.getQueryDetailsTool = exports.listQueriesTool = exports.setOnlineStatusTool = exports.getOnlineStatusTool = exports.getCacheSummaryTool = exports.serializeForAgent = void 0;
|
|
4
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
5
|
+
const devtools_actions_1 = require("../devtools-actions");
|
|
6
|
+
const agent_tools_1 = require("../../shared/agent-tools");
|
|
7
|
+
const DEFAULT_PAGE_LIMIT = 20;
|
|
8
|
+
const MAX_PAGE_LIMIT = 100;
|
|
9
|
+
const isPlainObject = (value) => {
|
|
10
|
+
return !!value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype;
|
|
11
|
+
};
|
|
12
|
+
const serializeForAgent = (value, seen = new WeakSet()) => {
|
|
13
|
+
if (value == null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === 'number') {
|
|
20
|
+
return Number.isFinite(value) ? value : String(value);
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'bigint') {
|
|
23
|
+
return value.toString();
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === 'function' || typeof value === 'symbol') {
|
|
26
|
+
return `[non-serializable:${typeof value}]`;
|
|
27
|
+
}
|
|
28
|
+
if (value instanceof Date) {
|
|
29
|
+
return value.toISOString();
|
|
30
|
+
}
|
|
31
|
+
if (value instanceof Error) {
|
|
32
|
+
return {
|
|
33
|
+
name: value.name,
|
|
34
|
+
message: value.message,
|
|
35
|
+
stack: value.stack ?? null,
|
|
36
|
+
cause: (0, exports.serializeForAgent)(value.cause, seen),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
return value.map((item) => (0, exports.serializeForAgent)(item, seen));
|
|
41
|
+
}
|
|
42
|
+
if (ArrayBuffer.isView(value)) {
|
|
43
|
+
return Array.from(value).map((item) => typeof item === 'number' ? item : Number(item));
|
|
44
|
+
}
|
|
45
|
+
if (value instanceof ArrayBuffer) {
|
|
46
|
+
return Array.from(new Uint8Array(value));
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'object') {
|
|
49
|
+
if (seen.has(value)) {
|
|
50
|
+
return '[circular]';
|
|
51
|
+
}
|
|
52
|
+
seen.add(value);
|
|
53
|
+
if (!isPlainObject(value)) {
|
|
54
|
+
return `[non-serializable:${value.constructor?.name ?? 'Object'}]`;
|
|
55
|
+
}
|
|
56
|
+
const entries = Object.entries(value).map(([key, nestedValue]) => [
|
|
57
|
+
key,
|
|
58
|
+
(0, exports.serializeForAgent)(nestedValue, seen),
|
|
59
|
+
]);
|
|
60
|
+
return Object.fromEntries(entries);
|
|
61
|
+
}
|
|
62
|
+
return String(value);
|
|
63
|
+
};
|
|
64
|
+
exports.serializeForAgent = serializeForAgent;
|
|
65
|
+
const sanitizeLimit = (limit) => {
|
|
66
|
+
if (typeof limit !== 'number' ||
|
|
67
|
+
!Number.isFinite(limit) ||
|
|
68
|
+
!Number.isInteger(limit) ||
|
|
69
|
+
limit < 1) {
|
|
70
|
+
return DEFAULT_PAGE_LIMIT;
|
|
71
|
+
}
|
|
72
|
+
return Math.min(limit, MAX_PAGE_LIMIT);
|
|
73
|
+
};
|
|
74
|
+
const encodeCursor = (kind, generation, offset) => {
|
|
75
|
+
return `${kind}:${generation}:${offset}`;
|
|
76
|
+
};
|
|
77
|
+
const decodeCursor = (cursor, kind, generation) => {
|
|
78
|
+
const [cursorKind, rawGeneration, rawOffset] = cursor.split(':', 3);
|
|
79
|
+
if (cursorKind !== kind || !rawGeneration || !rawOffset) {
|
|
80
|
+
throw new Error('Cursor does not match the requested listing. Run the command again.');
|
|
81
|
+
}
|
|
82
|
+
const cursorGeneration = Number(rawGeneration);
|
|
83
|
+
const offset = Number(rawOffset);
|
|
84
|
+
if (!Number.isInteger(cursorGeneration) || cursorGeneration !== generation) {
|
|
85
|
+
throw new Error('Cursor does not match the requested listing. Run the command again.');
|
|
86
|
+
}
|
|
87
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
88
|
+
throw new Error('Cursor is invalid. Run the command again.');
|
|
89
|
+
}
|
|
90
|
+
return offset;
|
|
91
|
+
};
|
|
92
|
+
const paginate = (rows, kind, generation, input) => {
|
|
93
|
+
const limit = sanitizeLimit(input.limit);
|
|
94
|
+
const startIndex = input.cursor ? decodeCursor(input.cursor, kind, generation) : 0;
|
|
95
|
+
const endIndex = Math.min(startIndex + limit, rows.length);
|
|
96
|
+
const hasMore = endIndex < rows.length;
|
|
97
|
+
return {
|
|
98
|
+
items: rows.slice(startIndex, endIndex),
|
|
99
|
+
page: {
|
|
100
|
+
limit,
|
|
101
|
+
hasMore,
|
|
102
|
+
...(hasMore ? { nextCursor: encodeCursor(kind, generation, endIndex) } : {}),
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
exports.getCacheSummaryTool = agent_tools_1.tanstackQueryToolDefinitions.getCacheSummary;
|
|
107
|
+
exports.getOnlineStatusTool = agent_tools_1.tanstackQueryToolDefinitions.getOnlineStatus;
|
|
108
|
+
exports.setOnlineStatusTool = agent_tools_1.tanstackQueryToolDefinitions.setOnlineStatus;
|
|
109
|
+
exports.listQueriesTool = agent_tools_1.tanstackQueryToolDefinitions.listQueries;
|
|
110
|
+
exports.getQueryDetailsTool = agent_tools_1.tanstackQueryToolDefinitions.getQueryDetails;
|
|
111
|
+
exports.refetchQueryTool = agent_tools_1.tanstackQueryToolDefinitions.refetchQuery;
|
|
112
|
+
exports.setQueryLoadingTool = agent_tools_1.tanstackQueryToolDefinitions.setQueryLoading;
|
|
113
|
+
exports.setQueryErrorTool = agent_tools_1.tanstackQueryToolDefinitions.setQueryError;
|
|
114
|
+
exports.invalidateQueryTool = agent_tools_1.tanstackQueryToolDefinitions.invalidateQuery;
|
|
115
|
+
exports.resetQueryTool = agent_tools_1.tanstackQueryToolDefinitions.resetQuery;
|
|
116
|
+
exports.removeQueryTool = agent_tools_1.tanstackQueryToolDefinitions.removeQuery;
|
|
117
|
+
exports.clearQueryCacheTool = agent_tools_1.tanstackQueryToolDefinitions.clearQueryCache;
|
|
118
|
+
exports.listMutationsTool = agent_tools_1.tanstackQueryToolDefinitions.listMutations;
|
|
119
|
+
exports.getMutationDetailsTool = agent_tools_1.tanstackQueryToolDefinitions.getMutationDetails;
|
|
120
|
+
exports.clearMutationCacheTool = agent_tools_1.tanstackQueryToolDefinitions.clearMutationCache;
|
|
121
|
+
exports.TANSTACK_QUERY_AGENT_TOOLS = Object.values(agent_tools_1.tanstackQueryToolDefinitions);
|
|
122
|
+
const pickObserverOptionsSummary = (options) => {
|
|
123
|
+
if (!options) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
enabled: (0, exports.serializeForAgent)(options.enabled),
|
|
128
|
+
networkMode: (0, exports.serializeForAgent)(options.networkMode),
|
|
129
|
+
staleTime: (0, exports.serializeForAgent)(options.staleTime),
|
|
130
|
+
gcTime: (0, exports.serializeForAgent)(options.gcTime),
|
|
131
|
+
retry: (0, exports.serializeForAgent)(options.retry),
|
|
132
|
+
retryDelay: (0, exports.serializeForAgent)(options.retryDelay),
|
|
133
|
+
refetchInterval: (0, exports.serializeForAgent)(options.refetchInterval),
|
|
134
|
+
refetchOnMount: (0, exports.serializeForAgent)(options.refetchOnMount),
|
|
135
|
+
refetchOnReconnect: (0, exports.serializeForAgent)(options.refetchOnReconnect),
|
|
136
|
+
refetchOnWindowFocus: (0, exports.serializeForAgent)(options.refetchOnWindowFocus),
|
|
137
|
+
subscribed: (0, exports.serializeForAgent)(options.subscribed),
|
|
138
|
+
meta: (0, exports.serializeForAgent)(options.meta),
|
|
139
|
+
hasQueryFn: typeof options.queryFn === 'function',
|
|
140
|
+
hasSelect: typeof options.select === 'function',
|
|
141
|
+
hasPlaceholderData: 'placeholderData' in options,
|
|
142
|
+
hasInitialData: 'initialData' in options,
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
const pickMutationOptionsSummary = (options) => {
|
|
146
|
+
return {
|
|
147
|
+
mutationKey: (0, exports.serializeForAgent)(options.mutationKey),
|
|
148
|
+
networkMode: (0, exports.serializeForAgent)(options.networkMode),
|
|
149
|
+
gcTime: (0, exports.serializeForAgent)(options.gcTime),
|
|
150
|
+
retry: (0, exports.serializeForAgent)(options.retry),
|
|
151
|
+
retryDelay: (0, exports.serializeForAgent)(options.retryDelay),
|
|
152
|
+
meta: (0, exports.serializeForAgent)(options.meta),
|
|
153
|
+
scope: (0, exports.serializeForAgent)(options.scope),
|
|
154
|
+
hasMutationFn: typeof options.mutationFn === 'function',
|
|
155
|
+
hasOnMutate: typeof options.onMutate === 'function',
|
|
156
|
+
hasOnSuccess: typeof options.onSuccess === 'function',
|
|
157
|
+
hasOnError: typeof options.onError === 'function',
|
|
158
|
+
hasOnSettled: typeof options.onSettled === 'function',
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
const getQuerySortTimestamp = (query) => {
|
|
162
|
+
return Math.max(query.state.dataUpdatedAt, query.state.errorUpdatedAt);
|
|
163
|
+
};
|
|
164
|
+
const compareQueries = (a, b) => {
|
|
165
|
+
return (getQuerySortTimestamp(b) - getQuerySortTimestamp(a) ||
|
|
166
|
+
b.getObserversCount() - a.getObserversCount() ||
|
|
167
|
+
String(b.queryHash).localeCompare(String(a.queryHash)));
|
|
168
|
+
};
|
|
169
|
+
const compareMutations = (a, b) => {
|
|
170
|
+
return b.state.submittedAt - a.state.submittedAt || b.mutationId - a.mutationId;
|
|
171
|
+
};
|
|
172
|
+
const getQuerySummary = (query) => {
|
|
173
|
+
return {
|
|
174
|
+
queryHash: query.queryHash,
|
|
175
|
+
queryKey: (0, exports.serializeForAgent)(query.queryKey),
|
|
176
|
+
status: query.state.status,
|
|
177
|
+
fetchStatus: query.state.fetchStatus,
|
|
178
|
+
observersCount: query.getObserversCount(),
|
|
179
|
+
isInvalidated: query.state.isInvalidated,
|
|
180
|
+
dataUpdatedAt: query.state.dataUpdatedAt,
|
|
181
|
+
errorUpdatedAt: query.state.errorUpdatedAt,
|
|
182
|
+
hasData: query.state.data !== undefined,
|
|
183
|
+
hasError: query.state.error != null,
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
const getMutationStatus = (state) => {
|
|
187
|
+
return state.status;
|
|
188
|
+
};
|
|
189
|
+
const getMutationSummary = (mutation) => {
|
|
190
|
+
return {
|
|
191
|
+
mutationId: mutation.mutationId,
|
|
192
|
+
mutationKey: (0, exports.serializeForAgent)(mutation.options.mutationKey),
|
|
193
|
+
status: getMutationStatus(mutation.state),
|
|
194
|
+
isPaused: mutation.state.isPaused,
|
|
195
|
+
submittedAt: mutation.state.submittedAt,
|
|
196
|
+
failureCount: mutation.state.failureCount,
|
|
197
|
+
hasData: mutation.state.data !== undefined,
|
|
198
|
+
hasError: mutation.state.error != null,
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const resolveQuery = (queryClient, queryHash) => {
|
|
202
|
+
const query = queryClient.getQueryCache().get(queryHash);
|
|
203
|
+
if (!query) {
|
|
204
|
+
const available = queryClient
|
|
205
|
+
.getQueryCache()
|
|
206
|
+
.getAll()
|
|
207
|
+
.map((entry) => entry.queryHash)
|
|
208
|
+
.join(', ');
|
|
209
|
+
throw new Error(`Unknown queryHash "${queryHash}". Available: ${available || '(none)'}`);
|
|
210
|
+
}
|
|
211
|
+
return query;
|
|
212
|
+
};
|
|
213
|
+
const resolveMutation = (queryClient, mutationId) => {
|
|
214
|
+
const mutation = queryClient
|
|
215
|
+
.getMutationCache()
|
|
216
|
+
.getAll()
|
|
217
|
+
.find((entry) => entry.mutationId === mutationId);
|
|
218
|
+
if (!mutation) {
|
|
219
|
+
const available = queryClient
|
|
220
|
+
.getMutationCache()
|
|
221
|
+
.getAll()
|
|
222
|
+
.map((entry) => entry.mutationId)
|
|
223
|
+
.join(', ');
|
|
224
|
+
throw new Error(`Unknown mutationId "${mutationId}". Available: ${available || '(none)'}`);
|
|
225
|
+
}
|
|
226
|
+
return mutation;
|
|
227
|
+
};
|
|
228
|
+
const buildTanStackQueryCacheSummary = (queryClient) => {
|
|
229
|
+
const queries = queryClient.getQueryCache().getAll();
|
|
230
|
+
const mutations = queryClient.getMutationCache().getAll();
|
|
231
|
+
return {
|
|
232
|
+
online: react_query_1.onlineManager.isOnline(),
|
|
233
|
+
queries: {
|
|
234
|
+
total: queries.length,
|
|
235
|
+
active: queries.filter((query) => query.getObserversCount() > 0).length,
|
|
236
|
+
fetching: queries.filter((query) => query.state.fetchStatus === 'fetching').length,
|
|
237
|
+
pending: queries.filter((query) => query.state.status === 'pending').length,
|
|
238
|
+
success: queries.filter((query) => query.state.status === 'success').length,
|
|
239
|
+
error: queries.filter((query) => query.state.status === 'error').length,
|
|
240
|
+
invalidated: queries.filter((query) => query.state.isInvalidated).length,
|
|
241
|
+
},
|
|
242
|
+
mutations: {
|
|
243
|
+
total: mutations.length,
|
|
244
|
+
pending: mutations.filter((mutation) => mutation.state.status === 'pending').length,
|
|
245
|
+
success: mutations.filter((mutation) => mutation.state.status === 'success').length,
|
|
246
|
+
error: mutations.filter((mutation) => mutation.state.status === 'error').length,
|
|
247
|
+
paused: mutations.filter((mutation) => mutation.state.isPaused).length,
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
exports.buildTanStackQueryCacheSummary = buildTanStackQueryCacheSummary;
|
|
252
|
+
const createTanStackQueryAgentController = (queryClient) => {
|
|
253
|
+
const cursorState = {
|
|
254
|
+
queriesGeneration: 0,
|
|
255
|
+
mutationsGeneration: 0,
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
handleQueryCacheEvent(event) {
|
|
259
|
+
if (event.type === 'added' || event.type === 'removed') {
|
|
260
|
+
cursorState.queriesGeneration += 1;
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
handleMutationCacheEvent(event) {
|
|
264
|
+
if (event.type === 'added' || event.type === 'removed') {
|
|
265
|
+
cursorState.mutationsGeneration += 1;
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
getCacheSummary() {
|
|
269
|
+
return (0, exports.buildTanStackQueryCacheSummary)(queryClient);
|
|
270
|
+
},
|
|
271
|
+
getOnlineStatus() {
|
|
272
|
+
return {
|
|
273
|
+
online: react_query_1.onlineManager.isOnline(),
|
|
274
|
+
};
|
|
275
|
+
},
|
|
276
|
+
setOnlineStatus({ online }) {
|
|
277
|
+
react_query_1.onlineManager.setOnline(online);
|
|
278
|
+
return {
|
|
279
|
+
online: react_query_1.onlineManager.isOnline(),
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
listQueries(input = {}) {
|
|
283
|
+
const queries = [...queryClient.getQueryCache().getAll()].sort(compareQueries);
|
|
284
|
+
return {
|
|
285
|
+
...(0, exports.buildTanStackQueryCacheSummary)(queryClient),
|
|
286
|
+
total: queries.length,
|
|
287
|
+
...paginate(queries.map(getQuerySummary), 'queries', cursorState.queriesGeneration, input),
|
|
288
|
+
};
|
|
289
|
+
},
|
|
290
|
+
getQueryDetails({ queryHash }) {
|
|
291
|
+
const query = resolveQuery(queryClient, queryHash);
|
|
292
|
+
return {
|
|
293
|
+
summary: (0, exports.buildTanStackQueryCacheSummary)(queryClient),
|
|
294
|
+
query: {
|
|
295
|
+
...getQuerySummary(query),
|
|
296
|
+
data: (0, exports.serializeForAgent)(query.state.data),
|
|
297
|
+
error: (0, exports.serializeForAgent)(query.state.error),
|
|
298
|
+
observers: query.observers.map((observer) => ({
|
|
299
|
+
queryHash: query.queryHash,
|
|
300
|
+
options: pickObserverOptionsSummary(observer.options),
|
|
301
|
+
})),
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
},
|
|
305
|
+
async refetchQuery({ queryHash }) {
|
|
306
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
307
|
+
type: 'REFETCH',
|
|
308
|
+
queryHash,
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
async setQueryLoading({ queryHash, enabled }) {
|
|
312
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
313
|
+
type: enabled ? 'TRIGGER_LOADING' : 'RESTORE_LOADING',
|
|
314
|
+
queryHash,
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
async setQueryError({ queryHash, enabled }) {
|
|
318
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
319
|
+
type: enabled ? 'TRIGGER_ERROR' : 'RESTORE_ERROR',
|
|
320
|
+
queryHash,
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
async invalidateQuery({ queryHash }) {
|
|
324
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
325
|
+
type: 'INVALIDATE',
|
|
326
|
+
queryHash,
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
async resetQuery({ queryHash }) {
|
|
330
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
331
|
+
type: 'RESET',
|
|
332
|
+
queryHash,
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
async removeQuery({ queryHash }) {
|
|
336
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
337
|
+
type: 'REMOVE',
|
|
338
|
+
queryHash,
|
|
339
|
+
});
|
|
340
|
+
},
|
|
341
|
+
async clearQueryCache() {
|
|
342
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
343
|
+
type: 'CLEAR_QUERY_CACHE',
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
listMutations(input = {}) {
|
|
347
|
+
const mutations = [...queryClient.getMutationCache().getAll()].sort(compareMutations);
|
|
348
|
+
return {
|
|
349
|
+
...(0, exports.buildTanStackQueryCacheSummary)(queryClient),
|
|
350
|
+
total: mutations.length,
|
|
351
|
+
...paginate(mutations.map(getMutationSummary), 'mutations', cursorState.mutationsGeneration, input),
|
|
352
|
+
};
|
|
353
|
+
},
|
|
354
|
+
getMutationDetails({ mutationId }) {
|
|
355
|
+
const mutation = resolveMutation(queryClient, mutationId);
|
|
356
|
+
return {
|
|
357
|
+
summary: (0, exports.buildTanStackQueryCacheSummary)(queryClient),
|
|
358
|
+
mutation: {
|
|
359
|
+
...getMutationSummary(mutation),
|
|
360
|
+
variables: (0, exports.serializeForAgent)(mutation.state.variables),
|
|
361
|
+
data: (0, exports.serializeForAgent)(mutation.state.data),
|
|
362
|
+
error: (0, exports.serializeForAgent)(mutation.state.error),
|
|
363
|
+
context: (0, exports.serializeForAgent)(mutation.state.context),
|
|
364
|
+
failureReason: (0, exports.serializeForAgent)(mutation.state.failureReason),
|
|
365
|
+
options: pickMutationOptionsSummary(mutation.options),
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
async clearMutationCache() {
|
|
370
|
+
return (0, devtools_actions_1.applyTanStackQueryDevtoolsAction)(queryClient, {
|
|
371
|
+
type: 'CLEAR_MUTATION_CACHE',
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
exports.createTanStackQueryAgentController = createTanStackQueryAgentController;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTanStackQueryAgentTools = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const agent_bridge_1 = require("@rozenite/agent-bridge");
|
|
6
|
+
const tanstack_query_agent_1 = require("./tanstack-query-agent");
|
|
7
|
+
const agent_tools_1 = require("../../shared/agent-tools");
|
|
8
|
+
const useTanStackQueryAgentTools = (queryClient) => {
|
|
9
|
+
const controller = (0, react_1.useMemo)(() => (0, tanstack_query_agent_1.createTanStackQueryAgentController)(queryClient), [queryClient]);
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
const unsubscribeQueryCache = queryClient
|
|
12
|
+
.getQueryCache()
|
|
13
|
+
.subscribe((event) => controller.handleQueryCacheEvent(event));
|
|
14
|
+
const unsubscribeMutationCache = queryClient
|
|
15
|
+
.getMutationCache()
|
|
16
|
+
.subscribe((event) => controller.handleMutationCacheEvent(event));
|
|
17
|
+
return () => {
|
|
18
|
+
unsubscribeQueryCache();
|
|
19
|
+
unsubscribeMutationCache();
|
|
20
|
+
};
|
|
21
|
+
}, [controller, queryClient]);
|
|
22
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
23
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
24
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.getCacheSummary,
|
|
25
|
+
handler: () => controller.getCacheSummary(),
|
|
26
|
+
});
|
|
27
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
28
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
29
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.getOnlineStatus,
|
|
30
|
+
handler: () => controller.getOnlineStatus(),
|
|
31
|
+
});
|
|
32
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
33
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
34
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.setOnlineStatus,
|
|
35
|
+
handler: (input) => controller.setOnlineStatus(input),
|
|
36
|
+
});
|
|
37
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
38
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
39
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.listQueries,
|
|
40
|
+
handler: (input = {}) => controller.listQueries(input),
|
|
41
|
+
});
|
|
42
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
43
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
44
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.getQueryDetails,
|
|
45
|
+
handler: (input) => controller.getQueryDetails(input),
|
|
46
|
+
});
|
|
47
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
48
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
49
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.refetchQuery,
|
|
50
|
+
handler: (input) => controller.refetchQuery(input),
|
|
51
|
+
});
|
|
52
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
53
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
54
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.setQueryLoading,
|
|
55
|
+
handler: (input) => controller.setQueryLoading(input),
|
|
56
|
+
});
|
|
57
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
58
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
59
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.setQueryError,
|
|
60
|
+
handler: (input) => controller.setQueryError(input),
|
|
61
|
+
});
|
|
62
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
63
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
64
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.invalidateQuery,
|
|
65
|
+
handler: (input) => controller.invalidateQuery(input),
|
|
66
|
+
});
|
|
67
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
68
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
69
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.resetQuery,
|
|
70
|
+
handler: (input) => controller.resetQuery(input),
|
|
71
|
+
});
|
|
72
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
73
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
74
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.removeQuery,
|
|
75
|
+
handler: (input) => controller.removeQuery(input),
|
|
76
|
+
});
|
|
77
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
78
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
79
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.clearQueryCache,
|
|
80
|
+
handler: () => controller.clearQueryCache(),
|
|
81
|
+
});
|
|
82
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
83
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
84
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.listMutations,
|
|
85
|
+
handler: (input = {}) => controller.listMutations(input),
|
|
86
|
+
});
|
|
87
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
88
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
89
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.getMutationDetails,
|
|
90
|
+
handler: (input) => controller.getMutationDetails(input),
|
|
91
|
+
});
|
|
92
|
+
(0, agent_bridge_1.useRozenitePluginAgentTool)({
|
|
93
|
+
pluginId: agent_tools_1.TANSTACK_QUERY_AGENT_PLUGIN_ID,
|
|
94
|
+
tool: agent_tools_1.tanstackQueryToolDefinitions.clearMutationCache,
|
|
95
|
+
handler: () => controller.clearMutationCache(),
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
exports.useTanStackQueryAgentTools = useTanStackQueryAgentTools;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyTanStackQueryDevtoolsAction = void 0;
|
|
4
|
+
const getActiveQuery = (queryClient, queryHash) => {
|
|
5
|
+
if (!queryHash) {
|
|
6
|
+
throw new Error('queryHash is required for this TanStack Query action.');
|
|
7
|
+
}
|
|
8
|
+
const activeQuery = queryClient.getQueryCache().get(queryHash);
|
|
9
|
+
if (!activeQuery) {
|
|
10
|
+
throw new Error(`No active query found for hash: ${queryHash}`);
|
|
11
|
+
}
|
|
12
|
+
return activeQuery;
|
|
13
|
+
};
|
|
14
|
+
const applyTanStackQueryDevtoolsAction = async (queryClient, input) => {
|
|
15
|
+
switch (input.type) {
|
|
16
|
+
case 'CLEAR_QUERY_CACHE': {
|
|
17
|
+
const queryCountBefore = queryClient.getQueryCache().getAll().length;
|
|
18
|
+
queryClient.getQueryCache().clear();
|
|
19
|
+
return {
|
|
20
|
+
applied: true,
|
|
21
|
+
action: input.type,
|
|
22
|
+
cleared: true,
|
|
23
|
+
queryCountBefore,
|
|
24
|
+
queryCountAfter: queryClient.getQueryCache().getAll().length,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
case 'CLEAR_MUTATION_CACHE': {
|
|
28
|
+
const mutationCountBefore = queryClient.getMutationCache().getAll().length;
|
|
29
|
+
queryClient.getMutationCache().clear();
|
|
30
|
+
return {
|
|
31
|
+
applied: true,
|
|
32
|
+
action: input.type,
|
|
33
|
+
cleared: true,
|
|
34
|
+
mutationCountBefore,
|
|
35
|
+
mutationCountAfter: queryClient.getMutationCache().getAll().length,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
case 'SET_QUERY_DATA': {
|
|
39
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
40
|
+
queryClient.setQueryData(activeQuery.queryKey, input.metadata?.data);
|
|
41
|
+
return {
|
|
42
|
+
applied: true,
|
|
43
|
+
action: input.type,
|
|
44
|
+
queryHash: activeQuery.queryHash,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
case 'TRIGGER_ERROR': {
|
|
48
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
49
|
+
const previousQueryOptions = activeQuery.options;
|
|
50
|
+
const error = new Error('Unknown error from devtools');
|
|
51
|
+
activeQuery.setState({
|
|
52
|
+
status: 'error',
|
|
53
|
+
error,
|
|
54
|
+
fetchMeta: {
|
|
55
|
+
...activeQuery.state.fetchMeta,
|
|
56
|
+
// @ts-expect-error This does exist
|
|
57
|
+
__previousQueryOptions: previousQueryOptions,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
applied: true,
|
|
62
|
+
action: input.type,
|
|
63
|
+
queryHash: activeQuery.queryHash,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
case 'RESTORE_ERROR': {
|
|
67
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
68
|
+
await queryClient.resetQueries(activeQuery);
|
|
69
|
+
return {
|
|
70
|
+
applied: true,
|
|
71
|
+
action: input.type,
|
|
72
|
+
queryHash: activeQuery.queryHash,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
case 'TRIGGER_LOADING': {
|
|
76
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
77
|
+
const previousQueryOptions = activeQuery.options;
|
|
78
|
+
void activeQuery.fetch({
|
|
79
|
+
...previousQueryOptions,
|
|
80
|
+
queryFn: () => new Promise(() => {
|
|
81
|
+
// Never resolve - simulates perpetual loading
|
|
82
|
+
}),
|
|
83
|
+
gcTime: -1,
|
|
84
|
+
});
|
|
85
|
+
activeQuery.setState({
|
|
86
|
+
data: undefined,
|
|
87
|
+
status: 'pending',
|
|
88
|
+
fetchMeta: {
|
|
89
|
+
...activeQuery.state.fetchMeta,
|
|
90
|
+
// @ts-expect-error This does exist
|
|
91
|
+
__previousQueryOptions: previousQueryOptions,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
applied: true,
|
|
96
|
+
action: input.type,
|
|
97
|
+
queryHash: activeQuery.queryHash,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
case 'RESTORE_LOADING': {
|
|
101
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
102
|
+
const previousState = activeQuery.state;
|
|
103
|
+
const previousOptions = activeQuery.state.fetchMeta
|
|
104
|
+
? activeQuery.state.fetchMeta.__previousQueryOptions
|
|
105
|
+
: null;
|
|
106
|
+
activeQuery.cancel({ silent: true });
|
|
107
|
+
activeQuery.setState({
|
|
108
|
+
...previousState,
|
|
109
|
+
fetchStatus: 'idle',
|
|
110
|
+
fetchMeta: null,
|
|
111
|
+
});
|
|
112
|
+
if (previousOptions) {
|
|
113
|
+
void activeQuery.fetch(previousOptions);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
applied: true,
|
|
117
|
+
action: input.type,
|
|
118
|
+
queryHash: activeQuery.queryHash,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
case 'RESET': {
|
|
122
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
123
|
+
await queryClient.resetQueries(activeQuery);
|
|
124
|
+
return {
|
|
125
|
+
applied: true,
|
|
126
|
+
action: input.type,
|
|
127
|
+
queryHash: activeQuery.queryHash,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
case 'REMOVE': {
|
|
131
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
132
|
+
queryClient.removeQueries(activeQuery);
|
|
133
|
+
return {
|
|
134
|
+
applied: true,
|
|
135
|
+
action: input.type,
|
|
136
|
+
queryHash: activeQuery.queryHash,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
case 'REFETCH': {
|
|
140
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
141
|
+
await activeQuery.fetch().catch(() => {
|
|
142
|
+
// Ignore errors from refetch in the agent/UI bridge.
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
applied: true,
|
|
146
|
+
action: input.type,
|
|
147
|
+
queryHash: activeQuery.queryHash,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
case 'INVALIDATE': {
|
|
151
|
+
const activeQuery = getActiveQuery(queryClient, input.queryHash);
|
|
152
|
+
await queryClient.invalidateQueries(activeQuery);
|
|
153
|
+
return {
|
|
154
|
+
applied: true,
|
|
155
|
+
action: input.type,
|
|
156
|
+
queryHash: activeQuery.queryHash,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
exports.applyTanStackQueryDevtoolsAction = applyTanStackQueryDevtoolsAction;
|