@rozenite/tanstack-query-plugin 1.7.0-rc.2 → 1.7.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 +10 -0
- package/dist/devtools/assets/{CXEL7IU7-DJlSmt0p.js → CXEL7IU7-OLImOSaA.js} +1 -1
- package/dist/devtools/assets/{tanstack-query-_leiFatc.js → tanstack-query-Dk7i2Fss.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 +103 -91
- package/dist/rozenite.json +1 -1
- package/package.json +5 -5
- package/src/react-native/agent/__tests__/tanstack-query-agent.test.ts +65 -27
- package/src/react-native/devtools-actions.ts +17 -3
- package/src/react-native/useHandleDevToolsMessages.ts +14 -11
- package/src/shared/hydrate.ts +16 -13
- package/src/shared/messaging.ts +3 -0
- package/src/shared/query-data-sync.test.ts +93 -0
- package/src/shared/query-data-sync.ts +156 -0
- package/src/shared/types.ts +1 -0
- package/src/ui/tanstack-query.tsx +12 -0
|
@@ -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-Dk7i2Fss.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 O=require("@rozenite/plugin-bridge"),m=require("react"),b=require("@tanstack/react-query"),I=require("fast-deep-equal"),i=require("@rozenite/agent-bridge"),k=e=>e&&e.__esModule?e:{default:e},D=k(I),w=e=>{m.useEffect(()=>{if(!e)return;const r=b.onlineManager.subscribe(a=>{e.send("online-status-changed",{online:a})}),t=e.onMessage("online-status-changed",({online:a})=>{b.onlineManager.setOnline(a)});return()=>{r(),t.remove()}},[e])},g=(e,r)=>{if(!r)throw new Error("queryHash is required for this TanStack Query action.");const t=e.getQueryCache().get(r);if(!t)throw new Error(`No active query found for hash: ${r}`);return t},l=async(e,r)=>{switch(r.type){case"CLEAR_QUERY_CACHE":{const t=e.getQueryCache().getAll().length;return e.getQueryCache().clear(),{applied:!0,action:r.type,cleared:!0,queryCountBefore:t,queryCountAfter:e.getQueryCache().getAll().length}}case"CLEAR_MUTATION_CACHE":{const t=e.getMutationCache().getAll().length;return e.getMutationCache().clear(),{applied:!0,action:r.type,cleared:!0,mutationCountBefore:t,mutationCountAfter:e.getMutationCache().getAll().length}}case"TRIGGER_ERROR":{const t=g(e,r.queryHash),a=t.options,s=new Error("Unknown error from devtools");return t.setState({status:"error",error:s,fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:a}}),{applied:!0,action:r.type,queryHash:t.queryHash}}case"RESTORE_ERROR":{const t=g(e,r.queryHash);return await e.resetQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"TRIGGER_LOADING":{const t=g(e,r.queryHash),a=t.options;return t.fetch({...a,queryFn:()=>new Promise(()=>{}),gcTime:-1}),t.setState({data:void 0,status:"pending",fetchMeta:{...t.state.fetchMeta,__previousQueryOptions:a}}),{applied:!0,action:r.type,queryHash:t.queryHash}}case"RESTORE_LOADING":{const t=g(e,r.queryHash),a=t.state,s=t.state.fetchMeta?t.state.fetchMeta.__previousQueryOptions:null;return t.cancel({silent:!0}),t.setState({...a,fetchStatus:"idle",fetchMeta:null}),s&&t.fetch(s),{applied:!0,action:r.type,queryHash:t.queryHash}}case"RESET":{const t=g(e,r.queryHash);return await e.resetQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"REMOVE":{const t=g(e,r.queryHash);return e.removeQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"REFETCH":{const t=g(e,r.queryHash);return await t.fetch().catch(()=>{}),{applied:!0,action:r.type,queryHash:t.queryHash}}case"INVALIDATE":{const t=g(e,r.queryHash);return await e.invalidateQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}}},_=(e,r)=>{m.useEffect(()=>{if(!r)return;const t=r.onMessage("devtools-action",({type:a,queryHash:s})=>{l(e,{type:a,queryHash:s}).catch(d=>{const h=d instanceof Error?d.message:String(d);console.warn(`[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${a}": ${h}`)})});return()=>{t.remove()}},[r])},R=e=>e.observers.map(r=>({queryHash:e.queryHash,options:r.options})),T=e=>{const r=R(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:r}},v=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),C=e=>({queries:e.getQueryCache().getAll().map(T),mutations:e.getMutationCache().getAll().map(v)}),U=(e,r)=>{const t=m.useRef(new Map),a=m.useMemo(()=>s=>{if(!r||s.type==="observerResultsUpdated")return;if("query"in s){const{query:n,type:y}=s;if(y==="added"||y==="removed"){y==="removed"&&t.current.delete(n.queryHash);const p=T(n);r.send("sync-query-event",{type:y,data:p});return}if(y==="updated"&&"action"in s){const p=s.action;switch(p.type){case"fetch":{const u={queryHash:n.queryHash,state:{status:n.state.status,fetchStatus:n.state.fetchStatus,fetchMeta:n.state.fetchMeta,dataUpdatedAt:n.state.dataUpdatedAt,errorUpdatedAt:n.state.errorUpdatedAt}};r.send("sync-query-event",{type:"updated",action:"fetch",data:u});break}case"success":{const u={queryHash:n.queryHash,state:{status:n.state.status,data:n.state.data,dataUpdatedAt:n.state.dataUpdatedAt,error:n.state.error,errorUpdatedAt:n.state.errorUpdatedAt,fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"success",data:u});break}case"error":{const u={queryHash:n.queryHash,state:{status:n.state.status,error:n.state.error,errorUpdatedAt:n.state.errorUpdatedAt,fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"error",data:u});break}case"setState":{const u={queryHash:n.queryHash,state:p.state};r.send("sync-query-event",{type:"updated",action:"setState",data:u});break}case"invalidate":{const u={queryHash:n.queryHash,state:{isInvalidated:n.state.isInvalidated}};r.send("sync-query-event",{type:"updated",action:"invalidate",data:u});break}case"pause":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"pause",data:u});break}case"continue":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"continue",data:u});break}default:{const u=T(n);r.send("sync-query-event",{type:y,data:u})}}return}if(y==="observerAdded"||y==="observerRemoved"||y==="observerOptionsUpdated"){const p=R(n),u=t.current.get(n.queryHash);if(y==="observerOptionsUpdated"&&u&&D.default(u,p))return;t.current.set(n.queryHash,p),r.send("sync-query-event",{type:y,data:{queryHash:n.queryHash,observers:p}});return}}const{mutation:d,type:h}=s;if(d){const n=v(d);r.send("sync-mutation-event",{type:h,data:n})}},[r]);m.useEffect(()=>{if(!r)return;const s=e.getMutationCache().subscribe(a),d=e.getQueryCache().subscribe(a);return()=>{s(),d()}},[r,e,a])},P=(e,r)=>{m.useEffect(()=>{if(!r)return;const t=r.onMessage("request-initial-data",()=>{const a=C(e);r.send("sync-data",{data:a})});return()=>{t.remove()}},[r,e])},G="@rozenite/tanstack-query-plugin",j=20,z=100,N=e=>!!e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype,o=(e,r=new WeakSet)=>{if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="function"||typeof e=="symbol")return`[non-serializable:${typeof e}]`;if(e instanceof Date)return e.toISOString();if(e instanceof Error)return{name:e.name,message:e.message,stack:e.stack??null,cause:o(e.cause,r)};if(Array.isArray(e))return e.map(t=>o(t,r));if(ArrayBuffer.isView(e))return Array.from(e).map(t=>typeof t=="number"?t:Number(t));if(e instanceof ArrayBuffer)return Array.from(new Uint8Array(e));if(typeof e=="object"){if(r.has(e))return"[circular]";if(r.add(e),!N(e))return`[non-serializable:${e.constructor?.name??"Object"}]`;const t=Object.entries(e).map(([a,s])=>[a,o(s,r)]);return Object.fromEntries(t)}return String(e)},L=e=>typeof e!="number"||!Number.isFinite(e)||!Number.isInteger(e)||e<1?j:Math.min(e,z),F=(e,r,t)=>`${e}:${r}:${t}`,$=(e,r,t)=>{const[a,s,d]=e.split(":",3);if(a!==r||!s||!d)throw new Error("Cursor does not match the requested listing. Run the command again.");const h=Number(s),n=Number(d);if(!Number.isInteger(h)||h!==t)throw new Error("Cursor does not match the requested listing. Run the command again.");if(!Number.isInteger(n)||n<0)throw new Error("Cursor is invalid. Run the command again.");return n},A=(e,r,t,a)=>{const s=L(a.limit),d=a.cursor?$(a.cursor,r,t):0,h=Math.min(d+s,e.length),n=h<e.length;return{items:e.slice(d,h),page:{limit:s,hasMore:n,...n?{nextCursor:F(r,t,h)}:{}}}},f={queryHash:{type:"string",description:"TanStack Query queryHash identifying the query."}},K={mutationId:{type:"number",description:"TanStack Query mutationId identifying the mutation."}},E={limit:{type:"number",description:"Maximum number of items to return. Defaults to 20. Maximum 100."},cursor:{type:"string",description:"Opaque pagination cursor from a previous list call."}},Q={type:"object",properties:{}},x={name:"get-cache-summary",description:"Return aggregate TanStack Query cache health and count information.",inputSchema:Q},B={name:"get-online-status",description:"Return the current TanStack Query onlineManager status.",inputSchema:Q},V={name:"set-online-status",description:"Set the TanStack Query onlineManager status for testing offline/online behavior.",inputSchema:{type:"object",properties:{online:{type:"boolean",description:"Whether the TanStack Query onlineManager should be online."}},required:["online"]}},W={name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:E}},Y={name:"get-query-details",description:"Return a JSON-safe TanStack Query query snapshot and observer summary.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},J={name:"refetch-query",description:"Refetch a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},X={name:"set-query-loading",description:"Enable or disable TanStack Query loading-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash","enabled"]}},Z={name:"set-query-error",description:"Enable or disable TanStack Query error-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash","enabled"]}},ee={name:"invalidate-query",description:"Invalidate a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},te={name:"reset-query",description:"Reset a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},re={name:"remove-query",description:"Remove a TanStack Query query from the cache by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},ae={name:"clear-query-cache",description:"Clear the full TanStack Query query cache.",inputSchema:Q},ne={name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:E}},se={name:"get-mutation-details",description:"Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",inputSchema:{type:"object",properties:K,required:["mutationId"]}},oe={name:"clear-mutation-cache",description:"Clear the full TanStack Query mutation cache.",inputSchema:Q},ue=e=>e?{enabled:o(e.enabled),networkMode:o(e.networkMode),staleTime:o(e.staleTime),gcTime:o(e.gcTime),retry:o(e.retry),retryDelay:o(e.retryDelay),refetchInterval:o(e.refetchInterval),refetchOnMount:o(e.refetchOnMount),refetchOnReconnect:o(e.refetchOnReconnect),refetchOnWindowFocus:o(e.refetchOnWindowFocus),subscribed:o(e.subscribed),meta:o(e.meta),hasQueryFn:typeof e.queryFn=="function",hasSelect:typeof e.select=="function",hasPlaceholderData:"placeholderData"in e,hasInitialData:"initialData"in e}:null,ie=e=>({mutationKey:o(e.mutationKey),networkMode:o(e.networkMode),gcTime:o(e.gcTime),retry:o(e.retry),retryDelay:o(e.retryDelay),meta:o(e.meta),scope:o(e.scope),hasMutationFn:typeof e.mutationFn=="function",hasOnMutate:typeof e.onMutate=="function",hasOnSuccess:typeof e.onSuccess=="function",hasOnError:typeof e.onError=="function",hasOnSettled:typeof e.onSettled=="function"}),q=e=>Math.max(e.state.dataUpdatedAt,e.state.errorUpdatedAt),ce=(e,r)=>q(r)-q(e)||r.getObserversCount()-e.getObserversCount()||String(r.queryHash).localeCompare(String(e.queryHash)),de=(e,r)=>r.state.submittedAt-e.state.submittedAt||r.mutationId-e.mutationId,M=e=>({queryHash:e.queryHash,queryKey:o(e.queryKey),status:e.state.status,fetchStatus:e.state.fetchStatus,observersCount:e.getObserversCount(),isInvalidated:e.state.isInvalidated,dataUpdatedAt:e.state.dataUpdatedAt,errorUpdatedAt:e.state.errorUpdatedAt,hasData:e.state.data!==void 0,hasError:e.state.error!=null}),ye=e=>e.status,H=e=>({mutationId:e.mutationId,mutationKey:o(e.options.mutationKey),status:ye(e.state),isPaused:e.state.isPaused,submittedAt:e.state.submittedAt,failureCount:e.state.failureCount,hasData:e.state.data!==void 0,hasError:e.state.error!=null}),he=(e,r)=>{const t=e.getQueryCache().get(r);if(!t){const a=e.getQueryCache().getAll().map(s=>s.queryHash).join(", ");throw new Error(`Unknown queryHash "${r}". Available: ${a||"(none)"}`)}return t},le=(e,r)=>{const t=e.getMutationCache().getAll().find(a=>a.mutationId===r);if(!t){const a=e.getMutationCache().getAll().map(s=>s.mutationId).join(", ");throw new Error(`Unknown mutationId "${r}". Available: ${a||"(none)"}`)}return t},S=e=>{const r=e.getQueryCache().getAll(),t=e.getMutationCache().getAll();return{online:b.onlineManager.isOnline(),queries:{total:r.length,active:r.filter(a=>a.getObserversCount()>0).length,fetching:r.filter(a=>a.state.fetchStatus==="fetching").length,pending:r.filter(a=>a.state.status==="pending").length,success:r.filter(a=>a.state.status==="success").length,error:r.filter(a=>a.state.status==="error").length,invalidated:r.filter(a=>a.state.isInvalidated).length},mutations:{total:t.length,pending:t.filter(a=>a.state.status==="pending").length,success:t.filter(a=>a.state.status==="success").length,error:t.filter(a=>a.state.status==="error").length,paused:t.filter(a=>a.state.isPaused).length}}},pe=e=>{const r={queriesGeneration:0,mutationsGeneration:0};return{handleQueryCacheEvent(t){(t.type==="added"||t.type==="removed")&&(r.queriesGeneration+=1)},handleMutationCacheEvent(t){(t.type==="added"||t.type==="removed")&&(r.mutationsGeneration+=1)},getCacheSummary(){return S(e)},getOnlineStatus(){return{online:b.onlineManager.isOnline()}},setOnlineStatus({online:t}){return b.onlineManager.setOnline(t),{online:b.onlineManager.isOnline()}},listQueries(t={}){const a=[...e.getQueryCache().getAll()].sort(ce);return{...S(e),total:a.length,...A(a.map(M),"queries",r.queriesGeneration,t)}},getQueryDetails({queryHash:t}){const a=he(e,t);return{summary:S(e),query:{...M(a),data:o(a.state.data),error:o(a.state.error),observers:a.observers.map(s=>({queryHash:a.queryHash,options:ue(s.options)}))}}},async refetchQuery({queryHash:t}){return l(e,{type:"REFETCH",queryHash:t})},async setQueryLoading({queryHash:t,enabled:a}){return l(e,{type:a?"TRIGGER_LOADING":"RESTORE_LOADING",queryHash:t})},async setQueryError({queryHash:t,enabled:a}){return l(e,{type:a?"TRIGGER_ERROR":"RESTORE_ERROR",queryHash:t})},async invalidateQuery({queryHash:t}){return l(e,{type:"INVALIDATE",queryHash:t})},async resetQuery({queryHash:t}){return l(e,{type:"RESET",queryHash:t})},async removeQuery({queryHash:t}){return l(e,{type:"REMOVE",queryHash:t})},async clearQueryCache(){return l(e,{type:"CLEAR_QUERY_CACHE"})},listMutations(t={}){const a=[...e.getMutationCache().getAll()].sort(de);return{...S(e),total:a.length,...A(a.map(H),"mutations",r.mutationsGeneration,t)}},getMutationDetails({mutationId:t}){const a=le(e,t);return{summary:S(e),mutation:{...H(a),variables:o(a.state.variables),data:o(a.state.data),error:o(a.state.error),context:o(a.state.context),failureReason:o(a.state.failureReason),options:ie(a.options)}}},async clearMutationCache(){return l(e,{type:"CLEAR_MUTATION_CACHE"})}}},c=G,ge=e=>{const r=m.useMemo(()=>pe(e),[e]);m.useEffect(()=>{const t=e.getQueryCache().subscribe(s=>r.handleQueryCacheEvent(s)),a=e.getMutationCache().subscribe(s=>r.handleMutationCacheEvent(s));return()=>{t(),a()}},[r,e]),i.useRozenitePluginAgentTool({pluginId:c,tool:x,handler:()=>r.getCacheSummary()}),i.useRozenitePluginAgentTool({pluginId:c,tool:B,handler:()=>r.getOnlineStatus()}),i.useRozenitePluginAgentTool({pluginId:c,tool:V,handler:t=>r.setOnlineStatus(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:W,handler:(t={})=>r.listQueries(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:Y,handler:t=>r.getQueryDetails(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:J,handler:t=>r.refetchQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:X,handler:t=>r.setQueryLoading(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:Z,handler:t=>r.setQueryError(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:ee,handler:t=>r.invalidateQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:te,handler:t=>r.resetQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:re,handler:t=>r.removeQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:ae,handler:()=>r.clearQueryCache()}),i.useRozenitePluginAgentTool({pluginId:c,tool:ne,handler:(t={})=>r.listMutations(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:se,handler:t=>r.getMutationDetails(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:oe,handler:()=>r.clearMutationCache()})},me=e=>{const r=O.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});w(r),_(e,r),U(e,r),P(e,r),ge(e)};exports.useTanStackQueryDevTools=me;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@rozenite/plugin-bridge"),m=require("react"),b=require("@tanstack/react-query"),I=require("fast-deep-equal"),i=require("@rozenite/agent-bridge"),k=e=>e&&e.__esModule?e:{default:e},D=k(I),_=e=>{m.useEffect(()=>{if(!e)return;const r=b.onlineManager.subscribe(a=>{e.send("online-status-changed",{online:a})}),t=e.onMessage("online-status-changed",({online:a})=>{b.onlineManager.setOnline(a)});return()=>{r(),t.remove()}},[e])},l=(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},p=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=l(e,r.queryHash);return e.setQueryData(t.queryKey,r.metadata?.data),{applied:!0,action:r.type,queryHash:t.queryHash}}case"TRIGGER_ERROR":{const t=l(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=l(e,r.queryHash);return await e.resetQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"TRIGGER_LOADING":{const t=l(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=l(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=l(e,r.queryHash);return await e.resetQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"REMOVE":{const t=l(e,r.queryHash);return e.removeQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}case"REFETCH":{const t=l(e,r.queryHash);return await t.fetch().catch(()=>{}),{applied:!0,action:r.type,queryHash:t.queryHash}}case"INVALIDATE":{const t=l(e,r.queryHash);return await e.invalidateQueries(t),{applied:!0,action:r.type,queryHash:t.queryHash}}}},w=(e,r)=>{m.useEffect(()=>{if(!r)return;const t=r.onMessage("devtools-action",({type:a,queryHash:s,metadata:d})=>{p(e,{type:a,queryHash:s,metadata:d}).catch(y=>{const n=y instanceof Error?y.message:String(y);console.warn(`[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${a}": ${n}`)})});return()=>{t.remove()}},[r])},R=e=>e.observers.map(r=>({queryHash:e.queryHash,options:r.options})),T=e=>{const r=R(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:r}},E=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),U=e=>({queries:e.getQueryCache().getAll().map(T),mutations:e.getMutationCache().getAll().map(E)}),C=(e,r)=>{const t=m.useRef(new Map),a=m.useMemo(()=>s=>{if(!r||s.type==="observerResultsUpdated")return;if("query"in s){const{query:n,type:h}=s;if(h==="added"||h==="removed"){h==="removed"&&t.current.delete(n.queryHash);const g=T(n);r.send("sync-query-event",{type:h,data:g});return}if(h==="updated"&&"action"in s){const g=s.action;switch(g.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:g.state};r.send("sync-query-event",{type:"updated",action:"setState",data:u});break}case"invalidate":{const u={queryHash:n.queryHash,state:{isInvalidated:n.state.isInvalidated}};r.send("sync-query-event",{type:"updated",action:"invalidate",data:u});break}case"pause":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"pause",data:u});break}case"continue":{const u={queryHash:n.queryHash,state:{fetchStatus:n.state.fetchStatus}};r.send("sync-query-event",{type:"updated",action:"continue",data:u});break}default:{const u=T(n);r.send("sync-query-event",{type:h,data:u})}}return}if(h==="observerAdded"||h==="observerRemoved"||h==="observerOptionsUpdated"){const g=R(n),u=t.current.get(n.queryHash);if(h==="observerOptionsUpdated"&&u&&D.default(u,g))return;t.current.set(n.queryHash,g),r.send("sync-query-event",{type:h,data:{queryHash:n.queryHash,observers:g}});return}}const{mutation:d,type:y}=s;if(d){const n=E(d);r.send("sync-mutation-event",{type:y,data:n})}},[r]);m.useEffect(()=>{if(!r)return;const s=e.getMutationCache().subscribe(a),d=e.getQueryCache().subscribe(a);return()=>{s(),d()}},[r,e,a])},P=(e,r)=>{m.useEffect(()=>{if(!r)return;const t=r.onMessage("request-initial-data",()=>{const a=U(e);r.send("sync-data",{data:a})});return()=>{t.remove()}},[r,e])},G="@rozenite/tanstack-query-plugin",j=20,z=100,N=e=>!!e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype,o=(e,r=new WeakSet)=>{if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="function"||typeof e=="symbol")return`[non-serializable:${typeof e}]`;if(e instanceof Date)return e.toISOString();if(e instanceof Error)return{name:e.name,message:e.message,stack:e.stack??null,cause:o(e.cause,r)};if(Array.isArray(e))return e.map(t=>o(t,r));if(ArrayBuffer.isView(e))return Array.from(e).map(t=>typeof t=="number"?t:Number(t));if(e instanceof ArrayBuffer)return Array.from(new Uint8Array(e));if(typeof e=="object"){if(r.has(e))return"[circular]";if(r.add(e),!N(e))return`[non-serializable:${e.constructor?.name??"Object"}]`;const t=Object.entries(e).map(([a,s])=>[a,o(s,r)]);return Object.fromEntries(t)}return String(e)},L=e=>typeof e!="number"||!Number.isFinite(e)||!Number.isInteger(e)||e<1?j:Math.min(e,z),F=(e,r,t)=>`${e}:${r}:${t}`,$=(e,r,t)=>{const[a,s,d]=e.split(":",3);if(a!==r||!s||!d)throw new Error("Cursor does not match the requested listing. Run the command again.");const y=Number(s),n=Number(d);if(!Number.isInteger(y)||y!==t)throw new Error("Cursor does not match the requested listing. Run the command again.");if(!Number.isInteger(n)||n<0)throw new Error("Cursor is invalid. Run the command again.");return n},A=(e,r,t,a)=>{const s=L(a.limit),d=a.cursor?$(a.cursor,r,t):0,y=Math.min(d+s,e.length),n=y<e.length;return{items:e.slice(d,y),page:{limit:s,hasMore:n,...n?{nextCursor:F(r,t,y)}:{}}}},f={queryHash:{type:"string",description:"TanStack Query queryHash identifying the query."}},K={mutationId:{type:"number",description:"TanStack Query mutationId identifying the mutation."}},v={limit:{type:"number",description:"Maximum number of items to return. Defaults to 20. Maximum 100."},cursor:{type:"string",description:"Opaque pagination cursor from a previous list call."}},Q={type:"object",properties:{}},x={name:"get-cache-summary",description:"Return aggregate TanStack Query cache health and count information.",inputSchema:Q},B={name:"get-online-status",description:"Return the current TanStack Query onlineManager status.",inputSchema:Q},V={name:"set-online-status",description:"Set the TanStack Query onlineManager status for testing offline/online behavior.",inputSchema:{type:"object",properties:{online:{type:"boolean",description:"Whether the TanStack Query onlineManager should be online."}},required:["online"]}},W={name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:v}},Y={name:"get-query-details",description:"Return a JSON-safe TanStack Query query snapshot and observer summary.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},J={name:"refetch-query",description:"Refetch a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},X={name:"set-query-loading",description:"Enable or disable TanStack Query loading-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash","enabled"]}},Z={name:"set-query-error",description:"Enable or disable TanStack Query error-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash","enabled"]}},ee={name:"invalidate-query",description:"Invalidate a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},te={name:"reset-query",description:"Reset a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},re={name:"remove-query",description:"Remove a TanStack Query query from the cache by queryHash.",inputSchema:{type:"object",properties:f,required:["queryHash"]}},ae={name:"clear-query-cache",description:"Clear the full TanStack Query query cache.",inputSchema:Q},ne={name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:v}},se={name:"get-mutation-details",description:"Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",inputSchema:{type:"object",properties:K,required:["mutationId"]}},oe={name:"clear-mutation-cache",description:"Clear the full TanStack Query mutation cache.",inputSchema:Q},ue=e=>e?{enabled:o(e.enabled),networkMode:o(e.networkMode),staleTime:o(e.staleTime),gcTime:o(e.gcTime),retry:o(e.retry),retryDelay:o(e.retryDelay),refetchInterval:o(e.refetchInterval),refetchOnMount:o(e.refetchOnMount),refetchOnReconnect:o(e.refetchOnReconnect),refetchOnWindowFocus:o(e.refetchOnWindowFocus),subscribed:o(e.subscribed),meta:o(e.meta),hasQueryFn:typeof e.queryFn=="function",hasSelect:typeof e.select=="function",hasPlaceholderData:"placeholderData"in e,hasInitialData:"initialData"in e}:null,ie=e=>({mutationKey:o(e.mutationKey),networkMode:o(e.networkMode),gcTime:o(e.gcTime),retry:o(e.retry),retryDelay:o(e.retryDelay),meta:o(e.meta),scope:o(e.scope),hasMutationFn:typeof e.mutationFn=="function",hasOnMutate:typeof e.onMutate=="function",hasOnSuccess:typeof e.onSuccess=="function",hasOnError:typeof e.onError=="function",hasOnSettled:typeof e.onSettled=="function"}),q=e=>Math.max(e.state.dataUpdatedAt,e.state.errorUpdatedAt),ce=(e,r)=>q(r)-q(e)||r.getObserversCount()-e.getObserversCount()||String(r.queryHash).localeCompare(String(e.queryHash)),de=(e,r)=>r.state.submittedAt-e.state.submittedAt||r.mutationId-e.mutationId,M=e=>({queryHash:e.queryHash,queryKey:o(e.queryKey),status:e.state.status,fetchStatus:e.state.fetchStatus,observersCount:e.getObserversCount(),isInvalidated:e.state.isInvalidated,dataUpdatedAt:e.state.dataUpdatedAt,errorUpdatedAt:e.state.errorUpdatedAt,hasData:e.state.data!==void 0,hasError:e.state.error!=null}),ye=e=>e.status,H=e=>({mutationId:e.mutationId,mutationKey:o(e.options.mutationKey),status:ye(e.state),isPaused:e.state.isPaused,submittedAt:e.state.submittedAt,failureCount:e.state.failureCount,hasData:e.state.data!==void 0,hasError:e.state.error!=null}),he=(e,r)=>{const t=e.getQueryCache().get(r);if(!t){const a=e.getQueryCache().getAll().map(s=>s.queryHash).join(", ");throw new Error(`Unknown queryHash "${r}". Available: ${a||"(none)"}`)}return t},le=(e,r)=>{const t=e.getMutationCache().getAll().find(a=>a.mutationId===r);if(!t){const a=e.getMutationCache().getAll().map(s=>s.mutationId).join(", ");throw new Error(`Unknown mutationId "${r}". Available: ${a||"(none)"}`)}return t},S=e=>{const r=e.getQueryCache().getAll(),t=e.getMutationCache().getAll();return{online:b.onlineManager.isOnline(),queries:{total:r.length,active:r.filter(a=>a.getObserversCount()>0).length,fetching:r.filter(a=>a.state.fetchStatus==="fetching").length,pending:r.filter(a=>a.state.status==="pending").length,success:r.filter(a=>a.state.status==="success").length,error:r.filter(a=>a.state.status==="error").length,invalidated:r.filter(a=>a.state.isInvalidated).length},mutations:{total:t.length,pending:t.filter(a=>a.state.status==="pending").length,success:t.filter(a=>a.state.status==="success").length,error:t.filter(a=>a.state.status==="error").length,paused:t.filter(a=>a.state.isPaused).length}}},pe=e=>{const r={queriesGeneration:0,mutationsGeneration:0};return{handleQueryCacheEvent(t){(t.type==="added"||t.type==="removed")&&(r.queriesGeneration+=1)},handleMutationCacheEvent(t){(t.type==="added"||t.type==="removed")&&(r.mutationsGeneration+=1)},getCacheSummary(){return S(e)},getOnlineStatus(){return{online:b.onlineManager.isOnline()}},setOnlineStatus({online:t}){return b.onlineManager.setOnline(t),{online:b.onlineManager.isOnline()}},listQueries(t={}){const a=[...e.getQueryCache().getAll()].sort(ce);return{...S(e),total:a.length,...A(a.map(M),"queries",r.queriesGeneration,t)}},getQueryDetails({queryHash:t}){const a=he(e,t);return{summary:S(e),query:{...M(a),data:o(a.state.data),error:o(a.state.error),observers:a.observers.map(s=>({queryHash:a.queryHash,options:ue(s.options)}))}}},async refetchQuery({queryHash:t}){return p(e,{type:"REFETCH",queryHash:t})},async setQueryLoading({queryHash:t,enabled:a}){return p(e,{type:a?"TRIGGER_LOADING":"RESTORE_LOADING",queryHash:t})},async setQueryError({queryHash:t,enabled:a}){return p(e,{type:a?"TRIGGER_ERROR":"RESTORE_ERROR",queryHash:t})},async invalidateQuery({queryHash:t}){return p(e,{type:"INVALIDATE",queryHash:t})},async resetQuery({queryHash:t}){return p(e,{type:"RESET",queryHash:t})},async removeQuery({queryHash:t}){return p(e,{type:"REMOVE",queryHash:t})},async clearQueryCache(){return p(e,{type:"CLEAR_QUERY_CACHE"})},listMutations(t={}){const a=[...e.getMutationCache().getAll()].sort(de);return{...S(e),total:a.length,...A(a.map(H),"mutations",r.mutationsGeneration,t)}},getMutationDetails({mutationId:t}){const a=le(e,t);return{summary:S(e),mutation:{...H(a),variables:o(a.state.variables),data:o(a.state.data),error:o(a.state.error),context:o(a.state.context),failureReason:o(a.state.failureReason),options:ie(a.options)}}},async clearMutationCache(){return p(e,{type:"CLEAR_MUTATION_CACHE"})}}},c=G,ge=e=>{const r=m.useMemo(()=>pe(e),[e]);m.useEffect(()=>{const t=e.getQueryCache().subscribe(s=>r.handleQueryCacheEvent(s)),a=e.getMutationCache().subscribe(s=>r.handleMutationCacheEvent(s));return()=>{t(),a()}},[r,e]),i.useRozenitePluginAgentTool({pluginId:c,tool:x,handler:()=>r.getCacheSummary()}),i.useRozenitePluginAgentTool({pluginId:c,tool:B,handler:()=>r.getOnlineStatus()}),i.useRozenitePluginAgentTool({pluginId:c,tool:V,handler:t=>r.setOnlineStatus(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:W,handler:(t={})=>r.listQueries(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:Y,handler:t=>r.getQueryDetails(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:J,handler:t=>r.refetchQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:X,handler:t=>r.setQueryLoading(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:Z,handler:t=>r.setQueryError(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:ee,handler:t=>r.invalidateQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:te,handler:t=>r.resetQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:re,handler:t=>r.removeQuery(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:ae,handler:()=>r.clearQueryCache()}),i.useRozenitePluginAgentTool({pluginId:c,tool:ne,handler:(t={})=>r.listMutations(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:se,handler:t=>r.getMutationDetails(t)}),i.useRozenitePluginAgentTool({pluginId:c,tool:oe,handler:()=>r.clearMutationCache()})},me=e=>{const r=O.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});_(r),w(e,r),C(e,r),P(e,r),ge(e)};exports.useTanStackQueryDevTools=me;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useRozeniteDevToolsClient as R } from "@rozenite/plugin-bridge";
|
|
2
|
-
import { useEffect as S, useRef as k, useMemo as
|
|
2
|
+
import { useEffect as S, useRef as k, useMemo as E } from "react";
|
|
3
3
|
import { onlineManager as g } from "@tanstack/react-query";
|
|
4
4
|
import D from "fast-deep-equal";
|
|
5
|
-
import { useRozenitePluginAgentTool as
|
|
5
|
+
import { useRozenitePluginAgentTool as c } from "@rozenite/agent-bridge";
|
|
6
6
|
const w = (e) => {
|
|
7
7
|
S(() => {
|
|
8
8
|
if (!e)
|
|
@@ -19,14 +19,14 @@ const w = (e) => {
|
|
|
19
19
|
r(), t.remove();
|
|
20
20
|
};
|
|
21
21
|
}, [e]);
|
|
22
|
-
},
|
|
22
|
+
}, p = (e, r) => {
|
|
23
23
|
if (!r)
|
|
24
24
|
throw new Error("queryHash is required for this TanStack Query action.");
|
|
25
25
|
const t = e.getQueryCache().get(r);
|
|
26
26
|
if (!t)
|
|
27
27
|
throw new Error(`No active query found for hash: ${r}`);
|
|
28
28
|
return t;
|
|
29
|
-
},
|
|
29
|
+
}, l = async (e, r) => {
|
|
30
30
|
switch (r.type) {
|
|
31
31
|
case "CLEAR_QUERY_CACHE": {
|
|
32
32
|
const t = e.getQueryCache().getAll().length;
|
|
@@ -48,8 +48,16 @@ const w = (e) => {
|
|
|
48
48
|
mutationCountAfter: e.getMutationCache().getAll().length
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
case "SET_QUERY_DATA": {
|
|
52
|
+
const t = p(e, r.queryHash);
|
|
53
|
+
return e.setQueryData(t.queryKey, r.metadata?.data), {
|
|
54
|
+
applied: !0,
|
|
55
|
+
action: r.type,
|
|
56
|
+
queryHash: t.queryHash
|
|
57
|
+
};
|
|
58
|
+
}
|
|
51
59
|
case "TRIGGER_ERROR": {
|
|
52
|
-
const t =
|
|
60
|
+
const t = p(e, r.queryHash), a = t.options, n = new Error("Unknown error from devtools");
|
|
53
61
|
return t.setState({
|
|
54
62
|
status: "error",
|
|
55
63
|
error: n,
|
|
@@ -65,7 +73,7 @@ const w = (e) => {
|
|
|
65
73
|
};
|
|
66
74
|
}
|
|
67
75
|
case "RESTORE_ERROR": {
|
|
68
|
-
const t =
|
|
76
|
+
const t = p(e, r.queryHash);
|
|
69
77
|
return await e.resetQueries(t), {
|
|
70
78
|
applied: !0,
|
|
71
79
|
action: r.type,
|
|
@@ -73,7 +81,7 @@ const w = (e) => {
|
|
|
73
81
|
};
|
|
74
82
|
}
|
|
75
83
|
case "TRIGGER_LOADING": {
|
|
76
|
-
const t =
|
|
84
|
+
const t = p(e, r.queryHash), a = t.options;
|
|
77
85
|
return t.fetch({
|
|
78
86
|
...a,
|
|
79
87
|
queryFn: () => new Promise(() => {
|
|
@@ -94,7 +102,7 @@ const w = (e) => {
|
|
|
94
102
|
};
|
|
95
103
|
}
|
|
96
104
|
case "RESTORE_LOADING": {
|
|
97
|
-
const t =
|
|
105
|
+
const t = p(e, r.queryHash), a = t.state, n = t.state.fetchMeta ? t.state.fetchMeta.__previousQueryOptions : null;
|
|
98
106
|
return t.cancel({ silent: !0 }), t.setState({
|
|
99
107
|
...a,
|
|
100
108
|
fetchStatus: "idle",
|
|
@@ -106,7 +114,7 @@ const w = (e) => {
|
|
|
106
114
|
};
|
|
107
115
|
}
|
|
108
116
|
case "RESET": {
|
|
109
|
-
const t =
|
|
117
|
+
const t = p(e, r.queryHash);
|
|
110
118
|
return await e.resetQueries(t), {
|
|
111
119
|
applied: !0,
|
|
112
120
|
action: r.type,
|
|
@@ -114,7 +122,7 @@ const w = (e) => {
|
|
|
114
122
|
};
|
|
115
123
|
}
|
|
116
124
|
case "REMOVE": {
|
|
117
|
-
const t =
|
|
125
|
+
const t = p(e, r.queryHash);
|
|
118
126
|
return e.removeQueries(t), {
|
|
119
127
|
applied: !0,
|
|
120
128
|
action: r.type,
|
|
@@ -122,7 +130,7 @@ const w = (e) => {
|
|
|
122
130
|
};
|
|
123
131
|
}
|
|
124
132
|
case "REFETCH": {
|
|
125
|
-
const t =
|
|
133
|
+
const t = p(e, r.queryHash);
|
|
126
134
|
return await t.fetch().catch(() => {
|
|
127
135
|
}), {
|
|
128
136
|
applied: !0,
|
|
@@ -131,7 +139,7 @@ const w = (e) => {
|
|
|
131
139
|
};
|
|
132
140
|
}
|
|
133
141
|
case "INVALIDATE": {
|
|
134
|
-
const t =
|
|
142
|
+
const t = p(e, r.queryHash);
|
|
135
143
|
return await e.invalidateQueries(t), {
|
|
136
144
|
applied: !0,
|
|
137
145
|
action: r.type,
|
|
@@ -139,17 +147,21 @@ const w = (e) => {
|
|
|
139
147
|
};
|
|
140
148
|
}
|
|
141
149
|
}
|
|
142
|
-
},
|
|
150
|
+
}, _ = (e, r) => {
|
|
143
151
|
S(() => {
|
|
144
152
|
if (!r)
|
|
145
153
|
return;
|
|
146
154
|
const t = r.onMessage(
|
|
147
155
|
"devtools-action",
|
|
148
|
-
({ type: a, queryHash: n }) => {
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
({ type: a, queryHash: n, metadata: d }) => {
|
|
157
|
+
l(e, {
|
|
158
|
+
type: a,
|
|
159
|
+
queryHash: n,
|
|
160
|
+
metadata: d
|
|
161
|
+
}).catch((y) => {
|
|
162
|
+
const s = y instanceof Error ? y.message : String(y);
|
|
151
163
|
console.warn(
|
|
152
|
-
`[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${a}": ${
|
|
164
|
+
`[Rozenite, tanstack-query-plugin] Failed to apply devtools action "${a}": ${s}`
|
|
153
165
|
);
|
|
154
166
|
});
|
|
155
167
|
}
|
|
@@ -158,11 +170,11 @@ const w = (e) => {
|
|
|
158
170
|
t.remove();
|
|
159
171
|
};
|
|
160
172
|
}, [r]);
|
|
161
|
-
},
|
|
173
|
+
}, M = (e) => e.observers.map((r) => ({
|
|
162
174
|
queryHash: e.queryHash,
|
|
163
175
|
options: r.options
|
|
164
176
|
})), q = (e) => {
|
|
165
|
-
const r =
|
|
177
|
+
const r = M(e);
|
|
166
178
|
return {
|
|
167
179
|
state: e.state,
|
|
168
180
|
queryKey: e.queryKey,
|
|
@@ -176,23 +188,23 @@ const w = (e) => {
|
|
|
176
188
|
}), U = (e) => ({
|
|
177
189
|
queries: e.getQueryCache().getAll().map(q),
|
|
178
190
|
mutations: e.getMutationCache().getAll().map(O)
|
|
179
|
-
}),
|
|
191
|
+
}), C = (e, r) => {
|
|
180
192
|
const t = k(
|
|
181
193
|
/* @__PURE__ */ new Map()
|
|
182
|
-
), a =
|
|
194
|
+
), a = E(() => (n) => {
|
|
183
195
|
if (!r || n.type === "observerResultsUpdated")
|
|
184
196
|
return;
|
|
185
197
|
if ("query" in n) {
|
|
186
|
-
const { query: s, type:
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
r.send("sync-query-event", { type:
|
|
198
|
+
const { query: s, type: h } = n;
|
|
199
|
+
if (h === "added" || h === "removed") {
|
|
200
|
+
h === "removed" && t.current.delete(s.queryHash);
|
|
201
|
+
const m = q(s);
|
|
202
|
+
r.send("sync-query-event", { type: h, data: m });
|
|
191
203
|
return;
|
|
192
204
|
}
|
|
193
|
-
if (
|
|
194
|
-
const
|
|
195
|
-
switch (
|
|
205
|
+
if (h === "updated" && "action" in n) {
|
|
206
|
+
const m = n.action;
|
|
207
|
+
switch (m.type) {
|
|
196
208
|
case "fetch": {
|
|
197
209
|
const u = {
|
|
198
210
|
queryHash: s.queryHash,
|
|
@@ -250,7 +262,7 @@ const w = (e) => {
|
|
|
250
262
|
case "setState": {
|
|
251
263
|
const u = {
|
|
252
264
|
queryHash: s.queryHash,
|
|
253
|
-
state:
|
|
265
|
+
state: m.state
|
|
254
266
|
// Only the changed state parts
|
|
255
267
|
};
|
|
256
268
|
r.send("sync-query-event", {
|
|
@@ -304,35 +316,35 @@ const w = (e) => {
|
|
|
304
316
|
}
|
|
305
317
|
default: {
|
|
306
318
|
const u = q(s);
|
|
307
|
-
r.send("sync-query-event", { type:
|
|
319
|
+
r.send("sync-query-event", { type: h, data: u });
|
|
308
320
|
}
|
|
309
321
|
}
|
|
310
322
|
return;
|
|
311
323
|
}
|
|
312
|
-
if (
|
|
313
|
-
const
|
|
324
|
+
if (h === "observerAdded" || h === "observerRemoved" || h === "observerOptionsUpdated") {
|
|
325
|
+
const m = M(s), u = t.current.get(
|
|
314
326
|
s.queryHash
|
|
315
327
|
);
|
|
316
|
-
if (
|
|
328
|
+
if (h === "observerOptionsUpdated" && u && D(u, m))
|
|
317
329
|
return;
|
|
318
330
|
t.current.set(
|
|
319
331
|
s.queryHash,
|
|
320
|
-
|
|
332
|
+
m
|
|
321
333
|
), r.send("sync-query-event", {
|
|
322
|
-
type:
|
|
334
|
+
type: h,
|
|
323
335
|
data: {
|
|
324
336
|
queryHash: s.queryHash,
|
|
325
|
-
observers:
|
|
337
|
+
observers: m
|
|
326
338
|
}
|
|
327
339
|
});
|
|
328
340
|
return;
|
|
329
341
|
}
|
|
330
342
|
}
|
|
331
|
-
const { mutation: d, type:
|
|
343
|
+
const { mutation: d, type: y } = n;
|
|
332
344
|
if (d) {
|
|
333
345
|
const s = O(d);
|
|
334
346
|
r.send("sync-mutation-event", {
|
|
335
|
-
type:
|
|
347
|
+
type: y,
|
|
336
348
|
data: s
|
|
337
349
|
});
|
|
338
350
|
}
|
|
@@ -406,8 +418,8 @@ const w = (e) => {
|
|
|
406
418
|
throw new Error(
|
|
407
419
|
"Cursor does not match the requested listing. Run the command again."
|
|
408
420
|
);
|
|
409
|
-
const
|
|
410
|
-
if (!Number.isInteger(
|
|
421
|
+
const y = Number(n), s = Number(d);
|
|
422
|
+
if (!Number.isInteger(y) || y !== t)
|
|
411
423
|
throw new Error(
|
|
412
424
|
"Cursor does not match the requested listing. Run the command again."
|
|
413
425
|
);
|
|
@@ -415,13 +427,13 @@ const w = (e) => {
|
|
|
415
427
|
throw new Error("Cursor is invalid. Run the command again.");
|
|
416
428
|
return s;
|
|
417
429
|
}, A = (e, r, t, a) => {
|
|
418
|
-
const n = P(a.limit), d = a.cursor ? K(a.cursor, r, t) : 0,
|
|
430
|
+
const n = P(a.limit), d = a.cursor ? K(a.cursor, r, t) : 0, y = Math.min(d + n, e.length), s = y < e.length;
|
|
419
431
|
return {
|
|
420
|
-
items: e.slice(d,
|
|
432
|
+
items: e.slice(d, y),
|
|
421
433
|
page: {
|
|
422
434
|
limit: n,
|
|
423
435
|
hasMore: s,
|
|
424
|
-
...s ? { nextCursor: $(r, t,
|
|
436
|
+
...s ? { nextCursor: $(r, t, y) } : {}
|
|
425
437
|
}
|
|
426
438
|
};
|
|
427
439
|
}, f = {
|
|
@@ -570,7 +582,7 @@ const w = (e) => {
|
|
|
570
582
|
hasSelect: typeof e.select == "function",
|
|
571
583
|
hasPlaceholderData: "placeholderData" in e,
|
|
572
584
|
hasInitialData: "initialData" in e
|
|
573
|
-
} : null,
|
|
585
|
+
} : null, ce = (e) => ({
|
|
574
586
|
mutationKey: o(e.mutationKey),
|
|
575
587
|
networkMode: o(e.networkMode),
|
|
576
588
|
gcTime: o(e.gcTime),
|
|
@@ -583,7 +595,7 @@ const w = (e) => {
|
|
|
583
595
|
hasOnSuccess: typeof e.onSuccess == "function",
|
|
584
596
|
hasOnError: typeof e.onError == "function",
|
|
585
597
|
hasOnSettled: typeof e.onSettled == "function"
|
|
586
|
-
}),
|
|
598
|
+
}), H = (e) => Math.max(e.state.dataUpdatedAt, e.state.errorUpdatedAt), ie = (e, r) => H(r) - H(e) || r.getObserversCount() - e.getObserversCount() || String(r.queryHash).localeCompare(String(e.queryHash)), de = (e, r) => r.state.submittedAt - e.state.submittedAt || r.mutationId - e.mutationId, T = (e) => ({
|
|
587
599
|
queryHash: e.queryHash,
|
|
588
600
|
queryKey: o(e.queryKey),
|
|
589
601
|
status: e.state.status,
|
|
@@ -674,12 +686,12 @@ const w = (e) => {
|
|
|
674
686
|
};
|
|
675
687
|
},
|
|
676
688
|
listQueries(t = {}) {
|
|
677
|
-
const a = [...e.getQueryCache().getAll()].sort(
|
|
689
|
+
const a = [...e.getQueryCache().getAll()].sort(ie);
|
|
678
690
|
return {
|
|
679
691
|
...b(e),
|
|
680
692
|
total: a.length,
|
|
681
693
|
...A(
|
|
682
|
-
a.map(
|
|
694
|
+
a.map(T),
|
|
683
695
|
"queries",
|
|
684
696
|
r.queriesGeneration,
|
|
685
697
|
t
|
|
@@ -691,7 +703,7 @@ const w = (e) => {
|
|
|
691
703
|
return {
|
|
692
704
|
summary: b(e),
|
|
693
705
|
query: {
|
|
694
|
-
...
|
|
706
|
+
...T(a),
|
|
695
707
|
data: o(a.state.data),
|
|
696
708
|
error: o(a.state.error),
|
|
697
709
|
observers: a.observers.map((n) => ({
|
|
@@ -704,43 +716,43 @@ const w = (e) => {
|
|
|
704
716
|
};
|
|
705
717
|
},
|
|
706
718
|
async refetchQuery({ queryHash: t }) {
|
|
707
|
-
return
|
|
719
|
+
return l(e, {
|
|
708
720
|
type: "REFETCH",
|
|
709
721
|
queryHash: t
|
|
710
722
|
});
|
|
711
723
|
},
|
|
712
724
|
async setQueryLoading({ queryHash: t, enabled: a }) {
|
|
713
|
-
return
|
|
725
|
+
return l(e, {
|
|
714
726
|
type: a ? "TRIGGER_LOADING" : "RESTORE_LOADING",
|
|
715
727
|
queryHash: t
|
|
716
728
|
});
|
|
717
729
|
},
|
|
718
730
|
async setQueryError({ queryHash: t, enabled: a }) {
|
|
719
|
-
return
|
|
731
|
+
return l(e, {
|
|
720
732
|
type: a ? "TRIGGER_ERROR" : "RESTORE_ERROR",
|
|
721
733
|
queryHash: t
|
|
722
734
|
});
|
|
723
735
|
},
|
|
724
736
|
async invalidateQuery({ queryHash: t }) {
|
|
725
|
-
return
|
|
737
|
+
return l(e, {
|
|
726
738
|
type: "INVALIDATE",
|
|
727
739
|
queryHash: t
|
|
728
740
|
});
|
|
729
741
|
},
|
|
730
742
|
async resetQuery({ queryHash: t }) {
|
|
731
|
-
return
|
|
743
|
+
return l(e, {
|
|
732
744
|
type: "RESET",
|
|
733
745
|
queryHash: t
|
|
734
746
|
});
|
|
735
747
|
},
|
|
736
748
|
async removeQuery({ queryHash: t }) {
|
|
737
|
-
return
|
|
749
|
+
return l(e, {
|
|
738
750
|
type: "REMOVE",
|
|
739
751
|
queryHash: t
|
|
740
752
|
});
|
|
741
753
|
},
|
|
742
754
|
async clearQueryCache() {
|
|
743
|
-
return
|
|
755
|
+
return l(e, {
|
|
744
756
|
type: "CLEAR_QUERY_CACHE"
|
|
745
757
|
});
|
|
746
758
|
},
|
|
@@ -770,18 +782,18 @@ const w = (e) => {
|
|
|
770
782
|
error: o(a.state.error),
|
|
771
783
|
context: o(a.state.context),
|
|
772
784
|
failureReason: o(a.state.failureReason),
|
|
773
|
-
options:
|
|
785
|
+
options: ce(a.options)
|
|
774
786
|
}
|
|
775
787
|
};
|
|
776
788
|
},
|
|
777
789
|
async clearMutationCache() {
|
|
778
|
-
return
|
|
790
|
+
return l(e, {
|
|
779
791
|
type: "CLEAR_MUTATION_CACHE"
|
|
780
792
|
});
|
|
781
793
|
}
|
|
782
794
|
};
|
|
783
|
-
},
|
|
784
|
-
const r =
|
|
795
|
+
}, i = j, me = (e) => {
|
|
796
|
+
const r = E(
|
|
785
797
|
() => le(e),
|
|
786
798
|
[e]
|
|
787
799
|
);
|
|
@@ -790,64 +802,64 @@ const w = (e) => {
|
|
|
790
802
|
return () => {
|
|
791
803
|
t(), a();
|
|
792
804
|
};
|
|
793
|
-
}, [r, e]),
|
|
794
|
-
pluginId:
|
|
805
|
+
}, [r, e]), c({
|
|
806
|
+
pluginId: i,
|
|
795
807
|
tool: z,
|
|
796
808
|
handler: () => r.getCacheSummary()
|
|
797
|
-
}),
|
|
798
|
-
pluginId:
|
|
809
|
+
}), c({
|
|
810
|
+
pluginId: i,
|
|
799
811
|
tool: V,
|
|
800
812
|
handler: () => r.getOnlineStatus()
|
|
801
|
-
}),
|
|
802
|
-
pluginId:
|
|
813
|
+
}), c({
|
|
814
|
+
pluginId: i,
|
|
803
815
|
tool: B,
|
|
804
816
|
handler: (t) => r.setOnlineStatus(t)
|
|
805
|
-
}),
|
|
806
|
-
pluginId:
|
|
817
|
+
}), c({
|
|
818
|
+
pluginId: i,
|
|
807
819
|
tool: W,
|
|
808
820
|
handler: (t = {}) => r.listQueries(t)
|
|
809
|
-
}),
|
|
810
|
-
pluginId:
|
|
821
|
+
}), c({
|
|
822
|
+
pluginId: i,
|
|
811
823
|
tool: Y,
|
|
812
824
|
handler: (t) => r.getQueryDetails(t)
|
|
813
|
-
}),
|
|
814
|
-
pluginId:
|
|
825
|
+
}), c({
|
|
826
|
+
pluginId: i,
|
|
815
827
|
tool: J,
|
|
816
828
|
handler: (t) => r.refetchQuery(t)
|
|
817
|
-
}),
|
|
818
|
-
pluginId:
|
|
829
|
+
}), c({
|
|
830
|
+
pluginId: i,
|
|
819
831
|
tool: X,
|
|
820
832
|
handler: (t) => r.setQueryLoading(t)
|
|
821
|
-
}),
|
|
822
|
-
pluginId:
|
|
833
|
+
}), c({
|
|
834
|
+
pluginId: i,
|
|
823
835
|
tool: Z,
|
|
824
836
|
handler: (t) => r.setQueryError(t)
|
|
825
|
-
}),
|
|
826
|
-
pluginId:
|
|
837
|
+
}), c({
|
|
838
|
+
pluginId: i,
|
|
827
839
|
tool: ee,
|
|
828
840
|
handler: (t) => r.invalidateQuery(t)
|
|
829
|
-
}),
|
|
830
|
-
pluginId:
|
|
841
|
+
}), c({
|
|
842
|
+
pluginId: i,
|
|
831
843
|
tool: te,
|
|
832
844
|
handler: (t) => r.resetQuery(t)
|
|
833
|
-
}),
|
|
834
|
-
pluginId:
|
|
845
|
+
}), c({
|
|
846
|
+
pluginId: i,
|
|
835
847
|
tool: re,
|
|
836
848
|
handler: (t) => r.removeQuery(t)
|
|
837
|
-
}),
|
|
838
|
-
pluginId:
|
|
849
|
+
}), c({
|
|
850
|
+
pluginId: i,
|
|
839
851
|
tool: ae,
|
|
840
852
|
handler: () => r.clearQueryCache()
|
|
841
|
-
}),
|
|
842
|
-
pluginId:
|
|
853
|
+
}), c({
|
|
854
|
+
pluginId: i,
|
|
843
855
|
tool: se,
|
|
844
856
|
handler: (t = {}) => r.listMutations(t)
|
|
845
|
-
}),
|
|
846
|
-
pluginId:
|
|
857
|
+
}), c({
|
|
858
|
+
pluginId: i,
|
|
847
859
|
tool: ne,
|
|
848
860
|
handler: (t) => r.getMutationDetails(t)
|
|
849
|
-
}),
|
|
850
|
-
pluginId:
|
|
861
|
+
}), c({
|
|
862
|
+
pluginId: i,
|
|
851
863
|
tool: oe,
|
|
852
864
|
handler: () => r.clearMutationCache()
|
|
853
865
|
});
|
|
@@ -855,7 +867,7 @@ const w = (e) => {
|
|
|
855
867
|
const r = R({
|
|
856
868
|
pluginId: "@rozenite/tanstack-query-plugin"
|
|
857
869
|
});
|
|
858
|
-
w(r),
|
|
870
|
+
w(r), _(e, r), C(e, r), G(e, r), me(e);
|
|
859
871
|
};
|
|
860
872
|
export {
|
|
861
873
|
qe as useTanStackQueryDevTools
|
package/dist/rozenite.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@rozenite/tanstack-query-plugin","version":"1.7.0
|
|
1
|
+
{"name":"@rozenite/tanstack-query-plugin","version":"1.7.0","description":"TanStack Query for Rozenite.","panels":[{"name":"Tanstack Query","source":"/devtools/tanstack-query.html"}]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rozenite/tanstack-query-plugin",
|
|
3
|
-
"version": "1.7.0
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "TanStack Query for Rozenite.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/react-native/index.cjs",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"fast-deep-equal": "^3.1.3",
|
|
19
|
-
"@rozenite/agent-bridge": "1.7.0
|
|
20
|
-
"@rozenite/plugin-bridge": "1.7.0
|
|
19
|
+
"@rozenite/agent-bridge": "1.7.0",
|
|
20
|
+
"@rozenite/plugin-bridge": "1.7.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"tailwindcss-animate": "^1.0.7",
|
|
34
34
|
"typescript": "~5.9.3",
|
|
35
35
|
"vite": "^7.3.1",
|
|
36
|
-
"@rozenite/vite-plugin": "1.7.0
|
|
37
|
-
"rozenite": "1.7.0
|
|
36
|
+
"@rozenite/vite-plugin": "1.7.0",
|
|
37
|
+
"rozenite": "1.7.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@tanstack/react-query": "^5.0.0",
|