@typed/fx 1.18.4 → 1.20.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 (423) hide show
  1. package/AsyncData/package.json +6 -0
  2. package/Emitter/package.json +6 -0
  3. package/Form/package.json +6 -0
  4. package/FormEntry/package.json +6 -0
  5. package/Fx/package.json +6 -0
  6. package/Guard/package.json +6 -0
  7. package/Idle/package.json +6 -0
  8. package/Match/package.json +6 -0
  9. package/Pull/package.json +6 -0
  10. package/Push/package.json +6 -0
  11. package/RefArray/package.json +6 -0
  12. package/RefChunk/package.json +6 -0
  13. package/RefHashMap/package.json +6 -0
  14. package/RefHashSet/package.json +6 -0
  15. package/RefSubject/package.json +6 -0
  16. package/Sink/package.json +6 -0
  17. package/Stream/package.json +6 -0
  18. package/Subject/package.json +6 -0
  19. package/TypeId/package.json +6 -0
  20. package/Typeclass/package.json +6 -0
  21. package/Versioned/package.json +6 -0
  22. package/dist/cjs/AsyncData.js +177 -0
  23. package/dist/cjs/AsyncData.js.map +1 -0
  24. package/dist/cjs/Emitter.js +24 -21
  25. package/dist/cjs/Emitter.js.map +1 -1
  26. package/dist/cjs/Form.js +78 -21
  27. package/dist/cjs/Form.js.map +1 -1
  28. package/dist/cjs/FormEntry.js +75 -48
  29. package/dist/cjs/FormEntry.js.map +1 -1
  30. package/dist/cjs/Fx.js +517 -872
  31. package/dist/cjs/Fx.js.map +1 -1
  32. package/dist/cjs/Guard.js +21 -13
  33. package/dist/cjs/Guard.js.map +1 -1
  34. package/dist/cjs/Idle.js +49 -37
  35. package/dist/cjs/Idle.js.map +1 -1
  36. package/dist/cjs/Match.js +99 -61
  37. package/dist/cjs/Match.js.map +1 -1
  38. package/dist/cjs/Pull.js.map +1 -1
  39. package/dist/cjs/Push.js +168 -0
  40. package/dist/cjs/Push.js.map +1 -0
  41. package/dist/cjs/RefArray.js +32 -30
  42. package/dist/cjs/RefArray.js.map +1 -1
  43. package/dist/cjs/RefChunk.js +26 -24
  44. package/dist/cjs/RefChunk.js.map +1 -1
  45. package/dist/cjs/RefHashMap.js +20 -20
  46. package/dist/cjs/RefHashMap.js.map +1 -1
  47. package/dist/cjs/RefHashSet.js +11 -8
  48. package/dist/cjs/RefHashSet.js.map +1 -1
  49. package/dist/cjs/RefSubject.js +899 -158
  50. package/dist/cjs/RefSubject.js.map +1 -1
  51. package/dist/cjs/Sink.js +588 -62
  52. package/dist/cjs/Sink.js.map +1 -1
  53. package/dist/cjs/Stream.js +15 -10
  54. package/dist/cjs/Stream.js.map +1 -1
  55. package/dist/cjs/Subject.js +153 -55
  56. package/dist/cjs/Subject.js.map +1 -1
  57. package/dist/cjs/TypeId.js +10 -5
  58. package/dist/cjs/TypeId.js.map +1 -1
  59. package/dist/cjs/Typeclass.js +28 -31
  60. package/dist/cjs/Typeclass.js.map +1 -1
  61. package/dist/cjs/Versioned.js +118 -57
  62. package/dist/cjs/Versioned.js.map +1 -1
  63. package/dist/cjs/index.js +44 -8
  64. package/dist/cjs/index.js.map +1 -1
  65. package/dist/cjs/internal/{deferred-ref.js → DeferredRef.js} +45 -13
  66. package/dist/cjs/internal/DeferredRef.js.map +1 -0
  67. package/dist/cjs/internal/UnionToTuple.js +6 -0
  68. package/dist/cjs/internal/UnionToTuple.js.map +1 -0
  69. package/dist/cjs/internal/core.js +1590 -779
  70. package/dist/cjs/internal/core.js.map +1 -1
  71. package/dist/cjs/internal/diff.js +114 -0
  72. package/dist/cjs/internal/diff.js.map +1 -0
  73. package/dist/cjs/internal/effect-loop-operator.js +288 -0
  74. package/dist/cjs/internal/effect-loop-operator.js.map +1 -0
  75. package/dist/cjs/internal/effect-operator.js +46 -37
  76. package/dist/cjs/internal/effect-operator.js.map +1 -1
  77. package/dist/cjs/internal/effect-producer.js +74 -0
  78. package/dist/cjs/internal/effect-producer.js.map +1 -0
  79. package/dist/cjs/internal/helpers.js +158 -128
  80. package/dist/cjs/internal/helpers.js.map +1 -1
  81. package/dist/cjs/internal/keyed.js +136 -173
  82. package/dist/cjs/internal/keyed.js.map +1 -1
  83. package/dist/cjs/internal/loop-operator.js +213 -0
  84. package/dist/cjs/internal/loop-operator.js.map +1 -0
  85. package/dist/cjs/internal/operator.js +79 -0
  86. package/dist/cjs/internal/operator.js.map +1 -0
  87. package/dist/cjs/internal/protos.js +19 -81
  88. package/dist/cjs/internal/protos.js.map +1 -1
  89. package/dist/cjs/internal/provide.js +47 -25
  90. package/dist/cjs/internal/provide.js.map +1 -1
  91. package/dist/cjs/internal/requestIdleCallback.js +5 -5
  92. package/dist/cjs/internal/requestIdleCallback.js.map +1 -1
  93. package/dist/cjs/internal/share.js +12 -15
  94. package/dist/cjs/internal/share.js.map +1 -1
  95. package/dist/cjs/internal/sync-operator.js +50 -22
  96. package/dist/cjs/internal/sync-operator.js.map +1 -1
  97. package/dist/cjs/internal/sync-producer.js +114 -0
  98. package/dist/cjs/internal/sync-producer.js.map +1 -0
  99. package/dist/cjs/internal/withKey.js +45 -51
  100. package/dist/cjs/internal/withKey.js.map +1 -1
  101. package/dist/dts/AsyncData.d.ts +185 -0
  102. package/dist/dts/AsyncData.d.ts.map +1 -0
  103. package/dist/dts/Emitter.d.ts +13 -20
  104. package/dist/dts/Emitter.d.ts.map +1 -1
  105. package/dist/dts/Form.d.ts +45 -28
  106. package/dist/dts/Form.d.ts.map +1 -1
  107. package/dist/dts/FormEntry.d.ts +25 -13
  108. package/dist/dts/FormEntry.d.ts.map +1 -1
  109. package/dist/dts/Fx.d.ts +983 -1387
  110. package/dist/dts/Fx.d.ts.map +1 -1
  111. package/dist/dts/Guard.d.ts +8 -1
  112. package/dist/dts/Guard.d.ts.map +1 -1
  113. package/dist/dts/Idle.d.ts +3 -3
  114. package/dist/dts/Idle.d.ts.map +1 -1
  115. package/dist/dts/Match.d.ts +8 -8
  116. package/dist/dts/Match.d.ts.map +1 -1
  117. package/dist/dts/Pull.d.ts +5 -5
  118. package/dist/dts/Pull.d.ts.map +1 -1
  119. package/dist/dts/Push.d.ts +170 -0
  120. package/dist/dts/Push.d.ts.map +1 -0
  121. package/dist/dts/RefArray.d.ts +21 -23
  122. package/dist/dts/RefArray.d.ts.map +1 -1
  123. package/dist/dts/RefChunk.d.ts +17 -19
  124. package/dist/dts/RefChunk.d.ts.map +1 -1
  125. package/dist/dts/RefHashMap.d.ts +19 -20
  126. package/dist/dts/RefHashMap.d.ts.map +1 -1
  127. package/dist/dts/RefHashSet.d.ts +12 -16
  128. package/dist/dts/RefHashSet.d.ts.map +1 -1
  129. package/dist/dts/RefSubject.d.ts +396 -187
  130. package/dist/dts/RefSubject.d.ts.map +1 -1
  131. package/dist/dts/Sink.d.ts +193 -93
  132. package/dist/dts/Sink.d.ts.map +1 -1
  133. package/dist/dts/Stream.d.ts +7 -1
  134. package/dist/dts/Stream.d.ts.map +1 -1
  135. package/dist/dts/Subject.d.ts +27 -36
  136. package/dist/dts/Subject.d.ts.map +1 -1
  137. package/dist/dts/TypeId.d.ts +10 -0
  138. package/dist/dts/TypeId.d.ts.map +1 -1
  139. package/dist/dts/Typeclass.d.ts +2 -2
  140. package/dist/dts/Typeclass.d.ts.map +1 -1
  141. package/dist/dts/Versioned.d.ts +50 -78
  142. package/dist/dts/Versioned.d.ts.map +1 -1
  143. package/dist/dts/index.d.ts +66 -6
  144. package/dist/dts/index.d.ts.map +1 -1
  145. package/dist/dts/internal/DeferredRef.d.ts +20 -0
  146. package/dist/dts/internal/DeferredRef.d.ts.map +1 -0
  147. package/dist/dts/internal/UnionToTuple.d.ts +6 -0
  148. package/dist/dts/internal/UnionToTuple.d.ts.map +1 -0
  149. package/dist/dts/internal/core.d.ts +218 -450
  150. package/dist/dts/internal/core.d.ts.map +1 -1
  151. package/dist/dts/internal/diff.d.ts +38 -0
  152. package/dist/dts/internal/diff.d.ts.map +1 -0
  153. package/dist/dts/internal/effect-loop-operator.d.ts +34 -0
  154. package/dist/dts/internal/effect-loop-operator.d.ts.map +1 -0
  155. package/dist/dts/internal/effect-operator.d.ts +8 -5
  156. package/dist/dts/internal/effect-operator.d.ts.map +1 -1
  157. package/dist/dts/internal/effect-producer.d.ts +25 -0
  158. package/dist/dts/internal/effect-producer.d.ts.map +1 -0
  159. package/dist/dts/internal/helpers.d.ts +33 -24
  160. package/dist/dts/internal/helpers.d.ts.map +1 -1
  161. package/dist/dts/internal/keyed.d.ts +3 -3
  162. package/dist/dts/internal/keyed.d.ts.map +1 -1
  163. package/dist/dts/internal/loop-operator.d.ts +40 -0
  164. package/dist/dts/internal/loop-operator.d.ts.map +1 -0
  165. package/dist/dts/internal/operator.d.ts +16 -0
  166. package/dist/dts/internal/operator.d.ts.map +1 -0
  167. package/dist/dts/internal/protos.d.ts +16 -43
  168. package/dist/dts/internal/protos.d.ts.map +1 -1
  169. package/dist/dts/internal/provide.d.ts +7 -1
  170. package/dist/dts/internal/provide.d.ts.map +1 -1
  171. package/dist/dts/internal/share.d.ts +12 -9
  172. package/dist/dts/internal/share.d.ts.map +1 -1
  173. package/dist/dts/internal/sync-operator.d.ts +7 -3
  174. package/dist/dts/internal/sync-operator.d.ts.map +1 -1
  175. package/dist/dts/internal/sync-producer.d.ts +36 -0
  176. package/dist/dts/internal/sync-producer.d.ts.map +1 -0
  177. package/dist/dts/internal/withKey.d.ts +3 -3
  178. package/dist/dts/internal/withKey.d.ts.map +1 -1
  179. package/dist/esm/AsyncData.js +151 -0
  180. package/dist/esm/AsyncData.js.map +1 -0
  181. package/dist/esm/Emitter.js +24 -21
  182. package/dist/esm/Emitter.js.map +1 -1
  183. package/dist/esm/Form.js +69 -14
  184. package/dist/esm/Form.js.map +1 -1
  185. package/dist/esm/FormEntry.js +77 -52
  186. package/dist/esm/FormEntry.js.map +1 -1
  187. package/dist/esm/Fx.js +509 -874
  188. package/dist/esm/Fx.js.map +1 -1
  189. package/dist/esm/Guard.js +5 -1
  190. package/dist/esm/Guard.js.map +1 -1
  191. package/dist/esm/Idle.js +49 -39
  192. package/dist/esm/Idle.js.map +1 -1
  193. package/dist/esm/Match.js +103 -63
  194. package/dist/esm/Match.js.map +1 -1
  195. package/dist/esm/Pull.js.map +1 -1
  196. package/dist/esm/Push.js +159 -0
  197. package/dist/esm/Push.js.map +1 -0
  198. package/dist/esm/RefArray.js +32 -30
  199. package/dist/esm/RefArray.js.map +1 -1
  200. package/dist/esm/RefChunk.js +26 -24
  201. package/dist/esm/RefChunk.js.map +1 -1
  202. package/dist/esm/RefHashMap.js +20 -20
  203. package/dist/esm/RefHashMap.js.map +1 -1
  204. package/dist/esm/RefHashSet.js +11 -8
  205. package/dist/esm/RefHashSet.js.map +1 -1
  206. package/dist/esm/RefSubject.js +873 -150
  207. package/dist/esm/RefSubject.js.map +1 -1
  208. package/dist/esm/Sink.js +608 -57
  209. package/dist/esm/Sink.js.map +1 -1
  210. package/dist/esm/Stream.js +13 -9
  211. package/dist/esm/Stream.js.map +1 -1
  212. package/dist/esm/Subject.js +151 -56
  213. package/dist/esm/Subject.js.map +1 -1
  214. package/dist/esm/TypeId.js +9 -4
  215. package/dist/esm/TypeId.js.map +1 -1
  216. package/dist/esm/Typeclass.js +29 -29
  217. package/dist/esm/Typeclass.js.map +1 -1
  218. package/dist/esm/Versioned.js +110 -53
  219. package/dist/esm/Versioned.js.map +1 -1
  220. package/dist/esm/index.js +66 -6
  221. package/dist/esm/index.js.map +1 -1
  222. package/dist/esm/internal/DeferredRef.js +54 -0
  223. package/dist/esm/internal/DeferredRef.js.map +1 -0
  224. package/dist/esm/internal/UnionToTuple.js +2 -0
  225. package/dist/esm/internal/UnionToTuple.js.map +1 -0
  226. package/dist/esm/internal/core.js +1439 -719
  227. package/dist/esm/internal/core.js.map +1 -1
  228. package/dist/esm/internal/diff.js +82 -0
  229. package/dist/esm/internal/diff.js.map +1 -0
  230. package/dist/esm/internal/effect-loop-operator.js +269 -0
  231. package/dist/esm/internal/effect-loop-operator.js.map +1 -0
  232. package/dist/esm/internal/effect-operator.js +44 -37
  233. package/dist/esm/internal/effect-operator.js.map +1 -1
  234. package/dist/esm/internal/effect-producer.js +47 -0
  235. package/dist/esm/internal/effect-producer.js.map +1 -0
  236. package/dist/esm/internal/helpers.js +157 -129
  237. package/dist/esm/internal/helpers.js.map +1 -1
  238. package/dist/esm/internal/keyed.js +128 -139
  239. package/dist/esm/internal/keyed.js.map +1 -1
  240. package/dist/esm/internal/loop-operator.js +186 -0
  241. package/dist/esm/internal/loop-operator.js.map +1 -0
  242. package/dist/esm/internal/operator.js +68 -0
  243. package/dist/esm/internal/operator.js.map +1 -0
  244. package/dist/esm/internal/protos.js +16 -75
  245. package/dist/esm/internal/protos.js.map +1 -1
  246. package/dist/esm/internal/provide.js +33 -25
  247. package/dist/esm/internal/provide.js.map +1 -1
  248. package/dist/esm/internal/requestIdleCallback.js +5 -5
  249. package/dist/esm/internal/requestIdleCallback.js.map +1 -1
  250. package/dist/esm/internal/share.js +12 -12
  251. package/dist/esm/internal/share.js.map +1 -1
  252. package/dist/esm/internal/sync-operator.js +49 -21
  253. package/dist/esm/internal/sync-operator.js.map +1 -1
  254. package/dist/esm/internal/sync-producer.js +88 -0
  255. package/dist/esm/internal/sync-producer.js.map +1 -0
  256. package/dist/esm/internal/withKey.js +46 -47
  257. package/dist/esm/internal/withKey.js.map +1 -1
  258. package/package.json +22 -62
  259. package/src/AsyncData.ts +447 -0
  260. package/src/Emitter.ts +47 -38
  261. package/src/Form.ts +185 -65
  262. package/src/FormEntry.ts +142 -109
  263. package/src/Fx.ts +1685 -1851
  264. package/src/Guard.ts +12 -1
  265. package/src/Idle.ts +76 -62
  266. package/src/Match.ts +149 -93
  267. package/src/Pull.ts +8 -8
  268. package/src/Push.ts +472 -0
  269. package/src/RefArray.ts +53 -51
  270. package/src/RefChunk.ts +44 -41
  271. package/src/RefHashMap.ts +57 -43
  272. package/src/RefHashSet.ts +21 -31
  273. package/src/RefSubject.ts +1984 -457
  274. package/src/Sink.ts +922 -171
  275. package/src/Stream.ts +32 -20
  276. package/src/Subject.ts +230 -87
  277. package/src/TypeId.ts +16 -4
  278. package/src/Typeclass.ts +31 -32
  279. package/src/Versioned.ts +220 -168
  280. package/src/index.ts +78 -6
  281. package/src/internal/DeferredRef.ts +62 -0
  282. package/src/internal/UnionToTuple.ts +11 -0
  283. package/src/internal/core.ts +2491 -1950
  284. package/src/internal/diff.ts +157 -0
  285. package/src/internal/effect-loop-operator.ts +466 -0
  286. package/src/internal/effect-operator.ts +89 -54
  287. package/src/internal/effect-producer.ts +125 -0
  288. package/src/internal/helpers.ts +275 -205
  289. package/src/internal/keyed.ts +192 -241
  290. package/src/internal/loop-operator.ts +266 -0
  291. package/src/internal/operator.ts +87 -0
  292. package/src/internal/protos.ts +29 -104
  293. package/src/internal/provide.ts +48 -40
  294. package/src/internal/requestIdleCallback.ts +5 -6
  295. package/src/internal/share.ts +26 -24
  296. package/src/internal/sync-operator.ts +68 -27
  297. package/src/internal/sync-producer.ts +146 -0
  298. package/src/internal/withKey.ts +64 -74
  299. package/dist/cjs/Computed.js +0 -115
  300. package/dist/cjs/Computed.js.map +0 -1
  301. package/dist/cjs/Filtered.js +0 -95
  302. package/dist/cjs/Filtered.js.map +0 -1
  303. package/dist/cjs/Model.js +0 -119
  304. package/dist/cjs/Model.js.map +0 -1
  305. package/dist/cjs/RefAsyncData.js +0 -187
  306. package/dist/cjs/RefAsyncData.js.map +0 -1
  307. package/dist/cjs/RefAsyncDataArray.js +0 -38
  308. package/dist/cjs/RefAsyncDataArray.js.map +0 -1
  309. package/dist/cjs/RefBoolean.js +0 -45
  310. package/dist/cjs/RefBoolean.js.map +0 -1
  311. package/dist/cjs/RefNumber.js +0 -49
  312. package/dist/cjs/RefNumber.js.map +0 -1
  313. package/dist/cjs/internal/core-ref-subject.js +0 -254
  314. package/dist/cjs/internal/core-ref-subject.js.map +0 -1
  315. package/dist/cjs/internal/core-subject.js +0 -108
  316. package/dist/cjs/internal/core-subject.js.map +0 -1
  317. package/dist/cjs/internal/deferred-ref.js.map +0 -1
  318. package/dist/cjs/internal/effect-primitive.js +0 -47
  319. package/dist/cjs/internal/effect-primitive.js.map +0 -1
  320. package/dist/cjs/internal/fx-effect-proto.js +0 -58
  321. package/dist/cjs/internal/fx-effect-proto.js.map +0 -1
  322. package/dist/cjs/internal/fx-primitive.js +0 -193
  323. package/dist/cjs/internal/fx-primitive.js.map +0 -1
  324. package/dist/cjs/internal/fx.js +0 -240
  325. package/dist/cjs/internal/fx.js.map +0 -1
  326. package/dist/cjs/internal/matchers.js +0 -34
  327. package/dist/cjs/internal/matchers.js.map +0 -1
  328. package/dist/cjs/internal/run.js +0 -54
  329. package/dist/cjs/internal/run.js.map +0 -1
  330. package/dist/cjs/internal/schema-ref-subject.js +0 -132
  331. package/dist/cjs/internal/schema-ref-subject.js.map +0 -1
  332. package/dist/cjs/internal/versioned-transform.js +0 -46
  333. package/dist/cjs/internal/versioned-transform.js.map +0 -1
  334. package/dist/dts/Computed.d.ts +0 -106
  335. package/dist/dts/Computed.d.ts.map +0 -1
  336. package/dist/dts/Filtered.d.ts +0 -97
  337. package/dist/dts/Filtered.d.ts.map +0 -1
  338. package/dist/dts/Model.d.ts +0 -200
  339. package/dist/dts/Model.d.ts.map +0 -1
  340. package/dist/dts/RefAsyncData.d.ts +0 -236
  341. package/dist/dts/RefAsyncData.d.ts.map +0 -1
  342. package/dist/dts/RefAsyncDataArray.d.ts +0 -56
  343. package/dist/dts/RefAsyncDataArray.d.ts.map +0 -1
  344. package/dist/dts/RefBoolean.d.ts +0 -47
  345. package/dist/dts/RefBoolean.d.ts.map +0 -1
  346. package/dist/dts/RefNumber.d.ts +0 -48
  347. package/dist/dts/RefNumber.d.ts.map +0 -1
  348. package/dist/dts/internal/core-ref-subject.d.ts +0 -100
  349. package/dist/dts/internal/core-ref-subject.d.ts.map +0 -1
  350. package/dist/dts/internal/core-subject.d.ts +0 -5
  351. package/dist/dts/internal/core-subject.d.ts.map +0 -1
  352. package/dist/dts/internal/deferred-ref.d.ts +0 -12
  353. package/dist/dts/internal/deferred-ref.d.ts.map +0 -1
  354. package/dist/dts/internal/effect-primitive.d.ts +0 -6
  355. package/dist/dts/internal/effect-primitive.d.ts.map +0 -1
  356. package/dist/dts/internal/fx-effect-proto.d.ts +0 -30
  357. package/dist/dts/internal/fx-effect-proto.d.ts.map +0 -1
  358. package/dist/dts/internal/fx-primitive.d.ts +0 -109
  359. package/dist/dts/internal/fx-primitive.d.ts.map +0 -1
  360. package/dist/dts/internal/fx.d.ts +0 -245
  361. package/dist/dts/internal/fx.d.ts.map +0 -1
  362. package/dist/dts/internal/matchers.d.ts +0 -33
  363. package/dist/dts/internal/matchers.d.ts.map +0 -1
  364. package/dist/dts/internal/run.d.ts +0 -8
  365. package/dist/dts/internal/run.d.ts.map +0 -1
  366. package/dist/dts/internal/schema-ref-subject.d.ts +0 -5
  367. package/dist/dts/internal/schema-ref-subject.d.ts.map +0 -1
  368. package/dist/dts/internal/versioned-transform.d.ts +0 -17
  369. package/dist/dts/internal/versioned-transform.d.ts.map +0 -1
  370. package/dist/esm/Computed.js +0 -103
  371. package/dist/esm/Computed.js.map +0 -1
  372. package/dist/esm/Filtered.js +0 -83
  373. package/dist/esm/Filtered.js.map +0 -1
  374. package/dist/esm/Model.js +0 -100
  375. package/dist/esm/Model.js.map +0 -1
  376. package/dist/esm/RefAsyncData.js +0 -163
  377. package/dist/esm/RefAsyncData.js.map +0 -1
  378. package/dist/esm/RefAsyncDataArray.js +0 -27
  379. package/dist/esm/RefAsyncDataArray.js.map +0 -1
  380. package/dist/esm/RefBoolean.js +0 -31
  381. package/dist/esm/RefBoolean.js.map +0 -1
  382. package/dist/esm/RefNumber.js +0 -35
  383. package/dist/esm/RefNumber.js.map +0 -1
  384. package/dist/esm/internal/core-ref-subject.js +0 -242
  385. package/dist/esm/internal/core-ref-subject.js.map +0 -1
  386. package/dist/esm/internal/core-subject.js +0 -90
  387. package/dist/esm/internal/core-subject.js.map +0 -1
  388. package/dist/esm/internal/deferred-ref.js +0 -23
  389. package/dist/esm/internal/deferred-ref.js.map +0 -1
  390. package/dist/esm/internal/effect-primitive.js +0 -41
  391. package/dist/esm/internal/effect-primitive.js.map +0 -1
  392. package/dist/esm/internal/fx-effect-proto.js +0 -43
  393. package/dist/esm/internal/fx-effect-proto.js.map +0 -1
  394. package/dist/esm/internal/fx-primitive.js +0 -175
  395. package/dist/esm/internal/fx-primitive.js.map +0 -1
  396. package/dist/esm/internal/fx.js +0 -216
  397. package/dist/esm/internal/fx.js.map +0 -1
  398. package/dist/esm/internal/matchers.js +0 -38
  399. package/dist/esm/internal/matchers.js.map +0 -1
  400. package/dist/esm/internal/run.js +0 -32
  401. package/dist/esm/internal/run.js.map +0 -1
  402. package/dist/esm/internal/schema-ref-subject.js +0 -121
  403. package/dist/esm/internal/schema-ref-subject.js.map +0 -1
  404. package/dist/esm/internal/versioned-transform.js +0 -37
  405. package/dist/esm/internal/versioned-transform.js.map +0 -1
  406. package/src/Computed.ts +0 -289
  407. package/src/Filtered.ts +0 -274
  408. package/src/Model.ts +0 -483
  409. package/src/RefAsyncData.ts +0 -547
  410. package/src/RefAsyncDataArray.ts +0 -135
  411. package/src/RefBoolean.ts +0 -71
  412. package/src/RefNumber.ts +0 -77
  413. package/src/internal/core-ref-subject.ts +0 -528
  414. package/src/internal/core-subject.ts +0 -143
  415. package/src/internal/deferred-ref.ts +0 -26
  416. package/src/internal/effect-primitive.ts +0 -230
  417. package/src/internal/fx-effect-proto.ts +0 -56
  418. package/src/internal/fx-primitive.ts +0 -223
  419. package/src/internal/fx.ts +0 -619
  420. package/src/internal/matchers.ts +0 -83
  421. package/src/internal/run.ts +0 -51
  422. package/src/internal/schema-ref-subject.ts +0 -163
  423. package/src/internal/versioned-transform.ts +0 -48
@@ -1,217 +1,940 @@
1
1
  /**
2
- * A RefSubject is the core abstraction for keeping state and subscribing to its
3
- * changes over time.
4
- *
5
- * @since 1.18.0
2
+ * A RefSubject is a Subject that can be used to read and write a value.
3
+ * @since 1.20.0
6
4
  */
7
5
  import * as C from "@typed/context";
8
- import { Cause, Exit, identity } from "effect";
6
+ import { Fiber } from "effect";
7
+ import * as Boolean from "effect/Boolean";
8
+ import * as Cause from "effect/Cause";
9
9
  import * as Effect from "effect/Effect";
10
- import { equals } from "effect/Equal";
11
- import { dual } from "effect/Function";
10
+ import * as Equal from "effect/Equal";
11
+ import * as ExecutionStrategy from "effect/ExecutionStrategy";
12
+ import * as Exit from "effect/Exit";
13
+ import { dual, identity } from "effect/Function";
14
+ import * as Layer from "effect/Layer";
15
+ import { sum } from "effect/Number";
12
16
  import * as Option from "effect/Option";
13
- import { Computed, fromTag } from "./Computed.js";
14
- import { Filtered } from "./Filtered.js";
15
- import * as coreRefSubject from "./internal/core-ref-subject.js";
16
- import { fromStream, provide, skipRepeatsWith } from "./internal/core.js";
17
- import { exit, fromFxEffect } from "./internal/fx.js";
17
+ import * as ReadonlyArray from "effect/ReadonlyArray";
18
+ import * as Scope from "effect/Scope";
19
+ import * as core from "./internal/core.js";
20
+ import * as DeferredRef from "./internal/DeferredRef.js";
21
+ import { getExitEquivalence, matchEffectPrimitive, withScope } from "./internal/helpers.js";
18
22
  import { FxEffectBase } from "./internal/protos.js";
19
- import { fromRefSubject, toRefSubject } from "./internal/schema-ref-subject.js";
20
- import { ComputedTypeId, RefSubjectTypeId } from "./TypeId.js";
23
+ import { runtimeToLayer } from "./internal/provide.js";
24
+ import * as share from "./internal/share.js";
25
+ import * as Sink from "./Sink.js";
26
+ import * as Subject from "./Subject.js";
27
+ import { ComputedTypeId, FilteredTypeId, RefSubjectTypeId, TypeId } from "./TypeId.js";
21
28
  import * as Versioned from "./Versioned.js";
29
+ const UNBOUNDED = { concurrency: "unbounded" };
22
30
  /**
23
- * Construct a RefSubject with a lazily initialized value.
24
- * @since 1.18.0
25
- * @category constructors
31
+ * @since 1.20.0
26
32
  */
27
- export function fromEffect(initial, eq) {
28
- return coreRefSubject.fromEffect(initial, eq);
33
+ export function fromEffect(effect, options) {
34
+ return Effect.map(makeCore(effect, options), (core) => new RefSubjectImpl(core));
29
35
  }
30
36
  /**
31
- * Construct a RefSubject from a synchronous value.
32
- * @since 1.18.0
33
- * @category constructors
37
+ * @since 1.20.0
34
38
  */
35
- export function of(initial, eq) {
36
- return fromEffect(Effect.succeed(initial), eq);
39
+ export function fromFx(fx, options) {
40
+ return DeferredRef.make(getExitEquivalence(options?.eq ?? Equal.equals)).pipe(Effect.bindTo("deferredRef"), Effect.bind("core", ({ deferredRef }) => makeCore(deferredRef, options)), Effect.tap(({ core, deferredRef }) => Effect.forkIn(fx.run(Sink.make((cause) => Effect.flatMap(Effect.sync(() => deferredRef.done(Exit.failCause(cause))), () => core.subject.onFailure(cause)), (value) => Effect.flatMap(Effect.sync(() => deferredRef.done(Exit.succeed(value))), () => setCore(core, value)))), core.scope)), Effect.map(({ core }) => new RefSubjectImpl(core)));
37
41
  }
38
42
  /**
39
- * Construct a RefSubject from a synchronous value.
40
- * @since 1.18.0
41
- * @category constructors
43
+ * @since 1.20.0
44
+ */
45
+ export function fromRefSubject(ref, options) {
46
+ return DeferredRef.make(getExitEquivalence(options?.eq ?? Equal.equals)).pipe(Effect.bindTo("deferredRef"), Effect.bind("core", ({ deferredRef }) => makeCore(deferredRef, options)), Effect.tap(({ core, deferredRef }) => Effect.forkIn(ref.run(Sink.make((cause) => Effect.sync(() => deferredRef.done(Exit.failCause(cause))), (value) => Effect.sync(() => deferredRef.done(Exit.succeed(value))))), core.scope)), Effect.map(({ core }) => new DerivedImpl(core, persistCore(ref, core))));
47
+ }
48
+ function persistCore(ref, core) {
49
+ // Log any errors that fail to persist, but don't fail the consumer
50
+ return Effect.ignoreLogged(Effect.provide(Effect.flatMap(core.deferredRef, (value) => set(ref, value)), core.context));
51
+ }
52
+ /**
53
+ * @since 1.20.0
54
+ */
55
+ export const make = function make(fxOrEffect, options) {
56
+ if (RefSubjectTypeId in fxOrEffect)
57
+ return fromRefSubject(fxOrEffect, options);
58
+ else if (TypeId in fxOrEffect)
59
+ return fromFx(fxOrEffect, options);
60
+ else
61
+ return fromEffect(fxOrEffect, options);
62
+ };
63
+ /**
64
+ * @since 1.20.0
42
65
  */
43
- export function sync(initial, eq) {
44
- return fromEffect(Effect.sync(initial), eq);
66
+ export function of(a, options) {
67
+ return Effect.acquireRelease(withScopeAndFiberId((scope, id) => unsafeMake({
68
+ id,
69
+ initial: Effect.succeed(a),
70
+ initialValue: a,
71
+ options,
72
+ scope
73
+ }), options?.executionStrategy ?? ExecutionStrategy.sequential), (ref) => ref.interrupt);
74
+ }
75
+ const withScopeAndFiberId = (f, strategy) => Effect.fiberIdWith((id) => withScope((scope) => f(scope, id), strategy));
76
+ const emptyContext = C.empty();
77
+ /**
78
+ * @since 1.20.0
79
+ */
80
+ export function unsafeMake(params) {
81
+ const { id, initial, options, scope } = params;
82
+ return Effect.suspend(() => {
83
+ const core = unsafeMakeCore(initial, id, emptyContext, scope, options);
84
+ // Sometimes we might be instantiating directly from a known value
85
+ // Here we seed the value and ensure the subject has it as well for re-broadcasting
86
+ if ("initialValue" in params) {
87
+ core.deferredRef.done(Exit.succeed(params.initialValue));
88
+ return Effect.map(core.subject.onSuccess(params.initialValue), () => new RefSubjectImpl(core));
89
+ }
90
+ return Effect.succeed(new RefSubjectImpl(core));
91
+ });
45
92
  }
46
- export function make(fx, eq) {
47
- return coreRefSubject.make(fx, eq);
93
+ class RefSubjectImpl extends FxEffectBase {
94
+ core;
95
+ [ComputedTypeId] = ComputedTypeId;
96
+ [RefSubjectTypeId] = RefSubjectTypeId;
97
+ version;
98
+ interrupt;
99
+ subscriberCount;
100
+ getSetDelete;
101
+ constructor(core) {
102
+ super();
103
+ this.core = core;
104
+ this.version = Effect.sync(() => core.deferredRef.version);
105
+ this.interrupt = interruptCore(core);
106
+ this.subscriberCount = Effect.provide(core.subject.subscriberCount, core.context);
107
+ this.getSetDelete = getSetDelete(core);
108
+ this.runUpdates = this.runUpdates.bind(this);
109
+ this.onSuccess = this.onSuccess.bind(this);
110
+ this.onFailure = this.onFailure.bind(this);
111
+ }
112
+ run(sink) {
113
+ return Effect.matchCauseEffect(this.toEffect(), {
114
+ onFailure: (cause) => sink.onFailure(cause),
115
+ onSuccess: () => Effect.provide(this.core.subject.run(sink), this.core.context)
116
+ });
117
+ }
118
+ runUpdates(run, lock = true) {
119
+ return lock ? this.core.semaphore.withPermits(1)(run(this.getSetDelete)) : run(this.getSetDelete);
120
+ }
121
+ onSuccess(value) {
122
+ return setCore(this.core, value);
123
+ }
124
+ onFailure(cause) {
125
+ return onFailureCore(this.core, cause);
126
+ }
127
+ toEffect() {
128
+ return getOrInitializeCore(this.core, true);
129
+ }
48
130
  }
49
- export function tagged(defaultEq) {
50
- function makeTagged(identifier) {
51
- return new ContextImpl(C.Tagged(identifier), defaultEq);
131
+ class DerivedImpl extends RefSubjectImpl {
132
+ persist;
133
+ constructor(core, persist) {
134
+ super(core);
135
+ this.persist = persist;
52
136
  }
53
- return makeTagged;
54
137
  }
55
- class ContextImpl extends FxEffectBase {
56
- tag;
57
- defaultEq;
138
+ /**
139
+ * @since 1.20.0
140
+ */
141
+ export const set = dual(2, function set(ref, a) {
142
+ return ref.runUpdates((ref) => ref.set(a));
143
+ });
144
+ /**
145
+ * @since 1.20.0
146
+ */
147
+ export function reset(ref) {
148
+ return ref.runUpdates((ref) => ref.delete);
149
+ }
150
+ /**
151
+ * @since 1.20.0
152
+ */
153
+ export {
154
+ /**
155
+ * @since 1.20.0
156
+ */
157
+ reset as delete };
158
+ function getSetDelete(ref) {
159
+ return {
160
+ get: getOrInitializeCore(ref, false),
161
+ set: (a) => setCore(ref, a),
162
+ delete: deleteCore(ref)
163
+ };
164
+ }
165
+ /**
166
+ * @since 1.20.0
167
+ */
168
+ export const updateEffect = dual(2, function updateEffect(ref, f) {
169
+ return ref.runUpdates((ref) => Effect.flatMap(Effect.flatMap(ref.get, f), ref.set));
170
+ });
171
+ /**
172
+ * @since 1.20.0
173
+ */
174
+ export const update = dual(2, function update(ref, f) {
175
+ return updateEffect(ref, (value) => Effect.succeed(f(value)));
176
+ });
177
+ /**
178
+ * @since 1.20.0
179
+ */
180
+ export const modifyEffect = dual(2, function modifyEffect(ref, f) {
181
+ return ref.runUpdates((ref) => Effect.flatMap(ref.get, (value) => Effect.flatMap(f(value), ([b, a]) => Effect.flatMap(ref.set(a), () => Effect.succeed(b)))));
182
+ });
183
+ /**
184
+ * @since 1.20.0
185
+ */
186
+ export const modify = dual(2, function modify(ref, f) {
187
+ return modifyEffect(ref, (value) => Effect.succeed(f(value)));
188
+ });
189
+ const isRefSubjectDataFirst = (args) => isRefSubject(args[0]);
190
+ /**
191
+ * @since 1.20.0
192
+ */
193
+ export const runUpdates = dual(isRefSubjectDataFirst, function runUpdates(ref, f, options) {
194
+ if (!options) {
195
+ return ref.runUpdates(f);
196
+ }
197
+ else if (options.value === "initial") {
198
+ return ref.runUpdates((ref) => Effect.uninterruptibleMask((restore) => Effect.flatMap(ref.get, (initial) => f(ref).pipe(restore, Effect.tapErrorCause(Effect.unifiedFn((cause) => Cause.isInterruptedOnly(cause)
199
+ ? options.onInterrupt(initial)
200
+ : Effect.unit))))));
201
+ }
202
+ else {
203
+ return ref.runUpdates((ref) => Effect.uninterruptibleMask((restore) => f(ref).pipe(restore, Effect.tapErrorCause(Effect.unifiedFn((cause) => Cause.isInterruptedOnly(cause)
204
+ ? Effect.flatMap(ref.get, options.onInterrupt)
205
+ : Effect.unit)))));
206
+ }
207
+ });
208
+ class RefSubjectCore {
209
+ initial;
210
+ subject;
211
+ context;
212
+ scope;
213
+ deferredRef;
214
+ semaphore;
215
+ constructor(initial, subject, context, scope, deferredRef, semaphore) {
216
+ this.initial = initial;
217
+ this.subject = subject;
218
+ this.context = context;
219
+ this.scope = scope;
220
+ this.deferredRef = deferredRef;
221
+ this.semaphore = semaphore;
222
+ }
223
+ _fiber = undefined;
224
+ }
225
+ function makeCore(initial, options) {
226
+ return Effect.context().pipe(Effect.bindTo("ctx"), Effect.let("executionStrategy", () => options?.executionStrategy ?? ExecutionStrategy.parallel), Effect.bind("scope", ({ ctx, executionStrategy }) => Scope.fork(C.get(ctx, Scope.Scope), executionStrategy)), Effect.bind("deferredRef", () => DeferredRef.make(getExitEquivalence(options?.eq ?? Equal.equals))), Effect.let("subject", () => Subject.unsafeMake(Math.max(1, options?.replay ?? 1))), Effect.tap(({ scope, subject }) => Scope.addFinalizer(scope, subject.interrupt)), Effect.map(({ ctx, deferredRef, scope, subject }) => new RefSubjectCore(initial, subject, ctx, scope, deferredRef, Effect.unsafeMakeSemaphore(1))));
227
+ }
228
+ function unsafeMakeCore(initial, id, ctx, scope, options) {
229
+ return new RefSubjectCore(initial, Subject.unsafeMake(Math.max(1, options?.replay ?? 1)), ctx, scope, DeferredRef.unsafeMake(id, getExitEquivalence(options?.eq ?? Equal.equals)), Effect.unsafeMakeSemaphore(1));
230
+ }
231
+ function getOrInitializeCore(core, lockInitialize) {
232
+ return Effect.suspend(() => {
233
+ if (core._fiber === undefined && Option.isNone(core.deferredRef.current)) {
234
+ return initializeCoreAndTap(core, lockInitialize);
235
+ }
236
+ else {
237
+ return core.deferredRef;
238
+ }
239
+ });
240
+ }
241
+ function initializeCoreEffect(core, lock) {
242
+ const initialize = Effect.onExit(Effect.provide(core.initial, core.context), (exit) => {
243
+ core._fiber = undefined;
244
+ core.deferredRef.done(exit);
245
+ return Effect.unit;
246
+ });
247
+ return Effect.flatMap(Effect.forkIn(lock && core.semaphore ? core.semaphore.withPermits(1)(initialize) : initialize, core.scope), (fiber) => Effect.sync(() => core._fiber = fiber));
248
+ }
249
+ function initializeCore(core, lock) {
250
+ const onSuccess = (a) => {
251
+ core.deferredRef.done(Exit.succeed(a));
252
+ return Effect.succeed(Fiber.succeed(a));
253
+ };
254
+ const onCause = (cause) => {
255
+ core.deferredRef.done(Exit.failCause(cause));
256
+ return Effect.succeed(Fiber.failCause(cause));
257
+ };
258
+ const onError = (e) => onCause(Cause.fail(e));
259
+ return matchEffectPrimitive(core.initial, {
260
+ Success: onSuccess,
261
+ Failure: onCause,
262
+ Some: onSuccess,
263
+ None: onError,
264
+ Left: onError,
265
+ Right: onSuccess,
266
+ Sync: (f) => onSuccess(f()),
267
+ Otherwise: () => initializeCoreEffect(core, lock)
268
+ });
269
+ }
270
+ function initializeCoreAndTap(core, lock) {
271
+ return Effect.zipRight(initializeCore(core, lock), tapEventCore(core, core.deferredRef));
272
+ }
273
+ function setCore(core, a) {
274
+ const exit = Exit.succeed(a);
275
+ return Effect.suspend(() => {
276
+ if (core.deferredRef.done(exit)) {
277
+ // If the value changed, send an event
278
+ return Effect.as(sendEvent(core, exit), a);
279
+ }
280
+ else {
281
+ // Otherwise, just return the current value
282
+ return Effect.succeed(a);
283
+ }
284
+ });
285
+ }
286
+ function onFailureCore(core, cause) {
287
+ const exit = Exit.failCause(cause);
288
+ return Effect.suspend(() => {
289
+ if (core.deferredRef.done(exit)) {
290
+ return sendEvent(core, exit);
291
+ }
292
+ else {
293
+ return Effect.unit;
294
+ }
295
+ });
296
+ }
297
+ function interruptCore(core) {
298
+ return Effect.fiberIdWith((id) => {
299
+ core.deferredRef.reset();
300
+ return Scope.close(core.scope, Exit.interrupt(id));
301
+ });
302
+ }
303
+ function deleteCore(core) {
304
+ return Effect.suspend(() => {
305
+ const current = core.deferredRef.current;
306
+ core.deferredRef.reset();
307
+ if (Option.isNone(current)) {
308
+ return Effect.succeed(Option.none());
309
+ }
310
+ return core.subject.subscriberCount.pipe(Effect.provide(core.context), Effect.flatMap((count) => count > 0 && !core._fiber ? initializeCore(core, false) : Effect.unit), Effect.zipRight(Effect.asSome(current.value)));
311
+ });
312
+ }
313
+ function tapEventCore(core, effect) {
314
+ return effect.pipe(Effect.exit, Effect.tap((exit) => sendEvent(core, exit)), Effect.flatten);
315
+ }
316
+ function sendEvent(core, exit) {
317
+ if (Exit.isSuccess(exit)) {
318
+ return Effect.provide(core.subject.onSuccess(exit.value), core.context);
319
+ }
320
+ else {
321
+ return Effect.provide(core.subject.onFailure(exit.cause), core.context);
322
+ }
323
+ }
324
+ /**
325
+ * @since 1.20.0
326
+ */
327
+ export const mapEffect = dual(2, function mapEffect(versioned, f) {
328
+ return FilteredTypeId in versioned
329
+ ? FilteredImpl.make(versioned, (a) => Effect.asSome(f(a)))
330
+ : ComputedImpl.make(versioned, f);
331
+ });
332
+ /**
333
+ * @since 1.20.0
334
+ */
335
+ export const map = dual(2, function map(versioned, f) {
336
+ return mapEffect(versioned, (a) => Effect.succeed(f(a)));
337
+ });
338
+ /**
339
+ * @since 1.20.0
340
+ */
341
+ export const filterMapEffect = dual(2, function filterMapEffect(versioned, f) {
342
+ return FilteredImpl.make(versioned, f);
343
+ });
344
+ /**
345
+ * @since 1.20.0
346
+ */
347
+ export const filterMap = dual(2, function filterMap(versioned, f) {
348
+ return FilteredImpl.make(versioned, (a) => Effect.succeed(f(a)));
349
+ });
350
+ /**
351
+ * @since 1.20.0
352
+ */
353
+ export const compact = (versioned) => filterMap(versioned, identity);
354
+ /**
355
+ * @since 1.20.0
356
+ */
357
+ export const filterEffect = dual(2, function filterEffect(versioned, f) {
358
+ return FilteredImpl.make(versioned, (a) => Effect.map(f(a), (b) => b ? Option.some(a) : Option.none()));
359
+ });
360
+ /**
361
+ * @since 1.20.0
362
+ */
363
+ export const filter = dual(2, function filter(versioned, f) {
364
+ return FilteredImpl.make(versioned, (a) => Effect.succeed(f(a) ? Option.some(a) : Option.none()));
365
+ });
366
+ class ComputedImpl extends Versioned.VersionedTransform {
367
+ input;
368
+ f;
369
+ [ComputedTypeId] = ComputedTypeId;
370
+ constructor(input, f) {
371
+ super(input, (fx) => share.hold(core.mapEffect(fx, f)), Effect.flatMap(f));
372
+ this.input = input;
373
+ this.f = f;
374
+ }
375
+ static make(input, f) {
376
+ return new ComputedImpl(input, f);
377
+ }
378
+ }
379
+ class FilteredImpl extends Versioned.VersionedTransform {
380
+ input;
381
+ f;
382
+ [FilteredTypeId] = FilteredTypeId;
383
+ constructor(input, f) {
384
+ super(input, (fx) => share.hold(core.filterMapEffect(fx, f)), (effect) => Effect.flatten(Effect.flatMap(effect, f)));
385
+ this.input = input;
386
+ this.f = f;
387
+ }
388
+ static make(input, f) {
389
+ return new FilteredImpl(input, f);
390
+ }
391
+ asComputed() {
392
+ return ComputedImpl.make(this.input, this.f);
393
+ }
394
+ }
395
+ /**
396
+ * @since 1.20.0
397
+ */
398
+ export const skipRepeatsWith = dual(2, function skipRepeatsWith(ref, eq) {
399
+ const versioned = Versioned.transform(ref, (fx) => core.skipRepeatsWith(fx, eq), identity);
400
+ if (FilteredTypeId in ref) {
401
+ return FilteredImpl.make(versioned, Effect.succeedSome);
402
+ }
403
+ else {
404
+ return ComputedImpl.make(versioned, Effect.succeed);
405
+ }
406
+ });
407
+ export function skipRepeats(ref) {
408
+ return skipRepeatsWith(ref, Equal.equals);
409
+ }
410
+ /**
411
+ * @since 1.20.0
412
+ */
413
+ export function transform(ref, from, to) {
414
+ return new RefSubjectTransform(ref, from, to);
415
+ }
416
+ /**
417
+ * @since 1.20.0
418
+ */
419
+ export function transformOrFail(ref, from, to) {
420
+ return new RefSubjectTransformEffect(ref, from, to);
421
+ }
422
+ class RefSubjectTransform extends FxEffectBase {
423
+ ref;
424
+ from;
425
+ to;
426
+ [ComputedTypeId] = ComputedTypeId;
58
427
  [RefSubjectTypeId] = RefSubjectTypeId;
428
+ version;
429
+ interrupt;
430
+ subscriberCount;
431
+ constructor(ref, from, to) {
432
+ super();
433
+ this.ref = ref;
434
+ this.from = from;
435
+ this.to = to;
436
+ this.version = ref.version;
437
+ this.interrupt = ref.interrupt;
438
+ this.subscriberCount = ref.subscriberCount;
439
+ }
440
+ run(sink) {
441
+ return this.ref.run(Sink.map(sink, this.from));
442
+ }
443
+ runUpdates(run) {
444
+ return this.ref.runUpdates((ref) => run({
445
+ get: Effect.map(ref.get, this.from),
446
+ set: (b) => Effect.map(ref.set(this.to(b)), this.from),
447
+ delete: Effect.map(ref.delete, Option.map(this.from))
448
+ }));
449
+ }
450
+ onFailure(cause) {
451
+ return this.ref.onFailure(cause);
452
+ }
453
+ onSuccess(value) {
454
+ return this.ref.onSuccess(this.to(value));
455
+ }
456
+ toEffect() {
457
+ return Effect.map(this.ref, this.from);
458
+ }
459
+ }
460
+ class RefSubjectTransformEffect extends FxEffectBase {
461
+ ref;
462
+ from;
463
+ to;
59
464
  [ComputedTypeId] = ComputedTypeId;
465
+ [RefSubjectTypeId] = RefSubjectTypeId;
60
466
  version;
467
+ interrupt;
61
468
  subscriberCount;
62
- get;
63
- delete;
469
+ subject;
470
+ constructor(ref, from, to) {
471
+ super();
472
+ this.ref = ref;
473
+ this.from = from;
474
+ this.to = to;
475
+ this.version = ref.version;
476
+ this.interrupt = ref.interrupt;
477
+ this.subscriberCount = ref.subscriberCount;
478
+ this.subject = Subject.unsafeMake();
479
+ }
480
+ run(sink) {
481
+ return core.merge(core.mapEffect(this.ref, this.from), this.subject).run(sink);
482
+ }
483
+ runUpdates(run) {
484
+ return this.ref.runUpdates((ref) => run({
485
+ get: Effect.flatMap(ref.get, this.from),
486
+ set: (b) => Effect.matchCauseEffect(Effect.flatMap(this.to(b), ref.set), {
487
+ onFailure: (cause) => Effect.as(this.subject.onFailure(cause), b),
488
+ onSuccess: () => Effect.as(this.subject.onSuccess(b), b)
489
+ }),
490
+ delete: Effect.flatMap(ref.delete, Option.match({
491
+ onNone: () => Effect.succeedNone,
492
+ onSome: (b) => Effect.asSome(this.from(b))
493
+ }))
494
+ }));
495
+ }
496
+ onFailure(cause) {
497
+ return this.subject.onFailure(cause);
498
+ }
499
+ onSuccess(value) {
500
+ return Effect.matchCauseEffect(this.to(value), {
501
+ onFailure: (cause) => this.subject.onFailure(cause),
502
+ onSuccess: (a) => this.ref.onSuccess(a)
503
+ });
504
+ }
505
+ toEffect() {
506
+ return Effect.flatMap(this.ref, this.from);
507
+ }
508
+ }
509
+ /**
510
+ * @since 1.20.0
511
+ */
512
+ export function tuple(refs) {
513
+ const kind = getRefKind(refs);
514
+ switch (kind) {
515
+ case "r":
516
+ return makeTupleRef(refs);
517
+ case "c":
518
+ return makeTupleComputed(refs);
519
+ case "f":
520
+ return makeTupleFiltered(refs);
521
+ }
522
+ }
523
+ const join = (a, b) => {
524
+ if (a === "r")
525
+ return b;
526
+ if (b === "r")
527
+ return a;
528
+ if (a === "f")
529
+ return a;
530
+ if (b === "f")
531
+ return b;
532
+ return "c";
533
+ };
534
+ function getRefKind(refs) {
535
+ let kind = "r";
536
+ for (const ref of refs) {
537
+ if (FilteredTypeId in ref) {
538
+ kind = "f";
539
+ break;
540
+ }
541
+ else if (!(RefSubjectTypeId in ref)) {
542
+ kind = join(kind, "c");
543
+ }
544
+ }
545
+ return kind;
546
+ }
547
+ function makeTupleRef(refs) {
548
+ return new RefSubjectTuple(refs);
549
+ }
550
+ class RefSubjectTuple extends FxEffectBase {
551
+ refs;
552
+ [ComputedTypeId] = ComputedTypeId;
553
+ [RefSubjectTypeId] = RefSubjectTypeId;
554
+ version;
555
+ interrupt;
556
+ subscriberCount;
557
+ versioned;
558
+ getSetDelete;
559
+ constructor(refs) {
560
+ super();
561
+ this.refs = refs;
562
+ this.versioned = Versioned.tuple(refs);
563
+ this.version = this.versioned.version;
564
+ this.interrupt = Effect.all(refs.map((r) => r.interrupt), UNBOUNDED);
565
+ this.subscriberCount = Effect.map(Effect.all(refs.map((r) => r.subscriberCount), UNBOUNDED), ReadonlyArray.reduce(0, sum));
566
+ this.getSetDelete = {
567
+ get: this.versioned,
568
+ set: (a) => Effect.all(refs.map((r, i) => set(r, a[i])), UNBOUNDED),
569
+ delete: Effect.map(Effect.all(refs.map((r) => reset(r)), UNBOUNDED), Option.all)
570
+ };
571
+ this.runUpdates = this.runUpdates.bind(this);
572
+ this.onFailure = this.onFailure.bind(this);
573
+ this.onSuccess = this.onSuccess.bind(this);
574
+ }
575
+ run(sink) {
576
+ return this.versioned.run(sink);
577
+ }
578
+ toEffect() {
579
+ return this.versioned;
580
+ }
581
+ runUpdates(run) {
582
+ return run(this.getSetDelete);
583
+ }
584
+ onFailure(cause) {
585
+ return Effect.all(this.refs.map((ref) => ref.onFailure(cause)));
586
+ }
587
+ onSuccess(value) {
588
+ return Effect.catchAllCause(this.getSetDelete.set(value), (c) => this.onFailure(c));
589
+ }
590
+ }
591
+ function makeTupleComputed(refs) {
592
+ return new ComputedImpl(Versioned.tuple(refs), Effect.succeed);
593
+ }
594
+ function makeTupleFiltered(refs) {
595
+ return new FilteredImpl(Versioned.tuple(refs), Effect.succeedSome);
596
+ }
597
+ /**
598
+ * @since 1.20.0
599
+ */
600
+ export function struct(refs) {
601
+ const kind = getRefKind(Object.values(refs));
602
+ switch (kind) {
603
+ case "r":
604
+ return makeStructRef(refs);
605
+ case "c":
606
+ return makeStructComputed(refs);
607
+ case "f":
608
+ return makeStructFiltered(refs);
609
+ }
610
+ }
611
+ function makeStructRef(refs) {
612
+ return new RefSubjectStruct(refs);
613
+ }
614
+ class RefSubjectStruct extends FxEffectBase {
615
+ refs;
616
+ [ComputedTypeId] = ComputedTypeId;
617
+ [RefSubjectTypeId] = RefSubjectTypeId;
618
+ version;
64
619
  interrupt;
65
- constructor(tag, defaultEq) {
620
+ subscriberCount;
621
+ versioned;
622
+ getSetDelete;
623
+ constructor(refs) {
624
+ super();
625
+ this.refs = refs;
626
+ this.versioned = Versioned.struct(refs);
627
+ this.version = this.versioned.version;
628
+ this.interrupt = Effect.all(Object.values(refs).map((r) => r.interrupt), UNBOUNDED);
629
+ this.subscriberCount = Effect.map(Effect.all(Object.values(refs).map((r) => r.subscriberCount), UNBOUNDED), ReadonlyArray.reduce(0, sum));
630
+ this.getSetDelete = {
631
+ get: this.versioned,
632
+ set: (a) => Effect.all(Object.keys(refs).map((k) => set(refs[k], a[k])), UNBOUNDED),
633
+ delete: Effect.map(Effect.all(Object.values(refs).map((r) => reset(r)), UNBOUNDED), Option.all)
634
+ };
635
+ this.runUpdates = this.runUpdates.bind(this);
636
+ this.onFailure = this.onFailure.bind(this);
637
+ this.onSuccess = this.onSuccess.bind(this);
638
+ }
639
+ run(sink) {
640
+ return this.versioned.run(sink);
641
+ }
642
+ toEffect() {
643
+ return this.versioned;
644
+ }
645
+ runUpdates(run) {
646
+ return run(this.getSetDelete);
647
+ }
648
+ onFailure(cause) {
649
+ return Effect.all(Object.values(this.refs).map((ref) => ref.onFailure(cause)));
650
+ }
651
+ onSuccess(value) {
652
+ return Effect.catchAllCause(this.getSetDelete.set(value), (c) => this.onFailure(c));
653
+ }
654
+ }
655
+ function makeStructComputed(refs) {
656
+ return new ComputedImpl(Versioned.struct(refs), Effect.succeed);
657
+ }
658
+ function makeStructFiltered(refs) {
659
+ return new FilteredImpl(Versioned.struct(refs), Effect.succeedSome);
660
+ }
661
+ /**
662
+ * @since 1.20.0
663
+ */
664
+ export function tagged(replay) {
665
+ return (identifier) => new RefSubjectTagged(C.Tagged(identifier), replay);
666
+ }
667
+ class RefSubjectTagged extends FxEffectBase {
668
+ tag;
669
+ replay;
670
+ [ComputedTypeId] = ComputedTypeId;
671
+ [RefSubjectTypeId] = RefSubjectTypeId;
672
+ version;
673
+ interrupt;
674
+ subscriberCount;
675
+ constructor(tag, replay = 0) {
66
676
  super();
67
677
  this.tag = tag;
68
- this.defaultEq = defaultEq;
678
+ this.replay = replay;
69
679
  this.version = tag.withEffect((ref) => ref.version);
680
+ this.interrupt = tag.withEffect((ref) => ref.interrupt);
70
681
  this.subscriberCount = tag.withEffect((ref) => ref.subscriberCount);
71
- this.get = tag.withEffect((ref) => ref.get);
72
- this.delete = tag.withEffect((ref) => ref.delete);
73
- this.interrupt = tag.withEffect((r) => r.interrupt);
682
+ this.runUpdates = this.runUpdates.bind(this);
683
+ this.onFailure = this.onFailure.bind(this);
684
+ this.onSuccess = this.onSuccess.bind(this);
74
685
  }
75
- toFx() {
76
- return fromFxEffect(this.tag);
686
+ run(sink) {
687
+ return this.tag.withEffect((ref) => ref.run(sink));
77
688
  }
78
689
  toEffect() {
79
- return this.get;
80
- }
81
- runUpdate = (f, onInterrupt) => this.tag.withEffect((ref) => ref.runUpdate(f, onInterrupt));
82
- modifyEffect = (f) => this.tag.withEffect((ref) => ref.modifyEffect(f));
83
- modify = (f) => this.tag.withEffect((ref) => ref.modify(f));
84
- updateEffect = (f) => this.tag.withEffect((ref) => ref.updateEffect(f));
85
- update = (f) => this.tag.withEffect((ref) => ref.update(f));
86
- set = (a) => this.tag.withEffect((ref) => ref.set(a));
87
- mapEffect = (f) => Computed(this, f);
88
- map = (f) => Computed(this, (a) => Effect.sync(() => f(a)));
89
- filterMapEffect = (f) => Filtered(this, f);
90
- filterMap = (f) => Filtered(this, (a) => Effect.sync(() => f(a)));
91
- filter = (f) => this.filterMap((a) => f(a) ? Option.some(a) : Option.none());
92
- filterEffect = (f) => this.filterMapEffect((a) => Effect.map(f(a), (b) => b ? Option.some(a) : Option.none()));
93
- skipRepeats = (eq = equals) => fromTag(this.tag, (s) => s.skipRepeats(eq));
94
- onFailure = (cause) => this.tag.withEffect((ref) => ref.onFailure(cause));
95
- onSuccess = (a) => this.tag.withEffect((ref) => ref.onSuccess(a));
96
- make = (fx, eq) => this.tag.scoped(make(fx, eq || this.defaultEq));
97
- of = (value, eq) => this.tag.scoped(of(value, eq));
98
- provide = (fx, eq) => Effect.provide(this.make(fx, eq || this.defaultEq));
99
- provideFx = (fx, eq) => provide(this.make(fx, eq || this.defaultEq));
100
- }
101
- export function makeWithExtension(fx, f, eq) {
102
- return coreRefSubject.makeWithExtension(fx, f, eq);
103
- }
104
- /**
105
- * Construct a RefSubject with an initial value and the specified subject.
106
- * @since 1.18.0
107
- * @category constructors
690
+ return this.tag.withEffect((ref) => ref);
691
+ }
692
+ runUpdates(run) {
693
+ return this.tag.withEffect((ref) => ref.runUpdates(run));
694
+ }
695
+ onFailure(cause) {
696
+ return this.tag.withEffect((ref) => ref.onFailure(cause));
697
+ }
698
+ onSuccess(value) {
699
+ return this.tag.withEffect((ref) => ref.onSuccess(value));
700
+ }
701
+ make = (fxOrEffect) => this.tag.scoped(make(fxOrEffect));
702
+ }
703
+ /**
704
+ * @since 1.20.0
108
705
  */
109
- export const unsafeMake = coreRefSubject.unsafeMake;
706
+ export function fromTag(tag, f) {
707
+ return new RefSubjectFromTag(tag, f);
708
+ }
709
+ class RefSubjectFromTag extends FxEffectBase {
710
+ tag;
711
+ f;
712
+ [ComputedTypeId] = ComputedTypeId;
713
+ [RefSubjectTypeId] = RefSubjectTypeId;
714
+ version;
715
+ interrupt;
716
+ subscriberCount;
717
+ _get;
718
+ _fx;
719
+ constructor(tag, f) {
720
+ super();
721
+ this.tag = tag;
722
+ this.f = f;
723
+ this._get = Effect.map(tag, f);
724
+ this._fx = core.fromFxEffect(this._get);
725
+ this.version = Effect.flatMap(this._get, (ref) => ref.version);
726
+ this.interrupt = Effect.flatMap(this._get, (ref) => ref.interrupt);
727
+ this.subscriberCount = Effect.flatMap(this._get, (ref) => ref.subscriberCount);
728
+ }
729
+ run(sink) {
730
+ return this._fx.run(sink);
731
+ }
732
+ toEffect() {
733
+ return Effect.flatten(this._get);
734
+ }
735
+ runUpdates(run) {
736
+ return Effect.flatMap(this._get, (ref) => ref.runUpdates(run));
737
+ }
738
+ onFailure(cause) {
739
+ return Effect.flatMap(this._get, (ref) => ref.onFailure(cause));
740
+ }
741
+ onSuccess(value) {
742
+ return Effect.flatMap(this._get, (ref) => ref.onSuccess(value));
743
+ }
744
+ }
745
+ export function isRefSubject(u) {
746
+ return isObjectLike(u) && RefSubjectTypeId in u;
747
+ }
748
+ export function isComputed(u) {
749
+ return isObjectLike(u) && ComputedTypeId in u;
750
+ }
751
+ export function isFiltered(u) {
752
+ return isObjectLike(u) && FilteredTypeId in u;
753
+ }
754
+ export function isDerived(u) {
755
+ return isRefSubject(u) && "persist" in u;
756
+ }
757
+ function isObjectLike(u) {
758
+ if (u == null)
759
+ return false;
760
+ const type = typeof u;
761
+ return (type === "object" && !Array.isArray(u)) || type === "function";
762
+ }
110
763
  /**
111
- * Flatten an RefSubject of an Option into a Filtered.
112
- * @since 1.18.0
113
- * @category combinators
764
+ * @since 1.20.0
114
765
  */
115
- export const compact = (refSubject) => refSubject.filterMap(identity);
766
+ export function computedFromTag(tag, f) {
767
+ return new ComputedFromTag(tag, f);
768
+ }
769
+ class ComputedFromTag extends FxEffectBase {
770
+ tag;
771
+ f;
772
+ [ComputedTypeId] = ComputedTypeId;
773
+ version;
774
+ _get;
775
+ constructor(tag, f) {
776
+ super();
777
+ this.tag = tag;
778
+ this.f = f;
779
+ this._get = Effect.map(tag, f);
780
+ this.version = Effect.flatMap(this._get, (ref) => ref.version);
781
+ }
782
+ run(sink) {
783
+ return Effect.flatMap(this._get, (ref) => ref.run(sink));
784
+ }
785
+ toEffect() {
786
+ return Effect.flatten(this._get);
787
+ }
788
+ }
116
789
  /**
117
- * Split a RefSubject's into 2 Filtered values that track its errors and
118
- * success values separately.
119
- * @since 1.18.0
120
- * @category combinators
790
+ * @since 1.20.0
121
791
  */
122
- export const split = (refSubject) => {
123
- const versioned = Versioned.transform(refSubject, exit, Effect.exit);
124
- const left = Filtered(versioned, getLeft);
125
- const right = Filtered(versioned, getRight);
126
- return [left, right];
127
- };
128
- const getLeft = (exit) => Effect.succeed(Exit.match(exit, {
129
- onFailure: (cause) => Cause.failureOption(cause),
130
- onSuccess: () => Option.none()
131
- }));
132
- const getRight = (exit) => Effect.succeed(Exit.match(exit, {
133
- onFailure: Option.none,
134
- onSuccess: Option.some
135
- }));
136
- /**
137
- * Derive a RefSubjectSchema using the "from" or "encoded" value represented by a Schema.
138
- * @since 1.18.0
792
+ export function filteredFromTag(tag, f) {
793
+ return new FilteredFromTag(tag, f);
794
+ }
795
+ class FilteredFromTag extends FxEffectBase {
796
+ tag;
797
+ f;
798
+ [FilteredTypeId] = FilteredTypeId;
799
+ version;
800
+ _get;
801
+ constructor(tag, f) {
802
+ super();
803
+ this.tag = tag;
804
+ this.f = f;
805
+ this._get = Effect.map(tag, f);
806
+ this.version = Effect.flatMap(this._get, (ref) => ref.version);
807
+ }
808
+ run(sink) {
809
+ return Effect.flatMap(this._get, (ref) => ref.run(sink));
810
+ }
811
+ toEffect() {
812
+ return Effect.flatten(this._get);
813
+ }
814
+ asComputed() {
815
+ return new ComputedFromTag(this.tag, (s) => this.f(s).asComputed());
816
+ }
817
+ }
818
+ /**
819
+ * @since 1.20.0
139
820
  */
140
- export function deriveFromSchema(schema) {
141
- return fromRefSubject(schema);
821
+ export const provide = dual(2, function provide(ref, providing) {
822
+ const layer = Layer.isLayer(providing)
823
+ ? providing
824
+ : C.isContext(providing)
825
+ ? Layer.succeedContext(providing)
826
+ : runtimeToLayer(providing);
827
+ if (isComputed(ref)) {
828
+ return ComputedImpl.make(Versioned.provide(ref, layer), Effect.succeed);
829
+ }
830
+ else if (isFiltered(ref)) {
831
+ return FilteredImpl.make(Versioned.provide(ref, layer), Effect.succeedSome);
832
+ }
833
+ else {
834
+ return new RefSubjectProvide(ref, layer);
835
+ }
836
+ });
837
+ class RefSubjectProvide extends FxEffectBase {
838
+ ref;
839
+ layer;
840
+ [ComputedTypeId] = ComputedTypeId;
841
+ [RefSubjectTypeId] = RefSubjectTypeId;
842
+ interrupt;
843
+ subscriberCount;
844
+ constructor(ref, layer) {
845
+ super();
846
+ this.ref = ref;
847
+ this.layer = layer;
848
+ this.interrupt = Effect.provide(ref.interrupt, layer);
849
+ this.subscriberCount = Effect.provide(ref.subscriberCount, layer);
850
+ }
851
+ run(sink) {
852
+ return Effect.provide(this.ref.run(sink), this.layer);
853
+ }
854
+ toEffect() {
855
+ return Effect.provide(this.ref, this.layer);
856
+ }
142
857
  }
143
858
  /**
144
- * Derive a RefSubjectSchema using the "to" or "decoded" value represented by a Schema.
859
+ * Set the value to true
145
860
  * @since 1.18.0
146
861
  */
147
- export function deriveToSchema(schema) {
148
- return toRefSubject(schema);
149
- }
862
+ export const asTrue = (ref) => set(ref, true);
150
863
  /**
864
+ * Set the value to false
151
865
  * @since 1.18.0
152
866
  */
153
- export const tuple = coreRefSubject.tuple;
867
+ export const asFalse = (ref) => set(ref, false);
154
868
  /**
869
+ * Toggle the boolean value between true and false
155
870
  * @since 1.18.0
156
871
  */
157
- export const struct = coreRefSubject.struct;
872
+ export const toggle = (ref) => update(ref, Boolean.not);
873
+ const add = (x) => x + 1;
158
874
  /**
875
+ * Set the value to true
159
876
  * @since 1.18.0
160
877
  */
161
- export function fromSubscriptionRef(subscriptionRef) {
162
- return coreRefSubject.make(fromStream(subscriptionRef.changes));
163
- }
878
+ export const increment = (ref) => update(ref, add);
879
+ const sub = (x) => x - 1;
164
880
  /**
881
+ * Set the value to false
165
882
  * @since 1.18.0
166
883
  */
167
- export const transform = dual(3, function transform(ref, from, to) {
168
- return new TransformImpl(ref, from, to);
884
+ export const decrement = (ref) => update(ref, sub);
885
+ /**
886
+ * @since 1.20.0
887
+ */
888
+ export const slice = dual(3, function slice(ref, drop, take) {
889
+ return new RefSubjectSlice(ref, drop, take);
890
+ });
891
+ /**
892
+ * @since 1.20.0
893
+ */
894
+ export const drop = dual(2, function drop(ref, drop) {
895
+ return slice(ref, drop, Infinity);
169
896
  });
170
- class TransformImpl extends FxEffectBase {
897
+ /**
898
+ * @since 1.20.0
899
+ */
900
+ export const take = dual(2, function take(ref, take) {
901
+ return slice(ref, 0, take);
902
+ });
903
+ class RefSubjectSlice extends FxEffectBase {
171
904
  ref;
172
- from;
173
- to;
174
- [RefSubjectTypeId] = RefSubjectTypeId;
905
+ drop;
906
+ take;
175
907
  [ComputedTypeId] = ComputedTypeId;
908
+ [RefSubjectTypeId] = RefSubjectTypeId;
176
909
  version;
177
- subscriberCount;
178
- get;
179
- delete;
180
910
  interrupt;
181
- constructor(ref, from, to) {
911
+ subscriberCount;
912
+ _fx;
913
+ constructor(ref, drop, take) {
182
914
  super();
183
915
  this.ref = ref;
184
- this.from = from;
185
- this.to = to;
916
+ this.drop = drop;
917
+ this.take = take;
186
918
  this.version = ref.version;
187
- this.subscriberCount = ref.subscriberCount;
188
- this.get = Effect.map(ref.get, from);
189
- this.delete = Effect.map(ref.delete, Option.map(from));
190
919
  this.interrupt = ref.interrupt;
920
+ this.subscriberCount = ref.subscriberCount;
921
+ this._fx = share.hold(core.slice(ref, drop, take));
922
+ this._effect = ref;
191
923
  }
192
- toFx() {
193
- return this.ref.map(this.from);
924
+ run(sink) {
925
+ return this._fx.run(sink);
194
926
  }
195
927
  toEffect() {
196
- return this.ref.map(this.from);
197
- }
198
- set = (b) => Effect.map(this.ref.set(this.to(b)), this.from);
199
- update = (f) => Effect.map(this.ref.update((a) => this.to(f(this.from(a)))), this.from);
200
- updateEffect = (f) => Effect.map(this.ref.updateEffect((a) => Effect.map(f(this.from(a)), this.to)), this.from);
201
- modifyEffect = (f) => this.ref.modifyEffect((a) => Effect.map(f(this.from(a)), ([c, b]) => [c, this.to(b)]));
202
- modify = (f) => this.ref.modify((a) => {
203
- const [c, b] = f(this.from(a));
204
- return [c, this.to(b)];
205
- });
206
- runUpdate = (f) => this.ref.runUpdate((get, set) => f(Effect.map(get, this.from), (b) => Effect.map(set(this.to(b)), this.from)));
207
- mapEffect = (f) => Computed(this, f);
208
- map = (f) => this.mapEffect((b) => Effect.sync(() => f(b)));
209
- filterMapEffect = (f) => Filtered(this, f);
210
- filterMap = (f) => Filtered(this, (a) => Effect.sync(() => f(a)));
211
- filter = (f) => this.filterMap((a) => f(a) ? Option.some(a) : Option.none());
212
- filterEffect = (f) => this.filterMapEffect((a) => Effect.map(f(a), (b) => b ? Option.some(a) : Option.none()));
213
- onSuccess = (b) => this.ref.onSuccess(this.to(b));
214
- onFailure = (b) => this.ref.onFailure(b);
215
- skipRepeats = (eq = equals) => Computed(Versioned.transformFx(this, skipRepeatsWith(eq)), Effect.succeed);
928
+ return this.ref;
929
+ }
930
+ runUpdates(run) {
931
+ return this.ref.runUpdates(run);
932
+ }
933
+ onFailure(cause) {
934
+ return this.ref.onFailure(cause);
935
+ }
936
+ onSuccess(value) {
937
+ return this.ref.onSuccess(value);
938
+ }
216
939
  }
217
940
  //# sourceMappingURL=RefSubject.js.map