@rozenite/tanstack-query-plugin 1.5.0 → 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.
- package/CHANGELOG.md +19 -0
- package/README.md +22 -0
- package/dist/rozenite.json +1 -1
- package/dist/src/react-native/agent/__tests__/tanstack-query-agent.test.d.ts +1 -0
- package/dist/src/react-native/agent/tanstack-query-agent.d.ts +1000 -0
- package/dist/src/react-native/agent/useTanStackQueryAgentTools.d.ts +2 -0
- package/dist/src/react-native/devtools-actions.d.ts +103 -0
- package/dist/useTanStackQueryDevTools.cjs +1 -1
- package/dist/useTanStackQueryDevTools.js +755 -205
- package/package.json +5 -4
- package/src/react-native/agent/__tests__/tanstack-query-agent.test.ts +508 -0
- package/src/react-native/agent/tanstack-query-agent.ts +750 -0
- package/src/react-native/agent/useTanStackQueryAgentTools.ts +147 -0
- package/src/react-native/devtools-actions.ts +197 -0
- package/src/react-native/useHandleDevToolsMessages.ts +9 -104
- package/src/react-native/useTanStackQueryDevTools.ts +3 -0
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { DevToolsActionType } from '../shared/types';
|
|
3
|
+
type QueryScopedActionInput = {
|
|
4
|
+
type: Exclude<DevToolsActionType, 'CLEAR_MUTATION_CACHE' | 'CLEAR_QUERY_CACHE'>;
|
|
5
|
+
queryHash: string;
|
|
6
|
+
};
|
|
7
|
+
type CacheScopedActionInput = {
|
|
8
|
+
type: 'CLEAR_MUTATION_CACHE' | 'CLEAR_QUERY_CACHE';
|
|
9
|
+
queryHash?: string;
|
|
10
|
+
};
|
|
11
|
+
export type TanStackQueryDevtoolsActionInput = QueryScopedActionInput | CacheScopedActionInput;
|
|
12
|
+
export declare const applyTanStackQueryDevtoolsAction: (queryClient: QueryClient, input: TanStackQueryDevtoolsActionInput) => Promise<{
|
|
13
|
+
applied: boolean;
|
|
14
|
+
action: "CLEAR_QUERY_CACHE";
|
|
15
|
+
cleared: boolean;
|
|
16
|
+
queryCountBefore: number;
|
|
17
|
+
queryCountAfter: number;
|
|
18
|
+
mutationCountBefore?: undefined;
|
|
19
|
+
mutationCountAfter?: undefined;
|
|
20
|
+
queryHash?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
applied: boolean;
|
|
23
|
+
action: "CLEAR_MUTATION_CACHE";
|
|
24
|
+
cleared: boolean;
|
|
25
|
+
mutationCountBefore: number;
|
|
26
|
+
mutationCountAfter: number;
|
|
27
|
+
queryCountBefore?: undefined;
|
|
28
|
+
queryCountAfter?: undefined;
|
|
29
|
+
queryHash?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
applied: boolean;
|
|
32
|
+
action: "TRIGGER_ERROR";
|
|
33
|
+
queryHash: string;
|
|
34
|
+
cleared?: undefined;
|
|
35
|
+
queryCountBefore?: undefined;
|
|
36
|
+
queryCountAfter?: undefined;
|
|
37
|
+
mutationCountBefore?: undefined;
|
|
38
|
+
mutationCountAfter?: undefined;
|
|
39
|
+
} | {
|
|
40
|
+
applied: boolean;
|
|
41
|
+
action: "RESTORE_ERROR";
|
|
42
|
+
queryHash: string;
|
|
43
|
+
cleared?: undefined;
|
|
44
|
+
queryCountBefore?: undefined;
|
|
45
|
+
queryCountAfter?: undefined;
|
|
46
|
+
mutationCountBefore?: undefined;
|
|
47
|
+
mutationCountAfter?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
applied: boolean;
|
|
50
|
+
action: "TRIGGER_LOADING";
|
|
51
|
+
queryHash: string;
|
|
52
|
+
cleared?: undefined;
|
|
53
|
+
queryCountBefore?: undefined;
|
|
54
|
+
queryCountAfter?: undefined;
|
|
55
|
+
mutationCountBefore?: undefined;
|
|
56
|
+
mutationCountAfter?: undefined;
|
|
57
|
+
} | {
|
|
58
|
+
applied: boolean;
|
|
59
|
+
action: "RESTORE_LOADING";
|
|
60
|
+
queryHash: string;
|
|
61
|
+
cleared?: undefined;
|
|
62
|
+
queryCountBefore?: undefined;
|
|
63
|
+
queryCountAfter?: undefined;
|
|
64
|
+
mutationCountBefore?: undefined;
|
|
65
|
+
mutationCountAfter?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
applied: boolean;
|
|
68
|
+
action: "RESET";
|
|
69
|
+
queryHash: string;
|
|
70
|
+
cleared?: undefined;
|
|
71
|
+
queryCountBefore?: undefined;
|
|
72
|
+
queryCountAfter?: undefined;
|
|
73
|
+
mutationCountBefore?: undefined;
|
|
74
|
+
mutationCountAfter?: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
applied: boolean;
|
|
77
|
+
action: "REMOVE";
|
|
78
|
+
queryHash: string;
|
|
79
|
+
cleared?: undefined;
|
|
80
|
+
queryCountBefore?: undefined;
|
|
81
|
+
queryCountAfter?: undefined;
|
|
82
|
+
mutationCountBefore?: undefined;
|
|
83
|
+
mutationCountAfter?: undefined;
|
|
84
|
+
} | {
|
|
85
|
+
applied: boolean;
|
|
86
|
+
action: "REFETCH";
|
|
87
|
+
queryHash: string;
|
|
88
|
+
cleared?: undefined;
|
|
89
|
+
queryCountBefore?: undefined;
|
|
90
|
+
queryCountAfter?: undefined;
|
|
91
|
+
mutationCountBefore?: undefined;
|
|
92
|
+
mutationCountAfter?: undefined;
|
|
93
|
+
} | {
|
|
94
|
+
applied: boolean;
|
|
95
|
+
action: "INVALIDATE";
|
|
96
|
+
queryHash: string;
|
|
97
|
+
cleared?: undefined;
|
|
98
|
+
queryCountBefore?: undefined;
|
|
99
|
+
queryCountAfter?: undefined;
|
|
100
|
+
mutationCountBefore?: undefined;
|
|
101
|
+
mutationCountAfter?: undefined;
|
|
102
|
+
}>;
|
|
103
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@rozenite/plugin-bridge"),y=require("react"),p=require("@tanstack/react-query"),q=require("fast-deep-equal"),S=e=>e&&e.__esModule?e:{default:e},g=S(q),l=e=>{y.useEffect(()=>{if(!e)return;const a=p.onlineManager.subscribe(n=>{e.send("online-status-changed",{online:n})}),c=e.onMessage("online-status-changed",({online:n})=>{p.onlineManager.setOnline(n)});return()=>{a(),c.remove()}},[e])},M=(e,a)=>{y.useEffect(()=>{if(!a)return;const c=a.onMessage("devtools-action",({type:n,queryHash:o})=>{const s=e.getQueryCache().get(o);if(!s){console.warn(`No active query found for hash: ${o}`);return}switch(n){case"TRIGGER_ERROR":{const d=s.options,t=new Error("Unknown error from devtools");s.setState({status:"error",error:t,fetchMeta:{...s.state.fetchMeta,__previousQueryOptions:d}});break}case"RESTORE_ERROR":{e.resetQueries(s);break}case"TRIGGER_LOADING":{if(!s)return;const d=s.options;s.fetch({...d,queryFn:()=>new Promise(()=>{}),gcTime:-1}),s.setState({data:void 0,status:"pending",fetchMeta:{...s.state.fetchMeta,__previousQueryOptions:d}});break}case"RESTORE_LOADING":{const d=s.state,t=s.state.fetchMeta?s.state.fetchMeta.__previousQueryOptions:null;s.cancel({silent:!0}),s.setState({...d,fetchStatus:"idle",fetchMeta:null}),t&&s.fetch(t);break}case"RESET":{e.resetQueries(s);break}case"REMOVE":{e.removeQueries(s);break}case"REFETCH":{s.fetch().catch(()=>{});break}case"INVALIDATE":{e.invalidateQueries(s);break}default:console.warn(`Unknown devtools action: ${n}`)}});return()=>{c.remove()}},[a])},f=e=>e.observers.map(a=>({queryHash:e.queryHash,options:a.options})),h=e=>{const a=f(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:a}},v=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),H=e=>({queries:e.getQueryCache().getAll().map(h),mutations:e.getMutationCache().getAll().map(v)}),R=(e,a)=>{const c=y.useRef(new Map),n=y.useMemo(()=>o=>{if(!a||o.type==="observerResultsUpdated")return;if("query"in o){const{query:t,type:u}=o;if(u==="added"||u==="removed"){u==="removed"&&c.current.delete(t.queryHash);const i=h(t);a.send("sync-query-event",{type:u,data:i});return}if(u==="updated"&&"action"in o){const i=o.action;switch(i.type){case"fetch":{const r={queryHash:t.queryHash,state:{status:t.state.status,fetchStatus:t.state.fetchStatus,fetchMeta:t.state.fetchMeta,dataUpdatedAt:t.state.dataUpdatedAt,errorUpdatedAt:t.state.errorUpdatedAt}};a.send("sync-query-event",{type:"updated",action:"fetch",data:r});break}case"success":{const r={queryHash:t.queryHash,state:{status:t.state.status,data:t.state.data,dataUpdatedAt:t.state.dataUpdatedAt,error:t.state.error,errorUpdatedAt:t.state.errorUpdatedAt,fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"success",data:r});break}case"error":{const r={queryHash:t.queryHash,state:{status:t.state.status,error:t.state.error,errorUpdatedAt:t.state.errorUpdatedAt,fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"error",data:r});break}case"setState":{const r={queryHash:t.queryHash,state:i.state};a.send("sync-query-event",{type:"updated",action:"setState",data:r});break}case"invalidate":{const r={queryHash:t.queryHash,state:{isInvalidated:t.state.isInvalidated}};a.send("sync-query-event",{type:"updated",action:"invalidate",data:r});break}case"pause":{const r={queryHash:t.queryHash,state:{fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"pause",data:r});break}case"continue":{const r={queryHash:t.queryHash,state:{fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"continue",data:r});break}default:{const r=h(t);a.send("sync-query-event",{type:u,data:r})}}return}if(u==="observerAdded"||u==="observerRemoved"||u==="observerOptionsUpdated"){const i=f(t),r=c.current.get(t.queryHash);if(u==="observerOptionsUpdated"&&r&&g.default(r,i))return;c.current.set(t.queryHash,i),a.send("sync-query-event",{type:u,data:{queryHash:t.queryHash,observers:i}});return}}const{mutation:s,type:d}=o;if(s){const t=v(s);a.send("sync-mutation-event",{type:d,data:t})}},[a]);y.useEffect(()=>{if(!a)return;const o=e.getMutationCache().subscribe(n),s=e.getQueryCache().subscribe(n);return()=>{o(),s()}},[a,e,n])},k=(e,a)=>{y.useEffect(()=>{if(!a)return;const c=a.onMessage("request-initial-data",()=>{const n=H(e);a.send("sync-data",{data:n})});return()=>{c.remove()}},[a,e])},O=e=>{const a=b.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});l(a),M(e,a),R(e,a),k(e,a)};exports.useTanStackQueryDevTools=O;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@rozenite/plugin-bridge"),m=require("react"),b=require("@tanstack/react-query"),I=require("fast-deep-equal"),i=require("@rozenite/agent-bridge"),k=e=>e&&e.__esModule?e:{default:e},D=k(I),w=e=>{m.useEffect(()=>{if(!e)return;const r=b.onlineManager.subscribe(a=>{e.send("online-status-changed",{online:a})}),t=e.onMessage("online-status-changed",({online:a})=>{b.onlineManager.setOnline(a)});return()=>{r(),t.remove()}},[e])},g=(e,r)=>{if(!r)throw new Error("queryHash is required for this TanStack Query action.");const t=e.getQueryCache().get(r);if(!t)throw new Error(`No active query found for hash: ${r}`);return t},l=async(e,r)=>{switch(r.type){case"CLEAR_QUERY_CACHE":{const t=e.getQueryCache().getAll().length;return e.getQueryCache().clear(),{applied:!0,action:r.type,cleared:!0,queryCountBefore:t,queryCountAfter:e.getQueryCache().getAll().length}}case"CLEAR_MUTATION_CACHE":{const t=e.getMutationCache().getAll().length;return e.getMutationCache().clear(),{applied:!0,action:r.type,cleared:!0,mutationCountBefore:t,mutationCountAfter:e.getMutationCache().getAll().length}}case"TRIGGER_ERROR":{const t=g(e,r.queryHash),a=t.options,s=new Error("Unknown error from devtools");return t.setState({status:"error",error:s,fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:a}}),{applied:!0,action:r.type,queryHash:t.queryHash}}case"RESTORE_ERROR":{const t=g(e,r.queryHash);return await e.resetQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"TRIGGER_LOADING":{const t=g(e,r.queryHash),a=t.options;return t.fetch({...a,queryFn:()=>new Promise(()=>{}),gcTime:-1}),t.setState({data:void 0,status:"pending",fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:a}}),{applied:!0,action:r.type,queryHash:t.queryHash}}case"RESTORE_LOADING":{const t=g(e,r.queryHash),a=t.state,s=t.state.fetchMeta?t.state.fetchMeta.__previousQueryOptions:null;return t.cancel({silent:!0}),t.setState({...a,fetchStatus:"idle",fetchMeta:null}),s&&t.fetch(s),{applied:!0,action:r.type,queryHash:t.queryHash}}case"RESET":{const t=g(e,r.queryHash);return await e.resetQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"REMOVE":{const t=g(e,r.queryHash);return e.removeQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"REFETCH":{const t=g(e,r.queryHash);return await t.fetch().catch(()=>{}),{applied:!0,action:r.type,queryHash:t.queryHash}}case"INVALIDATE":{const t=g(e,r.queryHash);return await e.invalidateQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}}},_=(e,r)=>{m.useEffect(()=>{if(!r)return;const t=r.onMessage("devtools-action",({type:a,queryHash:s})=>{l(e,{type:a,queryHash:s}).catch(d=>{const h=d instanceof Error?d.message:String(d);console.warn(`[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${a}": ${h}`)})});return()=>{t.remove()}},[r])},R=e=>e.observers.map(r=>({queryHash:e.queryHash,options:r.options})),T=e=>{const r=R(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:r}},v=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),C=e=>({queries:e.getQueryCache().getAll().map(T),mutations:e.getMutationCache().getAll().map(v)}),U=(e,r)=>{const t=m.useRef(new Map),a=m.useMemo(()=>s=>{if(!r||s.type==="observerResultsUpdated")return;if("query"in s){const{query:n,type:y}=s;if(y==="added"||y==="removed"){y==="removed"&&t.current.delete(n.queryHash);const p=T(n);r.send("sync-query-event",{type:y,data:p});return}if(y==="updated"&&"action"in s){const p=s.action;switch(p.type){case"fetch":{const u={queryHash:n.queryHash,state:{status:n.state.status,fetchStatus:n.state.fetchStatus,fetchMeta:n.state.fetchMeta,dataUpdatedAt:n.state.dataUpdatedAt,errorUpdatedAt:n.state.errorUpdatedAt}};r.send("sync-query-event",{type:"updated",action:"fetch",data:u});break}case"success":{const u={queryHash:n.queryHash,state:{status:n.state.status,data:n.state.data,dataUpdatedAt:n.state.dataUpdatedAt,error:n.state.error,errorUpdatedAt:n.state.errorUpdatedAt,fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"success",data:u});break}case"error":{const u={queryHash:n.queryHash,state:{status:n.state.status,error:n.state.error,errorUpdatedAt:n.state.errorUpdatedAt,fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"error",data:u});break}case"setState":{const u={queryHash:n.queryHash,state:p.state};r.send("sync-query-event",{type:"updated",action:"setState",data:u});break}case"invalidate":{const u={queryHash:n.queryHash,state:{isInvalidated:n.state.isInvalidated}};r.send("sync-query-event",{type:"updated",action:"invalidate",data:u});break}case"pause":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"pause",data:u});break}case"continue":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"continue",data:u});break}default:{const u=T(n);r.send("sync-query-event",{type:y,data:u})}}return}if(y==="observerAdded"||y==="observerRemoved"||y==="observerOptionsUpdated"){const p=R(n),u=t.current.get(n.queryHash);if(y==="observerOptionsUpdated"&&u&&D.default(u,p))return;t.current.set(n.queryHash,p),r.send("sync-query-event",{type:y,data:{queryHash:n.queryHash,observers:p}});return}}const{mutation:d,type:h}=s;if(d){const n=v(d);r.send("sync-mutation-event",{type:h,data:n})}},[r]);m.useEffect(()=>{if(!r)return;const s=e.getMutationCache().subscribe(a),d=e.getQueryCache().subscribe(a);return()=>{s(),d()}},[r,e,a])},P=(e,r)=>{m.useEffect(()=>{if(!r)return;const t=r.onMessage("request-initial-data",()=>{const a=C(e);r.send("sync-data",{data:a})});return()=>{t.remove()}},[r,e])},G="@rozenite/tanstack-query-plugin",j=20,z=100,N=e=>!!e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype,o=(e,r=new WeakSet)=>{if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="function"||typeof e=="symbol")return`[non-serializable:${typeof e}]`;if(e instanceof Date)return e.toISOString();if(e instanceof Error)return{name:e.name,message:e.message,stack:e.stack??null,cause:o(e.cause,r)};if(Array.isArray(e))return e.map(t=>o(t,r));if(ArrayBuffer.isView(e))return Array.from(e).map(t=>typeof t=="number"?t:Number(t));if(e instanceof ArrayBuffer)return Array.from(new Uint8Array(e));if(typeof e=="object"){if(r.has(e))return"[circular]";if(r.add(e),!N(e))return`[non-serializable:${e.constructor?.name??"Object"}]`;const t=Object.entries(e).map(([a,s])=>[a,o(s,r)]);return Object.fromEntries(t)}return String(e)},L=e=>typeof e!="number"||!Number.isFinite(e)||!Number.isInteger(e)||e<1?j:Math.min(e,z),F=(e,r,t)=>`${e}:${r}:${t}`,$=(e,r,t)=>{const[a,s,d]=e.split(":",3);if(a!==r||!s||!d)throw new Error("Cursor does not match the requested listing. Run the command again.");const h=Number(s),n=Number(d);if(!Number.isInteger(h)||h!==t)throw new Error("Cursor does not match the requested listing. Run the command again.");if(!Number.isInteger(n)||n<0)throw new Error("Cursor is invalid. Run the command again.");return n},A=(e,r,t,a)=>{const s=L(a.limit),d=a.cursor?$(a.cursor,r,t):0,h=Math.min(d+s,e.length),n=h<e.length;return{items:e.slice(d,h),page:{limit:s,hasMore:n,...n?{nextCursor:F(r,t,h)}:{}}}},f={queryHash:{type:"string",description:"TanStack Query queryHash identifying the query."}},K={mutationId:{type:"number",description:"TanStack Query mutationId identifying the mutation."}},E={limit:{type:"number",description:"Maximum number of items to return. Defaults to 20. Maximum 100."},cursor:{type:"string",description:"Opaque pagination cursor from a previous list call."}},Q={type:"object",properties:{}},x={name:"get-cache-summary",description:"Return aggregate TanStack Query cache health and count information.",inputSchema:Q},B={name:"get-online-status",description:"Return the current TanStack Query onlineManager status.",inputSchema:Q},V={name:"set-online-status",description:"Set the TanStack Query onlineManager status for testing offline/online behavior.",inputSchema:{type:"object",properties:{online:{type:"boolean",description:"Whether the TanStack Query onlineManager should be online."}},required:["online"]}},W={name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:E}},Y={name:"get-query-details",description:"Return a JSON-safe TanStack Query query snapshot and observer summary.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},J={name:"refetch-query",description:"Refetch a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},X={name:"set-query-loading",description:"Enable or disable TanStack Query loading-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash","enabled"]}},Z={name:"set-query-error",description:"Enable or disable TanStack Query error-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash","enabled"]}},ee={name:"invalidate-query",description:"Invalidate a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},te={name:"reset-query",description:"Reset a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},re={name:"remove-query",description:"Remove a TanStack Query query from the cache by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},ae={name:"clear-query-cache",description:"Clear the full TanStack Query query cache.",inputSchema:Q},ne={name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:E}},se={name:"get-mutation-details",description:"Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",inputSchema:{type:"object",properties:K,required:["mutationId"]}},oe={name:"clear-mutation-cache",description:"Clear the full TanStack Query mutation cache.",inputSchema:Q},ue=e=>e?{enabled:o(e.enabled),networkMode:o(e.networkMode),staleTime:o(e.staleTime),gcTime:o(e.gcTime),retry:o(e.retry),retryDelay:o(e.retryDelay),refetchInterval:o(e.refetchInterval),refetchOnMount:o(e.refetchOnMount),refetchOnReconnect:o(e.refetchOnReconnect),refetchOnWindowFocus:o(e.refetchOnWindowFocus),subscribed:o(e.subscribed),meta:o(e.meta),hasQueryFn:typeof e.queryFn=="function",hasSelect:typeof e.select=="function",hasPlaceholderData:"placeholderData"in e,hasInitialData:"initialData"in e}:null,ie=e=>({mutationKey:o(e.mutationKey),networkMode:o(e.networkMode),gcTime:o(e.gcTime),retry:o(e.retry),retryDelay:o(e.retryDelay),meta:o(e.meta),scope:o(e.scope),hasMutationFn:typeof e.mutationFn=="function",hasOnMutate:typeof e.onMutate=="function",hasOnSuccess:typeof e.onSuccess=="function",hasOnError:typeof e.onError=="function",hasOnSettled:typeof e.onSettled=="function"}),q=e=>Math.max(e.state.dataUpdatedAt,e.state.errorUpdatedAt),ce=(e,r)=>q(r)-q(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,M=e=>({queryHash:e.queryHash,queryKey:o(e.queryKey),status:e.state.status,fetchStatus:e.state.fetchStatus,observersCount:e.getObserversCount(),isInvalidated:e.state.isInvalidated,dataUpdatedAt:e.state.dataUpdatedAt,errorUpdatedAt:e.state.errorUpdatedAt,hasData:e.state.data!==void 0,hasError:e.state.error!=null}),ye=e=>e.status,H=e=>({mutationId:e.mutationId,mutationKey:o(e.options.mutationKey),status:ye(e.state),isPaused:e.state.isPaused,submittedAt:e.state.submittedAt,failureCount:e.state.failureCount,hasData:e.state.data!==void 0,hasError:e.state.error!=null}),he=(e,r)=>{const t=e.getQueryCache().get(r);if(!t){const a=e.getQueryCache().getAll().map(s=>s.queryHash).join(", ");throw new Error(`Unknown queryHash "${r}". Available: ${a||"(none)"}`)}return t},le=(e,r)=>{const t=e.getMutationCache().getAll().find(a=>a.mutationId===r);if(!t){const a=e.getMutationCache().getAll().map(s=>s.mutationId).join(", ");throw new Error(`Unknown mutationId "${r}". Available: ${a||"(none)"}`)}return t},S=e=>{const r=e.getQueryCache().getAll(),t=e.getMutationCache().getAll();return{online:b.onlineManager.isOnline(),queries:{total:r.length,active:r.filter(a=>a.getObserversCount()>0).length,fetching:r.filter(a=>a.state.fetchStatus==="fetching").length,pending:r.filter(a=>a.state.status==="pending").length,success:r.filter(a=>a.state.status==="success").length,error:r.filter(a=>a.state.status==="error").length,invalidated:r.filter(a=>a.state.isInvalidated).length},mutations:{total:t.length,pending:t.filter(a=>a.state.status==="pending").length,success:t.filter(a=>a.state.status==="success").length,error:t.filter(a=>a.state.status==="error").length,paused:t.filter(a=>a.state.isPaused).length}}},pe=e=>{const r={queriesGeneration:0,mutationsGeneration:0};return{handleQueryCacheEvent(t){(t.type==="added"||t.type==="removed")&&(r.queriesGeneration+=1)},handleMutationCacheEvent(t){(t.type==="added"||t.type==="removed")&&(r.mutationsGeneration+=1)},getCacheSummary(){return S(e)},getOnlineStatus(){return{online:b.onlineManager.isOnline()}},setOnlineStatus({online:t}){return b.onlineManager.setOnline(t),{online:b.onlineManager.isOnline()}},listQueries(t={}){const a=[...e.getQueryCache().getAll()].sort(ce);return{...S(e),total:a.length,...A(a.map(M),"queries",r.queriesGeneration,t)}},getQueryDetails({queryHash:t}){const a=he(e,t);return{summary:S(e),query:{...M(a),data:o(a.state.data),error:o(a.state.error),observers:a.observers.map(s=>({queryHash:a.queryHash,options:ue(s.options)}))}}},async refetchQuery({queryHash:t}){return l(e,{type:"REFETCH",queryHash:t})},async setQueryLoading({queryHash:t,enabled:a}){return l(e,{type:a?"TRIGGER_LOADING":"RESTORE_LOADING",queryHash:t})},async setQueryError({queryHash:t,enabled:a}){return l(e,{type:a?"TRIGGER_ERROR":"RESTORE_ERROR",queryHash:t})},async invalidateQuery({queryHash:t}){return l(e,{type:"INVALIDATE",queryHash:t})},async resetQuery({queryHash:t}){return l(e,{type:"RESET",queryHash:t})},async removeQuery({queryHash:t}){return l(e,{type:"REMOVE",queryHash:t})},async clearQueryCache(){return l(e,{type:"CLEAR_QUERY_CACHE"})},listMutations(t={}){const a=[...e.getMutationCache().getAll()].sort(de);return{...S(e),total:a.length,...A(a.map(H),"mutations",r.mutationsGeneration,t)}},getMutationDetails({mutationId:t}){const a=le(e,t);return{summary:S(e),mutation:{...H(a),variables:o(a.state.variables),data:o(a.state.data),error:o(a.state.error),context:o(a.state.context),failureReason:o(a.state.failureReason),options:ie(a.options)}}},async clearMutationCache(){return l(e,{type:"CLEAR_MUTATION_CACHE"})}}},c=G,ge=e=>{const r=m.useMemo(()=>pe(e),[e]);m.useEffect(()=>{const t=e.getQueryCache().subscribe(s=>r.handleQueryCacheEvent(s)),a=e.getMutationCache().subscribe(s=>r.handleMutationCacheEvent(s));return()=>{t(),a()}},[r,e]),i.useRozenitePluginAgentTool({pluginId:c,tool:x,handler:()=>r.getCacheSummary()}),i.useRozenitePluginAgentTool({pluginId:c,tool:B,handler:()=>r.getOnlineStatus()}),i.useRozenitePluginAgentTool({pluginId:c,tool:V,handler:t=>r.setOnlineStatus(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:W,handler:(t={})=>r.listQueries(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:Y,handler:t=>r.getQueryDetails(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:J,handler:t=>r.refetchQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:X,handler:t=>r.setQueryLoading(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:Z,handler:t=>r.setQueryError(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:ee,handler:t=>r.invalidateQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:te,handler:t=>r.resetQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:re,handler:t=>r.removeQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:ae,handler:()=>r.clearQueryCache()}),i.useRozenitePluginAgentTool({pluginId:c,tool:ne,handler:(t={})=>r.listMutations(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:se,handler:t=>r.getMutationDetails(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:oe,handler:()=>r.clearMutationCache()})},me=e=>{const r=O.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});w(r),_(e,r),U(e,r),P(e,r),ge(e)};exports.useTanStackQueryDevTools=me;
|