@asaidimu/react-store 1.4.11 → 2.0.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/index.d.cts CHANGED
@@ -1,415 +1,9 @@
1
- /**
2
- * Interface for persistence adapters
3
- */
4
- interface DataStorePersistence<T> {
5
- /**
6
- * Persists data to storage
7
- * @param id The id of the consumer instance
8
- * @param state The state to persist
9
- * @returns boolean indicating success or Promise resolving to success status
10
- */
11
- set(id: string, state: T): boolean | Promise<boolean>;
12
- /**
13
- * Retrieves persisted data from storage
14
- * @returns The retrieved state or null if not found
15
- */
16
- get(): T | null | Promise<T | null>;
17
- /**
18
- * Subscribes to changes in persisted data (e.g., from other tabs)
19
- * @param id The id of the consumer instance
20
- * @param callback Function to call when persisted data changes
21
- * @returns Function to unsubscribe
22
- */
23
- subscribe(id: string, callback: (state: T) => void): () => void;
24
- /**
25
- * Clears the persisted data
26
- * @returns true if successful
27
- */
28
- clear(): boolean | Promise<boolean>;
29
- }
30
-
31
- /**
32
- * Reactive Data Store Implementation
33
- * A type-safe reactive data state for managing complex application state.
34
- * Arrays are treated as primitive values (stored and updated as whole units).
35
- */
36
-
37
- /**
38
- * Utility type for representing partial updates to the state.
39
- */
40
- type DeepPartial<T> = {
41
- [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P] | symbol;
42
- };
43
- /**
44
- * Interface for performance metrics of the state.
45
- */
46
- interface StoreMetrics {
47
- updateCount: number;
48
- listenerExecutions: number;
49
- averageUpdateTime: number;
50
- largestUpdateSize: number;
51
- mostActiveListenerPaths: string[];
52
- }
53
- /**
54
- * Extended store state for monitoring execution status
55
- */
56
- interface StoreExecutionState<T> {
57
- executing: boolean;
58
- changes: DeepPartial<T> | null;
59
- pendingChanges: Array<StateUpdater<T>>;
60
- middlewares: string[];
61
- runningMiddleware: {
62
- id: string;
63
- name: string;
64
- startTime: number;
65
- } | null;
66
- transactionActive: boolean;
67
- }
68
- /**
69
- * Event types emitted by the state for observability
70
- */
71
- type StoreEvent = "update:start" | "update:complete" | "middleware:start" | "middleware:complete" | "middleware:error" | "middleware:blocked" | "transaction:start" | "transaction:complete" | "transaction:error" | "persistence:ready";
72
- /**
73
- * Type for middleware functions. Return false to block the update.
74
- */
75
- type Middleware<T> = (state: T, update: DeepPartial<T>) => Promise<DeepPartial<T>> | Promise<void> | DeepPartial<T> | void;
76
- /**
77
- * Type for blocking middleware functions that can prevent updates.
78
- */
79
- type BlockingMiddleware<T> = (state: T, update: DeepPartial<T>) => boolean | Promise<boolean>;
80
- /**
81
- * Middleware execution information for tracking
82
- */
83
- interface MiddlewareExecution {
84
- id: string;
85
- name: string;
86
- startTime: number;
87
- endTime: number;
88
- duration: number;
89
- blocked: boolean;
90
- error?: Error;
91
- }
92
- /**
93
- * Represents a state update, which can be either a partial state object or a function.
94
- *
95
- * The function can be synchronous or asynchronous, and it receives the current state
96
- * as an argument and returns a partial state object.
97
- *
98
- * @template T The type of the state object.
99
- */
100
- type StateUpdater<T> = DeepPartial<T> | ((state: T) => DeepPartial<T> | Promise<DeepPartial<T>>);
101
- /**
102
- * Interface defining the contract for the data state.
103
- */
104
- interface DataStore<T extends object> {
105
- get(clone?: boolean): T;
106
- set(update: StateUpdater<T>): Promise<void>;
107
- subscribe(path: string, listener: (state: T) => void): () => void;
108
- transaction<R>(operation: () => R | Promise<R>): Promise<R>;
109
- getPerformanceMetrics(): StoreMetrics;
110
- onStoreEvent(event: StoreEvent, listener: (data: any) => void): () => void;
111
- getMiddlewareExecutions(): MiddlewareExecution[];
112
- }
113
- /**
114
- * Implementation of the reactive data state.
115
- */
116
- declare class ReactiveDataStore<T extends object> implements DataStore<T> {
117
- private readonly metrics;
118
- private middleware;
119
- private blockingMiddleware;
120
- private middlewareExecutions;
121
- private readonly maxExecutionHistory;
122
- private pendingUpdates;
123
- private isUpdating;
124
- private updateTimes;
125
- private cache;
126
- private updateBus;
127
- private eventBus;
128
- private executionState;
129
- private persistence?;
130
- private instanceID;
131
- private persistenceReady;
132
- /**
133
- * Creates a new instance of ReactiveDataStore.
134
- * @param initialData The initial state data.
135
- */
136
- constructor(initialData: T, persistence?: DataStorePersistence<T>);
137
- private setPersistenceReady;
138
- private setPersistence;
139
- isReady(): boolean;
140
- /**
141
- * Gets current execution state for monitoring
142
- * @returns The current execution state of the store
143
- */
144
- getExecutionState(): Readonly<StoreExecutionState<T>>;
145
- /**
146
- * Gets a specific part of the state at the given path.
147
- * @returns The current state
148
- */
149
- get(clone?: boolean): T;
150
- /**
151
- * Updates the state with the provided partial state.
152
- * @param update The partial state to update with.
153
- */
154
- set(update: StateUpdater<T>): Promise<void>;
155
- /**
156
- * Applies blocking middleware to the update.
157
- * If any middleware returns false or throws, the update is blocked.
158
- *
159
- * @param partialUpdate The partial update to apply middlewares to
160
- * @returns Result indicating if update was blocked and any error
161
- */
162
- private applyBlockingMiddleware;
163
- /**
164
- * Applies a chain of middleware functions to an initial state.
165
- *
166
- * @template T The type of the state object.
167
- * @param initialState The initial state to be transformed.
168
- * @param partialUpdate The original partial update (for context)
169
- * @returns The final transformed state.
170
- */
171
- private applyMiddleware;
172
- /**
173
- * Subscribes a callback function to changes in the data at the specified path.
174
- * @param path The path to subscribe to.
175
- * @param callback The callback function to call when the path changes.
176
- * @returns Function to unsubscribe the listener.
177
- */
178
- subscribe(path: string | Array<string>, callback: (state: T) => void): () => void;
179
- /**
180
- * returns instance id
181
- * @param path The path to subscribe to.
182
- * @param callback The callback function to call when the path changes.
183
- * @returns Function to unsubscribe the listener.
184
- */
185
- id(): string;
186
- /**
187
- * Executes an operation within a transaction that can be rolled back if an error occurs.
188
- * @param operation The operation to execute.
189
- * @returns The result of the operation.
190
- */
191
- /**
192
- * Executes an operation within a transaction that can be rolled back if an error occurs.
193
- * @param operation The operation to execute.
194
- * @returns The result of the operation.
195
- */
196
- transaction<R>(operation: () => R | Promise<R>): Promise<R>;
197
- /**
198
- * Adds a transformation middleware to the state.
199
- * These middleware functions can modify updates but cannot block them.
200
- *
201
- * @param middleware The middleware function
202
- * @param name Optional name for the middleware (for debugging)
203
- * @returns ID of the registered middleware for removal
204
- */
205
- use(middleware: Middleware<T>, name?: string): string;
206
- /**
207
- * Adds a blocking middleware to the state.
208
- * These middleware functions can block updates by returning false or throwing.
209
- *
210
- * @param middleware The blocking middleware function
211
- * @param name Optional name for the middleware (for debugging)
212
- * @returns ID of the registered middleware for removal
213
- */
214
- useBlockingMiddleware(middleware: BlockingMiddleware<T>, name?: string): string;
215
- /**
216
- * Removes a middleware by ID
217
- * @param id The middleware ID to remove
218
- * @returns true if middleware was found and removed
219
- */
220
- removeMiddleware(id: string): boolean;
221
- /**
222
- * Returns current performance metrics of the state.
223
- * @returns The state metrics.
224
- */
225
- getPerformanceMetrics(): StoreMetrics;
226
- /**
227
- * Returns the history of middleware executions.
228
- * @returns Array of middleware execution information
229
- */
230
- getMiddlewareExecutions(): MiddlewareExecution[];
231
- /**
232
- * Subscribe to state events for observability
233
- * @param event Event type to listen for
234
- * @param listener Callback function when event occurs
235
- * @returns Function to unsubscribe
236
- */
237
- onStoreEvent(event: StoreEvent, listener: (data: any) => void): () => void;
238
- /**
239
- * Notifies listeners whose subscribed paths are affected by the changes.
240
- * @param changedPaths Array of paths that have changed.
241
- */
242
- private notifyListeners;
243
- /**
244
- * Tracks middleware execution for debugging purposes
245
- * @param execution The middleware execution information
246
- */
247
- private trackMiddlewareExecution;
248
- }
249
-
250
- /**
251
- * Store Observability Module
252
- * A separate module to add debugging and observability capabilities to the ReactiveDataStore.
253
- */
254
-
255
- /**
256
- * Interface for debug event structure
257
- */
258
- interface DebugEvent {
259
- type: string;
260
- timestamp: number;
261
- data: any;
262
- }
263
- /**
264
- * Configuration options for the observability module
265
- */
266
- interface ObservabilityOptions {
267
- /** Maximum number of events to keep in history */
268
- maxEvents?: number;
269
- /** Whether to enable console logging */
270
- enableConsoleLogging?: boolean;
271
- maxStateHistory?: number;
272
- /** Options for specific event types to log */
273
- logEvents?: {
274
- updates?: boolean;
275
- middleware?: boolean;
276
- transactions?: boolean;
277
- };
278
- /** Time threshold in ms to highlight slow operations */
279
- performanceThresholds?: {
280
- updateTime?: number;
281
- middlewareTime?: number;
282
- };
283
- }
284
- /**
285
- * Class for observing and debugging a ReactiveDataStore instance
286
- */
287
- declare class StoreObservability<T extends object> {
288
- protected store: DataStore<T>;
289
- private eventHistory;
290
- private maxEvents;
291
- private enableConsoleLogging;
292
- private logEvents;
293
- private performanceThresholds;
294
- private unsubscribers;
295
- private stateHistory;
296
- private maxStateHistory;
297
- private activeTransactionCount;
298
- private activeBatches;
299
- /**
300
- * Creates a new StoreObservability instance
301
- * @param store The ReactiveDataStore to observe
302
- * @param options Configuration options
303
- */
304
- constructor(store: DataStore<T>, options?: ObservabilityOptions);
305
- /**
306
- * Sets up all event listeners
307
- */
308
- private setupEventListeners;
309
- /**
310
- * Records a state snapshot
311
- */
312
- private recordStateSnapshot;
313
- /**
314
- * Records an event to the history
315
- * @param type Event type
316
- * @param data Event data
317
- */
318
- private recordEvent;
319
- /**
320
- * Logs an event to the console with appropriate formatting
321
- * @param type Event type
322
- * @param data Event data
323
- */
324
- private logEventToConsole;
325
- /**
326
- * Checks for performance issues in the events
327
- * @param type Event type
328
- * @param data Event data
329
- */
330
- private checkPerformance;
331
- /**
332
- * Returns the event history
333
- * @returns Array of debug events
334
- */
335
- getEventHistory(): DebugEvent[];
336
- /**
337
- * Returns the state history
338
- * @returns Array of state snapshots
339
- */
340
- getStateHistory(): T[];
341
- /**
342
- * Returns middleware execution history from the state
343
- * @returns Array of middleware executions
344
- */
345
- getMiddlewareExecutions(): MiddlewareExecution[];
346
- /**
347
- * Returns state performance metrics
348
- * @returns Store metrics object
349
- */
350
- getPerformanceMetrics(): StoreMetrics;
351
- /**
352
- * Returns current transaction status
353
- * @returns Object with transaction status information
354
- */
355
- getTransactionStatus(): {
356
- activeTransactions: number;
357
- activeBatches: string[];
358
- };
359
- /**
360
- * Creates a middleware that logs all updates
361
- * @param options Options for the logging middleware
362
- * @returns A middleware function
363
- */
364
- createLoggingMiddleware(options?: {
365
- logLevel?: "debug" | "info" | "warn";
366
- logUpdates?: boolean;
367
- }): (state: T, update: DeepPartial<T>) => DeepPartial<T>;
368
- /**
369
- * Creates a middleware that validates updates against a schema
370
- * @param validator Function that validates updates
371
- * @returns A blocking middleware function
372
- */
373
- createValidationMiddleware(validator: (state: T, update: DeepPartial<T>) => boolean | {
374
- valid: boolean;
375
- reason?: string;
376
- }): (state: T, update: DeepPartial<T>) => boolean;
377
- /**
378
- * Clears all event and state history
379
- */
380
- clearHistory(): void;
381
- /**
382
- * Returns a simplified view of recent state changes
383
- * @param limit Maximum number of state changes to compare
384
- * @returns Array of state difference objects
385
- */
386
- getRecentChanges(limit?: number): Array<{
387
- timestamp: number;
388
- changedPaths: string[];
389
- from: Partial<T>;
390
- to: Partial<T>;
391
- }>;
392
- /**
393
- * Creates a time-travel debug middleware that lets you undo/redo state changes
394
- * @returns An object with undo/redo methods and state info
395
- */
396
- createTimeTravel(): {
397
- canUndo: () => boolean;
398
- canRedo: () => boolean;
399
- undo: () => void;
400
- redo: () => void;
401
- getHistoryLength: () => number;
402
- clear: () => void;
403
- };
404
- /**
405
- * Disconnects all event listeners and cleans up resources
406
- */
407
- disconnect(): void;
408
- }
1
+ import { SimplePersistence } from '@asaidimu/utils-persistence';
2
+ import { ObservabilityOptions, DeepPartial, BlockingMiddleware, Middleware, ReactiveDataStore, StoreObserver } from '@asaidimu/utils-store';
409
3
 
410
4
  type StoreOptions<T> = ObservabilityOptions & {
411
5
  enableMetrics?: boolean;
412
- persistence?: DataStorePersistence<T>;
6
+ persistence?: SimplePersistence<T>;
413
7
  };
414
8
  type Action<T> = (state: T, ...args: any[]) => DeepPartial<T>;
415
9
  type StoreSelector<T, S> = (state: T) => S;
@@ -459,7 +53,7 @@ declare function createStore<T extends Record<string, unknown>, R extends Action
459
53
  /** Direct store instance access */
460
54
  readonly store: ReactiveDataStore<T>;
461
55
  /** Performance monitoring tools when enabled */
462
- readonly observer: StoreObservability<T> | undefined;
56
+ readonly observer: StoreObserver<T> | undefined;
463
57
  /** Selector creator for subscribing to specific state */
464
58
  readonly select: <S>(selector: (state: T) => S) => S;
465
59
  /** Action dispatchers */
@@ -471,304 +65,4 @@ declare function createStore<T extends Record<string, unknown>, R extends Action
471
65
  readonly state: () => T;
472
66
  };
473
67
 
474
- /**
475
- * Configuration for external metrics destination
476
- */
477
- interface RemoteDestination {
478
- /** Unique identifier for this destination */
479
- id: string;
480
- /** Human-readable name of the destination */
481
- name: string;
482
- /** Function that handles sending metrics to the destination */
483
- send: (payload: RemoteMetricsPayload) => Promise<void>;
484
- /** Optional function to test connection to the destination */
485
- testConnection?: () => Promise<boolean>;
486
- /** Optional configuration for this destination */
487
- config?: Record<string, any>;
488
- }
489
- /**
490
- * Types of metrics that can be sent remotely
491
- */
492
- type MetricType = 'counter' | 'gauge' | 'histogram' | 'log' | 'trace';
493
- /**
494
- * Structure for remote metric payloads
495
- */
496
- interface RemoteMetricsPayload {
497
- /** Timestamp when the metrics were collected */
498
- timestamp: number;
499
- /** Source identifier (app name, instance ID, etc.) */
500
- source: string;
501
- /** Collection of metrics being reported */
502
- metrics: Array<{
503
- /** Metric name (should follow naming conventions) */
504
- name: string;
505
- /** Type of metric */
506
- type: MetricType;
507
- /** Value of the metric */
508
- value: number | string | object;
509
- /** Optional units for the metric */
510
- unit?: string;
511
- /** Contextual labels/tags for the metric */
512
- labels?: Record<string, string>;
513
- /** For trace type, references to parent spans */
514
- parentId?: string;
515
- /** For trace type, trace ID for grouping spans */
516
- traceId?: string;
517
- }>;
518
- }
519
- /**
520
- * Configuration options for RemoteObservability
521
- */
522
- interface RemoteObservabilityOptions extends ObservabilityOptions {
523
- /** Application/service name */
524
- serviceName: string;
525
- /** Environment (prod, staging, dev) */
526
- environment: string;
527
- /** Instance identifier (for distributed systems) */
528
- instanceId?: string;
529
- /** How frequently to send batched metrics (ms) */
530
- reportingInterval?: number;
531
- /** How many metrics to batch before sending */
532
- batchSize?: number;
533
- /** Whether to disable batching and send immediately */
534
- immediateReporting?: boolean;
535
- /** Which categories of metrics to collect */
536
- collectCategories?: {
537
- performance?: boolean;
538
- errors?: boolean;
539
- stateChanges?: boolean;
540
- middleware?: boolean;
541
- };
542
- /** Whether to compress payloads */
543
- compressPayloads?: boolean;
544
- }
545
- /**
546
- * Remote observability extension for store monitoring
547
- */
548
- declare class RemoteObservability<T extends object> extends StoreObservability<T> {
549
- private destinations;
550
- private metricsBatch;
551
- private reportingInterval;
552
- private batchSize;
553
- private serviceName;
554
- private environment;
555
- private instanceId;
556
- private immediateReporting;
557
- private collectCategories;
558
- private compressPayloads;
559
- private reportingTimer;
560
- private traceIdCounter;
561
- private activeTraces;
562
- /**
563
- * Creates a new RemoteObservability instance
564
- * @param store The ReactiveDataStore to observe
565
- * @param options Configuration options
566
- */
567
- constructor(store: DataStore<T>, options: RemoteObservabilityOptions);
568
- /**
569
- * Generate a unique instance ID if none provided
570
- */
571
- private generateInstanceId;
572
- /**
573
- * Setup additional event listeners for remote reporting
574
- */
575
- private setupRemoteEventListeners;
576
- /**
577
- * Begin a trace for performance tracking
578
- * @param name Name of the trace
579
- * @returns Trace ID
580
- */
581
- beginTrace(name: string): string;
582
- /**
583
- * Begin a span within a trace
584
- * @param traceId Parent trace ID
585
- * @param name Span name
586
- * @param labels Additional context labels
587
- * @returns Span ID
588
- */
589
- beginSpan(traceId: string, name: string, labels?: Record<string, string>): string;
590
- /**
591
- * End a span within a trace
592
- * @param traceId Parent trace ID
593
- * @param spanName Name of span to end (ends last matching span)
594
- */
595
- endSpan(traceId: string, spanName: string): void;
596
- /**
597
- * End a trace and send it to remote destinations
598
- * @param traceId Trace ID to end
599
- */
600
- endTrace(traceId: string): void;
601
- /**
602
- * Add a remote destination for metrics
603
- * @param destination Remote destination configuration
604
- * @returns Boolean indicating if destination was added successfully
605
- */
606
- addDestination(destination: RemoteDestination): boolean;
607
- /**
608
- * Remove a remote destination by ID
609
- * @param id Destination ID to remove
610
- * @returns Boolean indicating if destination was removed
611
- */
612
- removeDestination(id: string): boolean;
613
- /**
614
- * Get list of configured destinations
615
- * @returns Array of destination IDs and names
616
- */
617
- getDestinations(): Array<{
618
- id: string;
619
- name: string;
620
- }>;
621
- /**
622
- * Test connection to all destinations
623
- * @returns Object mapping destination IDs to connection status
624
- */
625
- testAllConnections(): Promise<Record<string, boolean>>;
626
- /**
627
- * Track a metric and add it to the batch
628
- * @param metric Metric to track
629
- */
630
- private trackMetric;
631
- /**
632
- * Flush metrics to all configured destinations
633
- */
634
- private flushMetrics;
635
- /**
636
- * Start the periodic reporting cycle
637
- */
638
- private startReportingCycle;
639
- /**
640
- * Change the reporting interval
641
- * @param intervalMs New interval in milliseconds
642
- */
643
- setReportingInterval(intervalMs: number): void;
644
- /**
645
- * Collect and report current store performance metrics
646
- */
647
- reportCurrentMetrics(): void;
648
- /**
649
- * Override disconnect to also flush metrics
650
- */
651
- disconnect(): void;
652
- }
653
-
654
- /**
655
- * Create a destination that sends metrics to an OpenTelemetry collector
656
- * @param config Configuration for the OpenTelemetry destination
657
- */
658
- declare function createOpenTelemetryDestination(config: {
659
- endpoint: string;
660
- apiKey?: string;
661
- resource?: Record<string, string>;
662
- }): RemoteDestination;
663
- /**
664
- * Create a destination that sends metrics to Prometheus
665
- * @param config Configuration for the Prometheus destination
666
- */
667
- declare function createPrometheusDestination(config: {
668
- pushgatewayUrl: string;
669
- username?: string;
670
- password?: string;
671
- jobName: string;
672
- }): RemoteDestination;
673
- /**
674
- * Create a destination that sends metrics to Grafana Cloud
675
- * @param config Configuration for the Grafana Cloud destination
676
- */
677
- declare function createGrafanaCloudDestination(config: {
678
- url: string;
679
- apiKey: string;
680
- }): RemoteDestination;
681
- /**
682
- * Create a destination that sends metrics to a generic HTTP endpoint
683
- * @param config Configuration for the HTTP destination
684
- */
685
- declare function createHttpDestination(config: {
686
- url: string;
687
- headers?: Record<string, string>;
688
- method?: 'POST' | 'PUT';
689
- transformPayload?: (payload: RemoteMetricsPayload) => any;
690
- }): RemoteDestination;
691
-
692
- /**
693
- * Hook to use the RemoteObservability instance with React
694
- * @param store Store instance
695
- * @param options Configuration options
696
- */
697
- declare function useRemoteObservability<T extends object>(store: DataStore<T>, options: RemoteObservabilityOptions): {
698
- remote: RemoteObservability<T>;
699
- addOpenTelemetryDestination: (config: Parameters<typeof createOpenTelemetryDestination>[0]) => boolean;
700
- addPrometheusDestination: (config: Parameters<typeof createPrometheusDestination>[0]) => boolean;
701
- addGrafanaCloudDestination: (config: Parameters<typeof createGrafanaCloudDestination>[0]) => boolean;
702
- addHttpDestination: (config: Parameters<typeof createHttpDestination>[0]) => boolean;
703
- };
704
-
705
- /**
706
- * Implements DataStorePersistence using web storage (localStorage or sessionStorage).
707
- * Supports cross-tab synchronization via an event bus and native storage events when using localStorage.
708
- */
709
- declare class WebStoragePersistence<T extends object> implements DataStorePersistence<T> {
710
- private readonly storageKey;
711
- private readonly eventBus;
712
- private readonly storage;
713
- /**
714
- * Initializes a new instance of WebStoragePersistence.
715
- * @param storageKey The key under which data is stored in web storage (e.g., 'user-profile').
716
- * @param session Optional flag; if true, uses sessionStorage instead of localStorage (default: false).
717
- */
718
- constructor(storageKey: string, session?: boolean);
719
- /**
720
- * Initializes the event bus with configured settings.
721
- * @returns Configured event bus instance.
722
- */
723
- private initializeEventBus;
724
- /**
725
- * Sets up a listener for native storage events to synchronize across tabs (localStorage only).
726
- */
727
- private setupStorageEventListener;
728
- /**
729
- * Persists the provided state to web storage and notifies subscribers.
730
- * @param instanceId Unique identifier of the instance making the update.
731
- * @param state The state to persist.
732
- * @returns True if successful, false if an error occurs.
733
- */
734
- set(instanceId: string, state: T): boolean;
735
- /**
736
- * Retrieves the current state from web storage.
737
- * @returns The persisted state, or null if not found or invalid.
738
- */
739
- get(): T | null;
740
- /**
741
- * Subscribes to updates in the persisted state, excluding the instance’s own changes.
742
- * @param instanceId Unique identifier of the subscribing instance.
743
- * @param onStateChange Callback to invoke with the updated state.
744
- * @returns Function to unsubscribe from updates.
745
- */
746
- subscribe(instanceId: string, onStateChange: (state: T) => void): () => void;
747
- /**
748
- * Removes the persisted state from web storage.
749
- * @returns True if successful, false if an error occurs.
750
- */
751
- clear(): boolean;
752
- }
753
- /**
754
- * Alias for WebStoragePersistence, maintained for backward compatibility.
755
- * @deprecated Use `WebStoragePersistence` instead, which supports both localStorage and sessionStorage.
756
- */
757
- declare const LocalStoragePersistence: typeof WebStoragePersistence;
758
-
759
- /**
760
- * IndexedDB persistence adapter with storeId and ephemeral instance IDs
761
- */
762
- declare class IndexedDBPersistence<T> implements DataStorePersistence<T> {
763
- private cursorPromise;
764
- private storeId;
765
- private eventBus;
766
- constructor(storeId: string);
767
- set(id: string, state: T): Promise<boolean>;
768
- get(): Promise<T | null>;
769
- subscribe(id: string, callback: (state: T) => void): () => void;
770
- clear(): Promise<boolean>;
771
- static closeAll(): Promise<void>;
772
- }
773
-
774
- export { type Action, type Actions, type BlockingMiddleware, type DataStore, type DataStorePersistence, type DebugEvent, type DeepPartial, IndexedDBPersistence, LocalStoragePersistence, type MetricType, type Middleware, type MiddlewareExecution, type ObservabilityOptions, ReactiveDataStore, type RemoteDestination, type RemoteMetricsPayload, RemoteObservability, type RemoteObservabilityOptions, type StoreDefinition, type StoreEvent, type StoreExecutionState, type StoreMetrics, StoreObservability, type StoreOptions, type StoreSelector, WebStoragePersistence, createGrafanaCloudDestination, createHttpDestination, createOpenTelemetryDestination, createPrometheusDestination, createStore, useRemoteObservability };
68
+ export { type Action, type Actions, type StoreDefinition, type StoreOptions, type StoreSelector, createStore };