hyperstack-react 0.3.14 → 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 +58 -76
- package/dist/index.esm.js +1070 -522
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1080 -521
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate,
|
|
3
|
-
export { ConnectionManager, ConnectionState, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityFrame, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, HyperStack, HyperStackConfig, HyperStackError, HyperStackOptions, HyperStackOptionsWithStorage, MemoryAdapter, RichUpdate, RichUpdateCallback, SnapshotEntity, SnapshotFrame, StorageAdapter, StorageAdapterConfig, Subscription, SubscriptionRegistry, Update, UpdateCallback, isSnapshotFrame, isValidFrame, parseFrame, parseFrameFromBlob } from 'hyperstack-typescript';
|
|
2
|
+
import { WalletAdapter, StackDefinition, ConnectionState, HyperStack, InstructionExecutorOptions, ExecutionResult, InstructionExecutor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, ViewGroup, ViewDef, InstructionHandler } from 'hyperstack-typescript';
|
|
3
|
+
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, ArgSchema, ArgType, BuiltInstruction, ConfirmationLevel, ConnectionManager, ConnectionState, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, HyperStack, HyperStackConfig, HyperStackError, HyperStackOptions, HyperStackOptionsWithStorage, InstructionDefinition, InstructionExecutor, InstructionExecutorOptions, InstructionHandler, MemoryAdapter, PdaConfig, PdaSeed, ProgramError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, SnapshotEntity, SnapshotFrame, StackDefinition, StorageAdapter, StorageAdapterConfig, Subscription, SubscriptionRegistry, Update, UpdateCallback, ViewDef, ViewGroup, WalletAdapter, WalletConnectOptions, WalletState, createInstructionExecutor, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, isSnapshotFrame, isValidFrame, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, serializeInstructionData, validateAccountResolution, waitForConfirmation } from 'hyperstack-typescript';
|
|
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
|
-
interface ViewDef<T, TMode extends ViewMode> {
|
|
12
|
-
readonly mode: TMode;
|
|
13
|
-
readonly view: string;
|
|
14
|
-
readonly _entity?: T;
|
|
15
|
-
}
|
|
16
7
|
interface TransactionDefinition<TParams = unknown> {
|
|
17
8
|
build: (params: TParams) => {
|
|
18
9
|
instruction: string;
|
|
@@ -23,37 +14,27 @@ interface TransactionDefinition<TParams = unknown> {
|
|
|
23
14
|
key?: string | ((params: TParams) => string);
|
|
24
15
|
}>;
|
|
25
16
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
list?: ViewDef<unknown, 'list'>;
|
|
34
|
-
/** Allow arbitrary derived views with any name */
|
|
35
|
-
[key: string]: ViewDef<unknown, ViewMode> | undefined;
|
|
36
|
-
}
|
|
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
|
+
*/
|
|
37
24
|
interface HyperstackConfig {
|
|
38
|
-
websocketUrl?: string;
|
|
39
|
-
network?: 'devnet' | 'mainnet' | 'localnet' | NetworkConfig;
|
|
40
|
-
apiKey?: string;
|
|
41
25
|
autoConnect?: boolean;
|
|
42
26
|
wallet?: WalletAdapter;
|
|
43
27
|
reconnectIntervals?: number[];
|
|
44
28
|
maxReconnectAttempts?: number;
|
|
45
29
|
maxEntriesPerView?: number | null;
|
|
46
|
-
/**
|
|
47
|
-
* Interval in milliseconds to buffer WebSocket updates before flushing to Zustand.
|
|
48
|
-
* Reduces React re-renders during high-frequency updates.
|
|
49
|
-
* Default: 16ms (one frame at 60fps)
|
|
50
|
-
* Set to 0 for immediate updates (no buffering).
|
|
51
|
-
*/
|
|
52
30
|
flushIntervalMs?: number;
|
|
53
31
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Options for useHyperstack hook
|
|
34
|
+
*/
|
|
35
|
+
interface UseHyperstackOptions {
|
|
36
|
+
/** Override the stack's embedded URL (useful for local development) */
|
|
37
|
+
url?: string;
|
|
57
38
|
}
|
|
58
39
|
interface ViewHookOptions {
|
|
59
40
|
enabled?: boolean;
|
|
@@ -98,6 +79,35 @@ interface ListViewHook<T> {
|
|
|
98
79
|
useOne: (params?: Omit<ListParamsBase, 'take'>, options?: ViewHookOptions) => ViewHookResult<T | undefined>;
|
|
99
80
|
}
|
|
100
81
|
|
|
82
|
+
interface HyperstackContextValue {
|
|
83
|
+
getOrCreateClient: <TStack extends StackDefinition>(stack: TStack, urlOverride?: string) => Promise<HyperStack<TStack>>;
|
|
84
|
+
getClient: <TStack extends StackDefinition>(stack: TStack | undefined) => HyperStack<TStack> | null;
|
|
85
|
+
config: HyperstackConfig;
|
|
86
|
+
}
|
|
87
|
+
declare function HyperstackProvider({ children, fallback, ...config }: HyperstackConfig & {
|
|
88
|
+
children: ReactNode;
|
|
89
|
+
fallback?: ReactNode;
|
|
90
|
+
}): React.JSX.Element;
|
|
91
|
+
declare function useHyperstackContext(): HyperstackContextValue;
|
|
92
|
+
declare function useConnectionState(stack?: StackDefinition): ConnectionState;
|
|
93
|
+
declare function useView<T>(stack: StackDefinition, viewPath: string): T[];
|
|
94
|
+
declare function useEntity<T>(stack: StackDefinition, viewPath: string, key: string): T | null;
|
|
95
|
+
|
|
96
|
+
type MutationStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
97
|
+
interface UseMutationOptions extends InstructionExecutorOptions {
|
|
98
|
+
onSuccess?: (result: ExecutionResult) => void;
|
|
99
|
+
onError?: (error: Error) => void;
|
|
100
|
+
}
|
|
101
|
+
interface UseMutationResult {
|
|
102
|
+
submit: (args: Record<string, unknown>, options?: Partial<UseMutationOptions>) => Promise<ExecutionResult>;
|
|
103
|
+
status: MutationStatus;
|
|
104
|
+
error: string | null;
|
|
105
|
+
signature: string | null;
|
|
106
|
+
isLoading: boolean;
|
|
107
|
+
reset: () => void;
|
|
108
|
+
}
|
|
109
|
+
declare function useInstructionMutation(execute: InstructionExecutor): UseMutationResult;
|
|
110
|
+
|
|
101
111
|
interface ZustandState {
|
|
102
112
|
entities: Map<string, Map<string, unknown>>;
|
|
103
113
|
sortedKeys: Map<string, string[]>;
|
|
@@ -141,37 +151,6 @@ declare class ZustandAdapter implements StorageAdapter {
|
|
|
141
151
|
private rebuildSortedKeys;
|
|
142
152
|
}
|
|
143
153
|
|
|
144
|
-
interface SubscriptionHandle {
|
|
145
|
-
view: string;
|
|
146
|
-
key?: string;
|
|
147
|
-
filters?: Record<string, string>;
|
|
148
|
-
take?: number;
|
|
149
|
-
skip?: number;
|
|
150
|
-
unsubscribe: () => void;
|
|
151
|
-
}
|
|
152
|
-
interface HyperstackRuntime {
|
|
153
|
-
zustandStore: UseBoundStore<StoreApi<HyperStackStore>>;
|
|
154
|
-
adapter: ZustandAdapter;
|
|
155
|
-
connection: ConnectionManager;
|
|
156
|
-
subscriptionRegistry: SubscriptionRegistry;
|
|
157
|
-
wallet?: WalletAdapter;
|
|
158
|
-
subscribe(view: string, key?: string, filters?: Record<string, string>, take?: number, skip?: number): SubscriptionHandle;
|
|
159
|
-
unsubscribe(handle: SubscriptionHandle): void;
|
|
160
|
-
}
|
|
161
|
-
declare function createRuntime(config: HyperstackConfig): HyperstackRuntime;
|
|
162
|
-
|
|
163
|
-
interface HyperstackContextValue {
|
|
164
|
-
runtime: HyperstackRuntime;
|
|
165
|
-
config: HyperstackConfig;
|
|
166
|
-
}
|
|
167
|
-
declare function HyperstackProvider({ children, ...config }: HyperstackConfig & {
|
|
168
|
-
children: ReactNode;
|
|
169
|
-
}): React.JSX.Element;
|
|
170
|
-
declare function useHyperstackContext(): HyperstackContextValue;
|
|
171
|
-
declare function useConnectionState(): ConnectionState;
|
|
172
|
-
declare function useView<T>(viewPath: string): T[];
|
|
173
|
-
declare function useEntity<T>(viewPath: string, key: string): T | null;
|
|
174
|
-
|
|
175
154
|
type ViewHookForDef<TDef> = TDef extends ViewDef<infer T, 'state'> ? {
|
|
176
155
|
use: (key?: Record<string, string>, options?: ViewHookOptions) => ViewHookResult<T>;
|
|
177
156
|
} : TDef extends ViewDef<infer T, 'list'> ? {
|
|
@@ -192,19 +171,22 @@ type BuildViewInterface<TViews extends Record<string, ViewGroup>> = {
|
|
|
192
171
|
[SubK in keyof TViews[K] as TViews[K][SubK] extends ViewDef<unknown, ViewMode> ? SubK : never]: ViewHookForDef<TViews[K][SubK]>;
|
|
193
172
|
};
|
|
194
173
|
};
|
|
174
|
+
type InstructionHook = {
|
|
175
|
+
useMutation: () => UseMutationResult;
|
|
176
|
+
execute: InstructionExecutor;
|
|
177
|
+
};
|
|
178
|
+
type BuildInstructionInterface<TInstructions extends Record<string, InstructionHandler> | undefined> = TInstructions extends Record<string, InstructionHandler> ? {
|
|
179
|
+
[K in keyof TInstructions]: InstructionHook;
|
|
180
|
+
} : {};
|
|
195
181
|
type StackClient<TStack extends StackDefinition> = {
|
|
196
182
|
views: BuildViewInterface<TStack['views']>;
|
|
197
|
-
|
|
198
|
-
[K in keyof TStack['transactions']]: TStack['transactions'][K]['build'];
|
|
199
|
-
} & {
|
|
200
|
-
useMutation: () => UseMutationReturn;
|
|
201
|
-
} : {
|
|
202
|
-
useMutation: () => UseMutationReturn;
|
|
203
|
-
};
|
|
183
|
+
instructions: BuildInstructionInterface<TStack['instructions']>;
|
|
204
184
|
zustandStore: UseBoundStore<StoreApi<HyperStackStore>>;
|
|
205
|
-
|
|
185
|
+
client: HyperStack<TStack>;
|
|
186
|
+
isLoading: boolean;
|
|
187
|
+
error: Error | null;
|
|
206
188
|
};
|
|
207
|
-
declare function useHyperstack<TStack extends StackDefinition>(stack: TStack): StackClient<TStack>;
|
|
189
|
+
declare function useHyperstack<TStack extends StackDefinition>(stack: TStack, options?: UseHyperstackOptions): StackClient<TStack>;
|
|
208
190
|
|
|
209
|
-
export { HyperstackProvider, ZustandAdapter,
|
|
210
|
-
export type { HyperStackStore, HyperstackConfig,
|
|
191
|
+
export { HyperstackProvider, ZustandAdapter, useConnectionState, useEntity, useHyperstack, useHyperstackContext, useInstructionMutation, useView };
|
|
192
|
+
export type { HyperStackStore, HyperstackConfig, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, MutationStatus, StateViewHook, TransactionDefinition, UseHyperstackOptions, UseMutationOptions, UseMutationResult, UseMutationReturn, ViewHookOptions, ViewHookResult, ViewMode };
|