@flurryx/store 1.0.1 → 1.1.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/dist/index.d.cts CHANGED
@@ -67,6 +67,8 @@ type StoreSnapshot<TData extends StoreDataShape<TData>, TKey extends StoreKey<TD
67
67
  }>;
68
68
  /** Delivery status of a broker message: `"pending"` → `"acknowledged"` or `"dead-letter"`. */
69
69
  type StoreMessageStatus = "pending" | "acknowledged" | "dead-letter";
70
+ /** Error message thrown when `restoreResource()` receives a key that is not a valid store key. */
71
+ declare const INVALID_STORE_KEY_ERROR = "Invalid store key";
70
72
 
71
73
  /**
72
74
  * Persisted broker message record stored in the active message channel.
@@ -256,7 +258,7 @@ interface IStore<TData extends StoreDataShape<TData>> {
256
258
  /**
257
259
  * Re-executes previously published channel message id(s).
258
260
  *
259
- * Unlike `travelTo(...)`, replay goes back through the broker/consumer path,
261
+ * Unlike `restoreStoreAt(...)`, replay goes back through the broker/consumer path,
260
262
  * so it can mutate the store again, truncate future history after time
261
263
  * travel, and record new acknowledged history entries.
262
264
  */
@@ -266,7 +268,19 @@ interface IStore<TData extends StoreDataShape<TData>> {
266
268
  *
267
269
  * This navigates snapshots only and does not re-run any message.
268
270
  */
269
- travelTo: StoreHistory<TData>["travelTo"];
271
+ restoreStoreAt: StoreHistory<TData>["restoreStoreAt"];
272
+ /**
273
+ * Restores a single store key to its state at a specific history index.
274
+ *
275
+ * Unlike `restoreStoreAt(index)` which restores the full snapshot, this method
276
+ * only restores the specified key while leaving other keys unaffected.
277
+ * This is snapshot navigation only. It does not publish or acknowledge any
278
+ * message and does not create a new history entry.
279
+ *
280
+ * @param key - The store key to restore.
281
+ * @param index - Optional history index. Defaults to the current index.
282
+ */
283
+ restoreResource: StoreHistory<TData>["restoreResource"];
270
284
  /** Moves one step backward in the recorded snapshot history when possible. */
271
285
  undo: StoreHistory<TData>["undo"];
272
286
  /** Moves one step forward in the recorded snapshot history when possible. */
@@ -293,7 +307,7 @@ interface IStore<TData extends StoreDataShape<TData>> {
293
307
  replayDeadLetter: StoreHistory<TData>["replayDeadLetter"];
294
308
  /** Attempts to replay all current dead-letter messages once. */
295
309
  replayDeadLetters: StoreHistory<TData>["replayDeadLetters"];
296
- /** Returns the currently restored snapshot index used by `travelTo`, `undo`, and `redo`. */
310
+ /** Returns the currently restored snapshot index used by `restoreStoreAt`, `undo`, and `redo`. */
297
311
  getCurrentIndex: StoreHistory<TData>["getCurrentIndex"];
298
312
  /** Merges a single entity into a keyed slot and sets its status to `'Success'`. */
299
313
  updateKeyedOne<K extends StoreKey<TData>>(key: K, resourceKey: KeyedResourceKey, entity: unknown): void;
@@ -345,7 +359,7 @@ declare function createSnapshotRestorePatch<TState extends ResourceState<unknown
345
359
  interface StoreHistoryEntry<TData extends StoreDataShape<TData>, TKey extends StoreKey<TData> = StoreKey<TData>> {
346
360
  /** Stable message id used by `replay(...)`; `null` for the initial snapshot entry. */
347
361
  readonly id: number | null;
348
- /** Snapshot position used by `travelTo(index)`, `undo()`, and `redo()`. */
362
+ /** Snapshot position used by `restoreStoreAt(index)`, `undo()`, and `redo()`. */
349
363
  readonly index: number;
350
364
  /** Acknowledged message that produced this snapshot; `null` for the initial entry. */
351
365
  readonly message: StoreMessage<TData, TKey> | null;
@@ -373,7 +387,7 @@ interface StoreDeadLetterEntry<TData extends StoreDataShape<TData>, TKey extends
373
387
  /**
374
388
  * Public history and recovery API exposed on every store instance.
375
389
  *
376
- * `travelTo(...)` navigates snapshots by history index, while `replay(...)`
390
+ * `restoreStoreAt(...)` navigates snapshots by history index, while `replay(...)`
377
391
  * re-executes previously published channel messages by their stable message ids.
378
392
  */
379
393
  interface StoreHistory<TData extends StoreDataShape<TData>, TKey extends StoreKey<TData> = StoreKey<TData>> {
@@ -406,11 +420,25 @@ interface StoreHistory<TData extends StoreDataShape<TData>, TKey extends StoreKe
406
420
  *
407
421
  * @throws {Error} When the index is outside the recorded history range.
408
422
  */
409
- travelTo(index: number): void;
423
+ restoreStoreAt(index: number): void;
424
+ /**
425
+ * Restores a single store key to its state at a specific history index.
426
+ *
427
+ * Unlike `restoreStoreAt(index)` which restores the full snapshot, this method
428
+ * only restores the specified key while leaving other keys unaffected.
429
+ * This is snapshot navigation only. It does not publish or acknowledge any
430
+ * message and does not create a new history entry.
431
+ *
432
+ * @param key - The store key to restore.
433
+ * @param index - Optional history index. Defaults to the current index.
434
+ * @throws {Error} When the key is not a valid store key.
435
+ * @throws {Error} When the index is outside the recorded history range.
436
+ */
437
+ restoreResource<K extends TKey>(key: K, index?: number): void;
410
438
  /**
411
439
  * Moves to the previous recorded snapshot.
412
440
  *
413
- * Equivalent to `travelTo(getCurrentIndex() - 1)` when possible.
441
+ * Equivalent to `restoreStoreAt(getCurrentIndex() - 1)` when possible.
414
442
  *
415
443
  * @returns `true` when the pointer moved, otherwise `false` at the initial snapshot.
416
444
  */
@@ -418,7 +446,7 @@ interface StoreHistory<TData extends StoreDataShape<TData>, TKey extends StoreKe
418
446
  /**
419
447
  * Moves to the next recorded snapshot when history exists ahead of the current pointer.
420
448
  *
421
- * Equivalent to `travelTo(getCurrentIndex() + 1)` when possible.
449
+ * Equivalent to `restoreStoreAt(getCurrentIndex() + 1)` when possible.
422
450
  *
423
451
  * @returns `true` when the pointer moved, otherwise `false` at the latest snapshot.
424
452
  */
@@ -485,7 +513,9 @@ declare abstract class BaseStore<TEnum extends Record<string, string | number>,
485
513
  private readonly storeKeys;
486
514
  private readonly historyDriver;
487
515
  /** @inheritDoc */
488
- readonly travelTo: (index: number) => void;
516
+ readonly restoreStoreAt: (index: number) => void;
517
+ /** @inheritDoc */
518
+ readonly restoreResource: <K extends StoreKey<TData>>(key: K, index?: number) => void;
489
519
  /** @inheritDoc */
490
520
  readonly undo: () => boolean;
491
521
  /** @inheritDoc */
@@ -604,7 +634,9 @@ declare class LazyStore<TData extends StoreDataShape<TData>> implements IStore<T
604
634
  private readonly hooks;
605
635
  private readonly historyDriver;
606
636
  /** @inheritDoc */
607
- readonly travelTo: (index: number) => void;
637
+ readonly restoreStoreAt: (index: number) => void;
638
+ /** @inheritDoc */
639
+ readonly restoreResource: <K extends StoreKey<TData>>(key: K, index?: number) => void;
608
640
  /** @inheritDoc */
609
641
  readonly undo: () => boolean;
610
642
  /** @inheritDoc */
@@ -968,4 +1000,4 @@ interface CollectKeyedOptions<TEntity> {
968
1000
  */
969
1001
  declare function collectKeyed<TSource extends StoreDataShape<TSource>, TTarget extends StoreDataShape<TTarget>, TEntity = unknown>(source: IStore<TSource>, sourceKey: StoreKey<TSource>, target: IStore<TTarget>, targetKeyOrOptions?: StoreKey<TTarget> | CollectKeyedOptions<TEntity>, options?: CollectKeyedOptions<TEntity>): () => void;
970
1002
 
971
- export { BaseStore, type BrowserStorageStoreMessageChannelOptions, type ClearAllStoreMessage, type ClearKeyedOneStoreMessage, type ClearStoreMessage, type CollectKeyedOptions, type CompositeStoreMessageChannelOptions, type ConfigToData, type IStore, LazyStore, type MirrorOptions, type StartKeyedLoadingStoreMessage, type StartLoadingStoreMessage, type StopLoadingStoreMessage, type StorageStoreMessageChannelOptions, Store, type StoreDeadLetterEntry, type StoreHistory, type StoreHistoryEntry, type StoreMessage, type StoreMessageChannel, type StoreMessageChannelOptions, type StoreMessageChannelStorage, type StoreMessageRecord, type StoreMessageStatus, type StoreOptions, type StoreSnapshot, type UpdateKeyedOneStoreMessage, type UpdateStoreMessage, clearAllStores, cloneValue, collectKeyed, createCompositeStoreMessageChannel, createInMemoryStoreMessageChannel, createLocalStorageStoreMessageChannel, createSessionStorageStoreMessageChannel, createSnapshotRestorePatch, createStorageStoreMessageChannel, mirrorKey };
1003
+ export { BaseStore, type BrowserStorageStoreMessageChannelOptions, type ClearAllStoreMessage, type ClearKeyedOneStoreMessage, type ClearStoreMessage, type CollectKeyedOptions, type CompositeStoreMessageChannelOptions, type ConfigToData, INVALID_STORE_KEY_ERROR, type IStore, LazyStore, type MirrorOptions, type StartKeyedLoadingStoreMessage, type StartLoadingStoreMessage, type StopLoadingStoreMessage, type StorageStoreMessageChannelOptions, Store, type StoreDeadLetterEntry, type StoreHistory, type StoreHistoryEntry, type StoreMessage, type StoreMessageChannel, type StoreMessageChannelOptions, type StoreMessageChannelStorage, type StoreMessageRecord, type StoreMessageStatus, type StoreOptions, type StoreSnapshot, type UpdateKeyedOneStoreMessage, type UpdateStoreMessage, clearAllStores, cloneValue, collectKeyed, createCompositeStoreMessageChannel, createInMemoryStoreMessageChannel, createLocalStorageStoreMessageChannel, createSessionStorageStoreMessageChannel, createSnapshotRestorePatch, createStorageStoreMessageChannel, mirrorKey };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,8 @@ type StoreSnapshot<TData extends StoreDataShape<TData>, TKey extends StoreKey<TD
67
67
  }>;
68
68
  /** Delivery status of a broker message: `"pending"` → `"acknowledged"` or `"dead-letter"`. */
69
69
  type StoreMessageStatus = "pending" | "acknowledged" | "dead-letter";
70
+ /** Error message thrown when `restoreResource()` receives a key that is not a valid store key. */
71
+ declare const INVALID_STORE_KEY_ERROR = "Invalid store key";
70
72
 
71
73
  /**
72
74
  * Persisted broker message record stored in the active message channel.
@@ -256,7 +258,7 @@ interface IStore<TData extends StoreDataShape<TData>> {
256
258
  /**
257
259
  * Re-executes previously published channel message id(s).
258
260
  *
259
- * Unlike `travelTo(...)`, replay goes back through the broker/consumer path,
261
+ * Unlike `restoreStoreAt(...)`, replay goes back through the broker/consumer path,
260
262
  * so it can mutate the store again, truncate future history after time
261
263
  * travel, and record new acknowledged history entries.
262
264
  */
@@ -266,7 +268,19 @@ interface IStore<TData extends StoreDataShape<TData>> {
266
268
  *
267
269
  * This navigates snapshots only and does not re-run any message.
268
270
  */
269
- travelTo: StoreHistory<TData>["travelTo"];
271
+ restoreStoreAt: StoreHistory<TData>["restoreStoreAt"];
272
+ /**
273
+ * Restores a single store key to its state at a specific history index.
274
+ *
275
+ * Unlike `restoreStoreAt(index)` which restores the full snapshot, this method
276
+ * only restores the specified key while leaving other keys unaffected.
277
+ * This is snapshot navigation only. It does not publish or acknowledge any
278
+ * message and does not create a new history entry.
279
+ *
280
+ * @param key - The store key to restore.
281
+ * @param index - Optional history index. Defaults to the current index.
282
+ */
283
+ restoreResource: StoreHistory<TData>["restoreResource"];
270
284
  /** Moves one step backward in the recorded snapshot history when possible. */
271
285
  undo: StoreHistory<TData>["undo"];
272
286
  /** Moves one step forward in the recorded snapshot history when possible. */
@@ -293,7 +307,7 @@ interface IStore<TData extends StoreDataShape<TData>> {
293
307
  replayDeadLetter: StoreHistory<TData>["replayDeadLetter"];
294
308
  /** Attempts to replay all current dead-letter messages once. */
295
309
  replayDeadLetters: StoreHistory<TData>["replayDeadLetters"];
296
- /** Returns the currently restored snapshot index used by `travelTo`, `undo`, and `redo`. */
310
+ /** Returns the currently restored snapshot index used by `restoreStoreAt`, `undo`, and `redo`. */
297
311
  getCurrentIndex: StoreHistory<TData>["getCurrentIndex"];
298
312
  /** Merges a single entity into a keyed slot and sets its status to `'Success'`. */
299
313
  updateKeyedOne<K extends StoreKey<TData>>(key: K, resourceKey: KeyedResourceKey, entity: unknown): void;
@@ -345,7 +359,7 @@ declare function createSnapshotRestorePatch<TState extends ResourceState<unknown
345
359
  interface StoreHistoryEntry<TData extends StoreDataShape<TData>, TKey extends StoreKey<TData> = StoreKey<TData>> {
346
360
  /** Stable message id used by `replay(...)`; `null` for the initial snapshot entry. */
347
361
  readonly id: number | null;
348
- /** Snapshot position used by `travelTo(index)`, `undo()`, and `redo()`. */
362
+ /** Snapshot position used by `restoreStoreAt(index)`, `undo()`, and `redo()`. */
349
363
  readonly index: number;
350
364
  /** Acknowledged message that produced this snapshot; `null` for the initial entry. */
351
365
  readonly message: StoreMessage<TData, TKey> | null;
@@ -373,7 +387,7 @@ interface StoreDeadLetterEntry<TData extends StoreDataShape<TData>, TKey extends
373
387
  /**
374
388
  * Public history and recovery API exposed on every store instance.
375
389
  *
376
- * `travelTo(...)` navigates snapshots by history index, while `replay(...)`
390
+ * `restoreStoreAt(...)` navigates snapshots by history index, while `replay(...)`
377
391
  * re-executes previously published channel messages by their stable message ids.
378
392
  */
379
393
  interface StoreHistory<TData extends StoreDataShape<TData>, TKey extends StoreKey<TData> = StoreKey<TData>> {
@@ -406,11 +420,25 @@ interface StoreHistory<TData extends StoreDataShape<TData>, TKey extends StoreKe
406
420
  *
407
421
  * @throws {Error} When the index is outside the recorded history range.
408
422
  */
409
- travelTo(index: number): void;
423
+ restoreStoreAt(index: number): void;
424
+ /**
425
+ * Restores a single store key to its state at a specific history index.
426
+ *
427
+ * Unlike `restoreStoreAt(index)` which restores the full snapshot, this method
428
+ * only restores the specified key while leaving other keys unaffected.
429
+ * This is snapshot navigation only. It does not publish or acknowledge any
430
+ * message and does not create a new history entry.
431
+ *
432
+ * @param key - The store key to restore.
433
+ * @param index - Optional history index. Defaults to the current index.
434
+ * @throws {Error} When the key is not a valid store key.
435
+ * @throws {Error} When the index is outside the recorded history range.
436
+ */
437
+ restoreResource<K extends TKey>(key: K, index?: number): void;
410
438
  /**
411
439
  * Moves to the previous recorded snapshot.
412
440
  *
413
- * Equivalent to `travelTo(getCurrentIndex() - 1)` when possible.
441
+ * Equivalent to `restoreStoreAt(getCurrentIndex() - 1)` when possible.
414
442
  *
415
443
  * @returns `true` when the pointer moved, otherwise `false` at the initial snapshot.
416
444
  */
@@ -418,7 +446,7 @@ interface StoreHistory<TData extends StoreDataShape<TData>, TKey extends StoreKe
418
446
  /**
419
447
  * Moves to the next recorded snapshot when history exists ahead of the current pointer.
420
448
  *
421
- * Equivalent to `travelTo(getCurrentIndex() + 1)` when possible.
449
+ * Equivalent to `restoreStoreAt(getCurrentIndex() + 1)` when possible.
422
450
  *
423
451
  * @returns `true` when the pointer moved, otherwise `false` at the latest snapshot.
424
452
  */
@@ -485,7 +513,9 @@ declare abstract class BaseStore<TEnum extends Record<string, string | number>,
485
513
  private readonly storeKeys;
486
514
  private readonly historyDriver;
487
515
  /** @inheritDoc */
488
- readonly travelTo: (index: number) => void;
516
+ readonly restoreStoreAt: (index: number) => void;
517
+ /** @inheritDoc */
518
+ readonly restoreResource: <K extends StoreKey<TData>>(key: K, index?: number) => void;
489
519
  /** @inheritDoc */
490
520
  readonly undo: () => boolean;
491
521
  /** @inheritDoc */
@@ -604,7 +634,9 @@ declare class LazyStore<TData extends StoreDataShape<TData>> implements IStore<T
604
634
  private readonly hooks;
605
635
  private readonly historyDriver;
606
636
  /** @inheritDoc */
607
- readonly travelTo: (index: number) => void;
637
+ readonly restoreStoreAt: (index: number) => void;
638
+ /** @inheritDoc */
639
+ readonly restoreResource: <K extends StoreKey<TData>>(key: K, index?: number) => void;
608
640
  /** @inheritDoc */
609
641
  readonly undo: () => boolean;
610
642
  /** @inheritDoc */
@@ -968,4 +1000,4 @@ interface CollectKeyedOptions<TEntity> {
968
1000
  */
969
1001
  declare function collectKeyed<TSource extends StoreDataShape<TSource>, TTarget extends StoreDataShape<TTarget>, TEntity = unknown>(source: IStore<TSource>, sourceKey: StoreKey<TSource>, target: IStore<TTarget>, targetKeyOrOptions?: StoreKey<TTarget> | CollectKeyedOptions<TEntity>, options?: CollectKeyedOptions<TEntity>): () => void;
970
1002
 
971
- export { BaseStore, type BrowserStorageStoreMessageChannelOptions, type ClearAllStoreMessage, type ClearKeyedOneStoreMessage, type ClearStoreMessage, type CollectKeyedOptions, type CompositeStoreMessageChannelOptions, type ConfigToData, type IStore, LazyStore, type MirrorOptions, type StartKeyedLoadingStoreMessage, type StartLoadingStoreMessage, type StopLoadingStoreMessage, type StorageStoreMessageChannelOptions, Store, type StoreDeadLetterEntry, type StoreHistory, type StoreHistoryEntry, type StoreMessage, type StoreMessageChannel, type StoreMessageChannelOptions, type StoreMessageChannelStorage, type StoreMessageRecord, type StoreMessageStatus, type StoreOptions, type StoreSnapshot, type UpdateKeyedOneStoreMessage, type UpdateStoreMessage, clearAllStores, cloneValue, collectKeyed, createCompositeStoreMessageChannel, createInMemoryStoreMessageChannel, createLocalStorageStoreMessageChannel, createSessionStorageStoreMessageChannel, createSnapshotRestorePatch, createStorageStoreMessageChannel, mirrorKey };
1003
+ export { BaseStore, type BrowserStorageStoreMessageChannelOptions, type ClearAllStoreMessage, type ClearKeyedOneStoreMessage, type ClearStoreMessage, type CollectKeyedOptions, type CompositeStoreMessageChannelOptions, type ConfigToData, INVALID_STORE_KEY_ERROR, type IStore, LazyStore, type MirrorOptions, type StartKeyedLoadingStoreMessage, type StartLoadingStoreMessage, type StopLoadingStoreMessage, type StorageStoreMessageChannelOptions, Store, type StoreDeadLetterEntry, type StoreHistory, type StoreHistoryEntry, type StoreMessage, type StoreMessageChannel, type StoreMessageChannelOptions, type StoreMessageChannelStorage, type StoreMessageRecord, type StoreMessageStatus, type StoreOptions, type StoreSnapshot, type UpdateKeyedOneStoreMessage, type UpdateStoreMessage, clearAllStores, cloneValue, collectKeyed, createCompositeStoreMessageChannel, createInMemoryStoreMessageChannel, createLocalStorageStoreMessageChannel, createSessionStorageStoreMessageChannel, createSnapshotRestorePatch, createStorageStoreMessageChannel, mirrorKey };