hyperstack-react 0.3.13 → 0.3.15
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 +50 -69
- package/dist/index.esm.js +1105 -522
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1115 -521
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
|
@@ -8,11 +8,6 @@ interface NetworkConfig {
|
|
|
8
8
|
name: string;
|
|
9
9
|
websocketUrl: string;
|
|
10
10
|
}
|
|
11
|
-
interface ViewDef<T, TMode extends ViewMode> {
|
|
12
|
-
readonly mode: TMode;
|
|
13
|
-
readonly view: string;
|
|
14
|
-
readonly _entity?: T;
|
|
15
|
-
}
|
|
16
11
|
interface TransactionDefinition<TParams = unknown> {
|
|
17
12
|
build: (params: TParams) => {
|
|
18
13
|
instruction: string;
|
|
@@ -23,17 +18,6 @@ interface TransactionDefinition<TParams = unknown> {
|
|
|
23
18
|
key?: string | ((params: TParams) => string);
|
|
24
19
|
}>;
|
|
25
20
|
}
|
|
26
|
-
interface StackDefinition {
|
|
27
|
-
readonly name: string;
|
|
28
|
-
readonly views: Record<string, ViewGroup>;
|
|
29
|
-
transactions?: Record<string, TransactionDefinition>;
|
|
30
|
-
}
|
|
31
|
-
interface ViewGroup {
|
|
32
|
-
state?: ViewDef<unknown, 'state'>;
|
|
33
|
-
list?: ViewDef<unknown, 'list'>;
|
|
34
|
-
/** Allow arbitrary derived views with any name */
|
|
35
|
-
[key: string]: ViewDef<unknown, ViewMode> | undefined;
|
|
36
|
-
}
|
|
37
21
|
interface HyperstackConfig {
|
|
38
22
|
websocketUrl?: string;
|
|
39
23
|
network?: 'devnet' | 'mainnet' | 'localnet' | NetworkConfig;
|
|
@@ -43,18 +27,8 @@ interface HyperstackConfig {
|
|
|
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
|
-
interface WalletAdapter {
|
|
55
|
-
publicKey: string;
|
|
56
|
-
signAndSend: (transaction: unknown) => Promise<string>;
|
|
57
|
-
}
|
|
58
32
|
interface ViewHookOptions {
|
|
59
33
|
enabled?: boolean;
|
|
60
34
|
initialData?: unknown;
|
|
@@ -98,6 +72,41 @@ interface ListViewHook<T> {
|
|
|
98
72
|
useOne: (params?: Omit<ListParamsBase, 'take'>, options?: ViewHookOptions) => ViewHookResult<T | undefined>;
|
|
99
73
|
}
|
|
100
74
|
|
|
75
|
+
interface HyperstackContextValue {
|
|
76
|
+
getOrCreateClient: <TStack extends StackDefinition>(stack: TStack) => Promise<HyperStack<TStack>>;
|
|
77
|
+
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
|
+
}
|
|
86
|
+
declare function HyperstackProvider({ children, fallback, ...config }: HyperstackConfig & {
|
|
87
|
+
children: ReactNode;
|
|
88
|
+
fallback?: ReactNode;
|
|
89
|
+
}): React.JSX.Element;
|
|
90
|
+
declare function useHyperstackContext(): HyperstackContextValue;
|
|
91
|
+
declare function useConnectionState(stack?: StackDefinition): ConnectionState;
|
|
92
|
+
declare function useView<T>(stack: StackDefinition, viewPath: string): T[];
|
|
93
|
+
declare function useEntity<T>(stack: StackDefinition, viewPath: string, key: string): T | null;
|
|
94
|
+
|
|
95
|
+
type MutationStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
96
|
+
interface UseMutationOptions extends InstructionExecutorOptions {
|
|
97
|
+
onSuccess?: (result: ExecutionResult) => void;
|
|
98
|
+
onError?: (error: Error) => void;
|
|
99
|
+
}
|
|
100
|
+
interface UseMutationResult {
|
|
101
|
+
submit: (args: Record<string, unknown>, options?: Partial<UseMutationOptions>) => Promise<ExecutionResult>;
|
|
102
|
+
status: MutationStatus;
|
|
103
|
+
error: string | null;
|
|
104
|
+
signature: string | null;
|
|
105
|
+
isLoading: boolean;
|
|
106
|
+
reset: () => void;
|
|
107
|
+
}
|
|
108
|
+
declare function useInstructionMutation(execute: InstructionExecutor): UseMutationResult;
|
|
109
|
+
|
|
101
110
|
interface ZustandState {
|
|
102
111
|
entities: Map<string, Map<string, unknown>>;
|
|
103
112
|
sortedKeys: Map<string, string[]>;
|
|
@@ -141,37 +150,6 @@ declare class ZustandAdapter implements StorageAdapter {
|
|
|
141
150
|
private rebuildSortedKeys;
|
|
142
151
|
}
|
|
143
152
|
|
|
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
153
|
type ViewHookForDef<TDef> = TDef extends ViewDef<infer T, 'state'> ? {
|
|
176
154
|
use: (key?: Record<string, string>, options?: ViewHookOptions) => ViewHookResult<T>;
|
|
177
155
|
} : TDef extends ViewDef<infer T, 'list'> ? {
|
|
@@ -192,19 +170,22 @@ type BuildViewInterface<TViews extends Record<string, ViewGroup>> = {
|
|
|
192
170
|
[SubK in keyof TViews[K] as TViews[K][SubK] extends ViewDef<unknown, ViewMode> ? SubK : never]: ViewHookForDef<TViews[K][SubK]>;
|
|
193
171
|
};
|
|
194
172
|
};
|
|
173
|
+
type InstructionHook = {
|
|
174
|
+
useMutation: () => UseMutationResult;
|
|
175
|
+
execute: InstructionExecutor;
|
|
176
|
+
};
|
|
177
|
+
type BuildInstructionInterface<TInstructions extends Record<string, InstructionHandler> | undefined> = TInstructions extends Record<string, InstructionHandler> ? {
|
|
178
|
+
[K in keyof TInstructions]: InstructionHook;
|
|
179
|
+
} : {};
|
|
195
180
|
type StackClient<TStack extends StackDefinition> = {
|
|
196
181
|
views: BuildViewInterface<TStack['views']>;
|
|
197
|
-
|
|
198
|
-
[K in keyof TStack['transactions']]: TStack['transactions'][K]['build'];
|
|
199
|
-
} & {
|
|
200
|
-
useMutation: () => UseMutationReturn;
|
|
201
|
-
} : {
|
|
202
|
-
useMutation: () => UseMutationReturn;
|
|
203
|
-
};
|
|
182
|
+
instructions: BuildInstructionInterface<TStack['instructions']>;
|
|
204
183
|
zustandStore: UseBoundStore<StoreApi<HyperStackStore>>;
|
|
205
|
-
|
|
184
|
+
client: HyperStack<TStack>;
|
|
185
|
+
isLoading: boolean;
|
|
186
|
+
error: Error | null;
|
|
206
187
|
};
|
|
207
188
|
declare function useHyperstack<TStack extends StackDefinition>(stack: TStack): StackClient<TStack>;
|
|
208
189
|
|
|
209
|
-
export { HyperstackProvider, ZustandAdapter,
|
|
210
|
-
export type { HyperStackStore, HyperstackConfig,
|
|
190
|
+
export { HyperstackProvider, ZustandAdapter, useConnectionState, useEntity, useHyperstack, useHyperstackContext, useInstructionMutation, useView };
|
|
191
|
+
export type { HyperStackStore, HyperstackConfig, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, MutationStatus, NetworkConfig, StateViewHook, TransactionDefinition, UseMutationOptions, UseMutationResult, UseMutationReturn, ViewHookOptions, ViewHookResult, ViewMode };
|