hyperstack-react 0.2.5 → 0.3.1
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 +46 -129
- package/dist/index.esm.js +7639 -302
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +7650 -302
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,8 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ConnectionState, ConnectionManager, SubscriptionRegistry } from 'hyperstack-typescript';
|
|
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';
|
|
4
|
+
import { UseBoundStore, StoreApi } from 'zustand';
|
|
3
5
|
|
|
4
|
-
interface EntityFrame<T = unknown> {
|
|
5
|
-
mode: 'state' | 'append' | 'list';
|
|
6
|
-
entity: string;
|
|
7
|
-
op: 'create' | 'upsert' | 'patch' | 'delete' | 'snapshot';
|
|
8
|
-
key: string;
|
|
9
|
-
data: T;
|
|
10
|
-
append?: string[];
|
|
11
|
-
}
|
|
12
|
-
interface SnapshotEntity<T = unknown> {
|
|
13
|
-
key: string;
|
|
14
|
-
data: T;
|
|
15
|
-
}
|
|
16
|
-
interface SnapshotFrame<T = unknown> {
|
|
17
|
-
mode: 'state' | 'append' | 'list';
|
|
18
|
-
entity: string;
|
|
19
|
-
op: 'snapshot';
|
|
20
|
-
data: SnapshotEntity<T>[];
|
|
21
|
-
}
|
|
22
|
-
type Frame<T = unknown> = EntityFrame<T> | SnapshotFrame<T>;
|
|
23
|
-
declare function isSnapshotFrame<T>(frame: Frame<T>): frame is SnapshotFrame<T>;
|
|
24
|
-
interface Subscription {
|
|
25
|
-
view: string;
|
|
26
|
-
key?: string;
|
|
27
|
-
partition?: string;
|
|
28
|
-
filters?: Record<string, string>;
|
|
29
|
-
}
|
|
30
|
-
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error' | 'reconnecting';
|
|
31
|
-
interface HyperState<T = unknown> {
|
|
32
|
-
connectionState: ConnectionState;
|
|
33
|
-
lastError?: string;
|
|
34
|
-
entities: Map<string, Map<string, T>>;
|
|
35
|
-
recentFrames: EntityFrame<T>[];
|
|
36
|
-
}
|
|
37
|
-
interface HyperSDKConfig {
|
|
38
|
-
websocketUrl?: string;
|
|
39
|
-
reconnectIntervals?: number[];
|
|
40
|
-
maxReconnectAttempts?: number;
|
|
41
|
-
initialSubscriptions?: Subscription[];
|
|
42
|
-
autoSubscribeDefault?: boolean;
|
|
43
|
-
maxEntriesPerView?: number | null;
|
|
44
|
-
}
|
|
45
|
-
declare const DEFAULT_CONFIG: HyperSDKConfig;
|
|
46
|
-
declare class HyperStreamError extends Error {
|
|
47
|
-
code: string;
|
|
48
|
-
details?: unknown | undefined;
|
|
49
|
-
constructor(message: string, code: string, details?: unknown | undefined);
|
|
50
|
-
}
|
|
51
6
|
type ViewMode = 'state' | 'list';
|
|
52
7
|
interface NetworkConfig {
|
|
53
8
|
name: string;
|
|
@@ -83,6 +38,9 @@ interface HyperstackConfig {
|
|
|
83
38
|
apiKey?: string;
|
|
84
39
|
autoConnect?: boolean;
|
|
85
40
|
wallet?: WalletAdapter;
|
|
41
|
+
reconnectIntervals?: number[];
|
|
42
|
+
maxReconnectAttempts?: number;
|
|
43
|
+
maxEntriesPerView?: number | null;
|
|
86
44
|
}
|
|
87
45
|
interface WalletAdapter {
|
|
88
46
|
publicKey: string;
|
|
@@ -121,86 +79,41 @@ interface ListViewHook<T> {
|
|
|
121
79
|
use: (params?: ListParams, options?: ViewHookOptions) => ViewHookResult<T[]>;
|
|
122
80
|
}
|
|
123
81
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
private config;
|
|
129
|
-
private reconnectAttempts;
|
|
130
|
-
private reconnectTimeout;
|
|
131
|
-
private pingInterval;
|
|
132
|
-
private currentState;
|
|
133
|
-
private subscriptionQueue;
|
|
134
|
-
private activeSubscriptions;
|
|
135
|
-
private onFrame?;
|
|
136
|
-
private onStateChange?;
|
|
137
|
-
constructor(config?: Partial<HyperSDKConfig>);
|
|
138
|
-
setHandlers(handlers: {
|
|
139
|
-
onFrame?: FrameHandler;
|
|
140
|
-
onStateChange?: StateHandler;
|
|
141
|
-
}): void;
|
|
142
|
-
getState(): ConnectionState;
|
|
143
|
-
getConfig(): HyperSDKConfig;
|
|
144
|
-
connect(): void;
|
|
145
|
-
disconnect(): void;
|
|
146
|
-
updateConfig(newConfig: Partial<HyperSDKConfig>): void;
|
|
147
|
-
subscribe(subscription: Subscription): void;
|
|
148
|
-
unsubscribe(view: string, key?: string): void;
|
|
149
|
-
private makeSubKey;
|
|
150
|
-
private resubscribeActive;
|
|
151
|
-
private parseBinaryFrame;
|
|
152
|
-
private updateState;
|
|
153
|
-
private handleReconnect;
|
|
154
|
-
private clearReconnectTimeout;
|
|
155
|
-
private startPingInterval;
|
|
156
|
-
private stopPingInterval;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
declare class ViewData<T = unknown> {
|
|
160
|
-
private entities;
|
|
161
|
-
private accessOrder;
|
|
162
|
-
get(key: string): T | undefined;
|
|
163
|
-
set(key: string, value: T): void;
|
|
164
|
-
delete(key: string): boolean;
|
|
165
|
-
has(key: string): boolean;
|
|
166
|
-
values(): IterableIterator<T>;
|
|
167
|
-
keys(): string[];
|
|
168
|
-
get size(): number;
|
|
169
|
-
touch(key: string): void;
|
|
170
|
-
evictOldest(): string | undefined;
|
|
171
|
-
toMap(): Map<string, T>;
|
|
172
|
-
}
|
|
173
|
-
type SubKey = string;
|
|
174
|
-
interface SubscriptionTracker {
|
|
175
|
-
subscription: Subscription;
|
|
176
|
-
refCount: number;
|
|
177
|
-
}
|
|
178
|
-
interface ViewMetadata {
|
|
179
|
-
mode: ViewMode;
|
|
180
|
-
keys: string[];
|
|
181
|
-
lastArgs?: any;
|
|
182
|
-
lastUpdatedAt?: number;
|
|
82
|
+
interface ZustandState {
|
|
83
|
+
entities: Map<string, Map<string, unknown>>;
|
|
84
|
+
connectionState: ConnectionState;
|
|
85
|
+
lastError?: string;
|
|
183
86
|
}
|
|
184
|
-
interface
|
|
185
|
-
|
|
87
|
+
interface ZustandActions {
|
|
88
|
+
_set: <T>(viewPath: string, key: string, data: T) => void;
|
|
89
|
+
_delete: (viewPath: string, key: string) => void;
|
|
90
|
+
_clear: (viewPath?: string) => void;
|
|
91
|
+
_setConnectionState: (state: ConnectionState, error?: string) => void;
|
|
186
92
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
93
|
+
type HyperStackStore = ZustandState & ZustandActions;
|
|
94
|
+
declare class ZustandAdapter implements StorageAdapter {
|
|
95
|
+
private updateCallbacks;
|
|
96
|
+
private richUpdateCallbacks;
|
|
97
|
+
private accessOrder;
|
|
98
|
+
readonly store: UseBoundStore<StoreApi<HyperStackStore>>;
|
|
99
|
+
constructor(_config?: StorageAdapterConfig);
|
|
100
|
+
get<T>(viewPath: string, key: string): T | null;
|
|
101
|
+
getAll<T>(viewPath: string): T[];
|
|
102
|
+
getAllSync<T>(viewPath: string): T[] | undefined;
|
|
103
|
+
getSync<T>(viewPath: string, key: string): T | null | undefined;
|
|
104
|
+
has(viewPath: string, key: string): boolean;
|
|
105
|
+
keys(viewPath: string): string[];
|
|
106
|
+
size(viewPath: string): number;
|
|
107
|
+
set<T>(viewPath: string, key: string, data: T): void;
|
|
108
|
+
delete(viewPath: string, key: string): void;
|
|
109
|
+
clear(viewPath?: string): void;
|
|
110
|
+
evictOldest(viewPath: string): string | undefined;
|
|
111
|
+
onUpdate(callback: UpdateCallback): () => void;
|
|
112
|
+
onRichUpdate(callback: RichUpdateCallback): () => void;
|
|
113
|
+
notifyUpdate<T>(viewPath: string, key: string, update: Update<T>): void;
|
|
114
|
+
notifyRichUpdate<T>(viewPath: string, key: string, update: RichUpdate<T>): void;
|
|
115
|
+
setConnectionState(state: ConnectionState, error?: string): void;
|
|
202
116
|
}
|
|
203
|
-
declare function createHyperStore(config?: Partial<HyperSDKConfig>): zustand.UseBoundStore<zustand.StoreApi<HyperStore>>;
|
|
204
117
|
|
|
205
118
|
interface SubscriptionHandle {
|
|
206
119
|
view: string;
|
|
@@ -209,8 +122,10 @@ interface SubscriptionHandle {
|
|
|
209
122
|
unsubscribe: () => void;
|
|
210
123
|
}
|
|
211
124
|
interface HyperstackRuntime {
|
|
212
|
-
|
|
125
|
+
zustandStore: UseBoundStore<StoreApi<HyperStackStore>>;
|
|
126
|
+
adapter: ZustandAdapter;
|
|
213
127
|
connection: ConnectionManager;
|
|
128
|
+
subscriptionRegistry: SubscriptionRegistry;
|
|
214
129
|
wallet?: WalletAdapter;
|
|
215
130
|
subscribe(view: string, key?: string, filters?: Record<string, string>): SubscriptionHandle;
|
|
216
131
|
unsubscribe(handle: SubscriptionHandle): void;
|
|
@@ -226,6 +141,8 @@ declare function HyperstackProvider({ children, ...config }: HyperstackConfig &
|
|
|
226
141
|
}): React.JSX.Element;
|
|
227
142
|
declare function useHyperstackContext(): HyperstackContextValue;
|
|
228
143
|
declare function useConnectionState(): ConnectionState;
|
|
144
|
+
declare function useView<T>(viewPath: string): T[];
|
|
145
|
+
declare function useEntity<T>(viewPath: string, key: string): T | null;
|
|
229
146
|
|
|
230
147
|
type BuildViewInterface<TViews extends Record<string, ViewGroup>> = {
|
|
231
148
|
[K in keyof TViews]: TViews[K] extends {
|
|
@@ -261,10 +178,10 @@ type StackClient<TStack extends StackDefinition> = {
|
|
|
261
178
|
} : {
|
|
262
179
|
useMutation: () => UseMutationReturn;
|
|
263
180
|
};
|
|
264
|
-
|
|
181
|
+
zustandStore: UseBoundStore<StoreApi<HyperStackStore>>;
|
|
265
182
|
runtime: HyperstackRuntime;
|
|
266
183
|
};
|
|
267
184
|
declare function useHyperstack<TStack extends StackDefinition>(stack: TStack): StackClient<TStack>;
|
|
268
185
|
|
|
269
|
-
export {
|
|
270
|
-
export type {
|
|
186
|
+
export { HyperstackProvider, ZustandAdapter, createRuntime, useConnectionState, useEntity, useHyperstack, useHyperstackContext, useView };
|
|
187
|
+
export type { HyperStackStore, HyperstackConfig, HyperstackRuntime, ListParams, ListViewHook, NetworkConfig, StackDefinition, StateViewHook, SubscriptionHandle, TransactionDefinition, UseMutationReturn, ViewDef, ViewGroup, ViewHookOptions, ViewHookResult, ViewMode, WalletAdapter };
|