@ersbeth/picoflow 1.0.1 → 1.1.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.
Files changed (183) hide show
  1. package/.cursor/plans/unifier-flowresource-avec-flowderivation-c9506e24.plan.md +372 -0
  2. package/README.md +17 -1
  3. package/biome.json +4 -1
  4. package/dist/picoflow.js +1155 -582
  5. package/dist/types/flow/base/flowDisposable.d.ts +67 -0
  6. package/dist/types/flow/base/flowDisposable.d.ts.map +1 -0
  7. package/dist/types/flow/base/flowEffect.d.ts +127 -0
  8. package/dist/types/flow/base/flowEffect.d.ts.map +1 -0
  9. package/dist/types/flow/base/flowGraph.d.ts +97 -0
  10. package/dist/types/flow/base/flowGraph.d.ts.map +1 -0
  11. package/dist/types/flow/base/flowSignal.d.ts +134 -0
  12. package/dist/types/flow/base/flowSignal.d.ts.map +1 -0
  13. package/dist/types/flow/base/flowTracker.d.ts +15 -0
  14. package/dist/types/flow/base/flowTracker.d.ts.map +1 -0
  15. package/dist/types/flow/base/index.d.ts +7 -0
  16. package/dist/types/flow/base/index.d.ts.map +1 -0
  17. package/dist/types/flow/base/utils.d.ts +20 -0
  18. package/dist/types/flow/base/utils.d.ts.map +1 -0
  19. package/dist/types/{advanced/array.d.ts → flow/collections/flowArray.d.ts} +50 -12
  20. package/dist/types/flow/collections/flowArray.d.ts.map +1 -0
  21. package/dist/types/flow/collections/flowMap.d.ts +224 -0
  22. package/dist/types/flow/collections/flowMap.d.ts.map +1 -0
  23. package/dist/types/flow/collections/index.d.ts +3 -0
  24. package/dist/types/flow/collections/index.d.ts.map +1 -0
  25. package/dist/types/flow/index.d.ts +4 -0
  26. package/dist/types/flow/index.d.ts.map +1 -0
  27. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts +137 -0
  28. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts.map +1 -0
  29. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts +137 -0
  30. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts.map +1 -0
  31. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts +343 -0
  32. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts.map +1 -0
  33. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts +81 -0
  34. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts.map +1 -0
  35. package/dist/types/flow/nodes/async/flowStateAsync.d.ts +111 -0
  36. package/dist/types/flow/nodes/async/flowStateAsync.d.ts.map +1 -0
  37. package/dist/types/flow/nodes/async/index.d.ts +6 -0
  38. package/dist/types/flow/nodes/async/index.d.ts.map +1 -0
  39. package/dist/types/flow/nodes/index.d.ts +3 -0
  40. package/dist/types/flow/nodes/index.d.ts.map +1 -0
  41. package/dist/types/flow/nodes/sync/flowConstant.d.ts +108 -0
  42. package/dist/types/flow/nodes/sync/flowConstant.d.ts.map +1 -0
  43. package/dist/types/flow/nodes/sync/flowDerivation.d.ts +100 -0
  44. package/dist/types/flow/nodes/sync/flowDerivation.d.ts.map +1 -0
  45. package/dist/types/flow/nodes/sync/flowNode.d.ts +314 -0
  46. package/dist/types/flow/nodes/sync/flowNode.d.ts.map +1 -0
  47. package/dist/types/flow/nodes/sync/flowReadonly.d.ts +57 -0
  48. package/dist/types/flow/nodes/sync/flowReadonly.d.ts.map +1 -0
  49. package/dist/types/flow/nodes/sync/flowState.d.ts +96 -0
  50. package/dist/types/flow/nodes/sync/flowState.d.ts.map +1 -0
  51. package/dist/types/flow/nodes/sync/index.d.ts +6 -0
  52. package/dist/types/flow/nodes/sync/index.d.ts.map +1 -0
  53. package/dist/types/index.d.ts +2 -4
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/dist/types/solid/converters.d.ts +34 -45
  56. package/dist/types/solid/converters.d.ts.map +1 -1
  57. package/dist/types/solid/index.d.ts +2 -2
  58. package/dist/types/solid/index.d.ts.map +1 -1
  59. package/dist/types/solid/primitives.d.ts +1 -0
  60. package/dist/types/solid/primitives.d.ts.map +1 -1
  61. package/docs/.vitepress/config.mts +1 -1
  62. package/docs/api/typedoc-sidebar.json +81 -1
  63. package/package.json +60 -58
  64. package/src/flow/base/flowDisposable.ts +71 -0
  65. package/src/flow/base/flowEffect.ts +171 -0
  66. package/src/flow/base/flowGraph.ts +288 -0
  67. package/src/flow/base/flowSignal.ts +207 -0
  68. package/src/flow/base/flowTracker.ts +17 -0
  69. package/src/flow/base/index.ts +6 -0
  70. package/src/flow/base/utils.ts +19 -0
  71. package/src/flow/collections/flowArray.ts +409 -0
  72. package/src/flow/collections/flowMap.ts +398 -0
  73. package/src/flow/collections/index.ts +2 -0
  74. package/src/flow/index.ts +3 -0
  75. package/src/flow/nodes/async/flowConstantAsync.ts +142 -0
  76. package/src/flow/nodes/async/flowDerivationAsync.ts +143 -0
  77. package/src/flow/nodes/async/flowNodeAsync.ts +474 -0
  78. package/src/flow/nodes/async/flowReadonlyAsync.ts +81 -0
  79. package/src/flow/nodes/async/flowStateAsync.ts +116 -0
  80. package/src/flow/nodes/async/index.ts +5 -0
  81. package/src/flow/nodes/await/advanced/index.ts +5 -0
  82. package/src/{advanced → flow/nodes/await/advanced}/resource.ts +37 -3
  83. package/src/{advanced → flow/nodes/await/advanced}/resourceAsync.ts +35 -3
  84. package/src/{advanced → flow/nodes/await/advanced}/stream.ts +40 -2
  85. package/src/{advanced → flow/nodes/await/advanced}/streamAsync.ts +38 -3
  86. package/src/flow/nodes/await/flowConstantAwait.ts +154 -0
  87. package/src/flow/nodes/await/flowDerivationAwait.ts +154 -0
  88. package/src/flow/nodes/await/flowNodeAwait.ts +508 -0
  89. package/src/flow/nodes/await/flowReadonlyAwait.ts +89 -0
  90. package/src/flow/nodes/await/flowStateAwait.ts +130 -0
  91. package/src/flow/nodes/await/index.ts +5 -0
  92. package/src/flow/nodes/index.ts +3 -0
  93. package/src/flow/nodes/sync/flowConstant.ts +111 -0
  94. package/src/flow/nodes/sync/flowDerivation.ts +105 -0
  95. package/src/flow/nodes/sync/flowNode.ts +439 -0
  96. package/src/flow/nodes/sync/flowReadonly.ts +57 -0
  97. package/src/flow/nodes/sync/flowState.ts +101 -0
  98. package/src/flow/nodes/sync/index.ts +5 -0
  99. package/src/index.ts +2 -47
  100. package/src/solid/converters.ts +60 -199
  101. package/src/solid/index.ts +2 -8
  102. package/src/solid/primitives.ts +4 -0
  103. package/test/base/flowEffect.test.ts +108 -0
  104. package/test/base/flowGraph.test.ts +485 -0
  105. package/test/base/flowSignal.test.ts +372 -0
  106. package/test/collections/flowArray.asyncStates.test.ts +1553 -0
  107. package/test/collections/flowArray.scalars.test.ts +1129 -0
  108. package/test/collections/flowArray.states.test.ts +1365 -0
  109. package/test/collections/flowMap.asyncStates.test.ts +1105 -0
  110. package/test/collections/flowMap.scalars.test.ts +877 -0
  111. package/test/collections/flowMap.states.test.ts +1097 -0
  112. package/test/nodes/async/flowConstantAsync.test.ts +860 -0
  113. package/test/nodes/async/flowDerivationAsync.test.ts +1517 -0
  114. package/test/nodes/async/flowStateAsync.test.ts +1387 -0
  115. package/test/{resource.test.ts → nodes/await/advanced/resource.test.ts} +21 -19
  116. package/test/{resourceAsync.test.ts → nodes/await/advanced/resourceAsync.test.ts} +3 -1
  117. package/test/{stream.test.ts → nodes/await/advanced/stream.test.ts} +30 -28
  118. package/test/{streamAsync.test.ts → nodes/await/advanced/streamAsync.test.ts} +16 -14
  119. package/test/nodes/await/flowConstantAwait.test.ts +643 -0
  120. package/test/nodes/await/flowDerivationAwait.test.ts +1583 -0
  121. package/test/nodes/await/flowStateAwait.test.ts +999 -0
  122. package/test/nodes/mixed/derivation.test.ts +1527 -0
  123. package/test/nodes/sync/flowConstant.test.ts +620 -0
  124. package/test/nodes/sync/flowDerivation.test.ts +1373 -0
  125. package/test/nodes/sync/flowState.test.ts +945 -0
  126. package/test/solid/converters.test.ts +721 -0
  127. package/test/solid/primitives.test.ts +1031 -0
  128. package/tsconfig.json +2 -1
  129. package/vitest.config.ts +7 -1
  130. package/IMPLEMENTATION_GUIDE.md +0 -1578
  131. package/dist/types/advanced/array.d.ts.map +0 -1
  132. package/dist/types/advanced/index.d.ts +0 -9
  133. package/dist/types/advanced/index.d.ts.map +0 -1
  134. package/dist/types/advanced/map.d.ts +0 -166
  135. package/dist/types/advanced/map.d.ts.map +0 -1
  136. package/dist/types/advanced/resource.d.ts +0 -78
  137. package/dist/types/advanced/resource.d.ts.map +0 -1
  138. package/dist/types/advanced/resourceAsync.d.ts +0 -56
  139. package/dist/types/advanced/resourceAsync.d.ts.map +0 -1
  140. package/dist/types/advanced/stream.d.ts +0 -117
  141. package/dist/types/advanced/stream.d.ts.map +0 -1
  142. package/dist/types/advanced/streamAsync.d.ts +0 -97
  143. package/dist/types/advanced/streamAsync.d.ts.map +0 -1
  144. package/dist/types/basic/constant.d.ts +0 -60
  145. package/dist/types/basic/constant.d.ts.map +0 -1
  146. package/dist/types/basic/derivation.d.ts +0 -89
  147. package/dist/types/basic/derivation.d.ts.map +0 -1
  148. package/dist/types/basic/disposable.d.ts +0 -82
  149. package/dist/types/basic/disposable.d.ts.map +0 -1
  150. package/dist/types/basic/effect.d.ts +0 -67
  151. package/dist/types/basic/effect.d.ts.map +0 -1
  152. package/dist/types/basic/index.d.ts +0 -10
  153. package/dist/types/basic/index.d.ts.map +0 -1
  154. package/dist/types/basic/observable.d.ts +0 -83
  155. package/dist/types/basic/observable.d.ts.map +0 -1
  156. package/dist/types/basic/signal.d.ts +0 -69
  157. package/dist/types/basic/signal.d.ts.map +0 -1
  158. package/dist/types/basic/state.d.ts +0 -47
  159. package/dist/types/basic/state.d.ts.map +0 -1
  160. package/dist/types/basic/trackingContext.d.ts +0 -33
  161. package/dist/types/basic/trackingContext.d.ts.map +0 -1
  162. package/dist/types/creators.d.ts +0 -340
  163. package/dist/types/creators.d.ts.map +0 -1
  164. package/src/advanced/array.ts +0 -222
  165. package/src/advanced/index.ts +0 -12
  166. package/src/advanced/map.ts +0 -193
  167. package/src/basic/constant.ts +0 -97
  168. package/src/basic/derivation.ts +0 -147
  169. package/src/basic/disposable.ts +0 -86
  170. package/src/basic/effect.ts +0 -104
  171. package/src/basic/index.ts +0 -9
  172. package/src/basic/observable.ts +0 -109
  173. package/src/basic/signal.ts +0 -145
  174. package/src/basic/state.ts +0 -60
  175. package/src/basic/trackingContext.ts +0 -45
  176. package/src/creators.ts +0 -395
  177. package/test/array.test.ts +0 -600
  178. package/test/constant.test.ts +0 -44
  179. package/test/derivation.test.ts +0 -539
  180. package/test/effect.test.ts +0 -29
  181. package/test/map.test.ts +0 -240
  182. package/test/signal.test.ts +0 -72
  183. package/test/state.test.ts +0 -212
@@ -0,0 +1,224 @@
1
+ import { FlowNode, FlowState } from '../nodes';
2
+ /**
3
+ * Represents the actions that can be performed on a FlowMap.
4
+ * @public
5
+ */
6
+ export type FlowMapAction<K, V> = {
7
+ type: "set";
8
+ map: Map<K, V>;
9
+ } | {
10
+ type: "add";
11
+ key: K;
12
+ value: V;
13
+ } | {
14
+ type: "update";
15
+ key: K;
16
+ value: V;
17
+ } | {
18
+ type: "delete";
19
+ key: K;
20
+ value: V;
21
+ } | {
22
+ type: "clear";
23
+ };
24
+ /**
25
+ * Represents a reactive map that extends {@link FlowState} for tracking key-value pairs.
26
+ *
27
+ * @remarks
28
+ * FlowMap wraps a native JavaScript Map and provides reactive tracking at multiple granularity levels.
29
+ * Unlike plain reactive state, FlowMap offers fine-grained reactivity that lets you track:
30
+ *
31
+ * 1. **Whole map changes**: Via `get(t)` or `pick()` on the FlowMap itself
32
+ * 2. **Last action**: Via the `$lastAction` signal, track the most recent operation performed on the map
33
+ *
34
+ * **Reactive Signals:**
35
+ * - **$lastAction**: A FlowState containing a {@link FlowMapAction} that describes the most recent operation
36
+ * (set, add, update, delete, or clear) performed on the map
37
+ *
38
+ * These signals enable fine-grained reactivity patterns where effects can respond to specific
39
+ * map operations without re-processing the entire map.
40
+ *
41
+ * **Use Cases:**
42
+ * - Entity stores where you want to track additions/removals separately
43
+ * - Cache implementations with granular invalidation
44
+ * - Collections where operations on individual keys matter
45
+ * - UI state where you want to animate specific additions or removals
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const $users = map<string, User>();
50
+ *
51
+ * // Track the whole map
52
+ * effect((t) => {
53
+ * const users = $users.get(t);
54
+ * console.log(`Total users: ${users.size}`);
55
+ * });
56
+ *
57
+ * // Track last action
58
+ * effect((t) => {
59
+ * const action = $users.$lastAction.get(t);
60
+ * switch (action.type) {
61
+ * case 'add':
62
+ * console.log(`User ${action.key} was added:`, action.value);
63
+ * break;
64
+ * case 'update':
65
+ * console.log(`User ${action.key} was updated:`, action.value);
66
+ * break;
67
+ * case 'delete':
68
+ * console.log(`User ${action.key} was deleted:`, action.value);
69
+ * break;
70
+ * case 'set':
71
+ * console.log('Map was replaced');
72
+ * break;
73
+ * case 'clear':
74
+ * console.log('Map was cleared');
75
+ * break;
76
+ * }
77
+ * });
78
+ *
79
+ * // Modify the map
80
+ * $users.add('user1', { name: 'John', age: 30 });
81
+ * $users.add('user2', { name: 'Jane', age: 25 });
82
+ * $users.update('user1', { name: 'John', age: 31 });
83
+ * $users.delete('user1');
84
+ * $users.clear();
85
+ * ```
86
+ *
87
+ * @typeParam K - The type of the map keys.
88
+ * @typeParam V - The type of the map values.
89
+ *
90
+ * @public
91
+ */
92
+ export declare class FlowMap<K, V> extends FlowNode<Map<K, V>> {
93
+ /**
94
+ * Last action performed on the FlowMap.
95
+ * @public
96
+ */
97
+ $lastAction: FlowState<FlowMapAction<K, V>>;
98
+ protected _value: Map<K, V>;
99
+ /**
100
+ * Creates an instance of FlowMap.
101
+ * @param value - Initial map value.
102
+ * @public
103
+ */
104
+ constructor(value?: Map<K, V>);
105
+ /**
106
+ * Adds a new key-value pair to the map.
107
+ *
108
+ * @param key - The key to add.
109
+ * @param value - The value to associate with the key.
110
+ * @throws If the FlowMap instance is disposed.
111
+ * @throws If the key already exists in the map.
112
+ *
113
+ * @remarks
114
+ * Adds a new entry to the internal map, emits the key-value pair via {@link FlowMap.$lastAction},
115
+ * and notifies all subscribers of the change.
116
+ *
117
+ * @public
118
+ */
119
+ add(key: K, value: V): Promise<void>;
120
+ /**
121
+ * Updates an existing key-value pair in the map.
122
+ *
123
+ * @param key - The key to update.
124
+ * @param value - The new value to associate with the key.
125
+ * @throws If the FlowMap instance is disposed.
126
+ * @throws If the key does not exist in the map.
127
+ *
128
+ * @remarks
129
+ * Updates an existing entry in the internal map, emits the key-value pair via {@link FlowMap.$lastAction},
130
+ * and notifies all subscribers of the change.
131
+ *
132
+ * @public
133
+ */
134
+ update(key: K, value: V): Promise<void>;
135
+ /**
136
+ * Deletes the value at the specified key from the underlying map.
137
+ *
138
+ * @param key - The key to delete.
139
+ * @throws If the FlowMap instance is disposed.
140
+ *
141
+ * @remarks
142
+ * Removes the key from the internal map, emits the deleted key and its value via {@link FlowMap.$lastAction},
143
+ * and notifies all subscribers of the change.
144
+ *
145
+ * @public
146
+ */
147
+ delete(key: K): Promise<void>;
148
+ /**
149
+ * Replaces the entire map with new entries.
150
+ *
151
+ * @param map - The new map of entries.
152
+ * @throws If the FlowMap instance is disposed.
153
+ *
154
+ * @remarks
155
+ * Replaces all entries in the internal map, disposes the old values (if they are disposable),
156
+ * emits the new map via {@link FlowMap.$lastAction}, and notifies all subscribers of the change.
157
+ *
158
+ * @public
159
+ */
160
+ set(map: Map<K, V>): Promise<void>;
161
+ /**
162
+ * Clears all entries from the map.
163
+ *
164
+ * @throws If the FlowMap instance is disposed.
165
+ *
166
+ * @remarks
167
+ * Removes all entries from the internal map, disposes the removed values (if they are disposable),
168
+ * emits a clear action via {@link FlowMap.$lastAction}, and notifies all subscribers of the change.
169
+ *
170
+ * @public
171
+ */
172
+ clear(): Promise<void>;
173
+ /**
174
+ * Disposes the FlowMap and its values.
175
+ * @param options - Disposal options.
176
+ * @public
177
+ */
178
+ dispose(options?: {
179
+ self: boolean;
180
+ }): void;
181
+ }
182
+ /**
183
+ * Creates a new reactive map state with fine-grained tracking of operations.
184
+ *
185
+ * @typeParam K - The type of the keys.
186
+ * @typeParam V - The type of the values.
187
+ * @param initial - An optional record of key-value pairs or a Map to initialize the map.
188
+ * @returns A new instance of {@link FlowMap}.
189
+ *
190
+ * @remarks
191
+ * A reactive map wraps a native JavaScript Map and provides multiple levels of reactivity:
192
+ * tracking the entire map, tracking individual set operations, and tracking individual
193
+ * delete operations. The initial record (if provided) is converted to a native Map.
194
+ * If a Map is provided, it is used directly.
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const $users = map<string, User>({
199
+ * 'user1': { name: 'John', age: 30 }
200
+ * });
201
+ *
202
+ * // Or with a Map
203
+ * const $users2 = map<string, User>(new Map([['user1', { name: 'John', age: 30 }]]));
204
+ *
205
+ * // Track the whole map
206
+ * effect((t) => {
207
+ * console.log('Users:', $users.get(t).size);
208
+ * });
209
+ *
210
+ * // Track last action
211
+ * effect((t) => {
212
+ * const action = $users.$lastAction.get(t);
213
+ * if (action.type === 'add') {
214
+ * console.log(`Added: ${action.key}`);
215
+ * }
216
+ * });
217
+ *
218
+ * $users.add('user2', { name: 'Jane', age: 25 });
219
+ * ```
220
+ *
221
+ * @public
222
+ */
223
+ export declare function map<K extends string | number | symbol, V>(initial?: Record<K, V> | Map<K, V>): FlowMap<K, V>;
224
+ //# sourceMappingURL=flowMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowMap.d.ts","sourceRoot":"","sources":["../../../../src/flow/collections/flowMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,SAAS,EAAS,MAAM,UAAU,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAC3B;IACA,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACd,GACD;IACA,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,CAAC,CAAC;IACP,KAAK,EAAE,CAAC,CAAC;CACR,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,CAAC,CAAC;IACP,KAAK,EAAE,CAAC,CAAC;CACR,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,CAAC,CAAC;IACP,KAAK,EAAE,CAAC,CAAC;CACR,GACD;IACA,IAAI,EAAE,OAAO,CAAC;CACb,CAAC;AAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD;;;OAGG;IACI,WAAW,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACnD,UAAkB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpC;;;;OAIG;gBACS,KAAK,GAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAa;IAQxC;;;;;;;;;;;;;OAaG;IACU,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BjD;;;;;;;;;;;;;OAaG;IACU,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCpD;;;;;;;;;;;OAWG;IACU,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B1C;;;;;;;;;;;OAWG;IACY,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCjD;;;;;;;;;;OAUG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BnC;;;;OAIG;IACM,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAOnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EACxD,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAOf"}
@@ -0,0 +1,3 @@
1
+ export * from './flowArray';
2
+ export * from './flowMap';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/flow/collections/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './base';
2
+ export * from './collections';
3
+ export * from './nodes';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/flow/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,137 @@
1
+ import { FlowNodeAsync } from './flowNodeAsync';
2
+ /**
3
+ * Represents a constant value that can be computed lazily upon first access, with asynchronous values.
4
+ *
5
+ * @typeParam T - The type of the constant value (not the Promise itself).
6
+ *
7
+ * @remarks
8
+ * `FlowConstantAsync` is a type alias based on {@link FlowNodeAsync} with the `set()` and `refresh()`
9
+ * methods removed, making it immutable. It provides all the reactive capabilities of `FlowNodeAsync`
10
+ * (lazy computation, caching, dependency tracking) but prevents value mutation after initialization.
11
+ *
12
+ * Unlike {@link FlowStateAsync}, which is mutable via the `set()` method, a constant's value never
13
+ * changes after it's computed. This makes it ideal for values that should remain stable throughout
14
+ * the application lifecycle.
15
+ *
16
+ * **Asynchronous Nature:**
17
+ * All values in FlowConstantAsync are Promises. When you call `get()` or `pick()`, you receive a
18
+ * `Promise<T>` that you must await to get the actual value. This allows for seamless integration
19
+ * with async/await patterns and asynchronous data sources.
20
+ *
21
+ * **Lazy Computation:**
22
+ * Constants are created using the `constantAsync()` factory function, which accepts either a
23
+ * `Promise<T>` or a function returning `Promise<T>`. The computation doesn't run immediately
24
+ * upon creation when using a function. It executes only when:
25
+ * - The value is first read via `get()` or `pick()`
26
+ * - The constant is watched via `watch()`
27
+ * This allows you to defer expensive async computations until they're actually needed.
28
+ *
29
+ * **Initialization Patterns:**
30
+ * - **Constant Promise**: Pass a `Promise<T>` directly; it's stored immediately and can be accessed
31
+ * right away. The Promise resolves to the value of type T.
32
+ * - **Lazy initialization**: Pass a function `() => Promise<T>`; it's called only when the value
33
+ * is first accessed via `get()` or `pick()`. This is useful for expensive async operations that
34
+ * may not be needed immediately.
35
+ *
36
+ * **Caching:**
37
+ * Once computed (either immediately or lazily), the Promise is cached permanently. All subsequent
38
+ * accesses return the cached Promise without re-computation, ensuring the value remains constant
39
+ * and the computation runs only once.
40
+ *
41
+ * **Use Cases:**
42
+ * - Configuration values loaded asynchronously that don't change
43
+ * - Expensive async computations that should only run once
44
+ * - Initialization values for other reactive primitives
45
+ * - Values derived from external async sources that shouldn't be modified
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Constant Promise - initialized immediately
50
+ * const $config = constantAsync(Promise.resolve({ apiUrl: 'https://api.example.com' }));
51
+ * const config = await $config.pick(); // Resolves immediately
52
+ *
53
+ * // Lazy initialization - computed on first access
54
+ * const $expensiveValue = constantAsync(async () => {
55
+ * console.log('Computing...');
56
+ * return await performExpensiveAsyncCalculation();
57
+ * });
58
+ *
59
+ * // First access triggers computation
60
+ * const value1 = await $expensiveValue.pick(); // Logs: "Computing..."
61
+ *
62
+ * // Subsequent accesses return cached Promise
63
+ * const value2 = await $expensiveValue.pick(); // No log - returns cached value
64
+ *
65
+ * // Value cannot be changed (set() method is not available)
66
+ * // $expensiveValue.set(Promise.resolve(100)); // TypeScript error: Property 'set' does not exist
67
+ * ```
68
+ *
69
+ * @public
70
+ */
71
+ export type FlowConstantAsync<T> = Omit<FlowNodeAsync<T>, "set" | "refresh">;
72
+ /**
73
+ * Creates a new reactive constant with lazy initialization support.
74
+ *
75
+ * @typeParam T - The type of the constant value (not the Promise itself).
76
+ *
77
+ * @param value - Either a `Promise<T>` for immediate initialization, or a function `() => Promise<T>`
78
+ * for lazy initialization. The function will be called only when the value is first accessed.
79
+ *
80
+ * @returns A new instance of {@link FlowConstantAsync} that provides reactive access to the computed value.
81
+ *
82
+ * @remarks
83
+ * Constants are immutable reactive values that are computed once and cached permanently. Unlike
84
+ * states (created with `stateAsync()`), constants cannot be modified after initialization - they don't
85
+ * have a `set()` method.
86
+ *
87
+ * **Asynchronous Nature:**
88
+ * All values are Promises. When you access the constant via `get(t)` or `pick()`, you receive a
89
+ * `Promise<T>` that you must await to get the actual value. This allows for seamless integration
90
+ * with async/await patterns and asynchronous data sources.
91
+ *
92
+ * **Lazy Computation:**
93
+ * When you provide a function, the computation is not executed immediately upon creation. It runs only when:
94
+ * - The value is first read via `get(t)` or `pick()`
95
+ * - The constant is watched via `watch()`
96
+ *
97
+ * This lazy computation is useful for:
98
+ * - Expensive async computations that may not be needed immediately
99
+ * - Values that depend on resources not available at construction time
100
+ * - Deferring async operations until the value is actually needed
101
+ *
102
+ * **When to Use Constants:**
103
+ * - Use `constantAsync()` for values that should never change after initialization
104
+ * - Use `stateAsync()` for mutable values that can be updated
105
+ * - Use `derivationAsync()` for values that recompute when dependencies change
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Eager initialization with Promise
110
+ * const $config = constantAsync(Promise.resolve({
111
+ * apiUrl: 'https://api.example.com'
112
+ * }));
113
+ * const config = await $config.pick();
114
+ *
115
+ * // Lazy initialization with async function
116
+ * const $expensiveValue = constantAsync(async () => {
117
+ * return await loadConfigurationFromFile();
118
+ * });
119
+ *
120
+ * // Computation hasn't run yet
121
+ * // First access triggers it
122
+ * const value = await $expensiveValue.pick();
123
+ *
124
+ * // Subsequent accesses return cached Promise
125
+ * const value2 = await $expensiveValue.pick();
126
+ *
127
+ * // Use in reactive context
128
+ * effect(async (t) => {
129
+ * const cfg = await $config.get(t);
130
+ * console.log(`API URL: ${cfg.apiUrl}`);
131
+ * });
132
+ * ```
133
+ *
134
+ * @public
135
+ */
136
+ export declare function constantAsync<T>(value: Promise<T> | (() => Promise<T>)): FlowConstantAsync<T>;
137
+ //# sourceMappingURL=flowConstantAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowConstantAsync.d.ts","sourceRoot":"","sources":["../../../../../src/flow/nodes/async/flowConstantAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC9B,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GACpC,iBAAiB,CAAC,CAAC,CAAC,CAEtB"}
@@ -0,0 +1,137 @@
1
+ import { FlowTracker } from '../../base';
2
+ import { FlowNodeAsync } from './flowNodeAsync';
3
+ /**
4
+ * Represents a reactive derivation whose value is computed based on other reactive signals, with asynchronous values.
5
+ *
6
+ * @typeParam T - The type of the computed value (not the Promise itself).
7
+ *
8
+ * @remarks
9
+ * `FlowDerivationAsync` is a type alias based on {@link FlowNodeAsync} with the `set()` method removed,
10
+ * making it immutable. It provides all the reactive capabilities of `FlowNodeAsync` (dependency tracking,
11
+ * lazy computation, caching) but prevents value mutation after initialization.
12
+ *
13
+ * Unlike {@link FlowConstantAsync}, which computes its value once and never changes, derivations
14
+ * automatically recompute when any tracked dependency changes. This makes them ideal for
15
+ * creating derived state that stays in sync with its sources.
16
+ *
17
+ * **Asynchronous Nature:**
18
+ * All values in FlowDerivationAsync are Promises. When you call `get()` or `pick()`, you receive a
19
+ * `Promise<T>` that you must await to get the actual value. The compute function must return a
20
+ * `Promise<T>`. This allows for seamless integration with async/await patterns and asynchronous
21
+ * data sources.
22
+ *
23
+ * **Lazy Computation:**
24
+ * The compute function doesn't run immediately upon creation. It executes only when:
25
+ * - The value is first read via `get()` or `pick()`
26
+ * - The derivation is watched via `watch()`
27
+ * This allows you to defer expensive async computations until they're actually needed.
28
+ *
29
+ * **Automatic Recomputation:**
30
+ * When a tracked dependency changes, the derivation is marked as "dirty" but doesn't recompute
31
+ * immediately. Recomputation happens lazily on the next value access. This prevents unnecessary
32
+ * computations when multiple dependencies change in quick succession. The Promise is cached until
33
+ * dependencies change, ensuring efficient access patterns. You can also force recomputation using
34
+ * the `refresh()` method.
35
+ *
36
+ * **Dynamic Dependencies:**
37
+ * Dependencies are tracked dynamically during each computation. If the compute function
38
+ * conditionally tracks different observables, the dependency graph updates automatically.
39
+ * When accessing async dependencies via `.get(t)`, you must await the returned Promise.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const $firstName = stateAsync(Promise.resolve('John'));
44
+ * const $lastName = stateAsync(Promise.resolve('Doe'));
45
+ *
46
+ * const $fullName = derivationAsync(async (t) => {
47
+ * const first = await $firstName.get(t);
48
+ * const last = await $lastName.get(t);
49
+ * return `${first} ${last}`;
50
+ * });
51
+ *
52
+ * // Compute function hasn't run yet (lazy)
53
+ * const name = await $fullName.pick(); // Now it computes: "John Doe"
54
+ *
55
+ * // When dependencies change, derivation recomputes automatically
56
+ * await $firstName.set(Promise.resolve('Jane'));
57
+ * const newName = await $fullName.pick(); // "Jane Doe" (recomputed)
58
+ * ```
59
+ *
60
+ * @public
61
+ */
62
+ export type FlowDerivationAsync<T> = Omit<FlowNodeAsync<T>, "set">;
63
+ /**
64
+ * Creates a new reactive derivation whose value is computed based on other reactive signals.
65
+ *
66
+ * @typeParam T - The type of the derived value (not the Promise itself).
67
+ *
68
+ * @param fn - A function that computes the derived value using a tracking context. The function
69
+ * receives a tracking context (`t`) that should be used to access dependencies via `.get(t)`.
70
+ * The function must return a `Promise<T>`. The function is not executed immediately; it runs
71
+ * lazily on first access.
72
+ *
73
+ * @returns A new instance of {@link FlowDerivationAsync} that provides reactive access to the computed value.
74
+ *
75
+ * @remarks
76
+ * A derivation is a computed reactive value that automatically tracks its dependencies and
77
+ * recomputes when they change. The computation is lazy - it runs only when the value is
78
+ * accessed, not on construction. Use derivations to create derived state without manual
79
+ * dependency management.
80
+ *
81
+ * **Asynchronous Nature:**
82
+ * All values are Promises. When you access the derivation via `get(t)` or `pick()`, you receive a
83
+ * `Promise<T>` that you must await to get the actual value. The compute function must return a
84
+ * `Promise<T>`. When accessing async dependencies within the compute function, you must await
85
+ * the Promises returned by `.get(t)`.
86
+ *
87
+ * **Lazy Computation:**
88
+ * The compute function is not executed immediately upon creation. It runs only when:
89
+ * - The value is first read via `get(t)` or `pick()`
90
+ * - The derivation is watched via `watch()`
91
+ *
92
+ * This lazy computation is useful for:
93
+ * - Expensive async computations that may not be needed immediately
94
+ * - Values that depend on async resources
95
+ * - Deferring async operations until the value is actually needed
96
+ *
97
+ * **Automatic Recomputation:**
98
+ * When any tracked dependency changes, the derivation automatically recomputes on the next access.
99
+ * This ensures the derived value always stays in sync with its sources.
100
+ *
101
+ * **When to Use Derivations:**
102
+ * - Use `derivationAsync()` for values that should recompute when dependencies change
103
+ * - Use `constantAsync()` for values that compute once and never change
104
+ * - Use `stateAsync()` for mutable values that can be updated directly
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const $firstName = stateAsync(Promise.resolve('John'));
109
+ * const $lastName = stateAsync(Promise.resolve('Doe'));
110
+ *
111
+ * const $fullName = derivationAsync(async (t) => {
112
+ * const first = await $firstName.get(t);
113
+ * const last = await $lastName.get(t);
114
+ * return `${first} ${last}`;
115
+ * });
116
+ *
117
+ * // Use in reactive context
118
+ * effect(async (t) => {
119
+ * const name = await $fullName.get(t);
120
+ * console.log(name); // Logs: "John Doe"
121
+ * });
122
+ *
123
+ * // When dependencies change, derivation recomputes automatically
124
+ * await $firstName.set(Promise.resolve('Jane')); // Logs: "Jane Doe"
125
+ *
126
+ * // Async data fetching example
127
+ * const $userId = stateAsync(Promise.resolve(1));
128
+ * const $user = derivationAsync(async (t) => {
129
+ * const id = await $userId.get(t);
130
+ * return await fetchUser(id);
131
+ * });
132
+ * ```
133
+ *
134
+ * @public
135
+ */
136
+ export declare function derivationAsync<T>(fn: (t: FlowTracker) => Promise<T>): FlowDerivationAsync<T>;
137
+ //# sourceMappingURL=flowDerivationAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowDerivationAsync.d.ts","sourceRoot":"","sources":["../../../../../src/flow/nodes/async/flowDerivationAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAChC,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAChC,mBAAmB,CAAC,CAAC,CAAC,CAExB"}