@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,862 @@
1
+ import { useRozeniteDevToolsClient as R } from "@rozenite/plugin-bridge";
2
+ import { useEffect as S, useRef as k, useMemo as M } from "react";
3
+ import { onlineManager as g } from "@tanstack/react-query";
4
+ import D from "fast-deep-equal";
5
+ import { useRozenitePluginAgentTool as i } from "@rozenite/agent-bridge";
6
+ const w = (e) => {
7
+ S(() => {
8
+ if (!e)
9
+ return;
10
+ const r = g.subscribe((a) => {
11
+ e.send("online-status-changed", { online: a });
12
+ }), t = e.onMessage(
13
+ "online-status-changed",
14
+ ({ online: a }) => {
15
+ g.setOnline(a);
16
+ }
17
+ );
18
+ return () => {
19
+ r(), t.remove();
20
+ };
21
+ }, [e]);
22
+ }, m = (e, r) => {
23
+ if (!r)
24
+ throw new Error("queryHash is required for this TanStack Query action.");
25
+ const t = e.getQueryCache().get(r);
26
+ if (!t)
27
+ throw new Error(`No active query found for hash: ${r}`);
28
+ return t;
29
+ }, p = async (e, r) => {
30
+ switch (r.type) {
31
+ case "CLEAR_QUERY_CACHE": {
32
+ const t = e.getQueryCache().getAll().length;
33
+ return e.getQueryCache().clear(), {
34
+ applied: !0,
35
+ action: r.type,
36
+ cleared: !0,
37
+ queryCountBefore: t,
38
+ queryCountAfter: e.getQueryCache().getAll().length
39
+ };
40
+ }
41
+ case "CLEAR_MUTATION_CACHE": {
42
+ const t = e.getMutationCache().getAll().length;
43
+ return e.getMutationCache().clear(), {
44
+ applied: !0,
45
+ action: r.type,
46
+ cleared: !0,
47
+ mutationCountBefore: t,
48
+ mutationCountAfter: e.getMutationCache().getAll().length
49
+ };
50
+ }
51
+ case "TRIGGER_ERROR": {
52
+ const t = m(e, r.queryHash), a = t.options, n = new Error("Unknown error from devtools");
53
+ return t.setState({
54
+ status: "error",
55
+ error: n,
56
+ fetchMeta: {
57
+ ...t.state.fetchMeta,
58
+ // @ts-expect-error This does exist
59
+ __previousQueryOptions: a
60
+ }
61
+ }), {
62
+ applied: !0,
63
+ action: r.type,
64
+ queryHash: t.queryHash
65
+ };
66
+ }
67
+ case "RESTORE_ERROR": {
68
+ const t = m(e, r.queryHash);
69
+ return await e.resetQueries(t), {
70
+ applied: !0,
71
+ action: r.type,
72
+ queryHash: t.queryHash
73
+ };
74
+ }
75
+ case "TRIGGER_LOADING": {
76
+ const t = m(e, r.queryHash), a = t.options;
77
+ return t.fetch({
78
+ ...a,
79
+ queryFn: () => new Promise(() => {
80
+ }),
81
+ gcTime: -1
82
+ }), t.setState({
83
+ data: void 0,
84
+ status: "pending",
85
+ fetchMeta: {
86
+ ...t.state.fetchMeta,
87
+ // @ts-expect-error This does exist
88
+ __previousQueryOptions: a
89
+ }
90
+ }), {
91
+ applied: !0,
92
+ action: r.type,
93
+ queryHash: t.queryHash
94
+ };
95
+ }
96
+ case "RESTORE_LOADING": {
97
+ const t = m(e, r.queryHash), a = t.state, n = t.state.fetchMeta ? t.state.fetchMeta.__previousQueryOptions : null;
98
+ return t.cancel({ silent: !0 }), t.setState({
99
+ ...a,
100
+ fetchStatus: "idle",
101
+ fetchMeta: null
102
+ }), n && t.fetch(n), {
103
+ applied: !0,
104
+ action: r.type,
105
+ queryHash: t.queryHash
106
+ };
107
+ }
108
+ case "RESET": {
109
+ const t = m(e, r.queryHash);
110
+ return await e.resetQueries(t), {
111
+ applied: !0,
112
+ action: r.type,
113
+ queryHash: t.queryHash
114
+ };
115
+ }
116
+ case "REMOVE": {
117
+ const t = m(e, r.queryHash);
118
+ return e.removeQueries(t), {
119
+ applied: !0,
120
+ action: r.type,
121
+ queryHash: t.queryHash
122
+ };
123
+ }
124
+ case "REFETCH": {
125
+ const t = m(e, r.queryHash);
126
+ return await t.fetch().catch(() => {
127
+ }), {
128
+ applied: !0,
129
+ action: r.type,
130
+ queryHash: t.queryHash
131
+ };
132
+ }
133
+ case "INVALIDATE": {
134
+ const t = m(e, r.queryHash);
135
+ return await e.invalidateQueries(t), {
136
+ applied: !0,
137
+ action: r.type,
138
+ queryHash: t.queryHash
139
+ };
140
+ }
141
+ }
142
+ }, C = (e, r) => {
143
+ S(() => {
144
+ if (!r)
145
+ return;
146
+ const t = r.onMessage(
147
+ "devtools-action",
148
+ ({ type: a, queryHash: n }) => {
149
+ p(e, { type: a, queryHash: n }).catch((d) => {
150
+ const h = d instanceof Error ? d.message : String(d);
151
+ console.warn(
152
+ `[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${a}": ${h}`
153
+ );
154
+ });
155
+ }
156
+ );
157
+ return () => {
158
+ t.remove();
159
+ };
160
+ }, [r]);
161
+ }, E = (e) => e.observers.map((r) => ({
162
+ queryHash: e.queryHash,
163
+ options: r.options
164
+ })), q = (e) => {
165
+ const r = E(e);
166
+ return {
167
+ state: e.state,
168
+ queryKey: e.queryKey,
169
+ queryHash: e.queryHash,
170
+ observers: r
171
+ };
172
+ }, O = (e) => ({
173
+ mutationId: e.mutationId,
174
+ state: e.state,
175
+ options: e.options
176
+ }), U = (e) => ({
177
+ queries: e.getQueryCache().getAll().map(q),
178
+ mutations: e.getMutationCache().getAll().map(O)
179
+ }), _ = (e, r) => {
180
+ const t = k(
181
+ /* @__PURE__ */ new Map()
182
+ ), a = M(() => (n) => {
183
+ if (!r || n.type === "observerResultsUpdated")
184
+ return;
185
+ if ("query" in n) {
186
+ const { query: s, type: y } = n;
187
+ if (y === "added" || y === "removed") {
188
+ y === "removed" && t.current.delete(s.queryHash);
189
+ const l = q(s);
190
+ r.send("sync-query-event", { type: y, data: l });
191
+ return;
192
+ }
193
+ if (y === "updated" && "action" in n) {
194
+ const l = n.action;
195
+ switch (l.type) {
196
+ case "fetch": {
197
+ const u = {
198
+ queryHash: s.queryHash,
199
+ state: {
200
+ status: s.state.status,
201
+ fetchStatus: s.state.fetchStatus,
202
+ fetchMeta: s.state.fetchMeta,
203
+ dataUpdatedAt: s.state.dataUpdatedAt,
204
+ errorUpdatedAt: s.state.errorUpdatedAt
205
+ }
206
+ };
207
+ r.send("sync-query-event", {
208
+ type: "updated",
209
+ action: "fetch",
210
+ data: u
211
+ });
212
+ break;
213
+ }
214
+ case "success": {
215
+ const u = {
216
+ queryHash: s.queryHash,
217
+ state: {
218
+ status: s.state.status,
219
+ data: s.state.data,
220
+ dataUpdatedAt: s.state.dataUpdatedAt,
221
+ error: s.state.error,
222
+ errorUpdatedAt: s.state.errorUpdatedAt,
223
+ fetchStatus: s.state.fetchStatus
224
+ }
225
+ };
226
+ r.send("sync-query-event", {
227
+ type: "updated",
228
+ action: "success",
229
+ data: u
230
+ });
231
+ break;
232
+ }
233
+ case "error": {
234
+ const u = {
235
+ queryHash: s.queryHash,
236
+ state: {
237
+ status: s.state.status,
238
+ error: s.state.error,
239
+ errorUpdatedAt: s.state.errorUpdatedAt,
240
+ fetchStatus: s.state.fetchStatus
241
+ }
242
+ };
243
+ r.send("sync-query-event", {
244
+ type: "updated",
245
+ action: "error",
246
+ data: u
247
+ });
248
+ break;
249
+ }
250
+ case "setState": {
251
+ const u = {
252
+ queryHash: s.queryHash,
253
+ state: l.state
254
+ // Only the changed state parts
255
+ };
256
+ r.send("sync-query-event", {
257
+ type: "updated",
258
+ action: "setState",
259
+ data: u
260
+ });
261
+ break;
262
+ }
263
+ case "invalidate": {
264
+ const u = {
265
+ queryHash: s.queryHash,
266
+ state: {
267
+ isInvalidated: s.state.isInvalidated
268
+ }
269
+ };
270
+ r.send("sync-query-event", {
271
+ type: "updated",
272
+ action: "invalidate",
273
+ data: u
274
+ });
275
+ break;
276
+ }
277
+ case "pause": {
278
+ const u = {
279
+ queryHash: s.queryHash,
280
+ state: {
281
+ fetchStatus: s.state.fetchStatus
282
+ }
283
+ };
284
+ r.send("sync-query-event", {
285
+ type: "updated",
286
+ action: "pause",
287
+ data: u
288
+ });
289
+ break;
290
+ }
291
+ case "continue": {
292
+ const u = {
293
+ queryHash: s.queryHash,
294
+ state: {
295
+ fetchStatus: s.state.fetchStatus
296
+ }
297
+ };
298
+ r.send("sync-query-event", {
299
+ type: "updated",
300
+ action: "continue",
301
+ data: u
302
+ });
303
+ break;
304
+ }
305
+ default: {
306
+ const u = q(s);
307
+ r.send("sync-query-event", { type: y, data: u });
308
+ }
309
+ }
310
+ return;
311
+ }
312
+ if (y === "observerAdded" || y === "observerRemoved" || y === "observerOptionsUpdated") {
313
+ const l = E(s), u = t.current.get(
314
+ s.queryHash
315
+ );
316
+ if (y === "observerOptionsUpdated" && u && D(u, l))
317
+ return;
318
+ t.current.set(
319
+ s.queryHash,
320
+ l
321
+ ), r.send("sync-query-event", {
322
+ type: y,
323
+ data: {
324
+ queryHash: s.queryHash,
325
+ observers: l
326
+ }
327
+ });
328
+ return;
329
+ }
330
+ }
331
+ const { mutation: d, type: h } = n;
332
+ if (d) {
333
+ const s = O(d);
334
+ r.send("sync-mutation-event", {
335
+ type: h,
336
+ data: s
337
+ });
338
+ }
339
+ }, [r]);
340
+ S(() => {
341
+ if (!r)
342
+ return;
343
+ const n = e.getMutationCache().subscribe(a), d = e.getQueryCache().subscribe(a);
344
+ return () => {
345
+ n(), d();
346
+ };
347
+ }, [r, e, a]);
348
+ }, G = (e, r) => {
349
+ S(() => {
350
+ if (!r)
351
+ return;
352
+ const t = r.onMessage("request-initial-data", () => {
353
+ const a = U(e);
354
+ r.send("sync-data", { data: a });
355
+ });
356
+ return () => {
357
+ t.remove();
358
+ };
359
+ }, [r, e]);
360
+ }, j = "@rozenite/tanstack-query-plugin", N = 20, L = 100, F = (e) => !!e && typeof e == "object" && Object.getPrototypeOf(e) === Object.prototype, o = (e, r = /* @__PURE__ */ new WeakSet()) => {
361
+ if (e == null)
362
+ return null;
363
+ if (typeof e == "string" || typeof e == "boolean")
364
+ return e;
365
+ if (typeof e == "number")
366
+ return Number.isFinite(e) ? e : String(e);
367
+ if (typeof e == "bigint")
368
+ return e.toString();
369
+ if (typeof e == "function" || typeof e == "symbol")
370
+ return `[non-serializable:${typeof e}]`;
371
+ if (e instanceof Date)
372
+ return e.toISOString();
373
+ if (e instanceof Error)
374
+ return {
375
+ name: e.name,
376
+ message: e.message,
377
+ stack: e.stack ?? null,
378
+ cause: o(
379
+ e.cause,
380
+ r
381
+ )
382
+ };
383
+ if (Array.isArray(e))
384
+ return e.map((t) => o(t, r));
385
+ if (ArrayBuffer.isView(e))
386
+ return Array.from(e).map(
387
+ (t) => typeof t == "number" ? t : Number(t)
388
+ );
389
+ if (e instanceof ArrayBuffer)
390
+ return Array.from(new Uint8Array(e));
391
+ if (typeof e == "object") {
392
+ if (r.has(e))
393
+ return "[circular]";
394
+ if (r.add(e), !F(e))
395
+ return `[non-serializable:${e.constructor?.name ?? "Object"}]`;
396
+ const t = Object.entries(e).map(([a, n]) => [
397
+ a,
398
+ o(n, r)
399
+ ]);
400
+ return Object.fromEntries(t);
401
+ }
402
+ return String(e);
403
+ }, P = (e) => typeof e != "number" || !Number.isFinite(e) || !Number.isInteger(e) || e < 1 ? N : Math.min(e, L), $ = (e, r, t) => `${e}:${r}:${t}`, K = (e, r, t) => {
404
+ const [a, n, d] = e.split(":", 3);
405
+ if (a !== r || !n || !d)
406
+ throw new Error(
407
+ "Cursor does not match the requested listing. Run the command again."
408
+ );
409
+ const h = Number(n), s = Number(d);
410
+ if (!Number.isInteger(h) || h !== t)
411
+ throw new Error(
412
+ "Cursor does not match the requested listing. Run the command again."
413
+ );
414
+ if (!Number.isInteger(s) || s < 0)
415
+ throw new Error("Cursor is invalid. Run the command again.");
416
+ return s;
417
+ }, A = (e, r, t, a) => {
418
+ const n = P(a.limit), d = a.cursor ? K(a.cursor, r, t) : 0, h = Math.min(d + n, e.length), s = h < e.length;
419
+ return {
420
+ items: e.slice(d, h),
421
+ page: {
422
+ limit: n,
423
+ hasMore: s,
424
+ ...s ? { nextCursor: $(r, t, h) } : {}
425
+ }
426
+ };
427
+ }, f = {
428
+ queryHash: {
429
+ type: "string",
430
+ description: "TanStack Query queryHash identifying the query."
431
+ }
432
+ }, x = {
433
+ mutationId: {
434
+ type: "number",
435
+ description: "TanStack Query mutationId identifying the mutation."
436
+ }
437
+ }, I = {
438
+ limit: {
439
+ type: "number",
440
+ description: "Maximum number of items to return. Defaults to 20. Maximum 100."
441
+ },
442
+ cursor: {
443
+ type: "string",
444
+ description: "Opaque pagination cursor from a previous list call."
445
+ }
446
+ }, Q = {
447
+ type: "object",
448
+ properties: {}
449
+ }, z = {
450
+ name: "get-cache-summary",
451
+ description: "Return aggregate TanStack Query cache health and count information.",
452
+ inputSchema: Q
453
+ }, V = {
454
+ name: "get-online-status",
455
+ description: "Return the current TanStack Query onlineManager status.",
456
+ inputSchema: Q
457
+ }, B = {
458
+ name: "set-online-status",
459
+ description: "Set the TanStack Query onlineManager status for testing offline/online behavior.",
460
+ inputSchema: {
461
+ type: "object",
462
+ properties: {
463
+ online: {
464
+ type: "boolean",
465
+ description: "Whether the TanStack Query onlineManager should be online."
466
+ }
467
+ },
468
+ required: ["online"]
469
+ }
470
+ }, W = {
471
+ name: "list-queries",
472
+ description: "List TanStack Query query summaries using cursor pagination.",
473
+ inputSchema: {
474
+ type: "object",
475
+ properties: I
476
+ }
477
+ }, Y = {
478
+ name: "get-query-details",
479
+ description: "Return a JSON-safe TanStack Query query snapshot and observer summary.",
480
+ inputSchema: {
481
+ type: "object",
482
+ properties: f,
483
+ required: ["queryHash"]
484
+ }
485
+ }, J = {
486
+ name: "refetch-query",
487
+ description: "Refetch a TanStack Query query by queryHash.",
488
+ inputSchema: {
489
+ type: "object",
490
+ properties: f,
491
+ required: ["queryHash"]
492
+ }
493
+ }, X = {
494
+ name: "set-query-loading",
495
+ description: "Enable or disable TanStack Query loading-state simulation for a query by queryHash.",
496
+ inputSchema: {
497
+ type: "object",
498
+ properties: f,
499
+ required: ["queryHash", "enabled"]
500
+ }
501
+ }, Z = {
502
+ name: "set-query-error",
503
+ description: "Enable or disable TanStack Query error-state simulation for a query by queryHash.",
504
+ inputSchema: {
505
+ type: "object",
506
+ properties: f,
507
+ required: ["queryHash", "enabled"]
508
+ }
509
+ }, ee = {
510
+ name: "invalidate-query",
511
+ description: "Invalidate a TanStack Query query by queryHash.",
512
+ inputSchema: {
513
+ type: "object",
514
+ properties: f,
515
+ required: ["queryHash"]
516
+ }
517
+ }, te = {
518
+ name: "reset-query",
519
+ description: "Reset a TanStack Query query by queryHash.",
520
+ inputSchema: {
521
+ type: "object",
522
+ properties: f,
523
+ required: ["queryHash"]
524
+ }
525
+ }, re = {
526
+ name: "remove-query",
527
+ description: "Remove a TanStack Query query from the cache by queryHash.",
528
+ inputSchema: {
529
+ type: "object",
530
+ properties: f,
531
+ required: ["queryHash"]
532
+ }
533
+ }, ae = {
534
+ name: "clear-query-cache",
535
+ description: "Clear the full TanStack Query query cache.",
536
+ inputSchema: Q
537
+ }, se = {
538
+ name: "list-mutations",
539
+ description: "List TanStack Query mutation summaries using cursor pagination.",
540
+ inputSchema: {
541
+ type: "object",
542
+ properties: I
543
+ }
544
+ }, ne = {
545
+ name: "get-mutation-details",
546
+ description: "Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",
547
+ inputSchema: {
548
+ type: "object",
549
+ properties: x,
550
+ required: ["mutationId"]
551
+ }
552
+ }, oe = {
553
+ name: "clear-mutation-cache",
554
+ description: "Clear the full TanStack Query mutation cache.",
555
+ inputSchema: Q
556
+ }, ue = (e) => e ? {
557
+ enabled: o(e.enabled),
558
+ networkMode: o(e.networkMode),
559
+ staleTime: o(e.staleTime),
560
+ gcTime: o(e.gcTime),
561
+ retry: o(e.retry),
562
+ retryDelay: o(e.retryDelay),
563
+ refetchInterval: o(e.refetchInterval),
564
+ refetchOnMount: o(e.refetchOnMount),
565
+ refetchOnReconnect: o(e.refetchOnReconnect),
566
+ refetchOnWindowFocus: o(e.refetchOnWindowFocus),
567
+ subscribed: o(e.subscribed),
568
+ meta: o(e.meta),
569
+ hasQueryFn: typeof e.queryFn == "function",
570
+ hasSelect: typeof e.select == "function",
571
+ hasPlaceholderData: "placeholderData" in e,
572
+ hasInitialData: "initialData" in e
573
+ } : null, ie = (e) => ({
574
+ mutationKey: o(e.mutationKey),
575
+ networkMode: o(e.networkMode),
576
+ gcTime: o(e.gcTime),
577
+ retry: o(e.retry),
578
+ retryDelay: o(e.retryDelay),
579
+ meta: o(e.meta),
580
+ scope: o(e.scope),
581
+ hasMutationFn: typeof e.mutationFn == "function",
582
+ hasOnMutate: typeof e.onMutate == "function",
583
+ hasOnSuccess: typeof e.onSuccess == "function",
584
+ hasOnError: typeof e.onError == "function",
585
+ hasOnSettled: typeof e.onSettled == "function"
586
+ }), T = (e) => Math.max(e.state.dataUpdatedAt, e.state.errorUpdatedAt), ce = (e, r) => T(r) - T(e) || r.getObserversCount() - e.getObserversCount() || String(r.queryHash).localeCompare(String(e.queryHash)), de = (e, r) => r.state.submittedAt - e.state.submittedAt || r.mutationId - e.mutationId, H = (e) => ({
587
+ queryHash: e.queryHash,
588
+ queryKey: o(e.queryKey),
589
+ status: e.state.status,
590
+ fetchStatus: e.state.fetchStatus,
591
+ observersCount: e.getObserversCount(),
592
+ isInvalidated: e.state.isInvalidated,
593
+ dataUpdatedAt: e.state.dataUpdatedAt,
594
+ errorUpdatedAt: e.state.errorUpdatedAt,
595
+ hasData: e.state.data !== void 0,
596
+ hasError: e.state.error != null
597
+ }), ye = (e) => e.status, v = (e) => ({
598
+ mutationId: e.mutationId,
599
+ mutationKey: o(e.options.mutationKey),
600
+ status: ye(e.state),
601
+ isPaused: e.state.isPaused,
602
+ submittedAt: e.state.submittedAt,
603
+ failureCount: e.state.failureCount,
604
+ hasData: e.state.data !== void 0,
605
+ hasError: e.state.error != null
606
+ }), he = (e, r) => {
607
+ const t = e.getQueryCache().get(r);
608
+ if (!t) {
609
+ const a = e.getQueryCache().getAll().map((n) => n.queryHash).join(", ");
610
+ throw new Error(
611
+ `Unknown queryHash "${r}". Available: ${a || "(none)"}`
612
+ );
613
+ }
614
+ return t;
615
+ }, pe = (e, r) => {
616
+ const t = e.getMutationCache().getAll().find((a) => a.mutationId === r);
617
+ if (!t) {
618
+ const a = e.getMutationCache().getAll().map((n) => n.mutationId).join(", ");
619
+ throw new Error(
620
+ `Unknown mutationId "${r}". Available: ${a || "(none)"}`
621
+ );
622
+ }
623
+ return t;
624
+ }, b = (e) => {
625
+ const r = e.getQueryCache().getAll(), t = e.getMutationCache().getAll();
626
+ return {
627
+ online: g.isOnline(),
628
+ queries: {
629
+ total: r.length,
630
+ active: r.filter((a) => a.getObserversCount() > 0).length,
631
+ fetching: r.filter(
632
+ (a) => a.state.fetchStatus === "fetching"
633
+ ).length,
634
+ pending: r.filter((a) => a.state.status === "pending").length,
635
+ success: r.filter((a) => a.state.status === "success").length,
636
+ error: r.filter((a) => a.state.status === "error").length,
637
+ invalidated: r.filter((a) => a.state.isInvalidated).length
638
+ },
639
+ mutations: {
640
+ total: t.length,
641
+ pending: t.filter(
642
+ (a) => a.state.status === "pending"
643
+ ).length,
644
+ success: t.filter(
645
+ (a) => a.state.status === "success"
646
+ ).length,
647
+ error: t.filter((a) => a.state.status === "error").length,
648
+ paused: t.filter((a) => a.state.isPaused).length
649
+ }
650
+ };
651
+ }, le = (e) => {
652
+ const r = {
653
+ queriesGeneration: 0,
654
+ mutationsGeneration: 0
655
+ };
656
+ return {
657
+ handleQueryCacheEvent(t) {
658
+ (t.type === "added" || t.type === "removed") && (r.queriesGeneration += 1);
659
+ },
660
+ handleMutationCacheEvent(t) {
661
+ (t.type === "added" || t.type === "removed") && (r.mutationsGeneration += 1);
662
+ },
663
+ getCacheSummary() {
664
+ return b(e);
665
+ },
666
+ getOnlineStatus() {
667
+ return {
668
+ online: g.isOnline()
669
+ };
670
+ },
671
+ setOnlineStatus({ online: t }) {
672
+ return g.setOnline(t), {
673
+ online: g.isOnline()
674
+ };
675
+ },
676
+ listQueries(t = {}) {
677
+ const a = [...e.getQueryCache().getAll()].sort(ce);
678
+ return {
679
+ ...b(e),
680
+ total: a.length,
681
+ ...A(
682
+ a.map(H),
683
+ "queries",
684
+ r.queriesGeneration,
685
+ t
686
+ )
687
+ };
688
+ },
689
+ getQueryDetails({ queryHash: t }) {
690
+ const a = he(e, t);
691
+ return {
692
+ summary: b(e),
693
+ query: {
694
+ ...H(a),
695
+ data: o(a.state.data),
696
+ error: o(a.state.error),
697
+ observers: a.observers.map((n) => ({
698
+ queryHash: a.queryHash,
699
+ options: ue(
700
+ n.options
701
+ )
702
+ }))
703
+ }
704
+ };
705
+ },
706
+ async refetchQuery({ queryHash: t }) {
707
+ return p(e, {
708
+ type: "REFETCH",
709
+ queryHash: t
710
+ });
711
+ },
712
+ async setQueryLoading({ queryHash: t, enabled: a }) {
713
+ return p(e, {
714
+ type: a ? "TRIGGER_LOADING" : "RESTORE_LOADING",
715
+ queryHash: t
716
+ });
717
+ },
718
+ async setQueryError({ queryHash: t, enabled: a }) {
719
+ return p(e, {
720
+ type: a ? "TRIGGER_ERROR" : "RESTORE_ERROR",
721
+ queryHash: t
722
+ });
723
+ },
724
+ async invalidateQuery({ queryHash: t }) {
725
+ return p(e, {
726
+ type: "INVALIDATE",
727
+ queryHash: t
728
+ });
729
+ },
730
+ async resetQuery({ queryHash: t }) {
731
+ return p(e, {
732
+ type: "RESET",
733
+ queryHash: t
734
+ });
735
+ },
736
+ async removeQuery({ queryHash: t }) {
737
+ return p(e, {
738
+ type: "REMOVE",
739
+ queryHash: t
740
+ });
741
+ },
742
+ async clearQueryCache() {
743
+ return p(e, {
744
+ type: "CLEAR_QUERY_CACHE"
745
+ });
746
+ },
747
+ listMutations(t = {}) {
748
+ const a = [...e.getMutationCache().getAll()].sort(
749
+ de
750
+ );
751
+ return {
752
+ ...b(e),
753
+ total: a.length,
754
+ ...A(
755
+ a.map(v),
756
+ "mutations",
757
+ r.mutationsGeneration,
758
+ t
759
+ )
760
+ };
761
+ },
762
+ getMutationDetails({ mutationId: t }) {
763
+ const a = pe(e, t);
764
+ return {
765
+ summary: b(e),
766
+ mutation: {
767
+ ...v(a),
768
+ variables: o(a.state.variables),
769
+ data: o(a.state.data),
770
+ error: o(a.state.error),
771
+ context: o(a.state.context),
772
+ failureReason: o(a.state.failureReason),
773
+ options: ie(a.options)
774
+ }
775
+ };
776
+ },
777
+ async clearMutationCache() {
778
+ return p(e, {
779
+ type: "CLEAR_MUTATION_CACHE"
780
+ });
781
+ }
782
+ };
783
+ }, c = j, me = (e) => {
784
+ const r = M(
785
+ () => le(e),
786
+ [e]
787
+ );
788
+ S(() => {
789
+ const t = e.getQueryCache().subscribe((n) => r.handleQueryCacheEvent(n)), a = e.getMutationCache().subscribe((n) => r.handleMutationCacheEvent(n));
790
+ return () => {
791
+ t(), a();
792
+ };
793
+ }, [r, e]), i({
794
+ pluginId: c,
795
+ tool: z,
796
+ handler: () => r.getCacheSummary()
797
+ }), i({
798
+ pluginId: c,
799
+ tool: V,
800
+ handler: () => r.getOnlineStatus()
801
+ }), i({
802
+ pluginId: c,
803
+ tool: B,
804
+ handler: (t) => r.setOnlineStatus(t)
805
+ }), i({
806
+ pluginId: c,
807
+ tool: W,
808
+ handler: (t = {}) => r.listQueries(t)
809
+ }), i({
810
+ pluginId: c,
811
+ tool: Y,
812
+ handler: (t) => r.getQueryDetails(t)
813
+ }), i({
814
+ pluginId: c,
815
+ tool: J,
816
+ handler: (t) => r.refetchQuery(t)
817
+ }), i({
818
+ pluginId: c,
819
+ tool: X,
820
+ handler: (t) => r.setQueryLoading(t)
821
+ }), i({
822
+ pluginId: c,
823
+ tool: Z,
824
+ handler: (t) => r.setQueryError(t)
825
+ }), i({
826
+ pluginId: c,
827
+ tool: ee,
828
+ handler: (t) => r.invalidateQuery(t)
829
+ }), i({
830
+ pluginId: c,
831
+ tool: te,
832
+ handler: (t) => r.resetQuery(t)
833
+ }), i({
834
+ pluginId: c,
835
+ tool: re,
836
+ handler: (t) => r.removeQuery(t)
837
+ }), i({
838
+ pluginId: c,
839
+ tool: ae,
840
+ handler: () => r.clearQueryCache()
841
+ }), i({
842
+ pluginId: c,
843
+ tool: se,
844
+ handler: (t = {}) => r.listMutations(t)
845
+ }), i({
846
+ pluginId: c,
847
+ tool: ne,
848
+ handler: (t) => r.getMutationDetails(t)
849
+ }), i({
850
+ pluginId: c,
851
+ tool: oe,
852
+ handler: () => r.clearMutationCache()
853
+ });
854
+ }, qe = (e) => {
855
+ const r = R({
856
+ pluginId: "@rozenite/tanstack-query-plugin"
857
+ });
858
+ w(r), C(e, r), _(e, r), G(e, r), me(e);
859
+ };
860
+ export {
861
+ qe as useTanStackQueryDevTools
862
+ };