@zeix/cause-effect 0.15.0 → 0.15.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.
@@ -1,39 +1,39 @@
1
- import { type UnknownRecord } from './diff';
1
+ import { type UnknownRecord, type UnknownRecordOrArray } from './diff';
2
2
  import { type Signal } from './signal';
3
3
  import { type State } from './state';
4
4
  declare const TYPE_STORE = "Store";
5
- interface StoreAddEvent<T extends UnknownRecord> extends CustomEvent {
5
+ interface StoreAddEvent<T extends UnknownRecordOrArray> extends CustomEvent {
6
6
  type: 'store-add';
7
7
  detail: Partial<T>;
8
8
  }
9
- interface StoreChangeEvent<T extends UnknownRecord> extends CustomEvent {
9
+ interface StoreChangeEvent<T extends UnknownRecordOrArray> extends CustomEvent {
10
10
  type: 'store-change';
11
11
  detail: Partial<T>;
12
12
  }
13
- interface StoreRemoveEvent<T extends UnknownRecord> extends CustomEvent {
13
+ interface StoreRemoveEvent<T extends UnknownRecordOrArray> extends CustomEvent {
14
14
  type: 'store-remove';
15
15
  detail: Partial<T>;
16
16
  }
17
- type StoreEventMap<T extends UnknownRecord> = {
17
+ type StoreEventMap<T extends UnknownRecordOrArray> = {
18
18
  'store-add': StoreAddEvent<T>;
19
19
  'store-change': StoreChangeEvent<T>;
20
20
  'store-remove': StoreRemoveEvent<T>;
21
21
  };
22
- interface StoreEventTarget<T extends UnknownRecord> extends EventTarget {
22
+ interface StoreEventTarget<T extends UnknownRecordOrArray> extends EventTarget {
23
23
  addEventListener<K extends keyof StoreEventMap<T>>(type: K, listener: (event: StoreEventMap<T>[K]) => void, options?: boolean | AddEventListenerOptions): void;
24
24
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
25
25
  removeEventListener<K extends keyof StoreEventMap<T>>(type: K, listener: (event: StoreEventMap<T>[K]) => void, options?: boolean | EventListenerOptions): void;
26
26
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
27
27
  dispatchEvent(event: Event): boolean;
28
28
  }
29
- type Store<T extends UnknownRecord = UnknownRecord> = {
30
- [K in keyof T & string]: T[K] extends UnknownRecord ? Store<T[K]> : State<T[K]>;
29
+ type Store<T extends UnknownRecordOrArray = UnknownRecord> = {
30
+ [K in keyof T]: T[K] extends UnknownRecord ? Store<T[K]> : State<T[K]>;
31
31
  } & StoreEventTarget<T> & {
32
32
  [Symbol.toStringTag]: 'Store';
33
- [Symbol.iterator](): IterableIterator<[string, Signal<T[keyof T]>]>;
34
- add<K extends keyof T & string>(key: K, value: T[K]): void;
33
+ [Symbol.iterator](): IterableIterator<[keyof T, Signal<T[keyof T]>]>;
34
+ add<K extends keyof T>(key: K, value: T[K]): void;
35
35
  get(): T;
36
- remove<K extends keyof T & string>(key: K): void;
36
+ remove<K extends keyof T>(key: K): void;
37
37
  set(value: T): void;
38
38
  update(updater: (value: T) => T): void;
39
39
  size: State<number>;
@@ -41,11 +41,16 @@ type Store<T extends UnknownRecord = UnknownRecord> = {
41
41
  /**
42
42
  * Create a new store with deeply nested reactive properties
43
43
  *
44
+ * Supports both objects and arrays as initial values. Arrays are converted
45
+ * to records internally for storage but maintain their array type through
46
+ * the .get() method, which automatically converts objects with consecutive
47
+ * numeric keys back to arrays.
48
+ *
44
49
  * @since 0.15.0
45
- * @param {T} initialValue - initial object value of the store
46
- * @returns {Store<T>} - new store with reactive properties
50
+ * @param {T} initialValue - initial object or array value of the store
51
+ * @returns {Store<T>} - new store with reactive properties that preserves the original type T
47
52
  */
48
- declare const store: <T extends UnknownRecord>(initialValue: T) => Store<T>;
53
+ declare const store: <T extends UnknownRecordOrArray>(initialValue: T) => Store<T>;
49
54
  /**
50
55
  * Check if the provided value is a Store instance
51
56
  *
@@ -53,5 +58,5 @@ declare const store: <T extends UnknownRecord>(initialValue: T) => Store<T>;
53
58
  * @param {unknown} value - value to check
54
59
  * @returns {boolean} - true if the value is a Store instance, false otherwise
55
60
  */
56
- declare const isStore: <T extends UnknownRecord>(value: unknown) => value is Store<T>;
61
+ declare const isStore: <T extends UnknownRecordOrArray>(value: unknown) => value is Store<T>;
57
62
  export { TYPE_STORE, isStore, store, type Store, type StoreAddEvent, type StoreChangeEvent, type StoreRemoveEvent, type StoreEventMap, };
@@ -1,15 +1,14 @@
1
- declare const isNumber: (value: unknown) => value is number;
2
1
  declare const isString: (value: unknown) => value is string;
2
+ declare const isNumber: (value: unknown) => value is number;
3
3
  declare const isFunction: <T>(fn: unknown) => fn is (...args: unknown[]) => T;
4
4
  declare const isAsyncFunction: <T>(fn: unknown) => fn is (...args: unknown[]) => Promise<T>;
5
5
  declare const isObjectOfType: <T>(value: unknown, type: string) => value is T;
6
6
  declare const isRecord: <T extends Record<string, unknown>>(value: unknown) => value is T;
7
- declare const isPrimitive: (value: unknown) => boolean;
8
- declare const arrayToRecord: <T extends unknown & {}>(array: T[]) => Record<string, T>;
7
+ declare const validArrayIndexes: (keys: Array<PropertyKey>) => number[] | null;
9
8
  declare const hasMethod: <T extends object & Record<string, (...args: unknown[]) => unknown>>(obj: T, methodName: string) => obj is T & Record<string, (...args: unknown[]) => unknown>;
10
9
  declare const isAbortError: (error: unknown) => boolean;
11
10
  declare const toError: (reason: unknown) => Error;
12
11
  declare class CircularDependencyError extends Error {
13
12
  constructor(where: string);
14
13
  }
15
- export { isNumber, isString, isFunction, isAsyncFunction, isObjectOfType, isRecord, isPrimitive, arrayToRecord, hasMethod, isAbortError, toError, CircularDependencyError, };
14
+ export { isString, isNumber, isFunction, isAsyncFunction, isObjectOfType, isRecord, validArrayIndexes, hasMethod, isAbortError, toError, CircularDependencyError, };