@ersbeth/picoflow 1.1.2 → 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.
Files changed (383) hide show
  1. package/.vscode/settings.json +3 -3
  2. package/CHANGELOG.md +43 -0
  3. package/README.md +2 -18
  4. package/biome.json +45 -35
  5. package/dist/picoflow.js +856 -1530
  6. package/dist/types/api/base/flowDisposable.d.ts +41 -0
  7. package/dist/types/api/base/flowDisposable.d.ts.map +1 -0
  8. package/dist/types/api/base/flowObservable.d.ts +27 -0
  9. package/dist/types/api/base/flowObservable.d.ts.map +1 -0
  10. package/dist/types/api/base/flowSubscribable.d.ts +79 -0
  11. package/dist/types/api/base/flowSubscribable.d.ts.map +1 -0
  12. package/dist/types/api/base/flowTracker.d.ts +8 -0
  13. package/dist/types/api/base/flowTracker.d.ts.map +1 -0
  14. package/dist/types/api/base/index.d.ts +5 -0
  15. package/dist/types/api/base/index.d.ts.map +1 -0
  16. package/dist/types/api/index.d.ts +3 -0
  17. package/dist/types/api/index.d.ts.map +1 -0
  18. package/dist/types/api/nodes/async/flowConstantAsync.d.ts +31 -0
  19. package/dist/types/api/nodes/async/flowConstantAsync.d.ts.map +1 -0
  20. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts +37 -0
  21. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts.map +1 -0
  22. package/dist/types/api/nodes/async/flowStateAsync.d.ts +41 -0
  23. package/dist/types/api/nodes/async/flowStateAsync.d.ts.map +1 -0
  24. package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts +30 -0
  25. package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts.map +1 -0
  26. package/dist/types/{flow → api}/nodes/async/index.d.ts +1 -2
  27. package/dist/types/api/nodes/async/index.d.ts.map +1 -0
  28. package/dist/types/api/nodes/collections/flowArray.d.ts +134 -0
  29. package/dist/types/api/nodes/collections/flowArray.d.ts.map +1 -0
  30. package/dist/types/api/nodes/collections/flowMap.d.ts +98 -0
  31. package/dist/types/api/nodes/collections/flowMap.d.ts.map +1 -0
  32. package/dist/types/api/nodes/collections/index.d.ts.map +1 -0
  33. package/dist/types/api/nodes/flowEffect.d.ts +28 -0
  34. package/dist/types/api/nodes/flowEffect.d.ts.map +1 -0
  35. package/dist/types/api/nodes/flowSignal.d.ts +25 -0
  36. package/dist/types/api/nodes/flowSignal.d.ts.map +1 -0
  37. package/dist/types/api/nodes/flowValue.d.ts +35 -0
  38. package/dist/types/api/nodes/flowValue.d.ts.map +1 -0
  39. package/dist/types/api/nodes/index.d.ts +8 -0
  40. package/dist/types/api/nodes/index.d.ts.map +1 -0
  41. package/dist/types/api/nodes/sync/flowConstant.d.ts +29 -0
  42. package/dist/types/api/nodes/sync/flowConstant.d.ts.map +1 -0
  43. package/dist/types/api/nodes/sync/flowDerivation.d.ts +36 -0
  44. package/dist/types/api/nodes/sync/flowDerivation.d.ts.map +1 -0
  45. package/dist/types/api/nodes/sync/flowState.d.ts +39 -0
  46. package/dist/types/api/nodes/sync/flowState.d.ts.map +1 -0
  47. package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts +28 -0
  48. package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts.map +1 -0
  49. package/dist/types/{flow → api}/nodes/sync/index.d.ts +1 -2
  50. package/dist/types/api/nodes/sync/index.d.ts.map +1 -0
  51. package/dist/types/api/nodes/utils.d.ts +22 -0
  52. package/dist/types/api/nodes/utils.d.ts.map +1 -0
  53. package/dist/types/base/disposable.d.ts +11 -0
  54. package/dist/types/base/disposable.d.ts.map +1 -0
  55. package/dist/types/base/executionStack.d.ts +14 -0
  56. package/dist/types/base/executionStack.d.ts.map +1 -0
  57. package/dist/types/base/index.d.ts +6 -0
  58. package/dist/types/base/index.d.ts.map +1 -0
  59. package/dist/types/base/node.d.ts +27 -0
  60. package/dist/types/base/node.d.ts.map +1 -0
  61. package/dist/types/base/observable.d.ts +37 -0
  62. package/dist/types/base/observable.d.ts.map +1 -0
  63. package/dist/types/base/observer.d.ts +25 -0
  64. package/dist/types/base/observer.d.ts.map +1 -0
  65. package/dist/types/converters/index.d.ts +2 -0
  66. package/dist/types/converters/index.d.ts.map +1 -0
  67. package/dist/types/converters/solid.d.ts +46 -0
  68. package/dist/types/converters/solid.d.ts.map +1 -0
  69. package/dist/types/index.d.ts +2 -63
  70. package/dist/types/index.d.ts.map +1 -1
  71. package/dist/types/nodes/arrayNode.d.ts +2 -0
  72. package/dist/types/nodes/arrayNode.d.ts.map +1 -0
  73. package/dist/types/nodes/effectNode.d.ts +2 -0
  74. package/dist/types/nodes/effectNode.d.ts.map +1 -0
  75. package/dist/types/nodes/index.d.ts +9 -0
  76. package/dist/types/nodes/index.d.ts.map +1 -0
  77. package/dist/types/nodes/mapNode.d.ts +2 -0
  78. package/dist/types/nodes/mapNode.d.ts.map +1 -0
  79. package/dist/types/nodes/signalNode.d.ts +2 -0
  80. package/dist/types/nodes/signalNode.d.ts.map +1 -0
  81. package/dist/types/nodes/valueAsyncNode.d.ts +2 -0
  82. package/dist/types/nodes/valueAsyncNode.d.ts.map +1 -0
  83. package/dist/types/nodes/valueNode.d.ts +2 -0
  84. package/dist/types/nodes/valueNode.d.ts.map +1 -0
  85. package/dist/types/nodes/valueSyncNode.d.ts +2 -0
  86. package/dist/types/nodes/valueSyncNode.d.ts.map +1 -0
  87. package/dist/types/schedulers/asyncResolver.d.ts +2 -0
  88. package/dist/types/schedulers/asyncResolver.d.ts.map +1 -0
  89. package/dist/types/schedulers/asyncScheduler.d.ts +2 -0
  90. package/dist/types/schedulers/asyncScheduler.d.ts.map +1 -0
  91. package/dist/types/schedulers/index.d.ts +5 -0
  92. package/dist/types/schedulers/index.d.ts.map +1 -0
  93. package/dist/types/schedulers/pendingError.d.ts +2 -0
  94. package/dist/types/schedulers/pendingError.d.ts.map +1 -0
  95. package/dist/types/schedulers/scheduler.d.ts +2 -0
  96. package/dist/types/schedulers/scheduler.d.ts.map +1 -0
  97. package/dist/types/schedulers/syncResolver.d.ts +2 -0
  98. package/dist/types/schedulers/syncResolver.d.ts.map +1 -0
  99. package/dist/types/schedulers/syncScheduler.d.ts +2 -0
  100. package/dist/types/schedulers/syncScheduler.d.ts.map +1 -0
  101. package/docs/.vitepress/config.mts +128 -93
  102. package/docs/api/functions/array.md +14 -37
  103. package/docs/api/functions/constant.md +13 -25
  104. package/docs/api/functions/constantAsync.md +69 -0
  105. package/docs/api/functions/derivation.md +14 -33
  106. package/docs/api/functions/derivationAsync.md +34 -0
  107. package/docs/api/functions/from.md +62 -153
  108. package/docs/api/functions/isDisposable.md +8 -30
  109. package/docs/api/functions/map.md +15 -36
  110. package/docs/api/functions/signal.md +8 -23
  111. package/docs/api/functions/state.md +43 -23
  112. package/docs/api/functions/stateAsync.md +69 -0
  113. package/docs/api/functions/subscribe.md +40 -0
  114. package/docs/api/functions/writableDerivation.md +33 -0
  115. package/docs/api/functions/writableDerivationAsync.md +34 -0
  116. package/docs/api/index.md +45 -102
  117. package/docs/api/interfaces/FlowArray.md +439 -0
  118. package/docs/api/interfaces/FlowConstant.md +220 -0
  119. package/docs/api/interfaces/FlowConstantAsync.md +221 -0
  120. package/docs/api/interfaces/FlowDerivation.md +241 -0
  121. package/docs/api/interfaces/FlowDerivationAsync.md +242 -0
  122. package/docs/api/interfaces/FlowDisposable.md +32 -38
  123. package/docs/api/interfaces/FlowEffect.md +64 -0
  124. package/docs/api/interfaces/FlowMap.md +374 -0
  125. package/docs/api/interfaces/FlowObservable.md +155 -0
  126. package/docs/api/interfaces/FlowSignal.md +156 -0
  127. package/docs/api/interfaces/FlowState.md +269 -0
  128. package/docs/api/interfaces/FlowStateAsync.md +268 -0
  129. package/docs/api/interfaces/FlowSubscribable.md +55 -0
  130. package/docs/api/interfaces/FlowTracker.md +61 -0
  131. package/docs/api/interfaces/FlowValue.md +222 -0
  132. package/docs/api/interfaces/FlowWritableDerivation.md +292 -0
  133. package/docs/api/interfaces/FlowWritableDerivationAsync.md +293 -0
  134. package/docs/api/type-aliases/DerivationFunction.md +28 -0
  135. package/docs/api/type-aliases/DerivationFunctionAsync.md +28 -0
  136. package/docs/api/type-aliases/FlowArrayAction.md +19 -8
  137. package/docs/api/type-aliases/FlowDataTracker.md +33 -0
  138. package/docs/api/type-aliases/FlowMapAction.md +48 -0
  139. package/docs/api/type-aliases/FlowOnDataListener.md +33 -0
  140. package/docs/api/type-aliases/FlowOnErrorListener.md +27 -0
  141. package/docs/api/type-aliases/FlowOnPendingListener.md +21 -0
  142. package/docs/api/type-aliases/FlowReadonly.md +22 -0
  143. package/docs/api/type-aliases/InitFunction.md +21 -0
  144. package/docs/api/type-aliases/InitFunctionAsync.md +21 -0
  145. package/docs/api/type-aliases/NotPromise.md +6 -3
  146. package/docs/api/type-aliases/UpdateFunction.md +27 -0
  147. package/docs/api/type-aliases/UpdateFunctionAsync.md +27 -0
  148. package/docs/api/typedoc-sidebar.json +1 -81
  149. package/docs/examples/examples.md +0 -2
  150. package/docs/guide/advanced/architecture.md +1234 -0
  151. package/docs/guide/advanced/migration-v2.md +204 -0
  152. package/docs/guide/advanced/solidjs.md +2 -88
  153. package/docs/guide/introduction/concepts.md +4 -3
  154. package/docs/guide/introduction/conventions.md +2 -33
  155. package/docs/guide/introduction/getting-started.md +28 -23
  156. package/docs/guide/introduction/lifecycle.md +16 -19
  157. package/docs/guide/primitives/array.md +102 -216
  158. package/docs/guide/primitives/constant.md +39 -212
  159. package/docs/guide/primitives/derivations.md +55 -122
  160. package/docs/guide/primitives/effects.md +155 -241
  161. package/docs/guide/primitives/map.md +64 -186
  162. package/docs/guide/primitives/overview.md +45 -128
  163. package/docs/guide/primitives/signal.md +51 -88
  164. package/docs/guide/primitives/state.md +34 -130
  165. package/package.json +56 -60
  166. package/src/api/base/flowDisposable.ts +44 -0
  167. package/src/api/base/flowObservable.ts +28 -0
  168. package/src/api/base/flowSubscribable.ts +87 -0
  169. package/src/api/base/flowTracker.ts +7 -0
  170. package/src/api/base/index.ts +4 -0
  171. package/src/{flow → api}/index.ts +0 -1
  172. package/src/api/nodes/async/flowConstantAsync.ts +36 -0
  173. package/src/api/nodes/async/flowDerivationAsync.ts +42 -0
  174. package/src/api/nodes/async/flowStateAsync.ts +47 -0
  175. package/src/api/nodes/async/flowWritableDerivationAsync.ts +33 -0
  176. package/src/{flow → api}/nodes/async/index.ts +1 -2
  177. package/src/api/nodes/collections/flowArray.ts +155 -0
  178. package/src/api/nodes/collections/flowMap.ts +115 -0
  179. package/src/api/nodes/flowEffect.ts +42 -0
  180. package/src/api/nodes/flowSignal.ts +28 -0
  181. package/src/api/nodes/flowValue.ts +36 -0
  182. package/src/api/nodes/index.ts +7 -0
  183. package/src/api/nodes/sync/flowConstant.ts +33 -0
  184. package/src/api/nodes/sync/flowDerivation.ts +41 -0
  185. package/src/api/nodes/sync/flowState.ts +45 -0
  186. package/src/api/nodes/sync/flowWritableDerivation.ts +31 -0
  187. package/src/{flow → api}/nodes/sync/index.ts +1 -2
  188. package/src/api/nodes/utils.ts +22 -0
  189. package/src/base/disposable.ts +18 -0
  190. package/src/base/executionStack.ts +42 -0
  191. package/src/base/index.ts +5 -0
  192. package/src/base/node.ts +98 -0
  193. package/src/base/observable.ts +87 -0
  194. package/src/base/observer.ts +51 -0
  195. package/src/converters/index.ts +1 -0
  196. package/src/converters/solid.ts +109 -0
  197. package/src/index.ts +2 -64
  198. package/src/nodes/arrayNode.ts +172 -0
  199. package/src/nodes/effectNode.ts +59 -0
  200. package/src/nodes/index.ts +8 -0
  201. package/src/nodes/mapNode.ts +127 -0
  202. package/src/nodes/signalNode.ts +21 -0
  203. package/src/nodes/valueAsyncNode.ts +88 -0
  204. package/src/nodes/valueNode.ts +144 -0
  205. package/src/nodes/valueSyncNode.ts +128 -0
  206. package/src/schedulers/asyncResolver.ts +78 -0
  207. package/src/schedulers/asyncScheduler.ts +66 -0
  208. package/src/schedulers/index.ts +4 -0
  209. package/src/schedulers/pendingError.ts +13 -0
  210. package/src/schedulers/scheduler.ts +9 -0
  211. package/src/schedulers/syncResolver.ts +69 -0
  212. package/src/schedulers/syncScheduler.ts +55 -0
  213. package/test/base/pendingError.test.ts +67 -0
  214. package/test/converters/solid.derivation.browser.test.tsx +69 -0
  215. package/test/converters/solid.node.test.ts +654 -0
  216. package/test/converters/solid.state.browser.test.tsx +1592 -0
  217. package/test/reactivity/flowSignal.test.ts +226 -0
  218. package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +593 -0
  219. package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +317 -0
  220. package/test/reactivity/nodes/async/flowConstantAsync.test.ts +652 -0
  221. package/test/reactivity/nodes/async/flowDerivation.test.ts +898 -0
  222. package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +1716 -0
  223. package/test/reactivity/nodes/async/flowStateAsync.test.ts +708 -0
  224. package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +614 -0
  225. package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +1289 -0
  226. package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +961 -0
  227. package/test/reactivity/nodes/collections/flowArray.states.test.ts +1035 -0
  228. package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +960 -0
  229. package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +775 -0
  230. package/test/reactivity/nodes/collections/flowMap.states.test.ts +958 -0
  231. package/test/reactivity/nodes/sync/flowConstant.test.ts +377 -0
  232. package/test/reactivity/nodes/sync/flowDerivation.test.ts +896 -0
  233. package/test/reactivity/nodes/sync/flowState.test.ts +341 -0
  234. package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +603 -0
  235. package/test/vitest.d.ts +10 -0
  236. package/tsconfig.json +31 -20
  237. package/typedoc.json +35 -35
  238. package/vite.config.ts +25 -23
  239. package/vitest.browser.config.ts +21 -0
  240. package/vitest.config.ts +12 -12
  241. package/.cursor/plans/unifier-flowresource-avec-flowderivation-c9506e24.plan.md +0 -372
  242. package/.cursor/plans/update-js-e795d61b.plan.md +0 -567
  243. package/dist/types/flow/base/flowDisposable.d.ts +0 -67
  244. package/dist/types/flow/base/flowDisposable.d.ts.map +0 -1
  245. package/dist/types/flow/base/flowEffect.d.ts +0 -127
  246. package/dist/types/flow/base/flowEffect.d.ts.map +0 -1
  247. package/dist/types/flow/base/flowGraph.d.ts +0 -97
  248. package/dist/types/flow/base/flowGraph.d.ts.map +0 -1
  249. package/dist/types/flow/base/flowSignal.d.ts +0 -134
  250. package/dist/types/flow/base/flowSignal.d.ts.map +0 -1
  251. package/dist/types/flow/base/flowTracker.d.ts +0 -15
  252. package/dist/types/flow/base/flowTracker.d.ts.map +0 -1
  253. package/dist/types/flow/base/index.d.ts +0 -7
  254. package/dist/types/flow/base/index.d.ts.map +0 -1
  255. package/dist/types/flow/base/utils.d.ts +0 -20
  256. package/dist/types/flow/base/utils.d.ts.map +0 -1
  257. package/dist/types/flow/collections/flowArray.d.ts +0 -148
  258. package/dist/types/flow/collections/flowArray.d.ts.map +0 -1
  259. package/dist/types/flow/collections/flowMap.d.ts +0 -224
  260. package/dist/types/flow/collections/flowMap.d.ts.map +0 -1
  261. package/dist/types/flow/collections/index.d.ts.map +0 -1
  262. package/dist/types/flow/index.d.ts +0 -4
  263. package/dist/types/flow/index.d.ts.map +0 -1
  264. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts +0 -137
  265. package/dist/types/flow/nodes/async/flowConstantAsync.d.ts.map +0 -1
  266. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts +0 -137
  267. package/dist/types/flow/nodes/async/flowDerivationAsync.d.ts.map +0 -1
  268. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts +0 -343
  269. package/dist/types/flow/nodes/async/flowNodeAsync.d.ts.map +0 -1
  270. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts +0 -81
  271. package/dist/types/flow/nodes/async/flowReadonlyAsync.d.ts.map +0 -1
  272. package/dist/types/flow/nodes/async/flowStateAsync.d.ts +0 -111
  273. package/dist/types/flow/nodes/async/flowStateAsync.d.ts.map +0 -1
  274. package/dist/types/flow/nodes/async/index.d.ts.map +0 -1
  275. package/dist/types/flow/nodes/index.d.ts +0 -3
  276. package/dist/types/flow/nodes/index.d.ts.map +0 -1
  277. package/dist/types/flow/nodes/sync/flowConstant.d.ts +0 -108
  278. package/dist/types/flow/nodes/sync/flowConstant.d.ts.map +0 -1
  279. package/dist/types/flow/nodes/sync/flowDerivation.d.ts +0 -100
  280. package/dist/types/flow/nodes/sync/flowDerivation.d.ts.map +0 -1
  281. package/dist/types/flow/nodes/sync/flowNode.d.ts +0 -314
  282. package/dist/types/flow/nodes/sync/flowNode.d.ts.map +0 -1
  283. package/dist/types/flow/nodes/sync/flowReadonly.d.ts +0 -57
  284. package/dist/types/flow/nodes/sync/flowReadonly.d.ts.map +0 -1
  285. package/dist/types/flow/nodes/sync/flowState.d.ts +0 -96
  286. package/dist/types/flow/nodes/sync/flowState.d.ts.map +0 -1
  287. package/dist/types/flow/nodes/sync/index.d.ts.map +0 -1
  288. package/dist/types/solid/converters.d.ts +0 -57
  289. package/dist/types/solid/converters.d.ts.map +0 -1
  290. package/dist/types/solid/index.d.ts +0 -3
  291. package/dist/types/solid/index.d.ts.map +0 -1
  292. package/dist/types/solid/primitives.d.ts +0 -181
  293. package/dist/types/solid/primitives.d.ts.map +0 -1
  294. package/docs/api/classes/FlowArray.md +0 -489
  295. package/docs/api/classes/FlowConstant.md +0 -350
  296. package/docs/api/classes/FlowDerivation.md +0 -334
  297. package/docs/api/classes/FlowEffect.md +0 -100
  298. package/docs/api/classes/FlowMap.md +0 -512
  299. package/docs/api/classes/FlowObservable.md +0 -306
  300. package/docs/api/classes/FlowResource.md +0 -380
  301. package/docs/api/classes/FlowResourceAsync.md +0 -362
  302. package/docs/api/classes/FlowSignal.md +0 -160
  303. package/docs/api/classes/FlowState.md +0 -368
  304. package/docs/api/classes/FlowStream.md +0 -367
  305. package/docs/api/classes/FlowStreamAsync.md +0 -364
  306. package/docs/api/classes/SolidDerivation.md +0 -75
  307. package/docs/api/classes/SolidResource.md +0 -91
  308. package/docs/api/classes/SolidState.md +0 -71
  309. package/docs/api/classes/TrackingContext.md +0 -33
  310. package/docs/api/functions/effect.md +0 -49
  311. package/docs/api/functions/resource.md +0 -52
  312. package/docs/api/functions/resourceAsync.md +0 -50
  313. package/docs/api/functions/stream.md +0 -53
  314. package/docs/api/functions/streamAsync.md +0 -50
  315. package/docs/api/interfaces/SolidObservable.md +0 -19
  316. package/docs/api/type-aliases/FlowStreamDisposer.md +0 -15
  317. package/docs/api/type-aliases/FlowStreamSetter.md +0 -27
  318. package/docs/api/type-aliases/FlowStreamUpdater.md +0 -32
  319. package/docs/api/type-aliases/SolidGetter.md +0 -17
  320. package/docs/guide/primitives/resources.md +0 -858
  321. package/docs/guide/primitives/streams.md +0 -931
  322. package/src/flow/base/flowDisposable.ts +0 -71
  323. package/src/flow/base/flowEffect.ts +0 -171
  324. package/src/flow/base/flowGraph.ts +0 -288
  325. package/src/flow/base/flowSignal.ts +0 -207
  326. package/src/flow/base/flowTracker.ts +0 -17
  327. package/src/flow/base/index.ts +0 -6
  328. package/src/flow/base/utils.ts +0 -19
  329. package/src/flow/collections/flowArray.ts +0 -409
  330. package/src/flow/collections/flowMap.ts +0 -398
  331. package/src/flow/nodes/async/flowConstantAsync.ts +0 -142
  332. package/src/flow/nodes/async/flowDerivationAsync.ts +0 -143
  333. package/src/flow/nodes/async/flowNodeAsync.ts +0 -474
  334. package/src/flow/nodes/async/flowReadonlyAsync.ts +0 -81
  335. package/src/flow/nodes/async/flowStateAsync.ts +0 -116
  336. package/src/flow/nodes/await/advanced/index.ts +0 -5
  337. package/src/flow/nodes/await/advanced/resource.ts +0 -134
  338. package/src/flow/nodes/await/advanced/resourceAsync.ts +0 -109
  339. package/src/flow/nodes/await/advanced/stream.ts +0 -188
  340. package/src/flow/nodes/await/advanced/streamAsync.ts +0 -176
  341. package/src/flow/nodes/await/flowConstantAwait.ts +0 -154
  342. package/src/flow/nodes/await/flowDerivationAwait.ts +0 -154
  343. package/src/flow/nodes/await/flowNodeAwait.ts +0 -508
  344. package/src/flow/nodes/await/flowReadonlyAwait.ts +0 -89
  345. package/src/flow/nodes/await/flowStateAwait.ts +0 -130
  346. package/src/flow/nodes/await/index.ts +0 -5
  347. package/src/flow/nodes/index.ts +0 -3
  348. package/src/flow/nodes/sync/flowConstant.ts +0 -111
  349. package/src/flow/nodes/sync/flowDerivation.ts +0 -105
  350. package/src/flow/nodes/sync/flowNode.ts +0 -439
  351. package/src/flow/nodes/sync/flowReadonly.ts +0 -57
  352. package/src/flow/nodes/sync/flowState.ts +0 -101
  353. package/src/solid/converters.ts +0 -148
  354. package/src/solid/index.ts +0 -2
  355. package/src/solid/primitives.ts +0 -215
  356. package/test/base/flowEffect.test.ts +0 -108
  357. package/test/base/flowGraph.test.ts +0 -485
  358. package/test/base/flowSignal.test.ts +0 -372
  359. package/test/collections/flowArray.asyncStates.test.ts +0 -1553
  360. package/test/collections/flowArray.scalars.test.ts +0 -1129
  361. package/test/collections/flowArray.states.test.ts +0 -1365
  362. package/test/collections/flowMap.asyncStates.test.ts +0 -1105
  363. package/test/collections/flowMap.scalars.test.ts +0 -877
  364. package/test/collections/flowMap.states.test.ts +0 -1097
  365. package/test/nodes/async/flowConstantAsync.test.ts +0 -860
  366. package/test/nodes/async/flowDerivationAsync.test.ts +0 -1517
  367. package/test/nodes/async/flowStateAsync.test.ts +0 -1387
  368. package/test/nodes/await/advanced/resource.test.ts +0 -129
  369. package/test/nodes/await/advanced/resourceAsync.test.ts +0 -108
  370. package/test/nodes/await/advanced/stream.test.ts +0 -198
  371. package/test/nodes/await/advanced/streamAsync.test.ts +0 -196
  372. package/test/nodes/await/flowConstantAwait.test.ts +0 -643
  373. package/test/nodes/await/flowDerivationAwait.test.ts +0 -1583
  374. package/test/nodes/await/flowStateAwait.test.ts +0 -999
  375. package/test/nodes/mixed/derivation.test.ts +0 -1527
  376. package/test/nodes/sync/flowConstant.test.ts +0 -620
  377. package/test/nodes/sync/flowDerivation.test.ts +0 -1373
  378. package/test/nodes/sync/flowState.test.ts +0 -945
  379. package/test/solid/converters.test.ts +0 -721
  380. package/test/solid/primitives.test.ts +0 -1031
  381. /package/dist/types/{flow → api/nodes}/collections/index.d.ts +0 -0
  382. /package/docs/guide/advanced/{upgrading.md → migration-v1.md} +0 -0
  383. /package/src/{flow → api/nodes}/collections/index.ts +0 -0
@@ -0,0 +1,1035 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { array, type FlowState, state, subscribe } from "~";
3
+
4
+ describe("FlowArray", () => {
5
+ describe("unit", () => {
6
+ describe("initialization", () => {
7
+ it("should initialize with provided FlowState values", async () => {
8
+ const $array = array([state(1), state(2), state(3)]);
9
+
10
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([1, 2, 3]);
11
+ });
12
+
13
+ it("should initialize with empty array when no value provided", async () => {
14
+ const $array = array<FlowState<number>>();
15
+
16
+ expect(await $array.pick()).toEqual([]);
17
+ });
18
+ });
19
+
20
+ describe("disposal", () => {
21
+ it("should have disposed property set to false initially and true after disposal", () => {
22
+ const $array = array([state(1), state(2), state(3)]);
23
+ expect($array.disposed).toBe(false);
24
+ $array.dispose();
25
+ expect($array.disposed).toBe(true);
26
+ });
27
+
28
+ it("should throw error when disposed twice", () => {
29
+ const $array = array([state(1), state(2), state(3)]);
30
+ $array.dispose();
31
+ expect(() => $array.dispose()).toThrow("[PicoFlow] Primitive is disposed");
32
+ });
33
+
34
+ it("should throw when pick is called after disposal", async () => {
35
+ const $array = array([state(1), state(2), state(3)]);
36
+ $array.dispose();
37
+ await expect($array.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
38
+ });
39
+
40
+ it("should throw when set is called after disposal", () => {
41
+ const $array = array([state(1), state(2), state(3)]);
42
+ $array.dispose();
43
+ expect(() => $array.set([state(1)])).toThrow("[PicoFlow] Primitive is disposed");
44
+ });
45
+
46
+ it("should throw when update is called after disposal", () => {
47
+ const $array = array([state(1), state(2), state(3)]);
48
+ $array.dispose();
49
+ expect(() => $array.update(0, state(3))).toThrow("[PicoFlow] Primitive is disposed");
50
+ });
51
+
52
+ it("should throw when push is called after disposal", () => {
53
+ const $array = array([state(1), state(2), state(3)]);
54
+ $array.dispose();
55
+ expect(() => $array.push(state(3))).toThrow("[PicoFlow] Primitive is disposed");
56
+ });
57
+
58
+ it("should throw when pop is called after disposal", () => {
59
+ const $array = array([state(1), state(2), state(3)]);
60
+ $array.dispose();
61
+ expect(() => $array.pop()).toThrow("[PicoFlow] Primitive is disposed");
62
+ });
63
+
64
+ it("should throw when unshift is called after disposal", () => {
65
+ const $array = array([state(1), state(2), state(3)]);
66
+ $array.dispose();
67
+ expect(() => $array.unshift(state(3))).toThrow("[PicoFlow] Primitive is disposed");
68
+ });
69
+
70
+ it("should throw when shift is called after disposal", () => {
71
+ const $array = array([state(1), state(2), state(3)]);
72
+ $array.dispose();
73
+ expect(() => $array.shift()).toThrow("[PicoFlow] Primitive is disposed");
74
+ });
75
+
76
+ it("should throw when splice is called after disposal", () => {
77
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
78
+ $array.dispose();
79
+ expect(() => $array.splice(1, 2)).toThrow("[PicoFlow] Primitive is disposed");
80
+ });
81
+
82
+ it("should throw when clear is called after disposal", () => {
83
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
84
+ $array.dispose();
85
+ expect(() => $array.clear()).toThrow("[PicoFlow] Primitive is disposed");
86
+ });
87
+ });
88
+
89
+ describe("length", () => {
90
+ it("should return correct length", () => {
91
+ const $array = array([state(1), state(2), state(3)]);
92
+ expect($array.length).toBe(3);
93
+ });
94
+
95
+ it("should return zero for empty array", () => {
96
+ const $array = array<FlowState<number>>([]);
97
+ expect($array.length).toBe(0);
98
+ });
99
+
100
+ it("should throw when length is accessed after disposal", () => {
101
+ const $array = array([state(1), state(2), state(3)]);
102
+ $array.dispose();
103
+ expect(() => $array.length).toThrow("[PicoFlow] Primitive is disposed");
104
+ });
105
+
106
+ it("should update length when array is modified", () => {
107
+ const $array = array<FlowState<number>>([]);
108
+ expect($array.length).toBe(0);
109
+
110
+ $array.push(state(1));
111
+ expect($array.length).toBe(1);
112
+
113
+ $array.push(state(2));
114
+ expect($array.length).toBe(2);
115
+
116
+ $array.pop();
117
+ expect($array.length).toBe(1);
118
+
119
+ $array.unshift(state(0));
120
+ expect($array.length).toBe(2);
121
+
122
+ $array.shift();
123
+ expect($array.length).toBe(1);
124
+
125
+ $array.clear();
126
+ expect($array.length).toBe(0);
127
+ });
128
+ });
129
+
130
+ describe("set", () => {
131
+ it("should update array when set is called with FlowStates", async () => {
132
+ const $array = array([state(0), state(1), state(2)]);
133
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1, 2]);
134
+
135
+ $array.set([state(1), state(2), state(3)]);
136
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([1, 2, 3]);
137
+ });
138
+ });
139
+
140
+ describe("update", () => {
141
+ it("should update item at specific index", async () => {
142
+ const $array = array([state(0), state(1), state(2)]);
143
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1, 2]);
144
+
145
+ $array.update(0, state(1));
146
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([1, 1, 2]);
147
+
148
+ $array.update(1, state(2));
149
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([1, 2, 2]);
150
+
151
+ $array.update(2, state(3));
152
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([1, 2, 3]);
153
+ });
154
+
155
+ it("should throw when update is called with negative index", () => {
156
+ const $array = array([state(1), state(2), state(3)]);
157
+ expect(() => $array.update(-1, state(0))).toThrow("[PicoFlow] Index out of bounds");
158
+ });
159
+
160
+ it("should throw when update is called with index >= length", () => {
161
+ const $array = array([state(1), state(2), state(3)]);
162
+ expect(() => $array.update(3, state(0))).toThrow("[PicoFlow] Index out of bounds");
163
+ expect(() => $array.update(10, state(0))).toThrow("[PicoFlow] Index out of bounds");
164
+ });
165
+
166
+ it("should handle boundary indices correctly", async () => {
167
+ const $array = array([state(0), state(1), state(2)]);
168
+ $array.update(0, state(10));
169
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([10, 1, 2]);
170
+
171
+ $array.update(2, state(20));
172
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([10, 1, 20]);
173
+ });
174
+ });
175
+
176
+ describe("push", () => {
177
+ it("should append FlowState to end of array", async () => {
178
+ const $array = array<FlowState<number>>([]);
179
+ expect(await $array.pick()).toEqual([]);
180
+
181
+ $array.push(state(0));
182
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0]);
183
+
184
+ $array.push(state(1));
185
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1]);
186
+
187
+ $array.push(state(2));
188
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1, 2]);
189
+ });
190
+
191
+ it("should handle operations on empty array", () => {
192
+ const $array = array<FlowState<number>>([]);
193
+ expect($array.length).toBe(0);
194
+ $array.push(state(1));
195
+ expect($array.length).toBe(1);
196
+ });
197
+ });
198
+
199
+ describe("pop", () => {
200
+ it("should remove last FlowState from array", async () => {
201
+ const $array = array([state(0), state(1), state(2)]);
202
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1, 2]);
203
+
204
+ $array.pop();
205
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1]);
206
+
207
+ $array.pop();
208
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0]);
209
+
210
+ $array.pop();
211
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([]);
212
+ });
213
+
214
+ it("should handle operations on empty array", () => {
215
+ const $array = array<FlowState<number>>([]);
216
+ expect($array.length).toBe(0);
217
+ $array.pop();
218
+ expect($array.length).toBe(0);
219
+ });
220
+ });
221
+
222
+ describe("unshift", () => {
223
+ it("should insert FlowState at beginning of array", async () => {
224
+ const $array = array<FlowState<number>>([]);
225
+ expect(await $array.pick()).toEqual([]);
226
+
227
+ $array.unshift(state(0));
228
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0]);
229
+
230
+ $array.unshift(state(1));
231
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([1, 0]);
232
+
233
+ $array.unshift(state(2));
234
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([2, 1, 0]);
235
+ });
236
+ });
237
+
238
+ describe("shift", () => {
239
+ it("should remove first FlowState from array", async () => {
240
+ const $array = array([state(0), state(1), state(2)]);
241
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1, 2]);
242
+
243
+ $array.shift();
244
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([1, 2]);
245
+
246
+ $array.shift();
247
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([2]);
248
+
249
+ $array.shift();
250
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([]);
251
+ });
252
+
253
+ it("should handle operations on empty array", () => {
254
+ const $array = array<FlowState<number>>([]);
255
+ expect($array.length).toBe(0);
256
+ $array.shift();
257
+ expect($array.length).toBe(0);
258
+ });
259
+ });
260
+
261
+ describe("splice", () => {
262
+ it("should remove FlowStates from array", async () => {
263
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
264
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1, 2, 3, 4]);
265
+
266
+ $array.splice(1, 2);
267
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 3, 4]);
268
+ });
269
+
270
+ it("should insert FlowStates into array", async () => {
271
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
272
+ $array.splice(1, 0, state(10), state(11));
273
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([
274
+ 0, 10, 11, 1, 2, 3, 4,
275
+ ]);
276
+ });
277
+
278
+ it("should replace FlowStates in array", async () => {
279
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
280
+ $array.splice(1, 2, state(10), state(11));
281
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([
282
+ 0, 10, 11, 3, 4,
283
+ ]);
284
+ });
285
+ });
286
+
287
+ describe("clear", () => {
288
+ it("should remove all FlowStates from array", async () => {
289
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
290
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 1, 2, 3, 4]);
291
+
292
+ $array.clear();
293
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([]);
294
+ });
295
+ });
296
+
297
+ describe("$lastAction", () => {
298
+ describe("set action", () => {
299
+ it("should initialize $lastAction with set action on creation", async () => {
300
+ const $array = array([state(1), state(2), state(3)]);
301
+ const action = await $array.$lastAction.pick();
302
+ expect(action.type).toBe("set");
303
+ if (action.type === "set") {
304
+ expect(action.setItems).toHaveLength(3);
305
+ expect(action.setItems[0]).toBeInstanceOf(Object);
306
+ expect(action.setItems[1]).toBeInstanceOf(Object);
307
+ expect(action.setItems[2]).toBeInstanceOf(Object);
308
+ expect(action.clearedItems).toEqual([]);
309
+ }
310
+ });
311
+
312
+ it("should update $lastAction with set action when set is called", async () => {
313
+ const $array = array([state(0), state(1), state(2)]);
314
+ $array.set([state(1), state(2), state(3)]);
315
+ const action = await $array.$lastAction.pick();
316
+ expect(action.type).toBe("set");
317
+ if (action.type === "set") {
318
+ expect(action.setItems).toHaveLength(3);
319
+ expect(action.clearedItems).toHaveLength(3);
320
+ }
321
+ });
322
+
323
+ it("should have correct structure for set action (setItems and clearedItems)", async () => {
324
+ const $array = array([state(1), state(2), state(3)]);
325
+ const action = await $array.$lastAction.pick();
326
+ expect(action).toHaveProperty("type", "set");
327
+ if (action.type === "set") {
328
+ expect(action).toHaveProperty("setItems");
329
+ expect(action).toHaveProperty("clearedItems");
330
+ expect(Array.isArray(action.setItems)).toBe(true);
331
+ expect(Array.isArray(action.clearedItems)).toBe(true);
332
+ expect(action.setItems).toHaveLength(3);
333
+ expect(action.clearedItems).toEqual([]);
334
+ }
335
+ });
336
+ });
337
+
338
+ describe("update action", () => {
339
+ it("should update $lastAction with update action when update is called", async () => {
340
+ const $array = array([state(0), state(1), state(2)]);
341
+ const $newItem = state(10);
342
+ $array.update(1, $newItem);
343
+ const action = await $array.$lastAction.pick();
344
+ expect(action.type).toBe("update");
345
+ if (action.type === "update") {
346
+ expect(action.index).toBe(1);
347
+ expect(action.setItem).toBe($newItem);
348
+ expect(action.clearedItem).toBeInstanceOf(Object);
349
+ }
350
+ });
351
+
352
+ it("should have correct structure for update action (index, setItem, clearedItem)", async () => {
353
+ const $array = array([state(1), state(2), state(3)]);
354
+ const $newItem = state(10);
355
+ $array.update(0, $newItem);
356
+ const action = await $array.$lastAction.pick();
357
+ expect(action).toHaveProperty("type", "update");
358
+ if (action.type === "update") {
359
+ expect(action).toHaveProperty("index");
360
+ expect(action).toHaveProperty("setItem");
361
+ expect(action).toHaveProperty("clearedItem");
362
+ expect(action.index).toBe(0);
363
+ expect(action.setItem).toBe($newItem);
364
+ expect(action.clearedItem).toBeInstanceOf(Object);
365
+ }
366
+ });
367
+ });
368
+
369
+ describe("push action", () => {
370
+ it("should update $lastAction with push action when push is called", async () => {
371
+ const $array = array<FlowState<number>>([]);
372
+ const $newItem = state(42);
373
+ $array.push($newItem);
374
+ const action = await $array.$lastAction.pick();
375
+ expect(action.type).toBe("push");
376
+ if (action.type === "push") {
377
+ expect(action.addedItem).toBe($newItem);
378
+ }
379
+ });
380
+
381
+ it("should have correct structure for push action (addedItem)", async () => {
382
+ const $array = array<FlowState<number>>([]);
383
+ const $newItem = state(100);
384
+ $array.push($newItem);
385
+ const action = await $array.$lastAction.pick();
386
+ expect(action).toHaveProperty("type", "push");
387
+ if (action.type === "push") {
388
+ expect(action).toHaveProperty("addedItem");
389
+ expect(action.addedItem).toBe($newItem);
390
+ }
391
+ });
392
+ });
393
+
394
+ describe("pop action", () => {
395
+ it("should update $lastAction with pop action when pop is called", async () => {
396
+ const $array = array([state(1), state(2), state(3)]);
397
+ $array.pop();
398
+ const action = await $array.$lastAction.pick();
399
+ expect(action).toEqual({
400
+ type: "pop",
401
+ removedItem: expect.any(Object),
402
+ });
403
+ });
404
+
405
+ it("should have correct structure for pop action (removedItem)", async () => {
406
+ const $array = array([state(1), state(2), state(3)]);
407
+ $array.pop();
408
+ const action = await $array.$lastAction.pick();
409
+ expect(action).toHaveProperty("type", "pop");
410
+ if (action.type === "pop") {
411
+ expect(action).toHaveProperty("removedItem");
412
+ expect(action.removedItem).toBeInstanceOf(Object);
413
+ }
414
+ });
415
+
416
+ it("should have removedItem undefined when pop is called on empty array", async () => {
417
+ const $array = array<FlowState<number>>([]);
418
+ $array.pop();
419
+ const action = await $array.$lastAction.pick();
420
+ expect(action).toHaveProperty("type", "pop");
421
+ if (action.type === "pop") {
422
+ expect(action).toHaveProperty("removedItem");
423
+ expect(action.removedItem).toBeUndefined();
424
+ }
425
+ });
426
+ });
427
+
428
+ describe("unshift action", () => {
429
+ it("should update $lastAction with unshift action when unshift is called", async () => {
430
+ const $array = array<FlowState<number>>([]);
431
+ const $newItem = state(42);
432
+ $array.unshift($newItem);
433
+ const action = await $array.$lastAction.pick();
434
+ expect(action.type).toBe("unshift");
435
+ if (action.type === "unshift") {
436
+ expect(action.addedItem).toBe($newItem);
437
+ }
438
+ });
439
+
440
+ it("should have correct structure for unshift action (addedItem)", async () => {
441
+ const $array = array<FlowState<number>>([]);
442
+ const $newItem = state(200);
443
+ $array.unshift($newItem);
444
+ const action = await $array.$lastAction.pick();
445
+ expect(action).toHaveProperty("type", "unshift");
446
+ if (action.type === "unshift") {
447
+ expect(action).toHaveProperty("addedItem");
448
+ expect(action.addedItem).toBe($newItem);
449
+ }
450
+ });
451
+ });
452
+
453
+ describe("shift action", () => {
454
+ it("should update $lastAction with shift action when shift is called", async () => {
455
+ const $array = array([state(1), state(2), state(3)]);
456
+ $array.shift();
457
+ const action = await $array.$lastAction.pick();
458
+ expect(action).toEqual({
459
+ type: "shift",
460
+ removedItem: expect.any(Object),
461
+ });
462
+ });
463
+
464
+ it("should have correct structure for shift action (removedItem)", async () => {
465
+ const $array = array([state(1), state(2), state(3)]);
466
+ $array.shift();
467
+ const action = await $array.$lastAction.pick();
468
+ expect(action).toHaveProperty("type", "shift");
469
+ if (action.type === "shift") {
470
+ expect(action).toHaveProperty("removedItem");
471
+ expect(action.removedItem).toBeInstanceOf(Object);
472
+ }
473
+ });
474
+
475
+ it("should have removedItem undefined when shift is called on empty array", async () => {
476
+ const $array = array<FlowState<number>>([]);
477
+ $array.shift();
478
+ const action = await $array.$lastAction.pick();
479
+ expect(action).toHaveProperty("type", "shift");
480
+ if (action.type === "shift") {
481
+ expect(action).toHaveProperty("removedItem");
482
+ expect(action.removedItem).toBeUndefined();
483
+ }
484
+ });
485
+ });
486
+
487
+ describe("splice action", () => {
488
+ it("should update $lastAction with splice action when splice is called", async () => {
489
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
490
+ const $newItem1 = state(10);
491
+ const $newItem2 = state(11);
492
+ $array.splice(1, 2, $newItem1, $newItem2);
493
+ const action = await $array.$lastAction.pick();
494
+ expect(action.type).toBe("splice");
495
+ if (action.type === "splice") {
496
+ expect(action.start).toBe(1);
497
+ expect(action.deleteCount).toBe(2);
498
+ expect(action.addedItems).toHaveLength(2);
499
+ expect(action.addedItems[0]).toBe($newItem1);
500
+ expect(action.addedItems[1]).toBe($newItem2);
501
+ expect(action.removedItems).toHaveLength(2);
502
+ }
503
+ });
504
+
505
+ it("should have correct structure for splice action (start, deleteCount, addedItems, removedItems)", async () => {
506
+ const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
507
+ const $newItem = state(100);
508
+ $array.splice(1, 1, $newItem);
509
+ const action = await $array.$lastAction.pick();
510
+ expect(action).toHaveProperty("type", "splice");
511
+ if (action.type === "splice") {
512
+ expect(action).toHaveProperty("start");
513
+ expect(action).toHaveProperty("deleteCount");
514
+ expect(action).toHaveProperty("addedItems");
515
+ expect(action).toHaveProperty("removedItems");
516
+ expect(action.start).toBe(1);
517
+ expect(action.deleteCount).toBe(1);
518
+ expect(Array.isArray(action.addedItems)).toBe(true);
519
+ expect(Array.isArray(action.removedItems)).toBe(true);
520
+ expect(action.addedItems).toHaveLength(1);
521
+ expect(action.addedItems[0]).toBe($newItem);
522
+ expect(action.removedItems).toHaveLength(1);
523
+ }
524
+ });
525
+ });
526
+
527
+ describe("clear action", () => {
528
+ it("should update $lastAction with clear action when clear is called", async () => {
529
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
530
+ $array.clear();
531
+ const action = await $array.$lastAction.pick();
532
+ expect(action).toEqual({
533
+ type: "clear",
534
+ clearedItems: expect.any(Array),
535
+ });
536
+ if (action.type === "clear") {
537
+ expect(action.clearedItems).toHaveLength(5);
538
+ }
539
+ });
540
+
541
+ it("should have correct structure for clear action (clearedItems)", async () => {
542
+ const $array = array<FlowState<number>>([state(1), state(2), state(3)]);
543
+ $array.clear();
544
+ const action = await $array.$lastAction.pick();
545
+ expect(action).toHaveProperty("type", "clear");
546
+ if (action.type === "clear") {
547
+ expect(action).toHaveProperty("clearedItems");
548
+ expect(Array.isArray(action.clearedItems)).toBe(true);
549
+ expect(action.clearedItems).toHaveLength(3);
550
+ }
551
+ });
552
+ });
553
+ });
554
+
555
+ describe("edge cases", () => {
556
+ it("should handle multiple rapid operations", async () => {
557
+ const $array = array<FlowState<number>>([]);
558
+ $array.push(state(1));
559
+ $array.push(state(2));
560
+ $array.push(state(3));
561
+ $array.pop();
562
+ $array.shift();
563
+ $array.unshift(state(0));
564
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([0, 2]);
565
+ });
566
+
567
+ it("should handle boundary indices correctly", async () => {
568
+ const $array = array([state(0), state(1), state(2)]);
569
+ $array.update(0, state(10));
570
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([10, 1, 2]);
571
+
572
+ $array.update(2, state(20));
573
+ expect(await Promise.all((await $array.pick()).map((state) => state.pick()))).toEqual([10, 1, 20]);
574
+ });
575
+ });
576
+ });
577
+
578
+ describe("integration", () => {
579
+ describe("with effects", () => {
580
+ describe("reactivity", () => {
581
+ it("should call effect when initialized", async () => {
582
+ const $array = array([state(1), state(2), state(3)]);
583
+ const onData = vi.fn();
584
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
585
+
586
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
587
+ expect(onData).toHaveBeenLastCalledWith([1, 2, 3]);
588
+ });
589
+
590
+ it("should call effect when updated with set", async () => {
591
+ const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
592
+ const onData = vi.fn();
593
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
594
+
595
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
596
+ expect(onData).toHaveBeenLastCalledWith([0, 1, 2]);
597
+
598
+ $array.set([state(1), state(2), state(3)]);
599
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
600
+ expect(onData).toHaveBeenLastCalledWith([1, 2, 3]);
601
+ });
602
+
603
+ it("should call effect when updated with push/pop", async () => {
604
+ const $array = array<FlowState<number>>();
605
+ const onData = vi.fn();
606
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
607
+
608
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
609
+ expect(onData).toHaveBeenLastCalledWith([]);
610
+
611
+ $array.push(state(0));
612
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
613
+ expect(onData).toHaveBeenLastCalledWith([0]);
614
+
615
+ $array.push(state(1));
616
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
617
+ expect(onData).toHaveBeenLastCalledWith([0, 1]);
618
+
619
+ $array.push(state(2));
620
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
621
+ expect(onData).toHaveBeenLastCalledWith([0, 1, 2]);
622
+
623
+ $array.pop();
624
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(5));
625
+ expect(onData).toHaveBeenLastCalledWith([0, 1]);
626
+
627
+ $array.pop();
628
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(6));
629
+ expect(onData).toHaveBeenLastCalledWith([0]);
630
+
631
+ $array.pop();
632
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(7));
633
+ expect(onData).toHaveBeenLastCalledWith([]);
634
+ });
635
+
636
+ it("should call effect when updated with unshift/shift", async () => {
637
+ const $array = array<FlowState<number>>();
638
+ const onData = vi.fn();
639
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
640
+
641
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
642
+ expect(onData).toHaveBeenLastCalledWith([]);
643
+
644
+ $array.unshift(state(0));
645
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
646
+ expect(onData).toHaveBeenLastCalledWith([0]);
647
+
648
+ $array.unshift(state(1));
649
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
650
+ expect(onData).toHaveBeenLastCalledWith([1, 0]);
651
+
652
+ $array.unshift(state(2));
653
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
654
+ expect(onData).toHaveBeenLastCalledWith([2, 1, 0]);
655
+
656
+ $array.shift();
657
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(5));
658
+ expect(onData).toHaveBeenLastCalledWith([1, 0]);
659
+
660
+ $array.shift();
661
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(6));
662
+ expect(onData).toHaveBeenLastCalledWith([0]);
663
+
664
+ $array.shift();
665
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(7));
666
+ expect(onData).toHaveBeenLastCalledWith([]);
667
+ });
668
+
669
+ it("should call effect when updated with splice", async () => {
670
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
671
+ const onData = vi.fn();
672
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
673
+
674
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
675
+ expect(onData).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
676
+
677
+ $array.splice(1, 2);
678
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
679
+ expect(onData).toHaveBeenLastCalledWith([0, 3, 4]);
680
+
681
+ $array.splice(1, 0, state(1), state(2));
682
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
683
+ expect(onData).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
684
+ });
685
+
686
+ it("should call effect when updated with clear", async () => {
687
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
688
+ const onData = vi.fn();
689
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
690
+
691
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
692
+ expect(onData).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
693
+
694
+ $array.clear();
695
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
696
+ expect(onData).toHaveBeenLastCalledWith([]);
697
+ });
698
+ });
699
+
700
+ describe("item reactivity", () => {
701
+ it("should call effect when item is updated", async () => {
702
+ const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
703
+ const onData = vi.fn();
704
+ const onData0 = vi.fn();
705
+ const onData1 = vi.fn();
706
+ const onData2 = vi.fn();
707
+
708
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
709
+ subscribe((t) => $array.get(t)[0].get(t), onData0);
710
+ subscribe((t) => $array.get(t)[1].get(t), onData1);
711
+ subscribe((t) => $array.get(t)[2].get(t), onData2);
712
+
713
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
714
+ expect(onData).toHaveBeenLastCalledWith([0, 1, 2]);
715
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(1));
716
+ expect(onData0).toHaveBeenLastCalledWith(0);
717
+ await vi.waitFor(() => expect(onData1).toHaveBeenCalledTimes(1));
718
+ expect(onData1).toHaveBeenLastCalledWith(1);
719
+ await vi.waitFor(() => expect(onData2).toHaveBeenCalledTimes(1));
720
+ expect(onData2).toHaveBeenLastCalledWith(2);
721
+
722
+ (await $array.pick())[0].set(1);
723
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
724
+ expect(onData).toHaveBeenLastCalledWith([1, 1, 2]);
725
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(2));
726
+ expect(onData0).toHaveBeenLastCalledWith(1);
727
+ await vi.waitFor(() => expect(onData1).toHaveBeenCalledTimes(1));
728
+ expect(onData1).toHaveBeenLastCalledWith(1);
729
+ await vi.waitFor(() => expect(onData2).toHaveBeenCalledTimes(1));
730
+ expect(onData2).toHaveBeenLastCalledWith(2);
731
+
732
+ (await $array.pick())[1].set(2);
733
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
734
+ expect(onData).toHaveBeenLastCalledWith([1, 2, 2]);
735
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(2));
736
+ expect(onData0).toHaveBeenLastCalledWith(1);
737
+ await vi.waitFor(() => expect(onData1).toHaveBeenCalledTimes(2));
738
+ expect(onData1).toHaveBeenLastCalledWith(2);
739
+ await vi.waitFor(() => expect(onData2).toHaveBeenCalledTimes(1));
740
+ expect(onData2).toHaveBeenLastCalledWith(2);
741
+
742
+ (await $array.pick())[2].set(3);
743
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
744
+ expect(onData).toHaveBeenLastCalledWith([1, 2, 3]);
745
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(2));
746
+ expect(onData0).toHaveBeenLastCalledWith(1);
747
+ await vi.waitFor(() => expect(onData1).toHaveBeenCalledTimes(2));
748
+ expect(onData1).toHaveBeenLastCalledWith(2);
749
+ await vi.waitFor(() => expect(onData2).toHaveBeenCalledTimes(2));
750
+ expect(onData2).toHaveBeenLastCalledWith(3);
751
+ });
752
+
753
+ it("should call effect when item is replaced", async () => {
754
+ const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
755
+ const onData = vi.fn();
756
+ const onData0 = vi.fn();
757
+
758
+ subscribe((t) => $array.get(t).map((state) => state.get(t)), onData);
759
+ subscribe((t) => $array.get(t)[0].get(t), onData0);
760
+
761
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
762
+ expect(onData).toHaveBeenLastCalledWith([0, 1, 2]);
763
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(1));
764
+ expect(onData0).toHaveBeenLastCalledWith(0);
765
+
766
+ $array.update(0, state(3));
767
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
768
+ expect(onData).toHaveBeenLastCalledWith([3, 1, 2]);
769
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(2));
770
+ expect(onData0).toHaveBeenLastCalledWith(3);
771
+
772
+ $array.shift();
773
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
774
+ expect(onData).toHaveBeenLastCalledWith([1, 2]);
775
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(3));
776
+ expect(onData0).toHaveBeenLastCalledWith(1);
777
+
778
+ $array.unshift(state(4));
779
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(4));
780
+ expect(onData).toHaveBeenLastCalledWith([4, 1, 2]);
781
+ await vi.waitFor(() => expect(onData0).toHaveBeenCalledTimes(4));
782
+ expect(onData0).toHaveBeenLastCalledWith(4);
783
+ });
784
+ });
785
+
786
+ describe("lastAction reactivity", () => {
787
+ describe("set action", () => {
788
+ it("should call effect when $lastAction is updated with set action", async () => {
789
+ const $array = array([state(0), state(1), state(2)]);
790
+ const onData = vi.fn();
791
+ subscribe((t) => $array.$lastAction.get(t), onData);
792
+
793
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
794
+ expect(onData).toHaveBeenLastCalledWith(
795
+ expect.objectContaining({
796
+ type: "set",
797
+ setItems: expect.any(Array),
798
+ clearedItems: expect.any(Array),
799
+ }),
800
+ );
801
+
802
+ $array.set([state(1), state(2), state(3)]);
803
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
804
+ expect(onData).toHaveBeenLastCalledWith(
805
+ expect.objectContaining({
806
+ type: "set",
807
+ setItems: expect.any(Array),
808
+ clearedItems: expect.any(Array),
809
+ }),
810
+ );
811
+ });
812
+ });
813
+
814
+ describe("update action", () => {
815
+ it("should call effect when $lastAction is updated with update action", async () => {
816
+ const $array = array([state(0), state(1), state(2)]);
817
+ const onData = vi.fn();
818
+ subscribe((t) => $array.$lastAction.get(t), onData);
819
+
820
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
821
+
822
+ const $newItem = state(10);
823
+ $array.update(1, $newItem);
824
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
825
+ expect(onData).toHaveBeenLastCalledWith(
826
+ expect.objectContaining({
827
+ type: "update",
828
+ index: 1,
829
+ setItem: $newItem,
830
+ clearedItem: expect.any(Object),
831
+ }),
832
+ );
833
+ });
834
+ });
835
+
836
+ describe("push action", () => {
837
+ it("should call effect when $lastAction is updated with push action", async () => {
838
+ const $array = array<FlowState<number>>();
839
+ const onData = vi.fn();
840
+ subscribe((t) => $array.$lastAction.get(t), onData);
841
+
842
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
843
+ expect(onData).toHaveBeenLastCalledWith(
844
+ expect.objectContaining({
845
+ type: "set",
846
+ setItems: expect.any(Array),
847
+ clearedItems: expect.any(Array),
848
+ }),
849
+ );
850
+
851
+ const $newItem = state(0);
852
+ $array.push($newItem);
853
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
854
+ expect(onData).toHaveBeenLastCalledWith(
855
+ expect.objectContaining({
856
+ type: "push",
857
+ addedItem: $newItem,
858
+ }),
859
+ );
860
+
861
+ const $newItem2 = state(1);
862
+ $array.push($newItem2);
863
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
864
+ expect(onData).toHaveBeenLastCalledWith(
865
+ expect.objectContaining({
866
+ type: "push",
867
+ addedItem: $newItem2,
868
+ }),
869
+ );
870
+ });
871
+ });
872
+
873
+ describe("pop action", () => {
874
+ it("should call effect when $lastAction is updated with pop action", async () => {
875
+ const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
876
+ const onData = vi.fn();
877
+ subscribe((t) => $array.$lastAction.get(t), onData);
878
+
879
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
880
+
881
+ $array.pop();
882
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
883
+ expect(onData).toHaveBeenLastCalledWith(
884
+ expect.objectContaining({
885
+ type: "pop",
886
+ removedItem: expect.any(Object),
887
+ }),
888
+ );
889
+
890
+ $array.pop();
891
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
892
+ expect(onData).toHaveBeenLastCalledWith(
893
+ expect.objectContaining({
894
+ type: "pop",
895
+ removedItem: expect.any(Object),
896
+ }),
897
+ );
898
+ });
899
+ });
900
+
901
+ describe("unshift action", () => {
902
+ it("should call effect when $lastAction is updated with unshift action", async () => {
903
+ const $array = array<FlowState<number>>();
904
+ const onData = vi.fn();
905
+ subscribe((t) => $array.$lastAction.get(t), onData);
906
+
907
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
908
+ expect(onData).toHaveBeenLastCalledWith(
909
+ expect.objectContaining({
910
+ type: "set",
911
+ setItems: expect.any(Array),
912
+ clearedItems: expect.any(Array),
913
+ }),
914
+ );
915
+
916
+ const $newItem = state(0);
917
+ $array.unshift($newItem);
918
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
919
+ expect(onData).toHaveBeenLastCalledWith(
920
+ expect.objectContaining({
921
+ type: "unshift",
922
+ addedItem: $newItem,
923
+ }),
924
+ );
925
+
926
+ const $newItem2 = state(1);
927
+ $array.unshift($newItem2);
928
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
929
+ expect(onData).toHaveBeenLastCalledWith(
930
+ expect.objectContaining({
931
+ type: "unshift",
932
+ addedItem: $newItem2,
933
+ }),
934
+ );
935
+ });
936
+ });
937
+
938
+ describe("shift action", () => {
939
+ it("should call effect when $lastAction is updated with shift action", async () => {
940
+ const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
941
+ const onData = vi.fn();
942
+ subscribe((t) => $array.$lastAction.get(t), onData);
943
+
944
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
945
+
946
+ $array.shift();
947
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
948
+ expect(onData).toHaveBeenLastCalledWith(
949
+ expect.objectContaining({
950
+ type: "shift",
951
+ removedItem: expect.any(Object),
952
+ }),
953
+ );
954
+
955
+ $array.shift();
956
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
957
+ expect(onData).toHaveBeenLastCalledWith(
958
+ expect.objectContaining({
959
+ type: "shift",
960
+ removedItem: expect.any(Object),
961
+ }),
962
+ );
963
+ });
964
+ });
965
+
966
+ describe("splice action", () => {
967
+ it("should call effect when $lastAction is updated with splice action", async () => {
968
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
969
+ const onData = vi.fn();
970
+ subscribe((t) => $array.$lastAction.get(t), onData);
971
+
972
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
973
+ expect(onData).toHaveBeenLastCalledWith(
974
+ expect.objectContaining({
975
+ type: "set",
976
+ setItems: expect.any(Array),
977
+ clearedItems: expect.any(Array),
978
+ }),
979
+ );
980
+
981
+ $array.splice(1, 2);
982
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
983
+ expect(onData).toHaveBeenLastCalledWith(
984
+ expect.objectContaining({
985
+ type: "splice",
986
+ start: 1,
987
+ deleteCount: 2,
988
+ addedItems: expect.any(Array),
989
+ removedItems: expect.any(Array),
990
+ }),
991
+ );
992
+
993
+ $array.splice(1, 0, state(1), state(2));
994
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
995
+ expect(onData).toHaveBeenLastCalledWith(
996
+ expect.objectContaining({
997
+ type: "splice",
998
+ start: 1,
999
+ deleteCount: 0,
1000
+ addedItems: expect.any(Array),
1001
+ removedItems: expect.any(Array),
1002
+ }),
1003
+ );
1004
+ });
1005
+ });
1006
+
1007
+ describe("clear action", () => {
1008
+ it("should call effect when $lastAction is updated with clear action", async () => {
1009
+ const $array = array<FlowState<number>>([state(0), state(1), state(2), state(3), state(4)]);
1010
+ const onData = vi.fn();
1011
+ subscribe((t) => $array.$lastAction.get(t), onData);
1012
+
1013
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
1014
+ expect(onData).toHaveBeenLastCalledWith(
1015
+ expect.objectContaining({
1016
+ type: "set",
1017
+ setItems: expect.any(Array),
1018
+ clearedItems: expect.any(Array),
1019
+ }),
1020
+ );
1021
+
1022
+ $array.clear();
1023
+ await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
1024
+ expect(onData).toHaveBeenLastCalledWith(
1025
+ expect.objectContaining({
1026
+ type: "clear",
1027
+ clearedItems: expect.any(Array),
1028
+ }),
1029
+ );
1030
+ });
1031
+ });
1032
+ });
1033
+ });
1034
+ });
1035
+ });