@rozenite/tanstack-query-plugin 2.0.0 → 2.1.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.
@@ -22,7 +22,7 @@
22
22
  <script>
23
23
  var __ROZENITE_PANEL__ = true;
24
24
  </script>
25
- <script type="module" crossorigin src="../devtools/assets/tanstack-query-OfMbjvWS.js"></script>
25
+ <script type="module" crossorigin src="../devtools/assets/tanstack-query-CbF_imft.js"></script>
26
26
  </head>
27
27
  <body>
28
28
  <div id="root"></div>
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@rozenite/plugin-bridge"),b=require("react"),A=require("@tanstack/react-query"),C=require("fast-deep-equal"),i=require("@rozenite/agent-bridge"),c=require("@rozenite/agent-shared"),D=e=>e&&e.__esModule?e:{default:e},_=D(C),w=e=>{b.useEffect(()=>{if(!e)return;const a=A.onlineManager.subscribe(r=>{e.send("online-status-changed",{online:r})}),t=e.onMessage("online-status-changed",({online:r})=>{A.onlineManager.setOnline(r)});return()=>{a(),t.remove()}},[e])},g=(e,a)=>{if(!a)throw new Error("queryHash is required for this TanStack Query action.");const t=e.getQueryCache().get(a);if(!t)throw new Error(`No active query found for hash: ${a}`);return t},f=async(e,a)=>{switch(a.type){case"CLEAR_QUERY_CACHE":{const t=e.getQueryCache().getAll().length;return e.getQueryCache().clear(),{applied:!0,action:a.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:a.type,cleared:!0,mutationCountBefore:t,mutationCountAfter:e.getMutationCache().getAll().length}}case"SET_QUERY_DATA":{const t=g(e,a.queryHash);return e.setQueryData(t.queryKey,a.metadata?.data),{applied:!0,action:a.type,queryHash:t.queryHash}}case"TRIGGER_ERROR":{const t=g(e,a.queryHash),r=t.options,s=new Error("Unknown error from devtools");return t.setState({status:"error",error:s,fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:r}}),{applied:!0,action:a.type,queryHash:t.queryHash}}case"RESTORE_ERROR":{const t=g(e,a.queryHash);return await e.resetQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}case"TRIGGER_LOADING":{const t=g(e,a.queryHash),r=t.options;return t.fetch({...r,queryFn:()=>new Promise(()=>{}),gcTime:-1}),t.setState({data:void 0,status:"pending",fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:r}}),{applied:!0,action:a.type,queryHash:t.queryHash}}case"RESTORE_LOADING":{const t=g(e,a.queryHash),r=t.state,s=t.state.fetchMeta?t.state.fetchMeta.__previousQueryOptions:null;return t.cancel({silent:!0}),t.setState({...r,fetchStatus:"idle",fetchMeta:null}),s&&t.fetch(s),{applied:!0,action:a.type,queryHash:t.queryHash}}case"RESET":{const t=g(e,a.queryHash);return await e.resetQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}case"REMOVE":{const t=g(e,a.queryHash);return e.removeQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}case"REFETCH":{const t=g(e,a.queryHash);return await t.fetch().catch(()=>{}),{applied:!0,action:a.type,queryHash:t.queryHash}}case"INVALIDATE":{const t=g(e,a.queryHash);return await e.invalidateQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}}},U=(e,a)=>{b.useEffect(()=>{if(!a)return;const t=a.onMessage("devtools-action",({type:r,queryHash:s,metadata:h})=>{f(e,{type:r,queryHash:s,metadata:h}).catch(l=>{const n=l instanceof Error?l.message:String(l);console.warn(`[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${r}": ${n}`)})});return()=>{t.remove()}},[a])},O=e=>e.observers.map(a=>({queryHash:e.queryHash,options:a.options})),q=e=>{const a=O(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:a}},I=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),P=e=>({queries:e.getQueryCache().getAll().map(q),mutations:e.getMutationCache().getAll().map(I)}),G=(e,a)=>{const t=b.useRef(new Map),r=b.useMemo(()=>s=>{if(!a||s.type==="observerResultsUpdated")return;if("query"in s){const{query:n,type:p}=s;if(p==="added"||p==="removed"){p==="removed"&&t.current.delete(n.queryHash);const m=q(n);a.send("sync-query-event",{type:p,data:m});return}if(p==="updated"&&"action"in s){const m=s.action;switch(m.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}};a.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}};a.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}};a.send("sync-query-event",{type:"updated",action:"error",data:u});break}case"setState":{const u={queryHash:n.queryHash,state:m.state};a.send("sync-query-event",{type:"updated",action:"setState",data:u});break}case"invalidate":{const u={queryHash:n.queryHash,state:{isInvalidated:n.state.isInvalidated}};a.send("sync-query-event",{type:"updated",action:"invalidate",data:u});break}case"pause":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"pause",data:u});break}case"continue":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"continue",data:u});break}default:{const u=q(n);a.send("sync-query-event",{type:p,data:u})}}return}if(p==="observerAdded"||p==="observerRemoved"||p==="observerOptionsUpdated"){const m=O(n),u=t.current.get(n.queryHash);if(p==="observerOptionsUpdated"&&u&&_.default(u,m))return;t.current.set(n.queryHash,m),a.send("sync-query-event",{type:p,data:{queryHash:n.queryHash,observers:m}});return}}const{mutation:h,type:l}=s;if(h){const n=I(h);a.send("sync-mutation-event",{type:l,data:n})}},[a]);b.useEffect(()=>{if(!a)return;const s=e.getMutationCache().subscribe(r),h=e.getQueryCache().subscribe(r);return()=>{s(),h()}},[a,e,r])},j=(e,a)=>{b.useEffect(()=>{if(!a)return;const t=a.onMessage("request-initial-data",()=>{const r=P(e);a.send("sync-data",{data:r})});return()=>{t.remove()}},[a,e])},d="@rozenite/tanstack-query-plugin",S={queryHash:{type:"string",description:"TanStack Query queryHash identifying the query."}},z={mutationId:{type:"number",description:"TanStack Query mutationId identifying the mutation."}},M={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."}},T={type:"object",properties:{}},y={getCacheSummary:c.defineAgentToolContract({name:"get-cache-summary",description:"Return aggregate TanStack Query cache health and count information.",inputSchema:T}),getOnlineStatus:c.defineAgentToolContract({name:"get-online-status",description:"Return the current TanStack Query onlineManager status.",inputSchema:T}),setOnlineStatus:c.defineAgentToolContract({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"]}}),listQueries:c.definePaginatedAgentToolContract({name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:M},pagination:{kind:"cursor",fields:["queryHash","queryKey","status","fetchStatus","observersCount","isInvalidated","dataUpdatedAt","errorUpdatedAt","hasData","hasError"],defaultFields:["queryHash","queryKey","status","fetchStatus","hasError"]}}),getQueryDetails:c.defineAgentToolContract({name:"get-query-details",description:"Return a JSON-safe TanStack Query query snapshot and observer summary.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),refetchQuery:c.defineAgentToolContract({name:"refetch-query",description:"Refetch a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),setQueryLoading:c.defineAgentToolContract({name:"set-query-loading",description:"Enable or disable TanStack Query loading-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...S,enabled:{type:"boolean",description:"Whether the loading-state simulation should be enabled."}},required:["queryHash","enabled"]}}),setQueryError:c.defineAgentToolContract({name:"set-query-error",description:"Enable or disable TanStack Query error-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...S,enabled:{type:"boolean",description:"Whether the error-state simulation should be enabled."}},required:["queryHash","enabled"]}}),invalidateQuery:c.defineAgentToolContract({name:"invalidate-query",description:"Invalidate a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),resetQuery:c.defineAgentToolContract({name:"reset-query",description:"Reset a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),removeQuery:c.defineAgentToolContract({name:"remove-query",description:"Remove a TanStack Query query from the cache by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),clearQueryCache:c.defineAgentToolContract({name:"clear-query-cache",description:"Clear the full TanStack Query query cache.",inputSchema:T}),listMutations:c.definePaginatedAgentToolContract({name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:M},pagination:{kind:"cursor",fields:["mutationId","mutationKey","status","isPaused","submittedAt","failureCount","hasData","hasError"],defaultFields:["mutationId","mutationKey","status","hasError"]}}),getMutationDetails:c.defineAgentToolContract({name:"get-mutation-details",description:"Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",inputSchema:{type:"object",properties:z,required:["mutationId"]}}),clearMutationCache:c.defineAgentToolContract({name:"clear-mutation-cache",description:"Clear the full TanStack Query mutation cache.",inputSchema:T})},N=20,L=100,F=e=>!!e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype,o=(e,a=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,a)};if(Array.isArray(e))return e.map(t=>o(t,a));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(a.has(e))return"[circular]";if(a.add(e),!F(e))return`[non-serializable:${e.constructor?.name??"Object"}]`;const t=Object.entries(e).map(([r,s])=>[r,o(s,a)]);return Object.fromEntries(t)}return String(e)},K=e=>typeof e!="number"||!Number.isFinite(e)||!Number.isInteger(e)||e<1?N:Math.min(e,L),$=(e,a,t)=>`${e}:${a}:${t}`,x=(e,a,t)=>{const[r,s,h]=e.split(":",3);if(r!==a||!s||!h)throw new Error("Cursor does not match the requested listing. Run the command again.");const l=Number(s),n=Number(h);if(!Number.isInteger(l)||l!==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},E=(e,a,t,r)=>{const s=K(r.limit),h=r.cursor?x(r.cursor,a,t):0,l=Math.min(h+s,e.length),n=l<e.length;return{items:e.slice(h,l),page:{limit:s,hasMore:n,...n?{nextCursor:$(a,t,l)}:{}}}},B=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,W=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"}),H=e=>Math.max(e.state.dataUpdatedAt,e.state.errorUpdatedAt),V=(e,a)=>H(a)-H(e)||a.getObserversCount()-e.getObserversCount()||String(a.queryHash).localeCompare(String(e.queryHash)),Y=(e,a)=>a.state.submittedAt-e.state.submittedAt||a.mutationId-e.mutationId,v=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}),J=e=>e.status,R=e=>({mutationId:e.mutationId,mutationKey:o(e.options.mutationKey),status:J(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}),X=(e,a)=>{const t=e.getQueryCache().get(a);if(!t){const r=e.getQueryCache().getAll().map(s=>s.queryHash).join(", ");throw new Error(`Unknown queryHash "${a}". Available: ${r||"(none)"}`)}return t},Z=(e,a)=>{const t=e.getMutationCache().getAll().find(r=>r.mutationId===a);if(!t){const r=e.getMutationCache().getAll().map(s=>s.mutationId).join(", ");throw new Error(`Unknown mutationId "${a}". Available: ${r||"(none)"}`)}return t},Q=e=>{const a=e.getQueryCache().getAll(),t=e.getMutationCache().getAll();return{online:A.onlineManager.isOnline(),queries:{total:a.length,active:a.filter(r=>r.getObserversCount()>0).length,fetching:a.filter(r=>r.state.fetchStatus==="fetching").length,pending:a.filter(r=>r.state.status==="pending").length,success:a.filter(r=>r.state.status==="success").length,error:a.filter(r=>r.state.status==="error").length,invalidated:a.filter(r=>r.state.isInvalidated).length},mutations:{total:t.length,pending:t.filter(r=>r.state.status==="pending").length,success:t.filter(r=>r.state.status==="success").length,error:t.filter(r=>r.state.status==="error").length,paused:t.filter(r=>r.state.isPaused).length}}},ee=e=>{const a={queriesGeneration:0,mutationsGeneration:0};return{handleQueryCacheEvent(t){(t.type==="added"||t.type==="removed")&&(a.queriesGeneration+=1)},handleMutationCacheEvent(t){(t.type==="added"||t.type==="removed")&&(a.mutationsGeneration+=1)},getCacheSummary(){return Q(e)},getOnlineStatus(){return{online:A.onlineManager.isOnline()}},setOnlineStatus({online:t}){return A.onlineManager.setOnline(t),{online:A.onlineManager.isOnline()}},listQueries(t={}){const r=[...e.getQueryCache().getAll()].sort(V);return{...Q(e),total:r.length,...E(r.map(v),"queries",a.queriesGeneration,t)}},getQueryDetails({queryHash:t}){const r=X(e,t);return{summary:Q(e),query:{...v(r),data:o(r.state.data),error:o(r.state.error),observers:r.observers.map(s=>({queryHash:r.queryHash,options:B(s.options)}))}}},async refetchQuery({queryHash:t}){return f(e,{type:"REFETCH",queryHash:t})},async setQueryLoading({queryHash:t,enabled:r}){return f(e,{type:r?"TRIGGER_LOADING":"RESTORE_LOADING",queryHash:t})},async setQueryError({queryHash:t,enabled:r}){return f(e,{type:r?"TRIGGER_ERROR":"RESTORE_ERROR",queryHash:t})},async invalidateQuery({queryHash:t}){return f(e,{type:"INVALIDATE",queryHash:t})},async resetQuery({queryHash:t}){return f(e,{type:"RESET",queryHash:t})},async removeQuery({queryHash:t}){return f(e,{type:"REMOVE",queryHash:t})},async clearQueryCache(){return f(e,{type:"CLEAR_QUERY_CACHE"})},listMutations(t={}){const r=[...e.getMutationCache().getAll()].sort(Y);return{...Q(e),total:r.length,...E(r.map(R),"mutations",a.mutationsGeneration,t)}},getMutationDetails({mutationId:t}){const r=Z(e,t);return{summary:Q(e),mutation:{...R(r),variables:o(r.state.variables),data:o(r.state.data),error:o(r.state.error),context:o(r.state.context),failureReason:o(r.state.failureReason),options:W(r.options)}}},async clearMutationCache(){return f(e,{type:"CLEAR_MUTATION_CACHE"})}}},te=e=>{const a=b.useMemo(()=>ee(e),[e]);b.useEffect(()=>{const t=e.getQueryCache().subscribe(s=>a.handleQueryCacheEvent(s)),r=e.getMutationCache().subscribe(s=>a.handleMutationCacheEvent(s));return()=>{t(),r()}},[a,e]),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getCacheSummary,handler:()=>a.getCacheSummary()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getOnlineStatus,handler:()=>a.getOnlineStatus()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setOnlineStatus,handler:t=>a.setOnlineStatus(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.listQueries,handler:(t={})=>a.listQueries(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getQueryDetails,handler:t=>a.getQueryDetails(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.refetchQuery,handler:t=>a.refetchQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setQueryLoading,handler:t=>a.setQueryLoading(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setQueryError,handler:t=>a.setQueryError(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.invalidateQuery,handler:t=>a.invalidateQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.resetQuery,handler:t=>a.resetQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.removeQuery,handler:t=>a.removeQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.clearQueryCache,handler:()=>a.clearQueryCache()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.listMutations,handler:(t={})=>a.listMutations(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getMutationDetails,handler:t=>a.getMutationDetails(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.clearMutationCache,handler:()=>a.clearMutationCache()})},ae=e=>{const a=k.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});w(a),U(e,a),G(e,a),j(e,a),te(e)};exports.useTanStackQueryDevTools=ae;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@rozenite/plugin-bridge"),b=require("react"),A=require("@tanstack/react-query"),C=require("fast-deep-equal"),i=require("@rozenite/agent-bridge"),c=require("@rozenite/agent-shared"),D=e=>e&&e.__esModule?e:{default:e},_=D(C),w=e=>{b.useEffect(()=>{if(!e)return;const a=A.onlineManager.subscribe(r=>{e.send("online-status-changed",{online:r})}),t=e.onMessage("online-status-changed",({online:r})=>{A.onlineManager.setOnline(r)});return()=>{a(),t.remove()}},[e])},g=(e,a)=>{if(!a)throw new Error("queryHash is required for this TanStack Query action.");const t=e.getQueryCache().get(a);if(!t)throw new Error(`No active query found for hash: ${a}`);return t},f=async(e,a)=>{switch(a.type){case"CLEAR_QUERY_CACHE":{const t=e.getQueryCache().getAll().length;return e.getQueryCache().clear(),{applied:!0,action:a.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:a.type,cleared:!0,mutationCountBefore:t,mutationCountAfter:e.getMutationCache().getAll().length}}case"SET_QUERY_DATA":{const t=g(e,a.queryHash);return e.setQueryData(t.queryKey,a.metadata?.data),{applied:!0,action:a.type,queryHash:t.queryHash}}case"TRIGGER_ERROR":{const t=g(e,a.queryHash),r=t.options,s=new Error("Unknown error from devtools");return t.setState({status:"error",error:s,fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:r}}),{applied:!0,action:a.type,queryHash:t.queryHash}}case"RESTORE_ERROR":{const t=g(e,a.queryHash);return await e.resetQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}case"TRIGGER_LOADING":{const t=g(e,a.queryHash),r=t.options;return t.fetch({...r,queryFn:()=>new Promise(()=>{}),gcTime:-1}),t.setState({data:void 0,status:"pending",fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:r}}),{applied:!0,action:a.type,queryHash:t.queryHash}}case"RESTORE_LOADING":{const t=g(e,a.queryHash),r=t.state,s=t.state.fetchMeta?t.state.fetchMeta.__previousQueryOptions:null;return t.cancel({silent:!0}),t.setState({...r,fetchStatus:"idle",fetchMeta:null}),s&&t.fetch(s),{applied:!0,action:a.type,queryHash:t.queryHash}}case"RESET":{const t=g(e,a.queryHash);return await e.resetQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}case"REMOVE":{const t=g(e,a.queryHash);return e.removeQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}case"REFETCH":{const t=g(e,a.queryHash);return await t.fetch().catch(()=>{}),{applied:!0,action:a.type,queryHash:t.queryHash}}case"INVALIDATE":{const t=g(e,a.queryHash);return await e.invalidateQueries(t),{applied:!0,action:a.type,queryHash:t.queryHash}}}},U=(e,a)=>{b.useEffect(()=>{if(!a)return;const t=a.onMessage("devtools-action",({type:r,queryHash:s,metadata:h})=>{f(e,{type:r,queryHash:s,metadata:h}).catch(l=>{const n=l instanceof Error?l.message:String(l);console.warn(`[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${r}": ${n}`)})});return()=>{t.remove()}},[a])},O=e=>e.observers.map(a=>({queryHash:e.queryHash,options:a.options})),q=e=>{const a=O(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:a}},I=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),P=e=>({queries:e.getQueryCache().getAll().map(q),mutations:e.getMutationCache().getAll().map(I)}),G=(e,a)=>{const t=b.useRef(new Map),r=b.useMemo(()=>s=>{if(!a||s.type==="observerResultsUpdated")return;if("query"in s){const{query:n,type:p}=s;if(p==="added"||p==="removed"){p==="removed"&&t.current.delete(n.queryHash);const m=q(n);a.send("sync-query-event",{type:p,data:m});return}if(p==="updated"&&"action"in s){const m=s.action;switch(m.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}};a.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}};a.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}};a.send("sync-query-event",{type:"updated",action:"error",data:u});break}case"setState":{const u={queryHash:n.queryHash,state:m.state};a.send("sync-query-event",{type:"updated",action:"setState",data:u});break}case"invalidate":{const u={queryHash:n.queryHash,state:{isInvalidated:n.state.isInvalidated}};a.send("sync-query-event",{type:"updated",action:"invalidate",data:u});break}case"pause":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"pause",data:u});break}case"continue":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"continue",data:u});break}default:{const u=q(n);a.send("sync-query-event",{type:p,data:u})}}return}if(p==="observerAdded"||p==="observerRemoved"||p==="observerOptionsUpdated"){const m=O(n),u=t.current.get(n.queryHash);if(p==="observerOptionsUpdated"&&u&&_.default(u,m))return;t.current.set(n.queryHash,m),a.send("sync-query-event",{type:p,data:{queryHash:n.queryHash,observers:m}});return}}const{mutation:h,type:l}=s;if(h){const n=I(h);a.send("sync-mutation-event",{type:l,data:n})}},[a]);b.useEffect(()=>{if(!a)return;const s=e.getMutationCache().subscribe(r),h=e.getQueryCache().subscribe(r);return()=>{s(),h()}},[a,e,r])},j=(e,a)=>{b.useEffect(()=>{if(!a)return;const t=a.onMessage("request-initial-data",()=>{const r=P(e);a.send("sync-data",{data:r})});return a.send("device-ready",{}),()=>{t.remove()}},[a,e])},d="@rozenite/tanstack-query-plugin",S={queryHash:{type:"string",description:"TanStack Query queryHash identifying the query."}},z={mutationId:{type:"number",description:"TanStack Query mutationId identifying the mutation."}},M={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."}},T={type:"object",properties:{}},y={getCacheSummary:c.defineAgentToolContract({name:"get-cache-summary",description:"Return aggregate TanStack Query cache health and count information.",inputSchema:T}),getOnlineStatus:c.defineAgentToolContract({name:"get-online-status",description:"Return the current TanStack Query onlineManager status.",inputSchema:T}),setOnlineStatus:c.defineAgentToolContract({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"]}}),listQueries:c.definePaginatedAgentToolContract({name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:M},pagination:{kind:"cursor",fields:["queryHash","queryKey","status","fetchStatus","observersCount","isInvalidated","dataUpdatedAt","errorUpdatedAt","hasData","hasError"],defaultFields:["queryHash","queryKey","status","fetchStatus","hasError"]}}),getQueryDetails:c.defineAgentToolContract({name:"get-query-details",description:"Return a JSON-safe TanStack Query query snapshot and observer summary.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),refetchQuery:c.defineAgentToolContract({name:"refetch-query",description:"Refetch a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),setQueryLoading:c.defineAgentToolContract({name:"set-query-loading",description:"Enable or disable TanStack Query loading-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...S,enabled:{type:"boolean",description:"Whether the loading-state simulation should be enabled."}},required:["queryHash","enabled"]}}),setQueryError:c.defineAgentToolContract({name:"set-query-error",description:"Enable or disable TanStack Query error-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...S,enabled:{type:"boolean",description:"Whether the error-state simulation should be enabled."}},required:["queryHash","enabled"]}}),invalidateQuery:c.defineAgentToolContract({name:"invalidate-query",description:"Invalidate a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),resetQuery:c.defineAgentToolContract({name:"reset-query",description:"Reset a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),removeQuery:c.defineAgentToolContract({name:"remove-query",description:"Remove a TanStack Query query from the cache by queryHash.",inputSchema:{type:"object",properties:S,required:["queryHash"]}}),clearQueryCache:c.defineAgentToolContract({name:"clear-query-cache",description:"Clear the full TanStack Query query cache.",inputSchema:T}),listMutations:c.definePaginatedAgentToolContract({name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:M},pagination:{kind:"cursor",fields:["mutationId","mutationKey","status","isPaused","submittedAt","failureCount","hasData","hasError"],defaultFields:["mutationId","mutationKey","status","hasError"]}}),getMutationDetails:c.defineAgentToolContract({name:"get-mutation-details",description:"Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",inputSchema:{type:"object",properties:z,required:["mutationId"]}}),clearMutationCache:c.defineAgentToolContract({name:"clear-mutation-cache",description:"Clear the full TanStack Query mutation cache.",inputSchema:T})},N=20,L=100,F=e=>!!e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype,o=(e,a=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,a)};if(Array.isArray(e))return e.map(t=>o(t,a));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(a.has(e))return"[circular]";if(a.add(e),!F(e))return`[non-serializable:${e.constructor?.name??"Object"}]`;const t=Object.entries(e).map(([r,s])=>[r,o(s,a)]);return Object.fromEntries(t)}return String(e)},K=e=>typeof e!="number"||!Number.isFinite(e)||!Number.isInteger(e)||e<1?N:Math.min(e,L),$=(e,a,t)=>`${e}:${a}:${t}`,x=(e,a,t)=>{const[r,s,h]=e.split(":",3);if(r!==a||!s||!h)throw new Error("Cursor does not match the requested listing. Run the command again.");const l=Number(s),n=Number(h);if(!Number.isInteger(l)||l!==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},E=(e,a,t,r)=>{const s=K(r.limit),h=r.cursor?x(r.cursor,a,t):0,l=Math.min(h+s,e.length),n=l<e.length;return{items:e.slice(h,l),page:{limit:s,hasMore:n,...n?{nextCursor:$(a,t,l)}:{}}}},B=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,W=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"}),H=e=>Math.max(e.state.dataUpdatedAt,e.state.errorUpdatedAt),V=(e,a)=>H(a)-H(e)||a.getObserversCount()-e.getObserversCount()||String(a.queryHash).localeCompare(String(e.queryHash)),Y=(e,a)=>a.state.submittedAt-e.state.submittedAt||a.mutationId-e.mutationId,v=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}),J=e=>e.status,R=e=>({mutationId:e.mutationId,mutationKey:o(e.options.mutationKey),status:J(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}),X=(e,a)=>{const t=e.getQueryCache().get(a);if(!t){const r=e.getQueryCache().getAll().map(s=>s.queryHash).join(", ");throw new Error(`Unknown queryHash "${a}". Available: ${r||"(none)"}`)}return t},Z=(e,a)=>{const t=e.getMutationCache().getAll().find(r=>r.mutationId===a);if(!t){const r=e.getMutationCache().getAll().map(s=>s.mutationId).join(", ");throw new Error(`Unknown mutationId "${a}". Available: ${r||"(none)"}`)}return t},Q=e=>{const a=e.getQueryCache().getAll(),t=e.getMutationCache().getAll();return{online:A.onlineManager.isOnline(),queries:{total:a.length,active:a.filter(r=>r.getObserversCount()>0).length,fetching:a.filter(r=>r.state.fetchStatus==="fetching").length,pending:a.filter(r=>r.state.status==="pending").length,success:a.filter(r=>r.state.status==="success").length,error:a.filter(r=>r.state.status==="error").length,invalidated:a.filter(r=>r.state.isInvalidated).length},mutations:{total:t.length,pending:t.filter(r=>r.state.status==="pending").length,success:t.filter(r=>r.state.status==="success").length,error:t.filter(r=>r.state.status==="error").length,paused:t.filter(r=>r.state.isPaused).length}}},ee=e=>{const a={queriesGeneration:0,mutationsGeneration:0};return{handleQueryCacheEvent(t){(t.type==="added"||t.type==="removed")&&(a.queriesGeneration+=1)},handleMutationCacheEvent(t){(t.type==="added"||t.type==="removed")&&(a.mutationsGeneration+=1)},getCacheSummary(){return Q(e)},getOnlineStatus(){return{online:A.onlineManager.isOnline()}},setOnlineStatus({online:t}){return A.onlineManager.setOnline(t),{online:A.onlineManager.isOnline()}},listQueries(t={}){const r=[...e.getQueryCache().getAll()].sort(V);return{...Q(e),total:r.length,...E(r.map(v),"queries",a.queriesGeneration,t)}},getQueryDetails({queryHash:t}){const r=X(e,t);return{summary:Q(e),query:{...v(r),data:o(r.state.data),error:o(r.state.error),observers:r.observers.map(s=>({queryHash:r.queryHash,options:B(s.options)}))}}},async refetchQuery({queryHash:t}){return f(e,{type:"REFETCH",queryHash:t})},async setQueryLoading({queryHash:t,enabled:r}){return f(e,{type:r?"TRIGGER_LOADING":"RESTORE_LOADING",queryHash:t})},async setQueryError({queryHash:t,enabled:r}){return f(e,{type:r?"TRIGGER_ERROR":"RESTORE_ERROR",queryHash:t})},async invalidateQuery({queryHash:t}){return f(e,{type:"INVALIDATE",queryHash:t})},async resetQuery({queryHash:t}){return f(e,{type:"RESET",queryHash:t})},async removeQuery({queryHash:t}){return f(e,{type:"REMOVE",queryHash:t})},async clearQueryCache(){return f(e,{type:"CLEAR_QUERY_CACHE"})},listMutations(t={}){const r=[...e.getMutationCache().getAll()].sort(Y);return{...Q(e),total:r.length,...E(r.map(R),"mutations",a.mutationsGeneration,t)}},getMutationDetails({mutationId:t}){const r=Z(e,t);return{summary:Q(e),mutation:{...R(r),variables:o(r.state.variables),data:o(r.state.data),error:o(r.state.error),context:o(r.state.context),failureReason:o(r.state.failureReason),options:W(r.options)}}},async clearMutationCache(){return f(e,{type:"CLEAR_MUTATION_CACHE"})}}},te=e=>{const a=b.useMemo(()=>ee(e),[e]);b.useEffect(()=>{const t=e.getQueryCache().subscribe(s=>a.handleQueryCacheEvent(s)),r=e.getMutationCache().subscribe(s=>a.handleMutationCacheEvent(s));return()=>{t(),r()}},[a,e]),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getCacheSummary,handler:()=>a.getCacheSummary()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getOnlineStatus,handler:()=>a.getOnlineStatus()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setOnlineStatus,handler:t=>a.setOnlineStatus(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.listQueries,handler:(t={})=>a.listQueries(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getQueryDetails,handler:t=>a.getQueryDetails(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.refetchQuery,handler:t=>a.refetchQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setQueryLoading,handler:t=>a.setQueryLoading(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setQueryError,handler:t=>a.setQueryError(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.invalidateQuery,handler:t=>a.invalidateQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.resetQuery,handler:t=>a.resetQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.removeQuery,handler:t=>a.removeQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.clearQueryCache,handler:()=>a.clearQueryCache()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.listMutations,handler:(t={})=>a.listMutations(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getMutationDetails,handler:t=>a.getMutationDetails(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.clearMutationCache,handler:()=>a.clearMutationCache()})},ae=e=>{const a=k.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});w(a),U(e,a),G(e,a),j(e,a),te(e)};exports.useTanStackQueryDevTools=ae;
@@ -10,12 +10,9 @@ const _ = (e) => {
10
10
  return;
11
11
  const r = S.subscribe((a) => {
12
12
  e.send("online-status-changed", { online: a });
13
- }), t = e.onMessage(
14
- "online-status-changed",
15
- ({ online: a }) => {
16
- S.setOnline(a);
17
- }
18
- );
13
+ }), t = e.onMessage("online-status-changed", ({ online: a }) => {
14
+ S.setOnline(a);
15
+ });
19
16
  return () => {
20
17
  r(), t.remove();
21
18
  };
@@ -152,21 +149,18 @@ const _ = (e) => {
152
149
  A(() => {
153
150
  if (!r)
154
151
  return;
155
- const t = r.onMessage(
156
- "devtools-action",
157
- ({ type: a, queryHash: n, metadata: h }) => {
158
- f(e, {
159
- type: a,
160
- queryHash: n,
161
- metadata: h
162
- }).catch((p) => {
163
- const s = p instanceof Error ? p.message : String(p);
164
- console.warn(
165
- `[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${a}": ${s}`
166
- );
167
- });
168
- }
169
- );
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
+ });
170
164
  return () => {
171
165
  t.remove();
172
166
  };
@@ -190,9 +184,7 @@ const _ = (e) => {
190
184
  queries: e.getQueryCache().getAll().map(H),
191
185
  mutations: e.getMutationCache().getAll().map(D)
192
186
  }), N = (e, r) => {
193
- const t = C(
194
- /* @__PURE__ */ new Map()
195
- ), a = R(() => (n) => {
187
+ const t = C(/* @__PURE__ */ new Map()), a = R(() => (n) => {
196
188
  if (!r || n.type === "observerResultsUpdated")
197
189
  return;
198
190
  if ("query" in n) {
@@ -323,15 +315,10 @@ const _ = (e) => {
323
315
  return;
324
316
  }
325
317
  if (l === "observerAdded" || l === "observerRemoved" || l === "observerOptionsUpdated") {
326
- const g = k(s), u = t.current.get(
327
- s.queryHash
328
- );
318
+ const g = k(s), u = t.current.get(s.queryHash);
329
319
  if (l === "observerOptionsUpdated" && u && U(u, g))
330
320
  return;
331
- t.current.set(
332
- s.queryHash,
333
- g
334
- ), r.send("sync-query-event", {
321
+ t.current.set(s.queryHash, g), r.send("sync-query-event", {
335
322
  type: l,
336
323
  data: {
337
324
  queryHash: s.queryHash,
@@ -366,7 +353,7 @@ const _ = (e) => {
366
353
  const a = j(e);
367
354
  r.send("sync-data", { data: a });
368
355
  });
369
- return () => {
356
+ return r.send("device-ready", {}), () => {
370
357
  t.remove();
371
358
  };
372
359
  }, [r, e]);
@@ -438,13 +425,7 @@ const _ = (e) => {
438
425
  "hasData",
439
426
  "hasError"
440
427
  ],
441
- defaultFields: [
442
- "queryHash",
443
- "queryKey",
444
- "status",
445
- "fetchStatus",
446
- "hasError"
447
- ]
428
+ defaultFields: ["queryHash", "queryKey", "status", "fetchStatus", "hasError"]
448
429
  }
449
430
  }),
450
431
  getQueryDetails: y({
@@ -480,21 +461,23 @@ const _ = (e) => {
480
461
  required: ["queryHash", "enabled"]
481
462
  }
482
463
  }),
483
- setQueryError: y({
484
- name: "set-query-error",
485
- description: "Enable or disable TanStack Query error-state simulation for a query by queryHash.",
486
- inputSchema: {
487
- type: "object",
488
- properties: {
489
- ...b,
490
- enabled: {
491
- type: "boolean",
492
- description: "Whether the error-state simulation should be enabled."
493
- }
494
- },
495
- required: ["queryHash", "enabled"]
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
+ }
496
479
  }
497
- }),
480
+ ),
498
481
  invalidateQuery: y({
499
482
  name: "invalidate-query",
500
483
  description: "Invalidate a TanStack Query query by queryHash.",
@@ -581,10 +564,7 @@ const _ = (e) => {
581
564
  name: e.name,
582
565
  message: e.message,
583
566
  stack: e.stack ?? null,
584
- cause: o(
585
- e.cause,
586
- r
587
- )
567
+ cause: o(e.cause, r)
588
568
  };
589
569
  if (Array.isArray(e))
590
570
  return e.map((t) => o(t, r));
@@ -609,14 +589,10 @@ const _ = (e) => {
609
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) => {
610
590
  const [a, n, h] = e.split(":", 3);
611
591
  if (a !== r || !n || !h)
612
- throw new Error(
613
- "Cursor does not match the requested listing. Run the command again."
614
- );
592
+ throw new Error("Cursor does not match the requested listing. Run the command again.");
615
593
  const p = Number(n), s = Number(h);
616
594
  if (!Number.isInteger(p) || p !== t)
617
- throw new Error(
618
- "Cursor does not match the requested listing. Run the command again."
619
- );
595
+ throw new Error("Cursor does not match the requested listing. Run the command again.");
620
596
  if (!Number.isInteger(s) || s < 0)
621
597
  throw new Error("Cursor is invalid. Run the command again.");
622
598
  return s;
@@ -684,18 +660,14 @@ const _ = (e) => {
684
660
  const t = e.getQueryCache().get(r);
685
661
  if (!t) {
686
662
  const a = e.getQueryCache().getAll().map((n) => n.queryHash).join(", ");
687
- throw new Error(
688
- `Unknown queryHash "${r}". Available: ${a || "(none)"}`
689
- );
663
+ throw new Error(`Unknown queryHash "${r}". Available: ${a || "(none)"}`);
690
664
  }
691
665
  return t;
692
666
  }, ee = (e, r) => {
693
667
  const t = e.getMutationCache().getAll().find((a) => a.mutationId === r);
694
668
  if (!t) {
695
669
  const a = e.getMutationCache().getAll().map((n) => n.mutationId).join(", ");
696
- throw new Error(
697
- `Unknown mutationId "${r}". Available: ${a || "(none)"}`
698
- );
670
+ throw new Error(`Unknown mutationId "${r}". Available: ${a || "(none)"}`);
699
671
  }
700
672
  return t;
701
673
  }, Q = (e) => {
@@ -705,9 +677,7 @@ const _ = (e) => {
705
677
  queries: {
706
678
  total: r.length,
707
679
  active: r.filter((a) => a.getObserversCount() > 0).length,
708
- fetching: r.filter(
709
- (a) => a.state.fetchStatus === "fetching"
710
- ).length,
680
+ fetching: r.filter((a) => a.state.fetchStatus === "fetching").length,
711
681
  pending: r.filter((a) => a.state.status === "pending").length,
712
682
  success: r.filter((a) => a.state.status === "success").length,
713
683
  error: r.filter((a) => a.state.status === "error").length,
@@ -715,12 +685,8 @@ const _ = (e) => {
715
685
  },
716
686
  mutations: {
717
687
  total: t.length,
718
- pending: t.filter(
719
- (a) => a.state.status === "pending"
720
- ).length,
721
- success: t.filter(
722
- (a) => a.state.status === "success"
723
- ).length,
688
+ pending: t.filter((a) => a.state.status === "pending").length,
689
+ success: t.filter((a) => a.state.status === "success").length,
724
690
  error: t.filter((a) => a.state.status === "error").length,
725
691
  paused: t.filter((a) => a.state.isPaused).length
726
692
  }
@@ -751,18 +717,11 @@ const _ = (e) => {
751
717
  };
752
718
  },
753
719
  listQueries(t = {}) {
754
- const a = [...e.getQueryCache().getAll()].sort(
755
- Y
756
- );
720
+ const a = [...e.getQueryCache().getAll()].sort(Y);
757
721
  return {
758
722
  ...Q(e),
759
723
  total: a.length,
760
- ...M(
761
- a.map(I),
762
- "queries",
763
- r.queriesGeneration,
764
- t
765
- )
724
+ ...M(a.map(I), "queries", r.queriesGeneration, t)
766
725
  };
767
726
  },
768
727
  getQueryDetails({ queryHash: t }) {
@@ -824,9 +783,7 @@ const _ = (e) => {
824
783
  });
825
784
  },
826
785
  listMutations(t = {}) {
827
- const a = [...e.getMutationCache().getAll()].sort(
828
- J
829
- );
786
+ const a = [...e.getMutationCache().getAll()].sort(J);
830
787
  return {
831
788
  ...Q(e),
832
789
  total: a.length,
@@ -860,10 +817,7 @@ const _ = (e) => {
860
817
  }
861
818
  };
862
819
  }, re = (e) => {
863
- const r = R(
864
- () => te(e),
865
- [e]
866
- );
820
+ const r = R(() => te(e), [e]);
867
821
  A(() => {
868
822
  const t = e.getQueryCache().subscribe((n) => r.handleQueryCacheEvent(n)), a = e.getMutationCache().subscribe((n) => r.handleMutationCacheEvent(n));
869
823
  return () => {
@@ -1 +1 @@
1
- {"name":"@rozenite/tanstack-query-plugin","version":"2.0.0","description":"TanStack Query for Rozenite.","panels":[{"name":"Tanstack Query","source":"/devtools/tanstack-query.html"}]}
1
+ {"name":"@rozenite/tanstack-query-plugin","version":"2.1.0","description":"TanStack Query for Rozenite.","panels":[{"name":"Tanstack Query","source":"/devtools/tanstack-query.html"}]}
package/dist/sdk/index.js CHANGED
@@ -67,13 +67,7 @@ const u = "@rozenite/tanstack-query-plugin", t = {
67
67
  "hasData",
68
68
  "hasError"
69
69
  ],
70
- defaultFields: [
71
- "queryHash",
72
- "queryKey",
73
- "status",
74
- "fetchStatus",
75
- "hasError"
76
- ]
70
+ defaultFields: ["queryHash", "queryKey", "status", "fetchStatus", "hasError"]
77
71
  }
78
72
  }),
79
73
  getQueryDetails: e({
@@ -109,21 +103,23 @@ const u = "@rozenite/tanstack-query-plugin", t = {
109
103
  required: ["queryHash", "enabled"]
110
104
  }
111
105
  }),
112
- setQueryError: e({
113
- name: "set-query-error",
114
- description: "Enable or disable TanStack Query error-state simulation for a query by queryHash.",
115
- inputSchema: {
116
- type: "object",
117
- properties: {
118
- ...t,
119
- enabled: {
120
- type: "boolean",
121
- description: "Whether the error-state simulation should be enabled."
122
- }
123
- },
124
- required: ["queryHash", "enabled"]
106
+ setQueryError: e(
107
+ {
108
+ name: "set-query-error",
109
+ description: "Enable or disable TanStack Query error-state simulation for a query by queryHash.",
110
+ inputSchema: {
111
+ type: "object",
112
+ properties: {
113
+ ...t,
114
+ enabled: {
115
+ type: "boolean",
116
+ description: "Whether the error-state simulation should be enabled."
117
+ }
118
+ },
119
+ required: ["queryHash", "enabled"]
120
+ }
125
121
  }
126
- }),
122
+ ),
127
123
  invalidateQuery: e({
128
124
  name: "invalidate-query",
129
125
  description: "Invalidate a TanStack Query query by queryHash.",
package/package.json CHANGED
@@ -1,24 +1,42 @@
1
1
  {
2
2
  "name": "@rozenite/tanstack-query-plugin",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "TanStack Query for Rozenite.",
5
- "type": "module",
6
- "main": "./dist/react-native/index.cjs",
7
- "module": "./dist/react-native/index.js",
8
- "types": "./dist/react-native/index.d.ts",
9
5
  "homepage": "https://github.com/callstackincubator/rozenite#readme",
10
6
  "bugs": {
11
7
  "url": "https://github.com/callstackincubator/rozenite/issues"
12
8
  },
9
+ "license": "MIT",
13
10
  "repository": {
14
11
  "type": "git",
15
12
  "url": "https://github.com/callstackincubator/rozenite.git"
16
13
  },
14
+ "type": "module",
15
+ "main": "./dist/react-native/index.cjs",
16
+ "module": "./dist/react-native/index.js",
17
+ "types": "./dist/react-native/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/react-native/index.d.ts",
21
+ "import": "./dist/react-native/index.js",
22
+ "require": "./dist/react-native/index.cjs"
23
+ },
24
+ "./package.json": "./package.json",
25
+ "./sdk": {
26
+ "development": "./sdk.ts",
27
+ "types": "./dist/sdk/index.d.ts",
28
+ "import": "./dist/sdk/index.js",
29
+ "require": "./dist/sdk/index.cjs"
30
+ }
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
17
35
  "dependencies": {
18
36
  "fast-deep-equal": "^3.1.3",
19
- "@rozenite/agent-shared": "2.0.0",
20
- "@rozenite/agent-bridge": "2.0.0",
21
- "@rozenite/plugin-bridge": "2.0.0"
37
+ "@rozenite/agent-bridge": "2.1.0",
38
+ "@rozenite/agent-shared": "2.1.0",
39
+ "@rozenite/plugin-bridge": "2.1.0"
22
40
  },
23
41
  "devDependencies": {
24
42
  "@tanstack/react-query": "^5.0.0",
@@ -30,32 +48,14 @@
30
48
  "react-native-web": "^0.21.2",
31
49
  "typescript": "~5.9.3",
32
50
  "vite": "^7.3.1",
33
- "@rozenite/vite-plugin": "2.0.0",
34
- "rozenite": "2.0.0"
51
+ "@rozenite/vite-plugin": "2.1.0",
52
+ "rozenite": "2.1.0"
35
53
  },
36
54
  "peerDependencies": {
37
55
  "@tanstack/react-query": "^5.0.0",
38
56
  "react": "*",
39
57
  "react-native": "*"
40
58
  },
41
- "license": "MIT",
42
- "exports": {
43
- ".": {
44
- "types": "./dist/react-native/index.d.ts",
45
- "import": "./dist/react-native/index.js",
46
- "require": "./dist/react-native/index.cjs"
47
- },
48
- "./package.json": "./package.json",
49
- "./sdk": {
50
- "development": "./sdk.ts",
51
- "types": "./dist/sdk/index.d.ts",
52
- "import": "./dist/sdk/index.js",
53
- "require": "./dist/sdk/index.cjs"
54
- }
55
- },
56
- "publishConfig": {
57
- "access": "public"
58
- },
59
59
  "scripts": {
60
60
  "build": "rozenite build",
61
61
  "dev": "rozenite dev",
@@ -1,15 +1,7 @@
1
1
  import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import {
3
- Mutation,
4
- QueryClient,
5
- QueryObserver,
6
- onlineManager,
7
- } from '@tanstack/react-query';
2
+ import { Mutation, QueryClient, QueryObserver, onlineManager } from '@tanstack/react-query';
8
3
  import { applyTanStackQueryDevtoolsAction } from '../../devtools-actions';
9
- import {
10
- createTanStackQueryAgentController,
11
- serializeForAgent,
12
- } from '../tanstack-query-agent';
4
+ import { createTanStackQueryAgentController, serializeForAgent } from '../tanstack-query-agent';
13
5
  import { tanstackQueryToolDefinitions } from '../../../shared/agent-tools';
14
6
 
15
7
  const createQueryClient = () =>
@@ -87,9 +79,7 @@ afterEach(() => {
87
79
 
88
80
  describe('tanstack query agent controller', () => {
89
81
  it('exposes the expected tool names', () => {
90
- expect(
91
- Object.values(tanstackQueryToolDefinitions).map((tool) => tool.name),
92
- ).toEqual([
82
+ expect(Object.values(tanstackQueryToolDefinitions).map((tool) => tool.name)).toEqual([
93
83
  'get-cache-summary',
94
84
  'get-online-status',
95
85
  'set-online-status',
@@ -106,9 +96,10 @@ describe('tanstack query agent controller', () => {
106
96
  'get-mutation-details',
107
97
  'clear-mutation-cache',
108
98
  ]);
109
- expect(
110
- tanstackQueryToolDefinitions.setQueryLoading.inputSchema.required,
111
- ).toEqual(['queryHash', 'enabled']);
99
+ expect(tanstackQueryToolDefinitions.setQueryLoading.inputSchema.required).toEqual([
100
+ 'queryHash',
101
+ 'enabled',
102
+ ]);
112
103
  expect(tanstackQueryToolDefinitions.listQueries.pagination).toMatchObject({
113
104
  kind: 'cursor',
114
105
  fields: expect.arrayContaining(['queryHash', 'status', 'fetchStatus']),
@@ -116,10 +107,8 @@ describe('tanstack query agent controller', () => {
116
107
  });
117
108
 
118
109
  it('trims listQueries/listMutations defaultFields narrower than the full field set', () => {
119
- const listQueriesPagination =
120
- tanstackQueryToolDefinitions.listQueries.pagination;
121
- const listMutationsPagination =
122
- tanstackQueryToolDefinitions.listMutations.pagination;
110
+ const listQueriesPagination = tanstackQueryToolDefinitions.listQueries.pagination;
111
+ const listMutationsPagination = tanstackQueryToolDefinitions.listMutations.pagination;
123
112
 
124
113
  expect(listQueriesPagination?.defaultFields?.length).toBeLessThan(
125
114
  listQueriesPagination?.fields.length ?? 0,
@@ -155,9 +144,7 @@ describe('tanstack query agent controller', () => {
155
144
  limit: 1,
156
145
  cursor: firstPage.page.nextCursor,
157
146
  }),
158
- ).toThrow(
159
- 'Cursor does not match the requested listing. Run the command again.',
160
- );
147
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
161
148
 
162
149
  unsubscribe();
163
150
  });
@@ -178,9 +165,7 @@ describe('tanstack query agent controller', () => {
178
165
  limit: 1,
179
166
  cursor: firstPage.page.nextCursor,
180
167
  }),
181
- ).toThrow(
182
- 'Cursor does not match the requested listing. Run the command again.',
183
- );
168
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
184
169
 
185
170
  queryClient.setQueryData(['third'], { value: 3 });
186
171
  queryClient.setQueryData(['fourth'], { value: 4 });
@@ -192,9 +177,7 @@ describe('tanstack query agent controller', () => {
192
177
  limit: 1,
193
178
  cursor: secondPageSeed.page.nextCursor,
194
179
  }),
195
- ).toThrow(
196
- 'Cursor does not match the requested listing. Run the command again.',
197
- );
180
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
198
181
 
199
182
  unsubscribe();
200
183
  });
@@ -229,9 +212,7 @@ describe('tanstack query agent controller', () => {
229
212
  limit: 1,
230
213
  cursor: firstPage.page.nextCursor,
231
214
  }),
232
- ).toThrow(
233
- 'Cursor does not match the requested listing. Run the command again.',
234
- );
215
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
235
216
 
236
217
  const mutation = queryClient.getMutationCache().getAll()[0];
237
218
  queryClient.getMutationCache().remove(mutation);
@@ -244,9 +225,7 @@ describe('tanstack query agent controller', () => {
244
225
  limit: 1,
245
226
  cursor: secondPageSeed.page.nextCursor,
246
227
  }),
247
- ).toThrow(
248
- 'Cursor does not match the requested listing. Run the command again.',
249
- );
228
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
250
229
 
251
230
  unsubscribe();
252
231
  });
@@ -272,9 +251,7 @@ describe('tanstack query agent controller', () => {
272
251
  queryFn,
273
252
  });
274
253
 
275
- const queryHash = queryClient
276
- .getQueryCache()
277
- .find({ queryKey: ['todos', 1] })!.queryHash;
254
+ const queryHash = queryClient.getQueryCache().find({ queryKey: ['todos', 1] })!.queryHash;
278
255
  const details = controller.getQueryDetails({ queryHash });
279
256
 
280
257
  expect(details.query).toMatchObject({