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