@ikonai/sdk-ui 1.0.66 → 1.0.67

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.
@@ -0,0 +1,57 @@
1
+ import { StreamSnapshot } from './ui-store';
2
+ import { UiStreamSnapshotWire } from './ui-store-ops';
3
+ import { UiStylePayload } from './ikon-ui-core';
4
+ export interface LastSnapshotCacheConfig {
5
+ /** Stable per-app identifier (e.g. the space id). Part of the storage key. */
6
+ appId: string;
7
+ /** Connected user id, or null/undefined for anonymous. Part of the storage key. */
8
+ userId?: string | null;
9
+ /** Cached state older than this is treated as missing. Default 7 days. */
10
+ maxAgeMs?: number;
11
+ /** Serialized envelopes larger than this are dropped (not written). Default ~5 MB. */
12
+ maxBytes?: number;
13
+ /** Throttle window for writes (at most one write per window). Default 1000 ms. */
14
+ debounceMs?: number;
15
+ }
16
+ /** UI state recovered from the cache, shaped for `UiStore.applyStoreOp(ReplaceStreamSnapshot)`. */
17
+ export interface CachedUiState {
18
+ streams: UiStreamSnapshotWire[];
19
+ styles: UiStylePayload[];
20
+ }
21
+ /**
22
+ * Persists the last rendered UI snapshot (view tree + styles) per app/user in `localStorage`, so a
23
+ * return visit can paint the cached tree before the WebSocket connects. The store is
24
+ * schema-versioned, age-bounded, size-bounded, and silent on quota/serialization failure — a cache
25
+ * miss always degrades cleanly to the live connect path.
26
+ *
27
+ * Binary payloads (images etc.) are **not** cached: they would dominate the size and make every
28
+ * write re-encode unchanged bytes. The cached tree paints layout + text instantly; payload-backed
29
+ * content fills in once the live connection delivers it. Writes are throttled and run at idle time.
30
+ *
31
+ * The key embeds the user id, and sibling keys for other users of the same app are pruned on
32
+ * construction so a shared device never paints one user's UI for another.
33
+ */
34
+ export declare class LastSnapshotCache {
35
+ private readonly key;
36
+ private readonly appId;
37
+ private readonly userId;
38
+ private readonly maxAgeMs;
39
+ private readonly maxBytes;
40
+ private readonly debounceMs;
41
+ private writeTimer;
42
+ private pending;
43
+ constructor(config: LastSnapshotCacheConfig);
44
+ load(): CachedUiState | null;
45
+ /**
46
+ * Schedule a throttled write of the current UI state (at most one write per window, captured at
47
+ * the trailing edge). Streams with no root are skipped. The actual write runs at idle time.
48
+ */
49
+ save(streams: StreamSnapshot[], styles: readonly UiStylePayload[]): void;
50
+ /** Write any pending state immediately and synchronously (used on dispose / unmount). */
51
+ flush(): void;
52
+ dispose(): void;
53
+ private writePending;
54
+ private writeNow;
55
+ private remove;
56
+ private pruneOtherUsers;
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikonai/sdk-ui",
3
- "version": "1.0.66",
3
+ "version": "1.0.67",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",