@rozenite/tanstack-query-plugin 1.13.0 → 2.0.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 +9 -0
- package/dist/devtools/assets/{CXEL7IU7-DmbowaBr.js → CXEL7IU7-BtfXID7a.js} +1 -1
- package/dist/devtools/assets/{tanstack-query-DRBLkSCy.js → tanstack-query-OfMbjvWS.js} +12 -12
- package/dist/devtools/tanstack-query.html +1 -1
- package/dist/react-native/chunks/useTanStackQueryDevTools.require.cjs +1 -1
- package/dist/react-native/chunks/useTanStackQueryDevTools.require.js +135 -97
- package/dist/rozenite.json +1 -1
- package/dist/sdk/index.cjs +1 -1
- package/dist/sdk/index.js +55 -19
- package/package.json +10 -14
- package/sdk.ts +1 -4
- package/src/react-native/agent/__tests__/tanstack-query-agent.test.ts +28 -4
- package/src/react-native/agent/tanstack-query-agent.ts +29 -26
- package/src/react-native/agent/useTanStackQueryAgentTools.ts +2 -4
- package/src/react-native/useHandleInitialData.ts +1 -1
- package/src/react-native/useSyncTanStackCache.ts +4 -4
- package/src/shared/agent-tools.ts +56 -9
- package/src/shared/dehydrate.ts +1 -1
- package/src/shared/useSyncOnlineStatus.ts +2 -2
- package/src/ui/useHandleSyncMessages.ts +3 -3
- package/src/ui/useSyncDevToolsEvents.ts +1 -1
- package/src/ui/useSyncInitialData.ts +1 -1
- package/vite.config.ts +4 -1
|
@@ -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-
|
|
25
|
+
<script type="module" crossorigin src="../devtools/assets/tanstack-query-OfMbjvWS.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"),Q=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 r=Q.onlineManager.subscribe(a=>{e.send("online-status-changed",{online:a})}),t=e.onMessage("online-status-changed",({online:a})=>{Q.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},f=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"SET_QUERY_DATA":{const t=g(e,r.queryHash);return e.setQueryData(t.queryKey,r.metadata?.data),{applied:!0,action:r.type,queryHash:t.queryHash}}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}}}},U=(e,r)=>{b.useEffect(()=>{if(!r)return;const t=r.onMessage("devtools-action",({type:a,queryHash:s,metadata:h})=>{f(e,{type:a,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 "${a}": ${n}`)})});return()=>{t.remove()}},[r])},O=e=>e.observers.map(r=>({queryHash:e.queryHash,options:r.options})),q=e=>{const r=O(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:r}},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,r)=>{const t=b.useRef(new Map),a=b.useMemo(()=>s=>{if(!r||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);r.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}};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:m.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=q(n);r.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),r.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);r.send("sync-mutation-event",{type:l,data:n})}},[r]);b.useEffect(()=>{if(!r)return;const s=e.getMutationCache().subscribe(a),h=e.getQueryCache().subscribe(a);return()=>{s(),h()}},[r,e,a])},j=(e,r)=>{b.useEffect(()=>{if(!r)return;const t=r.onMessage("request-initial-data",()=>{const a=P(e);r.send("sync-data",{data:a})});return()=>{t.remove()}},[r,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.defineAgentToolContract({name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:M}}),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.defineAgentToolContract({name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:M}}),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,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),!F(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)},$=e=>typeof e!="number"||!Number.isFinite(e)||!Number.isInteger(e)||e<1?N:Math.min(e,L),K=(e,r,t)=>`${e}:${r}:${t}`,x=(e,r,t)=>{const[a,s,h]=e.split(":",3);if(a!==r||!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},H=(e,r,t,a)=>{const s=$(a.limit),h=a.cursor?x(a.cursor,r,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:K(r,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"}),v=e=>Math.max(e.state.dataUpdatedAt,e.state.errorUpdatedAt),V=(e,r)=>v(r)-v(e)||r.getObserversCount()-e.getObserversCount()||String(r.queryHash).localeCompare(String(e.queryHash)),Y=(e,r)=>r.state.submittedAt-e.state.submittedAt||r.mutationId-e.mutationId,E=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,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},Z=(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},A=e=>{const r=e.getQueryCache().getAll(),t=e.getMutationCache().getAll();return{online:Q.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}}},ee=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 A(e)},getOnlineStatus(){return{online:Q.onlineManager.isOnline()}},setOnlineStatus({online:t}){return Q.onlineManager.setOnline(t),{online:Q.onlineManager.isOnline()}},listQueries(t={}){const a=[...e.getQueryCache().getAll()].sort(V);return{...A(e),total:a.length,...H(a.map(E),"queries",r.queriesGeneration,t)}},getQueryDetails({queryHash:t}){const a=X(e,t);return{summary:A(e),query:{...E(a),data:o(a.state.data),error:o(a.state.error),observers:a.observers.map(s=>({queryHash:a.queryHash,options:B(s.options)}))}}},async refetchQuery({queryHash:t}){return f(e,{type:"REFETCH",queryHash:t})},async setQueryLoading({queryHash:t,enabled:a}){return f(e,{type:a?"TRIGGER_LOADING":"RESTORE_LOADING",queryHash:t})},async setQueryError({queryHash:t,enabled:a}){return f(e,{type:a?"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 a=[...e.getMutationCache().getAll()].sort(Y);return{...A(e),total:a.length,...H(a.map(R),"mutations",r.mutationsGeneration,t)}},getMutationDetails({mutationId:t}){const a=Z(e,t);return{summary:A(e),mutation:{...R(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:W(a.options)}}},async clearMutationCache(){return f(e,{type:"CLEAR_MUTATION_CACHE"})}}},te=e=>{const r=b.useMemo(()=>ee(e),[e]);b.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:d,tool:y.getCacheSummary,handler:()=>r.getCacheSummary()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getOnlineStatus,handler:()=>r.getOnlineStatus()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setOnlineStatus,handler:t=>r.setOnlineStatus(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.listQueries,handler:(t={})=>r.listQueries(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getQueryDetails,handler:t=>r.getQueryDetails(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.refetchQuery,handler:t=>r.refetchQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setQueryLoading,handler:t=>r.setQueryLoading(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.setQueryError,handler:t=>r.setQueryError(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.invalidateQuery,handler:t=>r.invalidateQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.resetQuery,handler:t=>r.resetQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.removeQuery,handler:t=>r.removeQuery(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.clearQueryCache,handler:()=>r.clearQueryCache()}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.listMutations,handler:(t={})=>r.listMutations(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.getMutationDetails,handler:t=>r.getMutationDetails(t)}),i.useRozenitePluginAgentTool({pluginId:d,tool:y.clearMutationCache,handler:()=>r.clearMutationCache()})},re=e=>{const r=k.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});w(r),U(e,r),G(e,r),j(e,r),te(e)};exports.useTanStackQueryDevTools=re;
|
|
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,9 +1,9 @@
|
|
|
1
|
-
import { useRozeniteDevToolsClient as
|
|
2
|
-
import { useEffect as A, useRef as
|
|
1
|
+
import { useRozeniteDevToolsClient as w } from "@rozenite/plugin-bridge";
|
|
2
|
+
import { useEffect as A, useRef as C, useMemo as R } from "react";
|
|
3
3
|
import { onlineManager as S } from "@tanstack/react-query";
|
|
4
|
-
import
|
|
4
|
+
import U from "fast-deep-equal";
|
|
5
5
|
import { useRozenitePluginAgentTool as i } from "@rozenite/agent-bridge";
|
|
6
|
-
import { defineAgentToolContract as
|
|
6
|
+
import { defineAgentToolContract as y, definePaginatedAgentToolContract as v } from "@rozenite/agent-shared";
|
|
7
7
|
const _ = (e) => {
|
|
8
8
|
A(() => {
|
|
9
9
|
if (!e)
|
|
@@ -148,7 +148,7 @@ const _ = (e) => {
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
},
|
|
151
|
+
}, G = (e, r) => {
|
|
152
152
|
A(() => {
|
|
153
153
|
if (!r)
|
|
154
154
|
return;
|
|
@@ -171,28 +171,28 @@ const _ = (e) => {
|
|
|
171
171
|
t.remove();
|
|
172
172
|
};
|
|
173
173
|
}, [r]);
|
|
174
|
-
},
|
|
174
|
+
}, k = (e) => e.observers.map((r) => ({
|
|
175
175
|
queryHash: e.queryHash,
|
|
176
176
|
options: r.options
|
|
177
177
|
})), H = (e) => {
|
|
178
|
-
const r =
|
|
178
|
+
const r = k(e);
|
|
179
179
|
return {
|
|
180
180
|
state: e.state,
|
|
181
181
|
queryKey: e.queryKey,
|
|
182
182
|
queryHash: e.queryHash,
|
|
183
183
|
observers: r
|
|
184
184
|
};
|
|
185
|
-
},
|
|
185
|
+
}, D = (e) => ({
|
|
186
186
|
mutationId: e.mutationId,
|
|
187
187
|
state: e.state,
|
|
188
188
|
options: e.options
|
|
189
|
-
}),
|
|
189
|
+
}), j = (e) => ({
|
|
190
190
|
queries: e.getQueryCache().getAll().map(H),
|
|
191
|
-
mutations: e.getMutationCache().getAll().map(
|
|
192
|
-
}),
|
|
193
|
-
const t =
|
|
191
|
+
mutations: e.getMutationCache().getAll().map(D)
|
|
192
|
+
}), N = (e, r) => {
|
|
193
|
+
const t = C(
|
|
194
194
|
/* @__PURE__ */ new Map()
|
|
195
|
-
), a =
|
|
195
|
+
), a = R(() => (n) => {
|
|
196
196
|
if (!r || n.type === "observerResultsUpdated")
|
|
197
197
|
return;
|
|
198
198
|
if ("query" in n) {
|
|
@@ -323,10 +323,10 @@ const _ = (e) => {
|
|
|
323
323
|
return;
|
|
324
324
|
}
|
|
325
325
|
if (l === "observerAdded" || l === "observerRemoved" || l === "observerOptionsUpdated") {
|
|
326
|
-
const g =
|
|
326
|
+
const g = k(s), u = t.current.get(
|
|
327
327
|
s.queryHash
|
|
328
328
|
);
|
|
329
|
-
if (l === "observerOptionsUpdated" && u &&
|
|
329
|
+
if (l === "observerOptionsUpdated" && u && U(u, g))
|
|
330
330
|
return;
|
|
331
331
|
t.current.set(
|
|
332
332
|
s.queryHash,
|
|
@@ -343,7 +343,7 @@ const _ = (e) => {
|
|
|
343
343
|
}
|
|
344
344
|
const { mutation: h, type: p } = n;
|
|
345
345
|
if (h) {
|
|
346
|
-
const s =
|
|
346
|
+
const s = D(h);
|
|
347
347
|
r.send("sync-mutation-event", {
|
|
348
348
|
type: p,
|
|
349
349
|
data: s
|
|
@@ -358,29 +358,29 @@ const _ = (e) => {
|
|
|
358
358
|
n(), h();
|
|
359
359
|
};
|
|
360
360
|
}, [r, e, a]);
|
|
361
|
-
},
|
|
361
|
+
}, L = (e, r) => {
|
|
362
362
|
A(() => {
|
|
363
363
|
if (!r)
|
|
364
364
|
return;
|
|
365
365
|
const t = r.onMessage("request-initial-data", () => {
|
|
366
|
-
const a =
|
|
366
|
+
const a = j(e);
|
|
367
367
|
r.send("sync-data", { data: a });
|
|
368
368
|
});
|
|
369
369
|
return () => {
|
|
370
370
|
t.remove();
|
|
371
371
|
};
|
|
372
372
|
}, [r, e]);
|
|
373
|
-
},
|
|
373
|
+
}, c = "@rozenite/tanstack-query-plugin", b = {
|
|
374
374
|
queryHash: {
|
|
375
375
|
type: "string",
|
|
376
376
|
description: "TanStack Query queryHash identifying the query."
|
|
377
377
|
}
|
|
378
|
-
},
|
|
378
|
+
}, F = {
|
|
379
379
|
mutationId: {
|
|
380
380
|
type: "number",
|
|
381
381
|
description: "TanStack Query mutationId identifying the mutation."
|
|
382
382
|
}
|
|
383
|
-
},
|
|
383
|
+
}, E = {
|
|
384
384
|
limit: {
|
|
385
385
|
type: "number",
|
|
386
386
|
description: "Maximum number of items to return. Defaults to 20. Maximum 100."
|
|
@@ -392,18 +392,18 @@ const _ = (e) => {
|
|
|
392
392
|
}, q = {
|
|
393
393
|
type: "object",
|
|
394
394
|
properties: {}
|
|
395
|
-
},
|
|
396
|
-
getCacheSummary:
|
|
395
|
+
}, d = {
|
|
396
|
+
getCacheSummary: y({
|
|
397
397
|
name: "get-cache-summary",
|
|
398
398
|
description: "Return aggregate TanStack Query cache health and count information.",
|
|
399
399
|
inputSchema: q
|
|
400
400
|
}),
|
|
401
|
-
getOnlineStatus:
|
|
401
|
+
getOnlineStatus: y({
|
|
402
402
|
name: "get-online-status",
|
|
403
403
|
description: "Return the current TanStack Query onlineManager status.",
|
|
404
404
|
inputSchema: q
|
|
405
405
|
}),
|
|
406
|
-
setOnlineStatus:
|
|
406
|
+
setOnlineStatus: y({
|
|
407
407
|
name: "set-online-status",
|
|
408
408
|
description: "Set the TanStack Query onlineManager status for testing offline/online behavior.",
|
|
409
409
|
inputSchema: {
|
|
@@ -417,15 +417,37 @@ const _ = (e) => {
|
|
|
417
417
|
required: ["online"]
|
|
418
418
|
}
|
|
419
419
|
}),
|
|
420
|
-
listQueries:
|
|
420
|
+
listQueries: v({
|
|
421
421
|
name: "list-queries",
|
|
422
422
|
description: "List TanStack Query query summaries using cursor pagination.",
|
|
423
423
|
inputSchema: {
|
|
424
424
|
type: "object",
|
|
425
|
-
properties:
|
|
425
|
+
properties: E
|
|
426
|
+
},
|
|
427
|
+
pagination: {
|
|
428
|
+
kind: "cursor",
|
|
429
|
+
fields: [
|
|
430
|
+
"queryHash",
|
|
431
|
+
"queryKey",
|
|
432
|
+
"status",
|
|
433
|
+
"fetchStatus",
|
|
434
|
+
"observersCount",
|
|
435
|
+
"isInvalidated",
|
|
436
|
+
"dataUpdatedAt",
|
|
437
|
+
"errorUpdatedAt",
|
|
438
|
+
"hasData",
|
|
439
|
+
"hasError"
|
|
440
|
+
],
|
|
441
|
+
defaultFields: [
|
|
442
|
+
"queryHash",
|
|
443
|
+
"queryKey",
|
|
444
|
+
"status",
|
|
445
|
+
"fetchStatus",
|
|
446
|
+
"hasError"
|
|
447
|
+
]
|
|
426
448
|
}
|
|
427
449
|
}),
|
|
428
|
-
getQueryDetails:
|
|
450
|
+
getQueryDetails: y({
|
|
429
451
|
name: "get-query-details",
|
|
430
452
|
description: "Return a JSON-safe TanStack Query query snapshot and observer summary.",
|
|
431
453
|
inputSchema: {
|
|
@@ -434,7 +456,7 @@ const _ = (e) => {
|
|
|
434
456
|
required: ["queryHash"]
|
|
435
457
|
}
|
|
436
458
|
}),
|
|
437
|
-
refetchQuery:
|
|
459
|
+
refetchQuery: y({
|
|
438
460
|
name: "refetch-query",
|
|
439
461
|
description: "Refetch a TanStack Query query by queryHash.",
|
|
440
462
|
inputSchema: {
|
|
@@ -443,7 +465,7 @@ const _ = (e) => {
|
|
|
443
465
|
required: ["queryHash"]
|
|
444
466
|
}
|
|
445
467
|
}),
|
|
446
|
-
setQueryLoading:
|
|
468
|
+
setQueryLoading: y({
|
|
447
469
|
name: "set-query-loading",
|
|
448
470
|
description: "Enable or disable TanStack Query loading-state simulation for a query by queryHash.",
|
|
449
471
|
inputSchema: {
|
|
@@ -458,7 +480,7 @@ const _ = (e) => {
|
|
|
458
480
|
required: ["queryHash", "enabled"]
|
|
459
481
|
}
|
|
460
482
|
}),
|
|
461
|
-
setQueryError:
|
|
483
|
+
setQueryError: y({
|
|
462
484
|
name: "set-query-error",
|
|
463
485
|
description: "Enable or disable TanStack Query error-state simulation for a query by queryHash.",
|
|
464
486
|
inputSchema: {
|
|
@@ -473,7 +495,7 @@ const _ = (e) => {
|
|
|
473
495
|
required: ["queryHash", "enabled"]
|
|
474
496
|
}
|
|
475
497
|
}),
|
|
476
|
-
invalidateQuery:
|
|
498
|
+
invalidateQuery: y({
|
|
477
499
|
name: "invalidate-query",
|
|
478
500
|
description: "Invalidate a TanStack Query query by queryHash.",
|
|
479
501
|
inputSchema: {
|
|
@@ -482,7 +504,7 @@ const _ = (e) => {
|
|
|
482
504
|
required: ["queryHash"]
|
|
483
505
|
}
|
|
484
506
|
}),
|
|
485
|
-
resetQuery:
|
|
507
|
+
resetQuery: y({
|
|
486
508
|
name: "reset-query",
|
|
487
509
|
description: "Reset a TanStack Query query by queryHash.",
|
|
488
510
|
inputSchema: {
|
|
@@ -491,7 +513,7 @@ const _ = (e) => {
|
|
|
491
513
|
required: ["queryHash"]
|
|
492
514
|
}
|
|
493
515
|
}),
|
|
494
|
-
removeQuery:
|
|
516
|
+
removeQuery: y({
|
|
495
517
|
name: "remove-query",
|
|
496
518
|
description: "Remove a TanStack Query query from the cache by queryHash.",
|
|
497
519
|
inputSchema: {
|
|
@@ -500,34 +522,48 @@ const _ = (e) => {
|
|
|
500
522
|
required: ["queryHash"]
|
|
501
523
|
}
|
|
502
524
|
}),
|
|
503
|
-
clearQueryCache:
|
|
525
|
+
clearQueryCache: y({
|
|
504
526
|
name: "clear-query-cache",
|
|
505
527
|
description: "Clear the full TanStack Query query cache.",
|
|
506
528
|
inputSchema: q
|
|
507
529
|
}),
|
|
508
|
-
listMutations:
|
|
530
|
+
listMutations: v({
|
|
509
531
|
name: "list-mutations",
|
|
510
532
|
description: "List TanStack Query mutation summaries using cursor pagination.",
|
|
511
533
|
inputSchema: {
|
|
512
534
|
type: "object",
|
|
513
|
-
properties:
|
|
535
|
+
properties: E
|
|
536
|
+
},
|
|
537
|
+
pagination: {
|
|
538
|
+
kind: "cursor",
|
|
539
|
+
fields: [
|
|
540
|
+
"mutationId",
|
|
541
|
+
"mutationKey",
|
|
542
|
+
"status",
|
|
543
|
+
"isPaused",
|
|
544
|
+
"submittedAt",
|
|
545
|
+
"failureCount",
|
|
546
|
+
"hasData",
|
|
547
|
+
"hasError"
|
|
548
|
+
],
|
|
549
|
+
defaultFields: ["mutationId", "mutationKey", "status", "hasError"]
|
|
514
550
|
}
|
|
515
551
|
}),
|
|
516
|
-
getMutationDetails:
|
|
552
|
+
getMutationDetails: y({
|
|
517
553
|
name: "get-mutation-details",
|
|
518
554
|
description: "Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",
|
|
519
555
|
inputSchema: {
|
|
520
556
|
type: "object",
|
|
521
|
-
properties:
|
|
557
|
+
properties: F,
|
|
522
558
|
required: ["mutationId"]
|
|
523
559
|
}
|
|
524
560
|
}),
|
|
525
|
-
clearMutationCache:
|
|
561
|
+
clearMutationCache: y({
|
|
526
562
|
name: "clear-mutation-cache",
|
|
527
563
|
description: "Clear the full TanStack Query mutation cache.",
|
|
528
564
|
inputSchema: q
|
|
529
565
|
})
|
|
530
|
-
},
|
|
566
|
+
}, P = 20, K = 100, $ = (e) => !!e && typeof e == "object" && Object.getPrototypeOf(e) === Object.prototype, o = (e, r = /* @__PURE__ */ new WeakSet()) => {
|
|
531
567
|
if (e == null)
|
|
532
568
|
return null;
|
|
533
569
|
if (typeof e == "string" || typeof e == "boolean")
|
|
@@ -570,7 +606,7 @@ const _ = (e) => {
|
|
|
570
606
|
return Object.fromEntries(t);
|
|
571
607
|
}
|
|
572
608
|
return String(e);
|
|
573
|
-
},
|
|
609
|
+
}, 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) => {
|
|
574
610
|
const [a, n, h] = e.split(":", 3);
|
|
575
611
|
if (a !== r || !n || !h)
|
|
576
612
|
throw new Error(
|
|
@@ -585,16 +621,16 @@ const _ = (e) => {
|
|
|
585
621
|
throw new Error("Cursor is invalid. Run the command again.");
|
|
586
622
|
return s;
|
|
587
623
|
}, M = (e, r, t, a) => {
|
|
588
|
-
const n =
|
|
624
|
+
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;
|
|
589
625
|
return {
|
|
590
626
|
items: e.slice(h, p),
|
|
591
627
|
page: {
|
|
592
628
|
limit: n,
|
|
593
629
|
hasMore: s,
|
|
594
|
-
...s ? { nextCursor:
|
|
630
|
+
...s ? { nextCursor: z(r, t, p) } : {}
|
|
595
631
|
}
|
|
596
632
|
};
|
|
597
|
-
},
|
|
633
|
+
}, V = (e) => e ? {
|
|
598
634
|
enabled: o(e.enabled),
|
|
599
635
|
networkMode: o(e.networkMode),
|
|
600
636
|
staleTime: o(e.staleTime),
|
|
@@ -611,7 +647,7 @@ const _ = (e) => {
|
|
|
611
647
|
hasSelect: typeof e.select == "function",
|
|
612
648
|
hasPlaceholderData: "placeholderData" in e,
|
|
613
649
|
hasInitialData: "initialData" in e
|
|
614
|
-
} : null,
|
|
650
|
+
} : null, B = (e) => ({
|
|
615
651
|
mutationKey: o(e.mutationKey),
|
|
616
652
|
networkMode: o(e.networkMode),
|
|
617
653
|
gcTime: o(e.gcTime),
|
|
@@ -624,7 +660,7 @@ const _ = (e) => {
|
|
|
624
660
|
hasOnSuccess: typeof e.onSuccess == "function",
|
|
625
661
|
hasOnError: typeof e.onError == "function",
|
|
626
662
|
hasOnSettled: typeof e.onSettled == "function"
|
|
627
|
-
}),
|
|
663
|
+
}), 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) => ({
|
|
628
664
|
queryHash: e.queryHash,
|
|
629
665
|
queryKey: o(e.queryKey),
|
|
630
666
|
status: e.state.status,
|
|
@@ -635,16 +671,16 @@ const _ = (e) => {
|
|
|
635
671
|
errorUpdatedAt: e.state.errorUpdatedAt,
|
|
636
672
|
hasData: e.state.data !== void 0,
|
|
637
673
|
hasError: e.state.error != null
|
|
638
|
-
}),
|
|
674
|
+
}), X = (e) => e.status, T = (e) => ({
|
|
639
675
|
mutationId: e.mutationId,
|
|
640
676
|
mutationKey: o(e.options.mutationKey),
|
|
641
|
-
status:
|
|
677
|
+
status: X(e.state),
|
|
642
678
|
isPaused: e.state.isPaused,
|
|
643
679
|
submittedAt: e.state.submittedAt,
|
|
644
680
|
failureCount: e.state.failureCount,
|
|
645
681
|
hasData: e.state.data !== void 0,
|
|
646
682
|
hasError: e.state.error != null
|
|
647
|
-
}),
|
|
683
|
+
}), Z = (e, r) => {
|
|
648
684
|
const t = e.getQueryCache().get(r);
|
|
649
685
|
if (!t) {
|
|
650
686
|
const a = e.getQueryCache().getAll().map((n) => n.queryHash).join(", ");
|
|
@@ -653,7 +689,7 @@ const _ = (e) => {
|
|
|
653
689
|
);
|
|
654
690
|
}
|
|
655
691
|
return t;
|
|
656
|
-
},
|
|
692
|
+
}, ee = (e, r) => {
|
|
657
693
|
const t = e.getMutationCache().getAll().find((a) => a.mutationId === r);
|
|
658
694
|
if (!t) {
|
|
659
695
|
const a = e.getMutationCache().getAll().map((n) => n.mutationId).join(", ");
|
|
@@ -689,7 +725,7 @@ const _ = (e) => {
|
|
|
689
725
|
paused: t.filter((a) => a.state.isPaused).length
|
|
690
726
|
}
|
|
691
727
|
};
|
|
692
|
-
},
|
|
728
|
+
}, te = (e) => {
|
|
693
729
|
const r = {
|
|
694
730
|
queriesGeneration: 0,
|
|
695
731
|
mutationsGeneration: 0
|
|
@@ -715,12 +751,14 @@ const _ = (e) => {
|
|
|
715
751
|
};
|
|
716
752
|
},
|
|
717
753
|
listQueries(t = {}) {
|
|
718
|
-
const a = [...e.getQueryCache().getAll()].sort(
|
|
754
|
+
const a = [...e.getQueryCache().getAll()].sort(
|
|
755
|
+
Y
|
|
756
|
+
);
|
|
719
757
|
return {
|
|
720
758
|
...Q(e),
|
|
721
759
|
total: a.length,
|
|
722
760
|
...M(
|
|
723
|
-
a.map(
|
|
761
|
+
a.map(I),
|
|
724
762
|
"queries",
|
|
725
763
|
r.queriesGeneration,
|
|
726
764
|
t
|
|
@@ -728,16 +766,16 @@ const _ = (e) => {
|
|
|
728
766
|
};
|
|
729
767
|
},
|
|
730
768
|
getQueryDetails({ queryHash: t }) {
|
|
731
|
-
const a =
|
|
769
|
+
const a = Z(e, t);
|
|
732
770
|
return {
|
|
733
771
|
summary: Q(e),
|
|
734
772
|
query: {
|
|
735
|
-
...
|
|
773
|
+
...I(a),
|
|
736
774
|
data: o(a.state.data),
|
|
737
775
|
error: o(a.state.error),
|
|
738
776
|
observers: a.observers.map((n) => ({
|
|
739
777
|
queryHash: a.queryHash,
|
|
740
|
-
options:
|
|
778
|
+
options: V(
|
|
741
779
|
n.options
|
|
742
780
|
)
|
|
743
781
|
}))
|
|
@@ -787,7 +825,7 @@ const _ = (e) => {
|
|
|
787
825
|
},
|
|
788
826
|
listMutations(t = {}) {
|
|
789
827
|
const a = [...e.getMutationCache().getAll()].sort(
|
|
790
|
-
|
|
828
|
+
J
|
|
791
829
|
);
|
|
792
830
|
return {
|
|
793
831
|
...Q(e),
|
|
@@ -801,7 +839,7 @@ const _ = (e) => {
|
|
|
801
839
|
};
|
|
802
840
|
},
|
|
803
841
|
getMutationDetails({ mutationId: t }) {
|
|
804
|
-
const a =
|
|
842
|
+
const a = ee(e, t);
|
|
805
843
|
return {
|
|
806
844
|
summary: Q(e),
|
|
807
845
|
mutation: {
|
|
@@ -811,7 +849,7 @@ const _ = (e) => {
|
|
|
811
849
|
error: o(a.state.error),
|
|
812
850
|
context: o(a.state.context),
|
|
813
851
|
failureReason: o(a.state.failureReason),
|
|
814
|
-
options:
|
|
852
|
+
options: B(a.options)
|
|
815
853
|
}
|
|
816
854
|
};
|
|
817
855
|
},
|
|
@@ -821,9 +859,9 @@ const _ = (e) => {
|
|
|
821
859
|
});
|
|
822
860
|
}
|
|
823
861
|
};
|
|
824
|
-
},
|
|
825
|
-
const r =
|
|
826
|
-
() =>
|
|
862
|
+
}, re = (e) => {
|
|
863
|
+
const r = R(
|
|
864
|
+
() => te(e),
|
|
827
865
|
[e]
|
|
828
866
|
);
|
|
829
867
|
A(() => {
|
|
@@ -832,72 +870,72 @@ const _ = (e) => {
|
|
|
832
870
|
t(), a();
|
|
833
871
|
};
|
|
834
872
|
}, [r, e]), i({
|
|
835
|
-
pluginId:
|
|
836
|
-
tool:
|
|
873
|
+
pluginId: c,
|
|
874
|
+
tool: d.getCacheSummary,
|
|
837
875
|
handler: () => r.getCacheSummary()
|
|
838
876
|
}), i({
|
|
839
|
-
pluginId:
|
|
840
|
-
tool:
|
|
877
|
+
pluginId: c,
|
|
878
|
+
tool: d.getOnlineStatus,
|
|
841
879
|
handler: () => r.getOnlineStatus()
|
|
842
880
|
}), i({
|
|
843
|
-
pluginId:
|
|
844
|
-
tool:
|
|
881
|
+
pluginId: c,
|
|
882
|
+
tool: d.setOnlineStatus,
|
|
845
883
|
handler: (t) => r.setOnlineStatus(t)
|
|
846
884
|
}), i({
|
|
847
|
-
pluginId:
|
|
848
|
-
tool:
|
|
885
|
+
pluginId: c,
|
|
886
|
+
tool: d.listQueries,
|
|
849
887
|
handler: (t = {}) => r.listQueries(t)
|
|
850
888
|
}), i({
|
|
851
|
-
pluginId:
|
|
852
|
-
tool:
|
|
889
|
+
pluginId: c,
|
|
890
|
+
tool: d.getQueryDetails,
|
|
853
891
|
handler: (t) => r.getQueryDetails(t)
|
|
854
892
|
}), i({
|
|
855
|
-
pluginId:
|
|
856
|
-
tool:
|
|
893
|
+
pluginId: c,
|
|
894
|
+
tool: d.refetchQuery,
|
|
857
895
|
handler: (t) => r.refetchQuery(t)
|
|
858
896
|
}), i({
|
|
859
|
-
pluginId:
|
|
860
|
-
tool:
|
|
897
|
+
pluginId: c,
|
|
898
|
+
tool: d.setQueryLoading,
|
|
861
899
|
handler: (t) => r.setQueryLoading(t)
|
|
862
900
|
}), i({
|
|
863
|
-
pluginId:
|
|
864
|
-
tool:
|
|
901
|
+
pluginId: c,
|
|
902
|
+
tool: d.setQueryError,
|
|
865
903
|
handler: (t) => r.setQueryError(t)
|
|
866
904
|
}), i({
|
|
867
|
-
pluginId:
|
|
868
|
-
tool:
|
|
905
|
+
pluginId: c,
|
|
906
|
+
tool: d.invalidateQuery,
|
|
869
907
|
handler: (t) => r.invalidateQuery(t)
|
|
870
908
|
}), i({
|
|
871
|
-
pluginId:
|
|
872
|
-
tool:
|
|
909
|
+
pluginId: c,
|
|
910
|
+
tool: d.resetQuery,
|
|
873
911
|
handler: (t) => r.resetQuery(t)
|
|
874
912
|
}), i({
|
|
875
|
-
pluginId:
|
|
876
|
-
tool:
|
|
913
|
+
pluginId: c,
|
|
914
|
+
tool: d.removeQuery,
|
|
877
915
|
handler: (t) => r.removeQuery(t)
|
|
878
916
|
}), i({
|
|
879
|
-
pluginId:
|
|
880
|
-
tool:
|
|
917
|
+
pluginId: c,
|
|
918
|
+
tool: d.clearQueryCache,
|
|
881
919
|
handler: () => r.clearQueryCache()
|
|
882
920
|
}), i({
|
|
883
|
-
pluginId:
|
|
884
|
-
tool:
|
|
921
|
+
pluginId: c,
|
|
922
|
+
tool: d.listMutations,
|
|
885
923
|
handler: (t = {}) => r.listMutations(t)
|
|
886
924
|
}), i({
|
|
887
|
-
pluginId:
|
|
888
|
-
tool:
|
|
925
|
+
pluginId: c,
|
|
926
|
+
tool: d.getMutationDetails,
|
|
889
927
|
handler: (t) => r.getMutationDetails(t)
|
|
890
928
|
}), i({
|
|
891
|
-
pluginId:
|
|
892
|
-
tool:
|
|
929
|
+
pluginId: c,
|
|
930
|
+
tool: d.clearMutationCache,
|
|
893
931
|
handler: () => r.clearMutationCache()
|
|
894
932
|
});
|
|
895
|
-
},
|
|
896
|
-
const r =
|
|
933
|
+
}, ce = (e) => {
|
|
934
|
+
const r = w({
|
|
897
935
|
pluginId: "@rozenite/tanstack-query-plugin"
|
|
898
936
|
});
|
|
899
|
-
_(r),
|
|
937
|
+
_(r), G(e, r), N(e, r), L(e, r), re(e);
|
|
900
938
|
};
|
|
901
939
|
export {
|
|
902
|
-
|
|
940
|
+
ce as useTanStackQueryDevTools
|
|
903
941
|
};
|
package/dist/rozenite.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@rozenite/tanstack-query-plugin","version":"
|
|
1
|
+
{"name":"@rozenite/tanstack-query-plugin","version":"2.0.0","description":"TanStack Query for Rozenite.","panels":[{"name":"Tanstack Query","source":"/devtools/tanstack-query.html"}]}
|