@rozenite/tanstack-query-plugin 1.5.1 → 1.6.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.
@@ -1,312 +1,862 @@
1
- import { useRozeniteDevToolsClient as b } from "@rozenite/plugin-bridge";
2
- import { useEffect as y, useRef as S, useMemo as q } from "react";
3
- import { onlineManager as h } from "@tanstack/react-query";
4
- import m from "fast-deep-equal";
5
- const H = (t) => {
6
- y(() => {
7
- if (!t)
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)
8
9
  return;
9
- const a = h.subscribe((n) => {
10
- t.send("online-status-changed", { online: n });
11
- }), d = t.onMessage(
10
+ const r = g.subscribe((a) => {
11
+ e.send("online-status-changed", { online: a });
12
+ }), t = e.onMessage(
12
13
  "online-status-changed",
13
- ({ online: n }) => {
14
- h.setOnline(n);
14
+ ({ online: a }) => {
15
+ g.setOnline(a);
15
16
  }
16
17
  );
17
18
  return () => {
18
- a(), d.remove();
19
+ r(), t.remove();
19
20
  };
20
- }, [t]);
21
- }, M = (t, a) => {
22
- y(() => {
23
- if (!a)
24
- return;
25
- const d = a.onMessage(
26
- "devtools-action",
27
- ({ type: n, queryHash: o }) => {
28
- const s = t.getQueryCache().get(o);
29
- if (!s) {
30
- console.warn(`No active query found for hash: ${o}`);
31
- return;
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
32
60
  }
33
- switch (n) {
34
- case "TRIGGER_ERROR": {
35
- const c = s.options, e = new Error("Unknown error from devtools");
36
- s.setState({
37
- status: "error",
38
- error: e,
39
- fetchMeta: {
40
- ...s.state.fetchMeta,
41
- // @ts-expect-error This does exist
42
- __previousQueryOptions: c
43
- }
44
- });
45
- break;
46
- }
47
- case "RESTORE_ERROR": {
48
- t.resetQueries(s);
49
- break;
50
- }
51
- case "TRIGGER_LOADING": {
52
- if (!s) return;
53
- const c = s.options;
54
- s.fetch({
55
- ...c,
56
- queryFn: () => new Promise(() => {
57
- }),
58
- gcTime: -1
59
- }), s.setState({
60
- data: void 0,
61
- status: "pending",
62
- fetchMeta: {
63
- ...s.state.fetchMeta,
64
- // @ts-expect-error This does exist
65
- __previousQueryOptions: c
66
- }
67
- });
68
- break;
69
- }
70
- case "RESTORE_LOADING": {
71
- const c = s.state, e = s.state.fetchMeta ? s.state.fetchMeta.__previousQueryOptions : null;
72
- s.cancel({ silent: !0 }), s.setState({
73
- ...c,
74
- fetchStatus: "idle",
75
- fetchMeta: null
76
- }), e && s.fetch(e);
77
- break;
78
- }
79
- case "RESET": {
80
- t.resetQueries(s);
81
- break;
82
- }
83
- case "REMOVE": {
84
- t.removeQueries(s);
85
- break;
86
- }
87
- case "REFETCH": {
88
- s.fetch().catch(() => {
89
- });
90
- break;
91
- }
92
- case "INVALIDATE": {
93
- t.invalidateQueries(s);
94
- break;
95
- }
96
- default:
97
- console.warn(`Unknown devtools action: ${n}`);
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
98
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
+ });
99
155
  }
100
156
  );
101
157
  return () => {
102
- d.remove();
158
+ t.remove();
103
159
  };
104
- }, [a]);
105
- }, f = (t) => t.observers.map((a) => ({
106
- queryHash: t.queryHash,
107
- options: a.options
108
- })), p = (t) => {
109
- const a = f(t);
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);
110
166
  return {
111
- state: t.state,
112
- queryKey: t.queryKey,
113
- queryHash: t.queryHash,
114
- observers: a
167
+ state: e.state,
168
+ queryKey: e.queryKey,
169
+ queryHash: e.queryHash,
170
+ observers: r
115
171
  };
116
- }, v = (t) => ({
117
- mutationId: t.mutationId,
118
- state: t.state,
119
- options: t.options
120
- }), g = (t) => ({
121
- queries: t.getQueryCache().getAll().map(p),
122
- mutations: t.getMutationCache().getAll().map(v)
123
- }), R = (t, a) => {
124
- const d = S(
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(
125
181
  /* @__PURE__ */ new Map()
126
- ), n = q(() => (o) => {
127
- if (!a || o.type === "observerResultsUpdated")
182
+ ), a = M(() => (n) => {
183
+ if (!r || n.type === "observerResultsUpdated")
128
184
  return;
129
- if ("query" in o) {
130
- const { query: e, type: u } = o;
131
- if (u === "added" || u === "removed") {
132
- u === "removed" && d.current.delete(e.queryHash);
133
- const i = p(e);
134
- a.send("sync-query-event", { type: u, data: i });
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 });
135
191
  return;
136
192
  }
137
- if (u === "updated" && "action" in o) {
138
- const i = o.action;
139
- switch (i.type) {
193
+ if (y === "updated" && "action" in n) {
194
+ const l = n.action;
195
+ switch (l.type) {
140
196
  case "fetch": {
141
- const r = {
142
- queryHash: e.queryHash,
197
+ const u = {
198
+ queryHash: s.queryHash,
143
199
  state: {
144
- status: e.state.status,
145
- fetchStatus: e.state.fetchStatus,
146
- fetchMeta: e.state.fetchMeta,
147
- dataUpdatedAt: e.state.dataUpdatedAt,
148
- errorUpdatedAt: e.state.errorUpdatedAt
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
149
205
  }
150
206
  };
151
- a.send("sync-query-event", {
207
+ r.send("sync-query-event", {
152
208
  type: "updated",
153
209
  action: "fetch",
154
- data: r
210
+ data: u
155
211
  });
156
212
  break;
157
213
  }
158
214
  case "success": {
159
- const r = {
160
- queryHash: e.queryHash,
215
+ const u = {
216
+ queryHash: s.queryHash,
161
217
  state: {
162
- status: e.state.status,
163
- data: e.state.data,
164
- dataUpdatedAt: e.state.dataUpdatedAt,
165
- error: e.state.error,
166
- errorUpdatedAt: e.state.errorUpdatedAt,
167
- fetchStatus: e.state.fetchStatus
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
168
224
  }
169
225
  };
170
- a.send("sync-query-event", {
226
+ r.send("sync-query-event", {
171
227
  type: "updated",
172
228
  action: "success",
173
- data: r
229
+ data: u
174
230
  });
175
231
  break;
176
232
  }
177
233
  case "error": {
178
- const r = {
179
- queryHash: e.queryHash,
234
+ const u = {
235
+ queryHash: s.queryHash,
180
236
  state: {
181
- status: e.state.status,
182
- error: e.state.error,
183
- errorUpdatedAt: e.state.errorUpdatedAt,
184
- fetchStatus: e.state.fetchStatus
237
+ status: s.state.status,
238
+ error: s.state.error,
239
+ errorUpdatedAt: s.state.errorUpdatedAt,
240
+ fetchStatus: s.state.fetchStatus
185
241
  }
186
242
  };
187
- a.send("sync-query-event", {
243
+ r.send("sync-query-event", {
188
244
  type: "updated",
189
245
  action: "error",
190
- data: r
246
+ data: u
191
247
  });
192
248
  break;
193
249
  }
194
250
  case "setState": {
195
- const r = {
196
- queryHash: e.queryHash,
197
- state: i.state
251
+ const u = {
252
+ queryHash: s.queryHash,
253
+ state: l.state
198
254
  // Only the changed state parts
199
255
  };
200
- a.send("sync-query-event", {
256
+ r.send("sync-query-event", {
201
257
  type: "updated",
202
258
  action: "setState",
203
- data: r
259
+ data: u
204
260
  });
205
261
  break;
206
262
  }
207
263
  case "invalidate": {
208
- const r = {
209
- queryHash: e.queryHash,
264
+ const u = {
265
+ queryHash: s.queryHash,
210
266
  state: {
211
- isInvalidated: e.state.isInvalidated
267
+ isInvalidated: s.state.isInvalidated
212
268
  }
213
269
  };
214
- a.send("sync-query-event", {
270
+ r.send("sync-query-event", {
215
271
  type: "updated",
216
272
  action: "invalidate",
217
- data: r
273
+ data: u
218
274
  });
219
275
  break;
220
276
  }
221
277
  case "pause": {
222
- const r = {
223
- queryHash: e.queryHash,
278
+ const u = {
279
+ queryHash: s.queryHash,
224
280
  state: {
225
- fetchStatus: e.state.fetchStatus
281
+ fetchStatus: s.state.fetchStatus
226
282
  }
227
283
  };
228
- a.send("sync-query-event", {
284
+ r.send("sync-query-event", {
229
285
  type: "updated",
230
286
  action: "pause",
231
- data: r
287
+ data: u
232
288
  });
233
289
  break;
234
290
  }
235
291
  case "continue": {
236
- const r = {
237
- queryHash: e.queryHash,
292
+ const u = {
293
+ queryHash: s.queryHash,
238
294
  state: {
239
- fetchStatus: e.state.fetchStatus
295
+ fetchStatus: s.state.fetchStatus
240
296
  }
241
297
  };
242
- a.send("sync-query-event", {
298
+ r.send("sync-query-event", {
243
299
  type: "updated",
244
300
  action: "continue",
245
- data: r
301
+ data: u
246
302
  });
247
303
  break;
248
304
  }
249
305
  default: {
250
- const r = p(e);
251
- a.send("sync-query-event", { type: u, data: r });
306
+ const u = q(s);
307
+ r.send("sync-query-event", { type: y, data: u });
252
308
  }
253
309
  }
254
310
  return;
255
311
  }
256
- if (u === "observerAdded" || u === "observerRemoved" || u === "observerOptionsUpdated") {
257
- const i = f(e), r = d.current.get(
258
- e.queryHash
312
+ if (y === "observerAdded" || y === "observerRemoved" || y === "observerOptionsUpdated") {
313
+ const l = E(s), u = t.current.get(
314
+ s.queryHash
259
315
  );
260
- if (u === "observerOptionsUpdated" && r && m(r, i))
316
+ if (y === "observerOptionsUpdated" && u && D(u, l))
261
317
  return;
262
- d.current.set(
263
- e.queryHash,
264
- i
265
- ), a.send("sync-query-event", {
266
- type: u,
318
+ t.current.set(
319
+ s.queryHash,
320
+ l
321
+ ), r.send("sync-query-event", {
322
+ type: y,
267
323
  data: {
268
- queryHash: e.queryHash,
269
- observers: i
324
+ queryHash: s.queryHash,
325
+ observers: l
270
326
  }
271
327
  });
272
328
  return;
273
329
  }
274
330
  }
275
- const { mutation: s, type: c } = o;
276
- if (s) {
277
- const e = v(s);
278
- a.send("sync-mutation-event", {
279
- type: c,
280
- data: e
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
281
337
  });
282
338
  }
283
- }, [a]);
284
- y(() => {
285
- if (!a)
339
+ }, [r]);
340
+ S(() => {
341
+ if (!r)
286
342
  return;
287
- const o = t.getMutationCache().subscribe(n), s = t.getQueryCache().subscribe(n);
343
+ const n = e.getMutationCache().subscribe(a), d = e.getQueryCache().subscribe(a);
288
344
  return () => {
289
- o(), s();
345
+ n(), d();
290
346
  };
291
- }, [a, t, n]);
292
- }, k = (t, a) => {
293
- y(() => {
294
- if (!a)
347
+ }, [r, e, a]);
348
+ }, G = (e, r) => {
349
+ S(() => {
350
+ if (!r)
295
351
  return;
296
- const d = a.onMessage("request-initial-data", () => {
297
- const n = g(t);
298
- a.send("sync-data", { data: n });
352
+ const t = r.onMessage("request-initial-data", () => {
353
+ const a = U(e);
354
+ r.send("sync-data", { data: a });
299
355
  });
300
356
  return () => {
301
- d.remove();
357
+ t.remove();
302
358
  };
303
- }, [a, t]);
304
- }, l = (t) => {
305
- const a = b({
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({
306
856
  pluginId: "@rozenite/tanstack-query-plugin"
307
857
  });
308
- H(a), M(t, a), R(t, a), k(t, a);
858
+ w(r), C(e, r), _(e, r), G(e, r), me(e);
309
859
  };
310
860
  export {
311
- l as useTanStackQueryDevTools
861
+ qe as useTanStackQueryDevTools
312
862
  };