@drakkar.software/starfish-client 1.4.0 → 1.5.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/dist/background-sync.d.ts +16 -0
- package/dist/background-sync.js +29 -0
- package/dist/bindings/legend.js +5 -5
- package/dist/bindings/suspense.d.ts +25 -0
- package/dist/bindings/suspense.js +49 -0
- package/dist/bindings/zustand.js +19 -11
- package/dist/broadcast.js +8 -3
- package/dist/client.d.ts +2 -1
- package/dist/client.js +1 -1
- package/dist/dedup.d.ts +6 -0
- package/dist/dedup.js +35 -0
- package/dist/export.d.ts +24 -0
- package/dist/export.js +115 -0
- package/dist/fetch.js +26 -16
- package/dist/hash.d.ts +10 -0
- package/dist/hash.js +34 -0
- package/dist/history.d.ts +1 -1
- package/dist/history.js +12 -4
- package/dist/index.d.ts +14 -3
- package/dist/index.js +8 -2
- package/dist/logger.d.ts +26 -2
- package/dist/logger.js +62 -2
- package/dist/migrate.js +6 -1
- package/dist/platform.d.ts +52 -0
- package/dist/platform.js +62 -0
- package/dist/polling.js +2 -2
- package/dist/resolvers.d.ts +19 -0
- package/dist/resolvers.js +65 -4
- package/dist/service-worker.d.ts +18 -0
- package/dist/service-worker.js +55 -0
- package/dist/storage/indexeddb.d.ts +17 -0
- package/dist/storage/indexeddb.js +59 -0
- package/dist/sync.js +17 -9
- package/package.json +2 -2
- package/dist/bindings/broadcast.d.ts +0 -19
- package/dist/bindings/broadcast.js +0 -65
- package/dist/bindings/react.d.ts +0 -12
- package/dist/bindings/react.js +0 -25
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Syncs a Zustand Starfish store across browser tabs using BroadcastChannel.
|
|
3
|
-
* Returns a cleanup function that closes the channel.
|
|
4
|
-
*/
|
|
5
|
-
export function setupBroadcastSync(store, name) {
|
|
6
|
-
const channel = new BroadcastChannel(`starfish-${name}`);
|
|
7
|
-
let lastReceivedData = null;
|
|
8
|
-
channel.onmessage = (event) => {
|
|
9
|
-
lastReceivedData = event.data.data;
|
|
10
|
-
store.setState({ data: event.data.data, dirty: event.data.dirty });
|
|
11
|
-
};
|
|
12
|
-
const unsub = store.subscribe((state, prev) => {
|
|
13
|
-
if (state.data === lastReceivedData)
|
|
14
|
-
return;
|
|
15
|
-
if (state.data !== prev.data || state.dirty !== prev.dirty) {
|
|
16
|
-
channel.postMessage({ data: state.data, dirty: state.dirty });
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return () => {
|
|
20
|
-
unsub();
|
|
21
|
-
channel.close();
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Syncs a Zustand Starfish store across browser tabs using storage events.
|
|
26
|
-
* Fallback for environments without BroadcastChannel.
|
|
27
|
-
* Returns a cleanup function.
|
|
28
|
-
*/
|
|
29
|
-
export function setupStorageFallback(store, name) {
|
|
30
|
-
const storageKey = `starfish-broadcast-${name}`;
|
|
31
|
-
let lastReceivedData = null;
|
|
32
|
-
const onStorage = (e) => {
|
|
33
|
-
if (e.key !== storageKey || !e.newValue)
|
|
34
|
-
return;
|
|
35
|
-
const payload = JSON.parse(e.newValue);
|
|
36
|
-
lastReceivedData = payload.data;
|
|
37
|
-
store.setState({ data: payload.data, dirty: payload.dirty });
|
|
38
|
-
};
|
|
39
|
-
globalThis.addEventListener("storage", onStorage);
|
|
40
|
-
const unsub = store.subscribe((state, prev) => {
|
|
41
|
-
if (state.data === lastReceivedData)
|
|
42
|
-
return;
|
|
43
|
-
if (state.data !== prev.data || state.dirty !== prev.dirty) {
|
|
44
|
-
localStorage.setItem(storageKey, JSON.stringify({ data: state.data, dirty: state.dirty }));
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return () => {
|
|
48
|
-
unsub();
|
|
49
|
-
globalThis.removeEventListener("storage", onStorage);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Auto-detects the best cross-tab sync mechanism and sets it up.
|
|
54
|
-
* Uses BroadcastChannel when available, falls back to storage events.
|
|
55
|
-
* Returns a cleanup function.
|
|
56
|
-
*/
|
|
57
|
-
export function setupCrossTabSync(store, name) {
|
|
58
|
-
if (typeof BroadcastChannel !== "undefined") {
|
|
59
|
-
return setupBroadcastSync(store, name);
|
|
60
|
-
}
|
|
61
|
-
if (typeof globalThis.addEventListener === "function" && typeof localStorage !== "undefined") {
|
|
62
|
-
return setupStorageFallback(store, name);
|
|
63
|
-
}
|
|
64
|
-
return () => { };
|
|
65
|
-
}
|
package/dist/bindings/react.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { StoreApi } from "zustand/vanilla";
|
|
2
|
-
import type { StarfishStore, StarfishState } from "./zustand.js";
|
|
3
|
-
/** Derived sync status for UI display. */
|
|
4
|
-
export type SyncStatus = "synced" | "syncing" | "pending" | "error" | "offline";
|
|
5
|
-
/** Derive a single sync status from store state. */
|
|
6
|
-
export declare function deriveSyncStatus(state: StarfishState): SyncStatus;
|
|
7
|
-
/** Use the full Starfish store state and actions. */
|
|
8
|
-
export declare function useStarfish(store: StoreApi<StarfishStore>): StarfishStore;
|
|
9
|
-
/** Use only the synced data, with an optional selector for fine-grained subscriptions. */
|
|
10
|
-
export declare function useStarfishData<T = Record<string, unknown>>(store: StoreApi<StarfishStore>, selector?: (data: Record<string, unknown>) => T): T;
|
|
11
|
-
/** Use the derived sync status (synced | syncing | pending | error | offline). */
|
|
12
|
-
export declare function useSyncStatus(store: StoreApi<StarfishStore>): SyncStatus;
|
package/dist/bindings/react.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useStore } from "zustand";
|
|
2
|
-
/** Derive a single sync status from store state. */
|
|
3
|
-
export function deriveSyncStatus(state) {
|
|
4
|
-
if (!state.online)
|
|
5
|
-
return "offline";
|
|
6
|
-
if (state.error)
|
|
7
|
-
return "error";
|
|
8
|
-
if (state.syncing)
|
|
9
|
-
return "syncing";
|
|
10
|
-
if (state.dirty)
|
|
11
|
-
return "pending";
|
|
12
|
-
return "synced";
|
|
13
|
-
}
|
|
14
|
-
/** Use the full Starfish store state and actions. */
|
|
15
|
-
export function useStarfish(store) {
|
|
16
|
-
return useStore(store);
|
|
17
|
-
}
|
|
18
|
-
/** Use only the synced data, with an optional selector for fine-grained subscriptions. */
|
|
19
|
-
export function useStarfishData(store, selector) {
|
|
20
|
-
return useStore(store, (state) => selector ? selector(state.data) : state.data);
|
|
21
|
-
}
|
|
22
|
-
/** Use the derived sync status (synced | syncing | pending | error | offline). */
|
|
23
|
-
export function useSyncStatus(store) {
|
|
24
|
-
return useStore(store, deriveSyncStatus);
|
|
25
|
-
}
|