@rozenite/tanstack-query-plugin 1.0.0-alpha.0 → 1.0.0-alpha.10
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/README.md +2 -2
- package/dist/assets/CXEL7IU7-BTFA0aeQ.js +1172 -0
- package/dist/assets/tanstack-query-DWTo8DT_.js +48 -0
- package/dist/react-native.cjs +1 -1
- package/dist/react-native.d.ts +1 -5
- package/dist/react-native.js +3 -86
- package/dist/rozenite.config.d.ts +7 -0
- package/dist/rozenite.json +1 -1
- package/dist/src/react-native/useHandleDevToolsMessages.d.ts +3 -0
- package/dist/src/react-native/useHandleInitialData.d.ts +3 -0
- package/dist/src/react-native/useSyncTanStackCache.d.ts +3 -0
- package/dist/src/react-native/useTanStackQueryDevTools.d.ts +2 -0
- package/dist/src/shared/dehydrate.d.ts +6 -0
- package/dist/src/shared/hydrate.d.ts +10 -0
- package/dist/src/shared/messaging.d.ts +34 -0
- package/dist/src/shared/types.d.ts +25 -0
- package/dist/src/shared/useSyncOnlineStatus.d.ts +2 -0
- package/dist/src/ui/tanstack-query.d.ts +1 -0
- package/dist/src/ui/useHandleSyncMessages.d.ts +2 -0
- package/dist/src/ui/useSyncDevToolsEvents.d.ts +2 -0
- package/dist/src/ui/useSyncInitialData.d.ts +2 -0
- package/dist/tanstack-query.html +1 -1
- package/dist/useTanstackQueryDevTools.cjs +1 -0
- package/dist/useTanstackQueryDevTools.js +312 -0
- package/package.json +14 -9
- package/project.json +12 -0
- package/react-native.ts +2 -2
- package/src/react-native/useHandleDevToolsMessages.ts +119 -0
- package/src/react-native/useHandleInitialData.ts +24 -0
- package/src/react-native/useSyncTanStackCache.ts +246 -0
- package/src/react-native/useTanstackQueryDevTools.ts +21 -0
- package/src/shared/dehydrate.ts +42 -0
- package/src/shared/hydrate.ts +250 -0
- package/src/shared/messaging.ts +54 -0
- package/src/shared/types.ts +48 -0
- package/src/shared/useSyncOnlineStatus.ts +29 -0
- package/src/ui/tanstack-query.tsx +21 -184
- package/src/ui/useHandleSyncMessages.ts +66 -0
- package/src/ui/useSyncDevToolsEvents.ts +55 -0
- package/src/ui/useSyncInitialData.ts +14 -0
- package/tsconfig.json +13 -6
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/assets/tanstack-query-CXp_Psxe.js +0 -48
- package/src/react-native/useTanStackQueryDevTools.ts +0 -214
package/dist/react-native.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.useTanStackQueryDevTools=void 0;process.env.NODE_ENV!=="production"?exports.useTanStackQueryDevTools=require("./useTanstackQueryDevTools.cjs").useTanStackQueryDevTools:exports.useTanStackQueryDevTools=()=>({isConnected:!1});
|
package/dist/react-native.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare let useTanStackQueryDevTools: useTanStackQueryDevTools_2;
|
|
4
|
-
|
|
5
|
-
export { }
|
|
1
|
+
export declare let useTanStackQueryDevTools: typeof import('./src/react-native/useTanStackQueryDevTools').useTanStackQueryDevTools;
|
package/dist/react-native.js
CHANGED
|
@@ -1,88 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const I = (u) => {
|
|
4
|
-
const e = D({
|
|
5
|
-
pluginId: "@rozenite/tanstack-query-plugin"
|
|
6
|
-
});
|
|
7
|
-
_(() => {
|
|
8
|
-
if (!e) return;
|
|
9
|
-
const n = e.onMessage("DEVTOOLS_TO_DEVICE_INITIAL_DATA_REQUEST", () => {
|
|
10
|
-
e.send("DEVICE_TO_DEVTOOLS_INITIAL_DATA", {
|
|
11
|
-
queries: u.getQueryCache().getAll(),
|
|
12
|
-
mutations: u.getMutationCache().getAll()
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
return () => n.remove();
|
|
16
|
-
}, [e, u]);
|
|
17
|
-
const o = i(/* @__PURE__ */ new Set()), a = V((n) => {
|
|
18
|
-
const O = (c) => u.getQueryCache().getAll().find((E) => E.queryHash === c);
|
|
19
|
-
((c) => {
|
|
20
|
-
var f;
|
|
21
|
-
const { type: E, queryHash: t, metadata: T, requestId: s } = c;
|
|
22
|
-
if (E === "REFETCH" && t && ((f = O(t)) == null || f.fetch(), s && (o.current.add(s), e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }), o.current.delete(s))), E === "INVALIDATE" && t) {
|
|
23
|
-
const r = O(t);
|
|
24
|
-
r && u.invalidateQueries({ queryKey: r.queryKey }), s && (e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }));
|
|
25
|
-
}
|
|
26
|
-
if (E === "RESET" && t) {
|
|
27
|
-
const r = O(t);
|
|
28
|
-
r && u.resetQueries({ queryKey: r.queryKey }), s && (e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }));
|
|
29
|
-
}
|
|
30
|
-
if (E === "REMOVE" && t) {
|
|
31
|
-
const r = O(t);
|
|
32
|
-
r && u.removeQueries({ queryKey: r.queryKey }), s && (e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }));
|
|
33
|
-
}
|
|
34
|
-
if (E === "TRIGGER_LOADING" && t) {
|
|
35
|
-
const r = O(t);
|
|
36
|
-
r && (r.setState({
|
|
37
|
-
...r.state,
|
|
38
|
-
fetchStatus: "fetching",
|
|
39
|
-
status: "pending",
|
|
40
|
-
error: null
|
|
41
|
-
}), s && (o.current.add(s), e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }), o.current.delete(s)));
|
|
42
|
-
}
|
|
43
|
-
if (E === "RESTORE_LOADING" && t) {
|
|
44
|
-
const r = O(t);
|
|
45
|
-
r && (r.setState({
|
|
46
|
-
...r.state,
|
|
47
|
-
fetchStatus: "idle"
|
|
48
|
-
}), s && (o.current.add(s), e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }), o.current.delete(s)));
|
|
49
|
-
}
|
|
50
|
-
if (E === "TRIGGER_ERROR" && t) {
|
|
51
|
-
const r = O(t);
|
|
52
|
-
r && (r.setState({
|
|
53
|
-
...r.state,
|
|
54
|
-
fetchStatus: "idle",
|
|
55
|
-
status: "error",
|
|
56
|
-
error: (T == null ? void 0 : T.error) || new Error("Forced error via devtools"),
|
|
57
|
-
errorUpdateCount: (r.state.errorUpdateCount ?? 0) + 1,
|
|
58
|
-
errorUpdatedAt: Date.now()
|
|
59
|
-
}), s && (o.current.add(s), e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }), o.current.delete(s)));
|
|
60
|
-
}
|
|
61
|
-
if (E === "RESTORE_ERROR" && t) {
|
|
62
|
-
const r = O(t);
|
|
63
|
-
r && u.resetQueries({ queryKey: r.queryKey }), s && (e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }));
|
|
64
|
-
}
|
|
65
|
-
E === "CLEAR_MUTATION_CACHE" && (u.getMutationCache().clear(), s && (e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 }))), E === "CLEAR_QUERY_CACHE" && (u.clear(), s && (e == null || e.send("DEVICE_TO_DEVTOOLS_ACK", { requestId: s, success: !0 })));
|
|
66
|
-
})(n);
|
|
67
|
-
}, [u, e]);
|
|
68
|
-
_(() => {
|
|
69
|
-
if (!e) return;
|
|
70
|
-
const n = e.onMessage("DEVTOOLS_TO_DEVICE", a);
|
|
71
|
-
return () => n.remove();
|
|
72
|
-
}, [a, e]), _(() => {
|
|
73
|
-
if (e)
|
|
74
|
-
return u.getQueryCache().subscribe((n) => {
|
|
75
|
-
o.current.size > 0 || e.send("DEVICE_TO_DEVTOOLS", n);
|
|
76
|
-
});
|
|
77
|
-
}, [e, u]), _(() => {
|
|
78
|
-
if (e)
|
|
79
|
-
return u.getMutationCache().subscribe((n) => {
|
|
80
|
-
o.current.size > 0 || e.send("DEVICE_TO_DEVTOOLS", n);
|
|
81
|
-
});
|
|
82
|
-
}, [e, u]);
|
|
83
|
-
};
|
|
84
|
-
let d;
|
|
85
|
-
process.env.NODE_ENV !== "production" ? d = I : d = () => ({ isConnected: !1 });
|
|
1
|
+
let e;
|
|
2
|
+
process.env.NODE_ENV !== "production" ? e = require("./useTanstackQueryDevTools.js").useTanStackQueryDevTools : e = () => ({ isConnected: !1 });
|
|
86
3
|
export {
|
|
87
|
-
|
|
4
|
+
e as useTanStackQueryDevTools
|
|
88
5
|
};
|
package/dist/rozenite.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@rozenite/tanstack-query-plugin","version":"1.0.0-alpha.
|
|
1
|
+
{"name":"@rozenite/tanstack-query-plugin","version":"1.0.0-alpha.8","description":"TanStack Query for Rozenite.","panels":[{"name":"Tanstack Query","source":"/tanstack-query.html"}]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Query, Mutation, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { SerializableQuery, SerializableMutation, SerializableObserver, SerializableQueryClient } from './types';
|
|
3
|
+
export declare const dehydrateObservers: (query: Query) => SerializableObserver[];
|
|
4
|
+
export declare const dehydrateQuery: (query: Query) => SerializableQuery;
|
|
5
|
+
export declare const dehydrateMutation: (mutation: Mutation) => SerializableMutation;
|
|
6
|
+
export declare const dehydrateQueryClient: (queryClient: QueryClient) => SerializableQueryClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { SerializableQuery, SerializableMutation, SerializableQueryClient, SerializableObserver, PartialQueryState } from './types';
|
|
3
|
+
export declare const hydrateQueryClient: (client: QueryClient, dehydratedState: SerializableQueryClient) => void;
|
|
4
|
+
export declare const applyQueryEvent: (queryClient: QueryClient, type: "added" | "updated" | "removed" | "observerAdded" | "observerRemoved" | "observerResultsUpdated" | "observerOptionsUpdated", data: SerializableQuery | PartialQueryState, action?: string) => void;
|
|
5
|
+
export declare const applyPartialQueryState: (queryClient: QueryClient, data: PartialQueryState) => void;
|
|
6
|
+
export declare const applyMutationEvent: (queryClient: QueryClient, type: "added" | "updated" | "removed" | "observerAdded" | "observerRemoved" | "observerResultsUpdated" | "observerOptionsUpdated", data: SerializableMutation) => void;
|
|
7
|
+
export declare const applyQueryObserverEvent: (queryClient: QueryClient, data: {
|
|
8
|
+
queryHash: string;
|
|
9
|
+
observers: SerializableObserver[];
|
|
10
|
+
}) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RozeniteDevToolsClient } from '@rozenite/plugin-bridge';
|
|
2
|
+
import { DevToolsActionType, SerializableQueryClient, SerializableQuery, SerializableMutation, SerializableObserver, PartialQueryState } from './types';
|
|
3
|
+
export type TanStackQueryPluginEventMap = {
|
|
4
|
+
'online-status-changed': {
|
|
5
|
+
online: boolean;
|
|
6
|
+
};
|
|
7
|
+
'devtools-action': {
|
|
8
|
+
type: DevToolsActionType;
|
|
9
|
+
queryHash: string;
|
|
10
|
+
};
|
|
11
|
+
'request-initial-data': unknown;
|
|
12
|
+
'sync-data': {
|
|
13
|
+
data: SerializableQueryClient;
|
|
14
|
+
};
|
|
15
|
+
'sync-query-event': {
|
|
16
|
+
type: 'added' | 'removed';
|
|
17
|
+
data: SerializableQuery;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'updated';
|
|
20
|
+
action?: string;
|
|
21
|
+
data: SerializableQuery | PartialQueryState;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'observerAdded' | 'observerRemoved' | 'observerOptionsUpdated';
|
|
24
|
+
data: {
|
|
25
|
+
queryHash: string;
|
|
26
|
+
observers: SerializableObserver[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
'sync-mutation-event': {
|
|
30
|
+
type: 'added' | 'updated' | 'removed' | 'observerAdded' | 'observerRemoved' | 'observerResultsUpdated' | 'observerOptionsUpdated';
|
|
31
|
+
data: SerializableMutation;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type TanStackQueryPluginClient = RozeniteDevToolsClient<TanStackQueryPluginEventMap>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { QueryKey, MutationState, QueryState, QueryObserverOptions, InfiniteQueryObserverOptions, MutationOptions } from '@tanstack/react-query';
|
|
2
|
+
export type SerializableQuery = {
|
|
3
|
+
queryHash: string;
|
|
4
|
+
state: QueryState;
|
|
5
|
+
queryKey: QueryKey;
|
|
6
|
+
observers: SerializableObserver[];
|
|
7
|
+
};
|
|
8
|
+
export type PartialQueryState = {
|
|
9
|
+
queryHash: string;
|
|
10
|
+
state: Partial<QueryState>;
|
|
11
|
+
};
|
|
12
|
+
export type SerializableMutation = {
|
|
13
|
+
mutationId: number;
|
|
14
|
+
options: MutationOptions;
|
|
15
|
+
state: MutationState;
|
|
16
|
+
};
|
|
17
|
+
export type SerializableObserver = {
|
|
18
|
+
queryHash: string;
|
|
19
|
+
options: QueryObserverOptions | InfiniteQueryObserverOptions;
|
|
20
|
+
};
|
|
21
|
+
export type SerializableQueryClient = {
|
|
22
|
+
queries: SerializableQuery[];
|
|
23
|
+
mutations: SerializableMutation[];
|
|
24
|
+
};
|
|
25
|
+
export type DevToolsActionType = 'REFETCH' | 'INVALIDATE' | 'RESET' | 'REMOVE' | 'TRIGGER_ERROR' | 'RESTORE_ERROR' | 'TRIGGER_LOADING' | 'RESTORE_LOADING' | 'CLEAR_MUTATION_CACHE' | 'CLEAR_QUERY_CACHE';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function TanStackQueryPanel(): import("react/jsx-runtime").JSX.Element;
|
package/dist/tanstack-query.html
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<script>
|
|
23
23
|
var __ROZENITE_PANEL__ = true;
|
|
24
24
|
</script>
|
|
25
|
-
<script type="module" crossorigin src="./assets/tanstack-query-
|
|
25
|
+
<script type="module" crossorigin src="./assets/tanstack-query-DWTo8DT_.js"></script>
|
|
26
26
|
</head>
|
|
27
27
|
<body>
|
|
28
28
|
<div id="root"></div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@rozenite/plugin-bridge"),y=require("react"),p=require("@tanstack/react-query"),q=require("fast-deep-equal"),S=e=>e&&e.__esModule?e:{default:e},g=S(q),l=e=>{y.useEffect(()=>{if(!e)return;const a=p.onlineManager.subscribe(n=>{e.send("online-status-changed",{online:n})}),c=e.onMessage("online-status-changed",({online:n})=>{p.onlineManager.setOnline(n)});return()=>{a(),c.remove()}},[e])},M=(e,a)=>{y.useEffect(()=>{if(!a)return;const c=a.onMessage("devtools-action",({type:n,queryHash:o})=>{const s=e.getQueryCache().get(o);if(!s){console.warn(`No active query found for hash: ${o}`);return}switch(n){case"TRIGGER_ERROR":{const d=s.options,t=new Error("Unknown error from devtools");s.setState({status:"error",error:t,fetchMeta:{...s.state.fetchMeta,__previousQueryOptions:d}});break}case"RESTORE_ERROR":{e.resetQueries(s);break}case"TRIGGER_LOADING":{if(!s)return;const d=s.options;s.fetch({...d,queryFn:()=>new Promise(()=>{}),gcTime:-1}),s.setState({data:void 0,status:"pending",fetchMeta:{...s.state.fetchMeta,__previousQueryOptions:d}});break}case"RESTORE_LOADING":{const d=s.state,t=s.state.fetchMeta?s.state.fetchMeta.__previousQueryOptions:null;s.cancel({silent:!0}),s.setState({...d,fetchStatus:"idle",fetchMeta:null}),t&&s.fetch(t);break}case"RESET":{e.resetQueries(s);break}case"REMOVE":{e.removeQueries(s);break}case"REFETCH":{s.fetch().catch(()=>{});break}case"INVALIDATE":{e.invalidateQueries(s);break}default:console.warn(`Unknown devtools action: ${n}`)}});return()=>{c.remove()}},[a])},f=e=>e.observers.map(a=>({queryHash:e.queryHash,options:a.options})),h=e=>{const a=f(e);return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash,observers:a}},v=e=>({mutationId:e.mutationId,state:e.state,options:e.options}),H=e=>({queries:e.getQueryCache().getAll().map(h),mutations:e.getMutationCache().getAll().map(v)}),R=(e,a)=>{const c=y.useRef(new Map),n=y.useMemo(()=>o=>{if(!a||o.type==="observerResultsUpdated")return;if("query"in o){const{query:t,type:u}=o;if(u==="added"||u==="removed"){u==="removed"&&c.current.delete(t.queryHash);const i=h(t);a.send("sync-query-event",{type:u,data:i});return}if(u==="updated"&&"action"in o){const i=o.action;switch(i.type){case"fetch":{const r={queryHash:t.queryHash,state:{status:t.state.status,fetchStatus:t.state.fetchStatus,fetchMeta:t.state.fetchMeta,dataUpdatedAt:t.state.dataUpdatedAt,errorUpdatedAt:t.state.errorUpdatedAt}};a.send("sync-query-event",{type:"updated",action:"fetch",data:r});break}case"success":{const r={queryHash:t.queryHash,state:{status:t.state.status,data:t.state.data,dataUpdatedAt:t.state.dataUpdatedAt,error:t.state.error,errorUpdatedAt:t.state.errorUpdatedAt,fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"success",data:r});break}case"error":{const r={queryHash:t.queryHash,state:{status:t.state.status,error:t.state.error,errorUpdatedAt:t.state.errorUpdatedAt,fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"error",data:r});break}case"setState":{const r={queryHash:t.queryHash,state:i.state};a.send("sync-query-event",{type:"updated",action:"setState",data:r});break}case"invalidate":{const r={queryHash:t.queryHash,state:{isInvalidated:t.state.isInvalidated}};a.send("sync-query-event",{type:"updated",action:"invalidate",data:r});break}case"pause":{const r={queryHash:t.queryHash,state:{fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"pause",data:r});break}case"continue":{const r={queryHash:t.queryHash,state:{fetchStatus:t.state.fetchStatus}};a.send("sync-query-event",{type:"updated",action:"continue",data:r});break}default:{const r=h(t);a.send("sync-query-event",{type:u,data:r})}}return}if(u==="observerAdded"||u==="observerRemoved"||u==="observerOptionsUpdated"){const i=f(t),r=c.current.get(t.queryHash);if(u==="observerOptionsUpdated"&&r&&g.default(r,i))return;c.current.set(t.queryHash,i),a.send("sync-query-event",{type:u,data:{queryHash:t.queryHash,observers:i}});return}}const{mutation:s,type:d}=o;if(s){const t=v(s);a.send("sync-mutation-event",{type:d,data:t})}},[a]);y.useEffect(()=>{if(!a)return;const o=e.getMutationCache().subscribe(n),s=e.getQueryCache().subscribe(n);return()=>{o(),s()}},[a,e,n])},k=(e,a)=>{y.useEffect(()=>{if(!a)return;const c=a.onMessage("request-initial-data",()=>{const n=H(e);a.send("sync-data",{data:n})});return()=>{c.remove()}},[a,e])},O=e=>{const a=b.useRozeniteDevToolsClient({pluginId:"@rozenite/tanstack-query-plugin"});l(a),M(e,a),R(e,a),k(e,a)};exports.useTanStackQueryDevTools=O;
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { useRozeniteDevToolsClient as b } from "@rozenite/plugin-bridge";
|
|
2
|
+
import { useEffect as y, useRef as S, useMemo as q } from "react";
|
|
3
|
+
import { onlineManager as h } from "@tanstack/react-query";
|
|
4
|
+
import m from "fast-deep-equal";
|
|
5
|
+
const H = (t) => {
|
|
6
|
+
y(() => {
|
|
7
|
+
if (!t)
|
|
8
|
+
return;
|
|
9
|
+
const a = h.subscribe((n) => {
|
|
10
|
+
t.send("online-status-changed", { online: n });
|
|
11
|
+
}), d = t.onMessage(
|
|
12
|
+
"online-status-changed",
|
|
13
|
+
({ online: n }) => {
|
|
14
|
+
h.setOnline(n);
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
return () => {
|
|
18
|
+
a(), d.remove();
|
|
19
|
+
};
|
|
20
|
+
}, [t]);
|
|
21
|
+
}, M = (t, a) => {
|
|
22
|
+
y(() => {
|
|
23
|
+
if (!a)
|
|
24
|
+
return;
|
|
25
|
+
const d = a.onMessage(
|
|
26
|
+
"devtools-action",
|
|
27
|
+
({ type: n, queryHash: o }) => {
|
|
28
|
+
const s = t.getQueryCache().get(o);
|
|
29
|
+
if (!s) {
|
|
30
|
+
console.warn(`No active query found for hash: ${o}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
switch (n) {
|
|
34
|
+
case "TRIGGER_ERROR": {
|
|
35
|
+
const c = s.options, e = new Error("Unknown error from devtools");
|
|
36
|
+
s.setState({
|
|
37
|
+
status: "error",
|
|
38
|
+
error: e,
|
|
39
|
+
fetchMeta: {
|
|
40
|
+
...s.state.fetchMeta,
|
|
41
|
+
// @ts-expect-error This does exist
|
|
42
|
+
__previousQueryOptions: c
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "RESTORE_ERROR": {
|
|
48
|
+
t.resetQueries(s);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "TRIGGER_LOADING": {
|
|
52
|
+
if (!s) return;
|
|
53
|
+
const c = s.options;
|
|
54
|
+
s.fetch({
|
|
55
|
+
...c,
|
|
56
|
+
queryFn: () => new Promise(() => {
|
|
57
|
+
}),
|
|
58
|
+
gcTime: -1
|
|
59
|
+
}), s.setState({
|
|
60
|
+
data: void 0,
|
|
61
|
+
status: "pending",
|
|
62
|
+
fetchMeta: {
|
|
63
|
+
...s.state.fetchMeta,
|
|
64
|
+
// @ts-expect-error This does exist
|
|
65
|
+
__previousQueryOptions: c
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case "RESTORE_LOADING": {
|
|
71
|
+
const c = s.state, e = s.state.fetchMeta ? s.state.fetchMeta.__previousQueryOptions : null;
|
|
72
|
+
s.cancel({ silent: !0 }), s.setState({
|
|
73
|
+
...c,
|
|
74
|
+
fetchStatus: "idle",
|
|
75
|
+
fetchMeta: null
|
|
76
|
+
}), e && s.fetch(e);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "RESET": {
|
|
80
|
+
t.resetQueries(s);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "REMOVE": {
|
|
84
|
+
t.removeQueries(s);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case "REFETCH": {
|
|
88
|
+
s.fetch().catch(() => {
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case "INVALIDATE": {
|
|
93
|
+
t.invalidateQueries(s);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
console.warn(`Unknown devtools action: ${n}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
return () => {
|
|
102
|
+
d.remove();
|
|
103
|
+
};
|
|
104
|
+
}, [a]);
|
|
105
|
+
}, f = (t) => t.observers.map((a) => ({
|
|
106
|
+
queryHash: t.queryHash,
|
|
107
|
+
options: a.options
|
|
108
|
+
})), p = (t) => {
|
|
109
|
+
const a = f(t);
|
|
110
|
+
return {
|
|
111
|
+
state: t.state,
|
|
112
|
+
queryKey: t.queryKey,
|
|
113
|
+
queryHash: t.queryHash,
|
|
114
|
+
observers: a
|
|
115
|
+
};
|
|
116
|
+
}, v = (t) => ({
|
|
117
|
+
mutationId: t.mutationId,
|
|
118
|
+
state: t.state,
|
|
119
|
+
options: t.options
|
|
120
|
+
}), g = (t) => ({
|
|
121
|
+
queries: t.getQueryCache().getAll().map(p),
|
|
122
|
+
mutations: t.getMutationCache().getAll().map(v)
|
|
123
|
+
}), R = (t, a) => {
|
|
124
|
+
const d = S(
|
|
125
|
+
/* @__PURE__ */ new Map()
|
|
126
|
+
), n = q(() => (o) => {
|
|
127
|
+
if (!a || o.type === "observerResultsUpdated")
|
|
128
|
+
return;
|
|
129
|
+
if ("query" in o) {
|
|
130
|
+
const { query: e, type: u } = o;
|
|
131
|
+
if (u === "added" || u === "removed") {
|
|
132
|
+
u === "removed" && d.current.delete(e.queryHash);
|
|
133
|
+
const i = p(e);
|
|
134
|
+
a.send("sync-query-event", { type: u, data: i });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (u === "updated" && "action" in o) {
|
|
138
|
+
const i = o.action;
|
|
139
|
+
switch (i.type) {
|
|
140
|
+
case "fetch": {
|
|
141
|
+
const r = {
|
|
142
|
+
queryHash: e.queryHash,
|
|
143
|
+
state: {
|
|
144
|
+
status: e.state.status,
|
|
145
|
+
fetchStatus: e.state.fetchStatus,
|
|
146
|
+
fetchMeta: e.state.fetchMeta,
|
|
147
|
+
dataUpdatedAt: e.state.dataUpdatedAt,
|
|
148
|
+
errorUpdatedAt: e.state.errorUpdatedAt
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
a.send("sync-query-event", {
|
|
152
|
+
type: "updated",
|
|
153
|
+
action: "fetch",
|
|
154
|
+
data: r
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case "success": {
|
|
159
|
+
const r = {
|
|
160
|
+
queryHash: e.queryHash,
|
|
161
|
+
state: {
|
|
162
|
+
status: e.state.status,
|
|
163
|
+
data: e.state.data,
|
|
164
|
+
dataUpdatedAt: e.state.dataUpdatedAt,
|
|
165
|
+
error: e.state.error,
|
|
166
|
+
errorUpdatedAt: e.state.errorUpdatedAt,
|
|
167
|
+
fetchStatus: e.state.fetchStatus
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
a.send("sync-query-event", {
|
|
171
|
+
type: "updated",
|
|
172
|
+
action: "success",
|
|
173
|
+
data: r
|
|
174
|
+
});
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case "error": {
|
|
178
|
+
const r = {
|
|
179
|
+
queryHash: e.queryHash,
|
|
180
|
+
state: {
|
|
181
|
+
status: e.state.status,
|
|
182
|
+
error: e.state.error,
|
|
183
|
+
errorUpdatedAt: e.state.errorUpdatedAt,
|
|
184
|
+
fetchStatus: e.state.fetchStatus
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
a.send("sync-query-event", {
|
|
188
|
+
type: "updated",
|
|
189
|
+
action: "error",
|
|
190
|
+
data: r
|
|
191
|
+
});
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case "setState": {
|
|
195
|
+
const r = {
|
|
196
|
+
queryHash: e.queryHash,
|
|
197
|
+
state: i.state
|
|
198
|
+
// Only the changed state parts
|
|
199
|
+
};
|
|
200
|
+
a.send("sync-query-event", {
|
|
201
|
+
type: "updated",
|
|
202
|
+
action: "setState",
|
|
203
|
+
data: r
|
|
204
|
+
});
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case "invalidate": {
|
|
208
|
+
const r = {
|
|
209
|
+
queryHash: e.queryHash,
|
|
210
|
+
state: {
|
|
211
|
+
isInvalidated: e.state.isInvalidated
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
a.send("sync-query-event", {
|
|
215
|
+
type: "updated",
|
|
216
|
+
action: "invalidate",
|
|
217
|
+
data: r
|
|
218
|
+
});
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case "pause": {
|
|
222
|
+
const r = {
|
|
223
|
+
queryHash: e.queryHash,
|
|
224
|
+
state: {
|
|
225
|
+
fetchStatus: e.state.fetchStatus
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
a.send("sync-query-event", {
|
|
229
|
+
type: "updated",
|
|
230
|
+
action: "pause",
|
|
231
|
+
data: r
|
|
232
|
+
});
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case "continue": {
|
|
236
|
+
const r = {
|
|
237
|
+
queryHash: e.queryHash,
|
|
238
|
+
state: {
|
|
239
|
+
fetchStatus: e.state.fetchStatus
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
a.send("sync-query-event", {
|
|
243
|
+
type: "updated",
|
|
244
|
+
action: "continue",
|
|
245
|
+
data: r
|
|
246
|
+
});
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
default: {
|
|
250
|
+
const r = p(e);
|
|
251
|
+
a.send("sync-query-event", { type: u, data: r });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (u === "observerAdded" || u === "observerRemoved" || u === "observerOptionsUpdated") {
|
|
257
|
+
const i = f(e), r = d.current.get(
|
|
258
|
+
e.queryHash
|
|
259
|
+
);
|
|
260
|
+
if (u === "observerOptionsUpdated" && r && m(r, i))
|
|
261
|
+
return;
|
|
262
|
+
d.current.set(
|
|
263
|
+
e.queryHash,
|
|
264
|
+
i
|
|
265
|
+
), a.send("sync-query-event", {
|
|
266
|
+
type: u,
|
|
267
|
+
data: {
|
|
268
|
+
queryHash: e.queryHash,
|
|
269
|
+
observers: i
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const { mutation: s, type: c } = o;
|
|
276
|
+
if (s) {
|
|
277
|
+
const e = v(s);
|
|
278
|
+
a.send("sync-mutation-event", {
|
|
279
|
+
type: c,
|
|
280
|
+
data: e
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}, [a]);
|
|
284
|
+
y(() => {
|
|
285
|
+
if (!a)
|
|
286
|
+
return;
|
|
287
|
+
const o = t.getMutationCache().subscribe(n), s = t.getQueryCache().subscribe(n);
|
|
288
|
+
return () => {
|
|
289
|
+
o(), s();
|
|
290
|
+
};
|
|
291
|
+
}, [a, t, n]);
|
|
292
|
+
}, k = (t, a) => {
|
|
293
|
+
y(() => {
|
|
294
|
+
if (!a)
|
|
295
|
+
return;
|
|
296
|
+
const d = a.onMessage("request-initial-data", () => {
|
|
297
|
+
const n = g(t);
|
|
298
|
+
a.send("sync-data", { data: n });
|
|
299
|
+
});
|
|
300
|
+
return () => {
|
|
301
|
+
d.remove();
|
|
302
|
+
};
|
|
303
|
+
}, [a, t]);
|
|
304
|
+
}, l = (t) => {
|
|
305
|
+
const a = b({
|
|
306
|
+
pluginId: "@rozenite/tanstack-query-plugin"
|
|
307
|
+
});
|
|
308
|
+
H(a), M(t, a), R(t, a), k(t, a);
|
|
309
|
+
};
|
|
310
|
+
export {
|
|
311
|
+
l as useTanStackQueryDevTools
|
|
312
|
+
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rozenite/tanstack-query-plugin",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.10",
|
|
4
4
|
"description": "TanStack Query for Rozenite.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/react-native.cjs",
|
|
7
7
|
"module": "./dist/react-native.js",
|
|
8
8
|
"types": "./dist/react-native.d.ts",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"
|
|
10
|
+
"fast-deep-equal": "^3.1.3",
|
|
11
|
+
"@rozenite/plugin-bridge": "1.0.0-alpha.10"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
14
|
+
"@tanstack/react-query": "^5.0.0",
|
|
13
15
|
"@tanstack/react-query-devtools": "^5.0.0",
|
|
16
|
+
"@types/react": "~18.3.12",
|
|
17
|
+
"react": "18.3.1",
|
|
18
|
+
"react-dom": "18.3.0",
|
|
19
|
+
"react-native": "0.76.0",
|
|
20
|
+
"react-native-web": "0.21.0",
|
|
14
21
|
"typescript": "^5.7.3",
|
|
15
22
|
"vite": "^6.0.0",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"rozenite": "1.0.0-alpha.2",
|
|
19
|
-
"@rozenite/vite-plugin": "1.0.0-alpha.1"
|
|
23
|
+
"rozenite": "1.0.0-alpha.10",
|
|
24
|
+
"@rozenite/vite-plugin": "1.0.0-alpha.10"
|
|
20
25
|
},
|
|
21
26
|
"peerDependencies": {
|
|
22
|
-
"react": "
|
|
23
|
-
"react
|
|
24
|
-
"
|
|
27
|
+
"@tanstack/react-query": "^5.0.0",
|
|
28
|
+
"react": "*",
|
|
29
|
+
"react-native": "*"
|
|
25
30
|
},
|
|
26
31
|
"license": "MIT",
|
|
27
32
|
"scripts": {
|
package/project.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
3
|
+
"name": "@rozenite/tanstack-query-plugin",
|
|
4
|
+
"targets": {
|
|
5
|
+
"build": {
|
|
6
|
+
"cache": true,
|
|
7
|
+
"dependsOn": ["^build"],
|
|
8
|
+
"inputs": ["{projectRoot}/src/**/*"],
|
|
9
|
+
"outputs": ["{projectRoot}/dist"]
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
package/react-native.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
1
|
export let useTanStackQueryDevTools: typeof import('./src/react-native/useTanStackQueryDevTools').useTanStackQueryDevTools;
|
|
3
2
|
|
|
4
3
|
if (process.env.NODE_ENV !== 'production') {
|
|
5
|
-
useTanStackQueryDevTools =
|
|
4
|
+
useTanStackQueryDevTools =
|
|
5
|
+
require('./src/react-native/useTanStackQueryDevTools').useTanStackQueryDevTools;
|
|
6
6
|
} else {
|
|
7
7
|
useTanStackQueryDevTools = () => ({ isConnected: false });
|
|
8
8
|
}
|