hyperstack-react 0.3.15 → 0.4.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/index.d.ts +18 -17
- package/dist/index.esm.js +15 -50
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15 -50
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,6 @@ export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResoluti
|
|
|
4
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
|
5
5
|
|
|
6
6
|
type ViewMode = 'state' | 'list';
|
|
7
|
-
interface NetworkConfig {
|
|
8
|
-
name: string;
|
|
9
|
-
websocketUrl: string;
|
|
10
|
-
}
|
|
11
7
|
interface TransactionDefinition<TParams = unknown> {
|
|
12
8
|
build: (params: TParams) => {
|
|
13
9
|
instruction: string;
|
|
@@ -18,10 +14,14 @@ interface TransactionDefinition<TParams = unknown> {
|
|
|
18
14
|
key?: string | ((params: TParams) => string);
|
|
19
15
|
}>;
|
|
20
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Global configuration for HyperstackProvider.
|
|
19
|
+
*
|
|
20
|
+
* Note: WebSocket URL is no longer configured here. The URL is:
|
|
21
|
+
* 1. Embedded in the stack definition (stack.url)
|
|
22
|
+
* 2. Optionally overridden per-hook via useHyperstack(stack, { url: '...' })
|
|
23
|
+
*/
|
|
21
24
|
interface HyperstackConfig {
|
|
22
|
-
websocketUrl?: string;
|
|
23
|
-
network?: 'devnet' | 'mainnet' | 'localnet' | NetworkConfig;
|
|
24
|
-
apiKey?: string;
|
|
25
25
|
autoConnect?: boolean;
|
|
26
26
|
wallet?: WalletAdapter;
|
|
27
27
|
reconnectIntervals?: number[];
|
|
@@ -29,6 +29,13 @@ interface HyperstackConfig {
|
|
|
29
29
|
maxEntriesPerView?: number | null;
|
|
30
30
|
flushIntervalMs?: number;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for useHyperstack hook
|
|
34
|
+
*/
|
|
35
|
+
interface UseHyperstackOptions {
|
|
36
|
+
/** Override the stack's embedded URL (useful for local development) */
|
|
37
|
+
url?: string;
|
|
38
|
+
}
|
|
32
39
|
interface ViewHookOptions {
|
|
33
40
|
enabled?: boolean;
|
|
34
41
|
initialData?: unknown;
|
|
@@ -73,15 +80,9 @@ interface ListViewHook<T> {
|
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
interface HyperstackContextValue {
|
|
76
|
-
getOrCreateClient: <TStack extends StackDefinition>(stack: TStack) => Promise<HyperStack<TStack>>;
|
|
83
|
+
getOrCreateClient: <TStack extends StackDefinition>(stack: TStack, urlOverride?: string) => Promise<HyperStack<TStack>>;
|
|
77
84
|
getClient: <TStack extends StackDefinition>(stack: TStack | undefined) => HyperStack<TStack> | null;
|
|
78
|
-
config:
|
|
79
|
-
websocketUrl: string;
|
|
80
|
-
autoConnect?: boolean;
|
|
81
|
-
reconnectIntervals?: number[];
|
|
82
|
-
maxReconnectAttempts?: number;
|
|
83
|
-
maxEntriesPerView?: number | null;
|
|
84
|
-
};
|
|
85
|
+
config: HyperstackConfig;
|
|
85
86
|
}
|
|
86
87
|
declare function HyperstackProvider({ children, fallback, ...config }: HyperstackConfig & {
|
|
87
88
|
children: ReactNode;
|
|
@@ -185,7 +186,7 @@ type StackClient<TStack extends StackDefinition> = {
|
|
|
185
186
|
isLoading: boolean;
|
|
186
187
|
error: Error | null;
|
|
187
188
|
};
|
|
188
|
-
declare function useHyperstack<TStack extends StackDefinition>(stack: TStack): StackClient<TStack>;
|
|
189
|
+
declare function useHyperstack<TStack extends StackDefinition>(stack: TStack, options?: UseHyperstackOptions): StackClient<TStack>;
|
|
189
190
|
|
|
190
191
|
export { HyperstackProvider, ZustandAdapter, useConnectionState, useEntity, useHyperstack, useHyperstackContext, useInstructionMutation, useView };
|
|
191
|
-
export type { HyperStackStore, HyperstackConfig, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, MutationStatus,
|
|
192
|
+
export type { HyperStackStore, HyperstackConfig, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, MutationStatus, StateViewHook, TransactionDefinition, UseHyperstackOptions, UseMutationOptions, UseMutationResult, UseMutationReturn, ViewHookOptions, ViewHookResult, ViewMode };
|
package/dist/index.esm.js
CHANGED
|
@@ -8267,66 +8267,36 @@ class HyperStack {
|
|
|
8267
8267
|
}
|
|
8268
8268
|
|
|
8269
8269
|
const HyperstackContext = createContext(null);
|
|
8270
|
-
function resolveNetworkConfig(network, websocketUrl) {
|
|
8271
|
-
if (websocketUrl) {
|
|
8272
|
-
return {
|
|
8273
|
-
name: 'custom',
|
|
8274
|
-
websocketUrl
|
|
8275
|
-
};
|
|
8276
|
-
}
|
|
8277
|
-
if (typeof network === 'object') {
|
|
8278
|
-
return network;
|
|
8279
|
-
}
|
|
8280
|
-
if (network === 'mainnet') {
|
|
8281
|
-
return {
|
|
8282
|
-
name: 'mainnet',
|
|
8283
|
-
websocketUrl: 'wss://mainnet.hyperstack.xyz',
|
|
8284
|
-
};
|
|
8285
|
-
}
|
|
8286
|
-
if (network === 'devnet') {
|
|
8287
|
-
return {
|
|
8288
|
-
name: 'devnet',
|
|
8289
|
-
websocketUrl: 'ws://localhost:8080',
|
|
8290
|
-
};
|
|
8291
|
-
}
|
|
8292
|
-
if (network === 'localnet') {
|
|
8293
|
-
return {
|
|
8294
|
-
name: 'localnet',
|
|
8295
|
-
websocketUrl: 'ws://localhost:8080',
|
|
8296
|
-
};
|
|
8297
|
-
}
|
|
8298
|
-
throw new Error('Must provide either network or websocketUrl');
|
|
8299
|
-
}
|
|
8300
8270
|
function HyperstackProvider({ children, fallback = null, ...config }) {
|
|
8301
|
-
const networkConfig = resolveNetworkConfig(config.network, config.websocketUrl);
|
|
8302
8271
|
const clientsRef = useRef(new Map());
|
|
8303
8272
|
const connectingRef = useRef(new Map());
|
|
8304
|
-
const getOrCreateClient = useCallback(async (stack) => {
|
|
8305
|
-
const
|
|
8273
|
+
const getOrCreateClient = useCallback(async (stack, urlOverride) => {
|
|
8274
|
+
const cacheKey = urlOverride ? `${stack.name}:${urlOverride}` : stack.name;
|
|
8275
|
+
const existing = clientsRef.current.get(cacheKey);
|
|
8306
8276
|
if (existing) {
|
|
8307
8277
|
return existing.client;
|
|
8308
8278
|
}
|
|
8309
|
-
const connecting = connectingRef.current.get(
|
|
8279
|
+
const connecting = connectingRef.current.get(cacheKey);
|
|
8310
8280
|
if (connecting) {
|
|
8311
8281
|
return connecting;
|
|
8312
8282
|
}
|
|
8313
8283
|
const connectionPromise = HyperStack.connect(stack, {
|
|
8314
|
-
url:
|
|
8284
|
+
url: urlOverride,
|
|
8315
8285
|
autoReconnect: config.autoConnect,
|
|
8316
8286
|
reconnectIntervals: config.reconnectIntervals,
|
|
8317
8287
|
maxReconnectAttempts: config.maxReconnectAttempts,
|
|
8318
8288
|
maxEntriesPerView: config.maxEntriesPerView,
|
|
8319
8289
|
}).then((client) => {
|
|
8320
|
-
clientsRef.current.set(
|
|
8290
|
+
clientsRef.current.set(cacheKey, {
|
|
8321
8291
|
client,
|
|
8322
8292
|
disconnect: () => client.disconnect()
|
|
8323
8293
|
});
|
|
8324
|
-
connectingRef.current.delete(
|
|
8294
|
+
connectingRef.current.delete(cacheKey);
|
|
8325
8295
|
return client;
|
|
8326
8296
|
});
|
|
8327
|
-
connectingRef.current.set(
|
|
8297
|
+
connectingRef.current.set(cacheKey, connectionPromise);
|
|
8328
8298
|
return connectionPromise;
|
|
8329
|
-
}, [
|
|
8299
|
+
}, [config.autoConnect, config.reconnectIntervals, config.maxReconnectAttempts, config.maxEntriesPerView]);
|
|
8330
8300
|
const getClient = useCallback((stack) => {
|
|
8331
8301
|
if (!stack)
|
|
8332
8302
|
return null;
|
|
@@ -8345,13 +8315,7 @@ function HyperstackProvider({ children, fallback = null, ...config }) {
|
|
|
8345
8315
|
const value = {
|
|
8346
8316
|
getOrCreateClient,
|
|
8347
8317
|
getClient,
|
|
8348
|
-
config
|
|
8349
|
-
websocketUrl: networkConfig.websocketUrl,
|
|
8350
|
-
autoConnect: config.autoConnect,
|
|
8351
|
-
reconnectIntervals: config.reconnectIntervals,
|
|
8352
|
-
maxReconnectAttempts: config.maxReconnectAttempts,
|
|
8353
|
-
maxEntriesPerView: config.maxEntriesPerView,
|
|
8354
|
-
}
|
|
8318
|
+
config,
|
|
8355
8319
|
};
|
|
8356
8320
|
return (React.createElement(HyperstackContext.Provider, { value: value }, children));
|
|
8357
8321
|
}
|
|
@@ -8699,21 +8663,22 @@ function useInstructionMutation(execute) {
|
|
|
8699
8663
|
};
|
|
8700
8664
|
}
|
|
8701
8665
|
|
|
8702
|
-
function useHyperstack(stack) {
|
|
8666
|
+
function useHyperstack(stack, options) {
|
|
8703
8667
|
const { getOrCreateClient, getClient } = useHyperstackContext();
|
|
8668
|
+
const urlOverride = options?.url;
|
|
8704
8669
|
const [client, setClient] = useState(getClient(stack));
|
|
8705
8670
|
const [isLoading, setIsLoading] = useState(!client);
|
|
8706
8671
|
const [error, setError] = useState(null);
|
|
8707
8672
|
useEffect(() => {
|
|
8708
8673
|
const existingClient = getClient(stack);
|
|
8709
|
-
if (existingClient) {
|
|
8674
|
+
if (existingClient && !urlOverride) {
|
|
8710
8675
|
setClient(existingClient);
|
|
8711
8676
|
setIsLoading(false);
|
|
8712
8677
|
return;
|
|
8713
8678
|
}
|
|
8714
8679
|
setIsLoading(true);
|
|
8715
8680
|
setError(null);
|
|
8716
|
-
getOrCreateClient(stack)
|
|
8681
|
+
getOrCreateClient(stack, urlOverride)
|
|
8717
8682
|
.then((newClient) => {
|
|
8718
8683
|
setClient(newClient);
|
|
8719
8684
|
setIsLoading(false);
|
|
@@ -8722,7 +8687,7 @@ function useHyperstack(stack) {
|
|
|
8722
8687
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
8723
8688
|
setIsLoading(false);
|
|
8724
8689
|
});
|
|
8725
|
-
}, [stack, getOrCreateClient, getClient]);
|
|
8690
|
+
}, [stack, getOrCreateClient, getClient, urlOverride]);
|
|
8726
8691
|
const views = useMemo(() => {
|
|
8727
8692
|
const result = {};
|
|
8728
8693
|
for (const [viewName, viewGroup] of Object.entries(stack.views)) {
|