@zeix/cause-effect 0.16.0 → 0.17.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.
Files changed (62) hide show
  1. package/.ai-context.md +71 -21
  2. package/.cursorrules +3 -2
  3. package/.github/copilot-instructions.md +59 -13
  4. package/CLAUDE.md +170 -24
  5. package/LICENSE +1 -1
  6. package/README.md +156 -52
  7. package/archive/benchmark.ts +688 -0
  8. package/archive/collection.ts +312 -0
  9. package/{src → archive}/computed.ts +33 -34
  10. package/archive/list.ts +551 -0
  11. package/archive/memo.ts +138 -0
  12. package/archive/state.ts +89 -0
  13. package/archive/store.ts +368 -0
  14. package/archive/task.ts +194 -0
  15. package/eslint.config.js +1 -0
  16. package/index.dev.js +902 -501
  17. package/index.js +1 -1
  18. package/index.ts +42 -22
  19. package/package.json +1 -1
  20. package/src/classes/collection.ts +272 -0
  21. package/src/classes/composite.ts +176 -0
  22. package/src/classes/computed.ts +333 -0
  23. package/src/classes/list.ts +304 -0
  24. package/src/classes/state.ts +98 -0
  25. package/src/classes/store.ts +210 -0
  26. package/src/diff.ts +28 -52
  27. package/src/effect.ts +9 -9
  28. package/src/errors.ts +50 -25
  29. package/src/signal.ts +58 -41
  30. package/src/system.ts +79 -42
  31. package/src/util.ts +16 -34
  32. package/test/batch.test.ts +15 -17
  33. package/test/benchmark.test.ts +4 -4
  34. package/test/collection.test.ts +796 -0
  35. package/test/computed.test.ts +138 -130
  36. package/test/diff.test.ts +2 -2
  37. package/test/effect.test.ts +36 -35
  38. package/test/list.test.ts +754 -0
  39. package/test/match.test.ts +25 -25
  40. package/test/resolve.test.ts +17 -19
  41. package/test/signal.test.ts +72 -121
  42. package/test/state.test.ts +44 -44
  43. package/test/store.test.ts +344 -1663
  44. package/types/index.d.ts +11 -9
  45. package/types/src/classes/collection.d.ts +32 -0
  46. package/types/src/classes/composite.d.ts +15 -0
  47. package/types/src/classes/computed.d.ts +97 -0
  48. package/types/src/classes/list.d.ts +41 -0
  49. package/types/src/classes/state.d.ts +52 -0
  50. package/types/src/classes/store.d.ts +51 -0
  51. package/types/src/diff.d.ts +8 -12
  52. package/types/src/errors.d.ts +12 -11
  53. package/types/src/signal.d.ts +27 -14
  54. package/types/src/system.d.ts +41 -20
  55. package/types/src/util.d.ts +6 -3
  56. package/src/state.ts +0 -98
  57. package/src/store.ts +0 -525
  58. package/types/src/collection.d.ts +0 -26
  59. package/types/src/computed.d.ts +0 -33
  60. package/types/src/scheduler.d.ts +0 -55
  61. package/types/src/state.d.ts +0 -24
  62. package/types/src/store.d.ts +0 -66
@@ -1,66 +0,0 @@
1
- import { type UnknownArray, type UnknownRecord, type UnknownRecordOrArray } from './diff';
2
- import { type State } from './state';
3
- import { type Cleanup } from './system';
4
- type ArrayItem<T> = T extends readonly (infer U extends {})[] ? U : never;
5
- type StoreChanges<T> = {
6
- add: Partial<T>;
7
- change: Partial<T>;
8
- remove: Partial<T>;
9
- sort: string[];
10
- };
11
- interface BaseStore {
12
- readonly [Symbol.toStringTag]: 'Store';
13
- readonly size: State<number>;
14
- }
15
- type RecordStore<T extends UnknownRecord> = BaseStore & {
16
- [K in keyof T]: T[K] extends readonly unknown[] | Record<string, unknown> ? Store<T[K]> : State<T[K]>;
17
- } & {
18
- [Symbol.iterator](): IterableIterator<[
19
- Extract<keyof T, string>,
20
- T[Extract<keyof T, string>] extends readonly unknown[] | Record<string, unknown> ? Store<T[Extract<keyof T, string>]> : State<T[Extract<keyof T, string>]>
21
- ]>;
22
- add<K extends Extract<keyof T, string>>(key: K, value: T[K]): void;
23
- get(): T;
24
- set(value: T): void;
25
- update(fn: (value: T) => T): void;
26
- sort<U = T[Extract<keyof T, string>]>(compareFn?: (a: U, b: U) => number): void;
27
- on<K extends keyof StoreChanges<T>>(type: K, listener: (change: StoreChanges<T>[K]) => void): Cleanup;
28
- remove<K extends Extract<keyof T, string>>(key: K): void;
29
- };
30
- type ArrayStore<T extends UnknownArray> = BaseStore & {
31
- [Symbol.iterator](): IterableIterator<ArrayItem<T> extends readonly unknown[] | Record<string, unknown> ? Store<ArrayItem<T>> : State<ArrayItem<T>>>;
32
- readonly [Symbol.isConcatSpreadable]: boolean;
33
- [n: number]: ArrayItem<T> extends readonly unknown[] | Record<string, unknown> ? Store<ArrayItem<T>> : State<ArrayItem<T>>;
34
- add(value: ArrayItem<T>): void;
35
- get(): T;
36
- set(value: T): void;
37
- update(fn: (value: T) => T): void;
38
- sort<U = ArrayItem<T>>(compareFn?: (a: U, b: U) => number): void;
39
- on<K extends keyof StoreChanges<T>>(type: K, listener: (change: StoreChanges<T>[K]) => void): Cleanup;
40
- remove(index: number): void;
41
- readonly length: number;
42
- };
43
- type Store<T extends UnknownRecord | UnknownArray> = T extends UnknownRecord ? RecordStore<T> : T extends UnknownArray ? ArrayStore<T> : never;
44
- declare const TYPE_STORE = "Store";
45
- /**
46
- * Create a new store with deeply nested reactive properties
47
- *
48
- * Supports both objects and arrays as initial values. Arrays are converted
49
- * to records internally for storage but maintain their array type through
50
- * the .get() method, which automatically converts objects with consecutive
51
- * numeric keys back to arrays.
52
- *
53
- * @since 0.15.0
54
- * @param {T} initialValue - initial object or array value of the store
55
- * @returns {Store<T>} - new store with reactive properties that preserves the original type T
56
- */
57
- declare const createStore: <T extends UnknownRecord | UnknownArray>(initialValue: T) => Store<T>;
58
- /**
59
- * Check if the provided value is a Store instance
60
- *
61
- * @since 0.15.0
62
- * @param {unknown} value - value to check
63
- * @returns {boolean} - true if the value is a Store instance, false otherwise
64
- */
65
- declare const isStore: <T extends UnknownRecordOrArray>(value: unknown) => value is Store<T>;
66
- export { TYPE_STORE, isStore, createStore, type Store, type StoreChanges };