hyperstack-typescript 0.3.1 → 0.3.3
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 +97 -7
- package/dist/index.esm.js +549 -44
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +551 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ interface Subscription {
|
|
|
44
44
|
key?: string;
|
|
45
45
|
partition?: string;
|
|
46
46
|
filters?: Record<string, string>;
|
|
47
|
+
take?: number;
|
|
48
|
+
skip?: number;
|
|
47
49
|
}
|
|
48
50
|
interface HyperStackOptions<TStack extends StackDefinition> {
|
|
49
51
|
stack: TStack;
|
|
@@ -93,7 +95,18 @@ type UnsubscribeFn = () => void;
|
|
|
93
95
|
type ConnectionStateCallback = (state: ConnectionState, error?: string) => void;
|
|
94
96
|
|
|
95
97
|
type FrameMode = 'state' | 'append' | 'list';
|
|
96
|
-
type FrameOp = 'create' | 'upsert' | 'patch' | 'delete' | 'snapshot';
|
|
98
|
+
type FrameOp = 'create' | 'upsert' | 'patch' | 'delete' | 'snapshot' | 'subscribed';
|
|
99
|
+
type SortOrder = 'asc' | 'desc';
|
|
100
|
+
interface SortConfig {
|
|
101
|
+
field: string[];
|
|
102
|
+
order: SortOrder;
|
|
103
|
+
}
|
|
104
|
+
interface SubscribedFrame {
|
|
105
|
+
op: 'subscribed';
|
|
106
|
+
view: string;
|
|
107
|
+
mode: FrameMode;
|
|
108
|
+
sort?: SortConfig;
|
|
109
|
+
}
|
|
97
110
|
interface EntityFrame<T = unknown> {
|
|
98
111
|
mode: FrameMode;
|
|
99
112
|
entity: string;
|
|
@@ -111,9 +124,13 @@ interface SnapshotFrame<T = unknown> {
|
|
|
111
124
|
entity: string;
|
|
112
125
|
op: 'snapshot';
|
|
113
126
|
data: SnapshotEntity<T>[];
|
|
127
|
+
/** Indicates if this is the final snapshot batch. When false, more batches will follow. */
|
|
128
|
+
complete?: boolean;
|
|
114
129
|
}
|
|
115
|
-
type Frame<T = unknown> = EntityFrame<T> | SnapshotFrame<T
|
|
130
|
+
type Frame<T = unknown> = EntityFrame<T> | SnapshotFrame<T> | SubscribedFrame;
|
|
116
131
|
declare function isSnapshotFrame<T>(frame: Frame<T>): frame is SnapshotFrame<T>;
|
|
132
|
+
declare function isSubscribedFrame(frame: Frame): frame is SubscribedFrame;
|
|
133
|
+
declare function isEntityFrame<T>(frame: Frame<T>): frame is EntityFrame<T>;
|
|
117
134
|
declare function parseFrame(data: ArrayBuffer | string): Frame;
|
|
118
135
|
declare function parseFrameFromBlob(blob: Blob): Promise<Frame>;
|
|
119
136
|
declare function isValidFrame(frame: unknown): frame is Frame;
|
|
@@ -153,10 +170,13 @@ declare class ConnectionManager {
|
|
|
153
170
|
}
|
|
154
171
|
|
|
155
172
|
type UpdateCallback<T = unknown> = (viewPath: string, key: string, update: Update<T>) => void;
|
|
156
|
-
type RichUpdateCallback<T = unknown> = (viewPath: string, key: string, update: RichUpdate<T>) => void;
|
|
173
|
+
type RichUpdateCallback$1<T = unknown> = (viewPath: string, key: string, update: RichUpdate<T>) => void;
|
|
157
174
|
interface StorageAdapterConfig {
|
|
158
175
|
maxEntriesPerView?: number | null;
|
|
159
176
|
}
|
|
177
|
+
interface ViewSortConfig {
|
|
178
|
+
sort?: SortConfig;
|
|
179
|
+
}
|
|
160
180
|
/**
|
|
161
181
|
* Storage adapter interface for HyperStack entity storage.
|
|
162
182
|
* Implement this to integrate with Zustand, Pinia, Svelte stores, Redux, IndexedDB, etc.
|
|
@@ -173,8 +193,10 @@ interface StorageAdapter {
|
|
|
173
193
|
delete(viewPath: string, key: string): void;
|
|
174
194
|
clear(viewPath?: string): void;
|
|
175
195
|
evictOldest?(viewPath: string): string | undefined;
|
|
196
|
+
setViewConfig?(viewPath: string, config: ViewSortConfig): void;
|
|
197
|
+
getViewConfig?(viewPath: string): ViewSortConfig | undefined;
|
|
176
198
|
onUpdate(callback: UpdateCallback): () => void;
|
|
177
|
-
onRichUpdate(callback: RichUpdateCallback): () => void;
|
|
199
|
+
onRichUpdate(callback: RichUpdateCallback$1): () => void;
|
|
178
200
|
notifyUpdate<T>(viewPath: string, key: string, update: Update<T>): void;
|
|
179
201
|
notifyRichUpdate<T>(viewPath: string, key: string, update: RichUpdate<T>): void;
|
|
180
202
|
}
|
|
@@ -221,18 +243,86 @@ declare class HyperStack<TStack extends StackDefinition> {
|
|
|
221
243
|
|
|
222
244
|
interface FrameProcessorConfig {
|
|
223
245
|
maxEntriesPerView?: number | null;
|
|
246
|
+
/**
|
|
247
|
+
* Interval in milliseconds to buffer frames before flushing to storage.
|
|
248
|
+
* Set to 0 for immediate processing (no buffering).
|
|
249
|
+
* Default: 0 (immediate)
|
|
250
|
+
*
|
|
251
|
+
* For React applications, 16ms (one frame at 60fps) is recommended to
|
|
252
|
+
* reduce unnecessary re-renders during high-frequency updates.
|
|
253
|
+
*/
|
|
254
|
+
flushIntervalMs?: number;
|
|
224
255
|
}
|
|
225
256
|
declare class FrameProcessor {
|
|
226
257
|
private storage;
|
|
227
258
|
private maxEntriesPerView;
|
|
259
|
+
private flushIntervalMs;
|
|
260
|
+
private pendingUpdates;
|
|
261
|
+
private flushTimer;
|
|
262
|
+
private isProcessing;
|
|
228
263
|
constructor(storage: StorageAdapter, config?: FrameProcessorConfig);
|
|
229
264
|
handleFrame<T>(frame: Frame<T>): void;
|
|
265
|
+
/**
|
|
266
|
+
* Immediately flush all pending updates.
|
|
267
|
+
* Useful for ensuring all updates are processed before reading state.
|
|
268
|
+
*/
|
|
269
|
+
flush(): void;
|
|
270
|
+
/**
|
|
271
|
+
* Clean up any pending timers. Call when disposing the processor.
|
|
272
|
+
*/
|
|
273
|
+
dispose(): void;
|
|
274
|
+
private scheduleFlush;
|
|
275
|
+
private flushPendingUpdates;
|
|
276
|
+
private processFrame;
|
|
277
|
+
private processFrameWithoutEnforce;
|
|
278
|
+
private handleSubscribedFrame;
|
|
230
279
|
private handleSnapshotFrame;
|
|
280
|
+
private handleSnapshotFrameWithoutEnforce;
|
|
231
281
|
private handleEntityFrame;
|
|
282
|
+
private handleEntityFrameWithoutEnforce;
|
|
232
283
|
private emitRichUpdate;
|
|
233
284
|
private enforceMaxEntries;
|
|
234
285
|
}
|
|
235
286
|
|
|
287
|
+
interface EntityStoreConfig {
|
|
288
|
+
maxEntriesPerView?: number | null;
|
|
289
|
+
}
|
|
290
|
+
interface ViewConfig {
|
|
291
|
+
sort?: SortConfig;
|
|
292
|
+
}
|
|
293
|
+
type EntityUpdateCallback = (viewPath: string, key: string, update: Update<unknown>) => void;
|
|
294
|
+
type RichUpdateCallback = (viewPath: string, key: string, update: RichUpdate<unknown>) => void;
|
|
295
|
+
declare class EntityStore {
|
|
296
|
+
private views;
|
|
297
|
+
private viewConfigs;
|
|
298
|
+
private updateCallbacks;
|
|
299
|
+
private richUpdateCallbacks;
|
|
300
|
+
private maxEntriesPerView;
|
|
301
|
+
constructor(config?: EntityStoreConfig);
|
|
302
|
+
private enforceMaxEntries;
|
|
303
|
+
handleFrame<T>(frame: Frame<T>): void;
|
|
304
|
+
private handleSubscribedFrame;
|
|
305
|
+
private handleSnapshotFrame;
|
|
306
|
+
private handleEntityFrame;
|
|
307
|
+
getAll<T>(viewPath: string): T[];
|
|
308
|
+
get<T>(viewPath: string, key: string): T | null;
|
|
309
|
+
getAllSync<T>(viewPath: string): T[] | undefined;
|
|
310
|
+
getSync<T>(viewPath: string, key: string): T | null | undefined;
|
|
311
|
+
keys(viewPath: string): string[];
|
|
312
|
+
size(viewPath: string): number;
|
|
313
|
+
clear(): void;
|
|
314
|
+
clearView(viewPath: string): void;
|
|
315
|
+
getViewConfig(viewPath: string): ViewConfig | undefined;
|
|
316
|
+
setViewConfig(viewPath: string, config: ViewConfig): void;
|
|
317
|
+
onUpdate(callback: EntityUpdateCallback): UnsubscribeFn;
|
|
318
|
+
onRichUpdate(callback: RichUpdateCallback): UnsubscribeFn;
|
|
319
|
+
subscribe<T>(viewPath: string, callback: SubscribeCallback<T>): UnsubscribeFn;
|
|
320
|
+
subscribeToKey<T>(viewPath: string, key: string, callback: SubscribeCallback<T>): UnsubscribeFn;
|
|
321
|
+
private notifyUpdate;
|
|
322
|
+
private notifyRichUpdate;
|
|
323
|
+
private notifyRichDelete;
|
|
324
|
+
}
|
|
325
|
+
|
|
236
326
|
declare class MemoryAdapter implements StorageAdapter {
|
|
237
327
|
private views;
|
|
238
328
|
private updateCallbacks;
|
|
@@ -250,7 +340,7 @@ declare class MemoryAdapter implements StorageAdapter {
|
|
|
250
340
|
clear(viewPath?: string): void;
|
|
251
341
|
evictOldest(viewPath: string): string | undefined;
|
|
252
342
|
onUpdate(callback: UpdateCallback): () => void;
|
|
253
|
-
onRichUpdate(callback: RichUpdateCallback): () => void;
|
|
343
|
+
onRichUpdate(callback: RichUpdateCallback$1): () => void;
|
|
254
344
|
notifyUpdate<T>(viewPath: string, key: string, update: Update<T>): void;
|
|
255
345
|
notifyRichUpdate<T>(viewPath: string, key: string, update: RichUpdate<T>): void;
|
|
256
346
|
}
|
|
@@ -262,5 +352,5 @@ declare function createTypedStateView<T>(viewDef: ViewDef<T, 'state'>, storage:
|
|
|
262
352
|
declare function createTypedListView<T>(viewDef: ViewDef<T, 'list'>, storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry): TypedListView<T>;
|
|
263
353
|
declare function createTypedViews<TStack extends StackDefinition>(stack: TStack, storage: StorageAdapter, subscriptionRegistry: SubscriptionRegistry): TypedViews<TStack['views']>;
|
|
264
354
|
|
|
265
|
-
export { ConnectionManager, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, FrameProcessor, HyperStack, HyperStackError, MemoryAdapter, SubscriptionRegistry, createRichUpdateStream, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, isSnapshotFrame, isValidFrame, parseFrame, parseFrameFromBlob };
|
|
266
|
-
export type { ConnectionState, ConnectionStateCallback, EntityFrame, Frame, FrameMode, FrameOp, FrameProcessorConfig, HyperStackConfig, HyperStackOptions, HyperStackOptionsWithStorage, RichUpdate, RichUpdateCallback, SnapshotEntity, SnapshotFrame, StackDefinition, StorageAdapter, StorageAdapterConfig, SubscribeCallback, Subscription, TypedListView, TypedStateView, TypedViewGroup, TypedViews, UnsubscribeFn, Update, UpdateCallback, ViewDef, ViewGroup };
|
|
355
|
+
export { ConnectionManager, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityStore, FrameProcessor, HyperStack, HyperStackError, MemoryAdapter, SubscriptionRegistry, createRichUpdateStream, createTypedListView, createTypedStateView, createTypedViews, createUpdateStream, isEntityFrame, isSnapshotFrame, isSubscribedFrame, isValidFrame, parseFrame, parseFrameFromBlob };
|
|
356
|
+
export type { ConnectionState, ConnectionStateCallback, EntityFrame, EntityStoreConfig, Frame, FrameMode, FrameOp, FrameProcessorConfig, HyperStackConfig, HyperStackOptions, HyperStackOptionsWithStorage, RichUpdate, RichUpdateCallback$1 as RichUpdateCallback, SnapshotEntity, SnapshotFrame, SortConfig, SortOrder, StackDefinition, StorageAdapter, StorageAdapterConfig, SubscribeCallback, SubscribedFrame, Subscription, TypedListView, TypedStateView, TypedViewGroup, TypedViews, UnsubscribeFn, Update, UpdateCallback, ViewConfig, ViewDef, ViewGroup, ViewSortConfig };
|