effect 4.0.0-beta.5 → 4.0.0-beta.51

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 (1512) hide show
  1. package/dist/Array.d.ts +213 -385
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +149 -102
  4. package/dist/Array.js.map +1 -1
  5. package/dist/BigDecimal.d.ts +82 -45
  6. package/dist/BigDecimal.d.ts.map +1 -1
  7. package/dist/BigDecimal.js +105 -52
  8. package/dist/BigDecimal.js.map +1 -1
  9. package/dist/BigInt.d.ts +39 -32
  10. package/dist/BigInt.d.ts.map +1 -1
  11. package/dist/BigInt.js +36 -33
  12. package/dist/BigInt.js.map +1 -1
  13. package/dist/Brand.d.ts +3 -5
  14. package/dist/Brand.d.ts.map +1 -1
  15. package/dist/Brand.js +1 -1
  16. package/dist/Brand.js.map +1 -1
  17. package/dist/Cache.d.ts +14 -45
  18. package/dist/Cache.d.ts.map +1 -1
  19. package/dist/Cache.js +21 -47
  20. package/dist/Cache.js.map +1 -1
  21. package/dist/Cause.d.ts +54 -23
  22. package/dist/Cause.d.ts.map +1 -1
  23. package/dist/Cause.js +108 -10
  24. package/dist/Cause.js.map +1 -1
  25. package/dist/Channel.d.ts +166 -48
  26. package/dist/Channel.d.ts.map +1 -1
  27. package/dist/Channel.js +182 -91
  28. package/dist/Channel.js.map +1 -1
  29. package/dist/Chunk.d.ts +112 -304
  30. package/dist/Chunk.d.ts.map +1 -1
  31. package/dist/Chunk.js +56 -88
  32. package/dist/Chunk.js.map +1 -1
  33. package/dist/Clock.d.ts +2 -2
  34. package/dist/Clock.d.ts.map +1 -1
  35. package/dist/Clock.js.map +1 -1
  36. package/dist/Combiner.d.ts +280 -13
  37. package/dist/Combiner.d.ts.map +1 -1
  38. package/dist/Combiner.js +198 -7
  39. package/dist/Combiner.js.map +1 -1
  40. package/dist/Config.d.ts +171 -11
  41. package/dist/Config.d.ts.map +1 -1
  42. package/dist/Config.js +69 -11
  43. package/dist/Config.js.map +1 -1
  44. package/dist/ConfigProvider.d.ts +6 -6
  45. package/dist/ConfigProvider.d.ts.map +1 -1
  46. package/dist/ConfigProvider.js +5 -5
  47. package/dist/ConfigProvider.js.map +1 -1
  48. package/dist/Console.d.ts +2 -2
  49. package/dist/Console.d.ts.map +1 -1
  50. package/dist/Console.js.map +1 -1
  51. package/dist/Context.d.ts +1150 -0
  52. package/dist/Context.d.ts.map +1 -0
  53. package/dist/{ServiceMap.js → Context.js} +181 -165
  54. package/dist/Context.js.map +1 -0
  55. package/dist/Cron.d.ts +11 -7
  56. package/dist/Cron.d.ts.map +1 -1
  57. package/dist/Cron.js +120 -63
  58. package/dist/Cron.js.map +1 -1
  59. package/dist/Data.d.ts +535 -366
  60. package/dist/Data.d.ts.map +1 -1
  61. package/dist/Data.js +132 -79
  62. package/dist/Data.js.map +1 -1
  63. package/dist/DateTime.d.ts +74 -255
  64. package/dist/DateTime.d.ts.map +1 -1
  65. package/dist/DateTime.js +17 -62
  66. package/dist/DateTime.js.map +1 -1
  67. package/dist/Deferred.d.ts +12 -5
  68. package/dist/Deferred.d.ts.map +1 -1
  69. package/dist/Deferred.js +13 -5
  70. package/dist/Deferred.js.map +1 -1
  71. package/dist/Duration.d.ts +62 -32
  72. package/dist/Duration.d.ts.map +1 -1
  73. package/dist/Duration.js +109 -79
  74. package/dist/Duration.js.map +1 -1
  75. package/dist/Effect.d.ts +1377 -1147
  76. package/dist/Effect.d.ts.map +1 -1
  77. package/dist/Effect.js +465 -446
  78. package/dist/Effect.js.map +1 -1
  79. package/dist/Encoding.d.ts +194 -0
  80. package/dist/Encoding.d.ts.map +1 -0
  81. package/dist/Encoding.js +352 -0
  82. package/dist/Encoding.js.map +1 -0
  83. package/dist/Equal.d.ts +276 -109
  84. package/dist/Equal.d.ts.map +1 -1
  85. package/dist/Equal.js +140 -48
  86. package/dist/Equal.js.map +1 -1
  87. package/dist/Equivalence.d.ts +60 -3
  88. package/dist/Equivalence.d.ts.map +1 -1
  89. package/dist/Equivalence.js +70 -13
  90. package/dist/Equivalence.js.map +1 -1
  91. package/dist/ErrorReporter.d.ts +374 -0
  92. package/dist/ErrorReporter.d.ts.map +1 -0
  93. package/dist/ErrorReporter.js +245 -0
  94. package/dist/ErrorReporter.js.map +1 -0
  95. package/dist/ExecutionPlan.d.ts +6 -6
  96. package/dist/ExecutionPlan.d.ts.map +1 -1
  97. package/dist/ExecutionPlan.js +4 -4
  98. package/dist/ExecutionPlan.js.map +1 -1
  99. package/dist/Exit.d.ts +24 -12
  100. package/dist/Exit.d.ts.map +1 -1
  101. package/dist/Exit.js +8 -4
  102. package/dist/Exit.js.map +1 -1
  103. package/dist/Fiber.d.ts +10 -8
  104. package/dist/Fiber.d.ts.map +1 -1
  105. package/dist/Fiber.js.map +1 -1
  106. package/dist/FiberHandle.d.ts +11 -10
  107. package/dist/FiberHandle.d.ts.map +1 -1
  108. package/dist/FiberHandle.js +12 -11
  109. package/dist/FiberHandle.js.map +1 -1
  110. package/dist/FiberMap.d.ts +22 -21
  111. package/dist/FiberMap.d.ts.map +1 -1
  112. package/dist/FiberMap.js +10 -10
  113. package/dist/FiberMap.js.map +1 -1
  114. package/dist/FiberSet.d.ts +2 -2
  115. package/dist/FiberSet.d.ts.map +1 -1
  116. package/dist/FiberSet.js +4 -4
  117. package/dist/FiberSet.js.map +1 -1
  118. package/dist/FileSystem.d.ts +20 -19
  119. package/dist/FileSystem.d.ts.map +1 -1
  120. package/dist/FileSystem.js +17 -13
  121. package/dist/FileSystem.js.map +1 -1
  122. package/dist/Filter.d.ts +4 -37
  123. package/dist/Filter.d.ts.map +1 -1
  124. package/dist/Filter.js +0 -13
  125. package/dist/Filter.js.map +1 -1
  126. package/dist/Formatter.d.ts +131 -47
  127. package/dist/Formatter.d.ts.map +1 -1
  128. package/dist/Formatter.js +229 -51
  129. package/dist/Formatter.js.map +1 -1
  130. package/dist/Function.d.ts +1 -9
  131. package/dist/Function.d.ts.map +1 -1
  132. package/dist/Function.js +2 -10
  133. package/dist/Function.js.map +1 -1
  134. package/dist/Graph.d.ts +65 -65
  135. package/dist/Graph.d.ts.map +1 -1
  136. package/dist/Graph.js +60 -62
  137. package/dist/Graph.js.map +1 -1
  138. package/dist/Hash.js +1 -1
  139. package/dist/Hash.js.map +1 -1
  140. package/dist/HashMap.d.ts +26 -19
  141. package/dist/HashMap.d.ts.map +1 -1
  142. package/dist/HashMap.js +7 -5
  143. package/dist/HashMap.js.map +1 -1
  144. package/dist/Iterable.d.ts +50 -50
  145. package/dist/Iterable.d.ts.map +1 -1
  146. package/dist/Iterable.js +106 -34
  147. package/dist/Iterable.js.map +1 -1
  148. package/dist/JsonSchema.d.ts +299 -10
  149. package/dist/JsonSchema.d.ts.map +1 -1
  150. package/dist/JsonSchema.js +323 -4
  151. package/dist/JsonSchema.js.map +1 -1
  152. package/dist/Latch.d.ts +175 -0
  153. package/dist/Latch.d.ts.map +1 -0
  154. package/dist/Latch.js +130 -0
  155. package/dist/Latch.js.map +1 -0
  156. package/dist/Layer.d.ts +599 -379
  157. package/dist/Layer.d.ts.map +1 -1
  158. package/dist/Layer.js +249 -180
  159. package/dist/Layer.js.map +1 -1
  160. package/dist/LayerMap.d.ts +27 -26
  161. package/dist/LayerMap.d.ts.map +1 -1
  162. package/dist/LayerMap.js +21 -18
  163. package/dist/LayerMap.js.map +1 -1
  164. package/dist/LogLevel.d.ts +32 -0
  165. package/dist/LogLevel.d.ts.map +1 -1
  166. package/dist/LogLevel.js +28 -100
  167. package/dist/LogLevel.js.map +1 -1
  168. package/dist/Logger.d.ts +31 -97
  169. package/dist/Logger.d.ts.map +1 -1
  170. package/dist/Logger.js +2 -3
  171. package/dist/Logger.js.map +1 -1
  172. package/dist/ManagedRuntime.d.ts +8 -8
  173. package/dist/ManagedRuntime.d.ts.map +1 -1
  174. package/dist/ManagedRuntime.js +34 -25
  175. package/dist/ManagedRuntime.js.map +1 -1
  176. package/dist/Metric.d.ts +23 -25
  177. package/dist/Metric.d.ts.map +1 -1
  178. package/dist/Metric.js +24 -26
  179. package/dist/Metric.js.map +1 -1
  180. package/dist/MutableHashMap.d.ts +7 -0
  181. package/dist/MutableHashMap.d.ts.map +1 -1
  182. package/dist/MutableHashMap.js +8 -0
  183. package/dist/MutableHashMap.js.map +1 -1
  184. package/dist/MutableHashSet.d.ts +7 -0
  185. package/dist/MutableHashSet.d.ts.map +1 -1
  186. package/dist/MutableHashSet.js +8 -0
  187. package/dist/MutableHashSet.js.map +1 -1
  188. package/dist/MutableList.d.ts.map +1 -1
  189. package/dist/MutableList.js +3 -0
  190. package/dist/MutableList.js.map +1 -1
  191. package/dist/Newtype.d.ts +291 -0
  192. package/dist/Newtype.d.ts.map +1 -0
  193. package/dist/Newtype.js +161 -0
  194. package/dist/Newtype.js.map +1 -0
  195. package/dist/Number.d.ts +74 -18
  196. package/dist/Number.d.ts.map +1 -1
  197. package/dist/Number.js +46 -18
  198. package/dist/Number.js.map +1 -1
  199. package/dist/Optic.d.ts +947 -18
  200. package/dist/Optic.d.ts.map +1 -1
  201. package/dist/Optic.js +454 -5
  202. package/dist/Optic.js.map +1 -1
  203. package/dist/Option.d.ts +25 -16
  204. package/dist/Option.d.ts.map +1 -1
  205. package/dist/Option.js +15 -9
  206. package/dist/Option.js.map +1 -1
  207. package/dist/Order.d.ts +6 -1
  208. package/dist/Order.d.ts.map +1 -1
  209. package/dist/Order.js +19 -14
  210. package/dist/Order.js.map +1 -1
  211. package/dist/PartitionedSemaphore.d.ts +146 -15
  212. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  213. package/dist/PartitionedSemaphore.js +174 -61
  214. package/dist/PartitionedSemaphore.js.map +1 -1
  215. package/dist/Path.d.ts +2 -2
  216. package/dist/Path.d.ts.map +1 -1
  217. package/dist/Path.js +2 -2
  218. package/dist/Path.js.map +1 -1
  219. package/dist/Pipeable.d.ts +17 -0
  220. package/dist/Pipeable.d.ts.map +1 -1
  221. package/dist/Pipeable.js +19 -1
  222. package/dist/Pipeable.js.map +1 -1
  223. package/dist/PlatformError.d.ts +2 -2
  224. package/dist/Pool.d.ts +6 -4
  225. package/dist/Pool.d.ts.map +1 -1
  226. package/dist/Pool.js +11 -9
  227. package/dist/Pool.js.map +1 -1
  228. package/dist/PubSub.d.ts +8 -6
  229. package/dist/PubSub.d.ts.map +1 -1
  230. package/dist/PubSub.js +18 -10
  231. package/dist/PubSub.js.map +1 -1
  232. package/dist/Pull.d.ts.map +1 -1
  233. package/dist/Pull.js +1 -1
  234. package/dist/Pull.js.map +1 -1
  235. package/dist/Queue.d.ts +9 -6
  236. package/dist/Queue.d.ts.map +1 -1
  237. package/dist/Queue.js +7 -5
  238. package/dist/Queue.js.map +1 -1
  239. package/dist/Random.d.ts +36 -2
  240. package/dist/Random.d.ts.map +1 -1
  241. package/dist/Random.js +46 -35
  242. package/dist/Random.js.map +1 -1
  243. package/dist/RcMap.d.ts +4 -4
  244. package/dist/RcMap.d.ts.map +1 -1
  245. package/dist/RcMap.js +13 -13
  246. package/dist/RcMap.js.map +1 -1
  247. package/dist/RcRef.d.ts +1 -1
  248. package/dist/RcRef.d.ts.map +1 -1
  249. package/dist/Record.d.ts +63 -160
  250. package/dist/Record.d.ts.map +1 -1
  251. package/dist/Record.js +37 -56
  252. package/dist/Record.js.map +1 -1
  253. package/dist/Redactable.d.ts +139 -62
  254. package/dist/Redactable.d.ts.map +1 -1
  255. package/dist/Redactable.js +59 -55
  256. package/dist/Redactable.js.map +1 -1
  257. package/dist/Reducer.d.ts +166 -7
  258. package/dist/Reducer.d.ts.map +1 -1
  259. package/dist/Reducer.js +135 -1
  260. package/dist/Reducer.js.map +1 -1
  261. package/dist/References.d.ts +257 -229
  262. package/dist/References.d.ts.map +1 -1
  263. package/dist/References.js +240 -259
  264. package/dist/References.js.map +1 -1
  265. package/dist/Request.d.ts +6 -6
  266. package/dist/Request.d.ts.map +1 -1
  267. package/dist/Request.js +2 -1
  268. package/dist/Request.js.map +1 -1
  269. package/dist/RequestResolver.d.ts +25 -45
  270. package/dist/RequestResolver.d.ts.map +1 -1
  271. package/dist/RequestResolver.js +15 -36
  272. package/dist/RequestResolver.js.map +1 -1
  273. package/dist/Resource.d.ts +0 -3
  274. package/dist/Resource.d.ts.map +1 -1
  275. package/dist/Resource.js +5 -4
  276. package/dist/Resource.js.map +1 -1
  277. package/dist/Result.d.ts +1 -1
  278. package/dist/Result.d.ts.map +1 -1
  279. package/dist/Result.js +1 -2
  280. package/dist/Result.js.map +1 -1
  281. package/dist/Runtime.d.ts +66 -0
  282. package/dist/Runtime.d.ts.map +1 -1
  283. package/dist/Runtime.js +79 -6
  284. package/dist/Runtime.js.map +1 -1
  285. package/dist/Schedule.d.ts +176 -293
  286. package/dist/Schedule.d.ts.map +1 -1
  287. package/dist/Schedule.js +162 -136
  288. package/dist/Schedule.js.map +1 -1
  289. package/dist/Scheduler.d.ts +36 -125
  290. package/dist/Scheduler.d.ts.map +1 -1
  291. package/dist/Scheduler.js +37 -126
  292. package/dist/Scheduler.js.map +1 -1
  293. package/dist/Schema.d.ts +3326 -383
  294. package/dist/Schema.d.ts.map +1 -1
  295. package/dist/Schema.js +2315 -283
  296. package/dist/Schema.js.map +1 -1
  297. package/dist/SchemaAST.d.ts +13 -2
  298. package/dist/SchemaAST.d.ts.map +1 -1
  299. package/dist/SchemaAST.js +340 -257
  300. package/dist/SchemaAST.js.map +1 -1
  301. package/dist/SchemaGetter.d.ts +57 -15
  302. package/dist/SchemaGetter.d.ts.map +1 -1
  303. package/dist/SchemaGetter.js +85 -25
  304. package/dist/SchemaGetter.js.map +1 -1
  305. package/dist/SchemaIssue.d.ts.map +1 -1
  306. package/dist/SchemaIssue.js +29 -11
  307. package/dist/SchemaIssue.js.map +1 -1
  308. package/dist/SchemaParser.d.ts +44 -54
  309. package/dist/SchemaParser.d.ts.map +1 -1
  310. package/dist/SchemaParser.js +69 -4
  311. package/dist/SchemaParser.js.map +1 -1
  312. package/dist/SchemaRepresentation.d.ts +46 -45
  313. package/dist/SchemaRepresentation.d.ts.map +1 -1
  314. package/dist/SchemaRepresentation.js +65 -38
  315. package/dist/SchemaRepresentation.js.map +1 -1
  316. package/dist/SchemaTransformation.d.ts +252 -3
  317. package/dist/SchemaTransformation.d.ts.map +1 -1
  318. package/dist/SchemaTransformation.js +319 -13
  319. package/dist/SchemaTransformation.js.map +1 -1
  320. package/dist/Scope.d.ts +2 -2
  321. package/dist/Scope.d.ts.map +1 -1
  322. package/dist/Scope.js.map +1 -1
  323. package/dist/ScopedCache.d.ts +2 -2
  324. package/dist/ScopedCache.d.ts.map +1 -1
  325. package/dist/ScopedCache.js +5 -5
  326. package/dist/ScopedCache.js.map +1 -1
  327. package/dist/Semaphore.d.ts +307 -0
  328. package/dist/Semaphore.d.ts.map +1 -0
  329. package/dist/Semaphore.js +220 -0
  330. package/dist/Semaphore.js.map +1 -0
  331. package/dist/Sink.d.ts +22 -19
  332. package/dist/Sink.d.ts.map +1 -1
  333. package/dist/Sink.js +54 -7
  334. package/dist/Sink.js.map +1 -1
  335. package/dist/Stdio.d.ts +18 -6
  336. package/dist/Stdio.d.ts.map +1 -1
  337. package/dist/Stdio.js +20 -2
  338. package/dist/Stdio.js.map +1 -1
  339. package/dist/Stream.d.ts +465 -542
  340. package/dist/Stream.d.ts.map +1 -1
  341. package/dist/Stream.js +321 -144
  342. package/dist/Stream.js.map +1 -1
  343. package/dist/String.d.ts +114 -47
  344. package/dist/String.d.ts.map +1 -1
  345. package/dist/String.js +29 -47
  346. package/dist/String.js.map +1 -1
  347. package/dist/Struct.d.ts +23 -7
  348. package/dist/Struct.d.ts.map +1 -1
  349. package/dist/Struct.js +22 -0
  350. package/dist/Struct.js.map +1 -1
  351. package/dist/SubscriptionRef.d.ts +3 -3
  352. package/dist/SubscriptionRef.d.ts.map +1 -1
  353. package/dist/SubscriptionRef.js +85 -117
  354. package/dist/SubscriptionRef.js.map +1 -1
  355. package/dist/SynchronizedRef.d.ts +2 -1
  356. package/dist/SynchronizedRef.d.ts.map +1 -1
  357. package/dist/SynchronizedRef.js +2 -1
  358. package/dist/SynchronizedRef.js.map +1 -1
  359. package/dist/Terminal.d.ts +5 -4
  360. package/dist/Terminal.d.ts.map +1 -1
  361. package/dist/Terminal.js +2 -2
  362. package/dist/Terminal.js.map +1 -1
  363. package/dist/Tracer.d.ts +21 -20
  364. package/dist/Tracer.d.ts.map +1 -1
  365. package/dist/Tracer.js +13 -9
  366. package/dist/Tracer.js.map +1 -1
  367. package/dist/Trie.d.ts +44 -31
  368. package/dist/Trie.d.ts.map +1 -1
  369. package/dist/Trie.js +13 -9
  370. package/dist/Trie.js.map +1 -1
  371. package/dist/TxChunk.d.ts +4 -4
  372. package/dist/TxChunk.d.ts.map +1 -1
  373. package/dist/TxChunk.js +4 -4
  374. package/dist/TxChunk.js.map +1 -1
  375. package/dist/TxDeferred.d.ts +328 -0
  376. package/dist/TxDeferred.d.ts.map +1 -0
  377. package/dist/TxDeferred.js +197 -0
  378. package/dist/TxDeferred.js.map +1 -0
  379. package/dist/TxHashMap.d.ts +105 -86
  380. package/dist/TxHashMap.d.ts.map +1 -1
  381. package/dist/TxHashMap.js +51 -44
  382. package/dist/TxHashMap.js.map +1 -1
  383. package/dist/TxHashSet.d.ts +2 -2
  384. package/dist/TxHashSet.d.ts.map +1 -1
  385. package/dist/TxHashSet.js +16 -15
  386. package/dist/TxHashSet.js.map +1 -1
  387. package/dist/TxPriorityQueue.d.ts +609 -0
  388. package/dist/TxPriorityQueue.d.ts.map +1 -0
  389. package/dist/TxPriorityQueue.js +416 -0
  390. package/dist/TxPriorityQueue.js.map +1 -0
  391. package/dist/TxPubSub.d.ts +585 -0
  392. package/dist/TxPubSub.d.ts.map +1 -0
  393. package/dist/TxPubSub.js +521 -0
  394. package/dist/TxPubSub.js.map +1 -0
  395. package/dist/TxQueue.d.ts +1 -1
  396. package/dist/TxQueue.d.ts.map +1 -1
  397. package/dist/TxQueue.js +42 -57
  398. package/dist/TxQueue.js.map +1 -1
  399. package/dist/TxReentrantLock.d.ts +500 -0
  400. package/dist/TxReentrantLock.d.ts.map +1 -0
  401. package/dist/TxReentrantLock.js +481 -0
  402. package/dist/TxReentrantLock.js.map +1 -0
  403. package/dist/TxRef.d.ts +14 -20
  404. package/dist/TxRef.d.ts.map +1 -1
  405. package/dist/TxRef.js +8 -10
  406. package/dist/TxRef.js.map +1 -1
  407. package/dist/TxSemaphore.d.ts +162 -2
  408. package/dist/TxSemaphore.d.ts.map +1 -1
  409. package/dist/TxSemaphore.js +25 -10
  410. package/dist/TxSemaphore.js.map +1 -1
  411. package/dist/TxSubscriptionRef.d.ts +508 -0
  412. package/dist/TxSubscriptionRef.d.ts.map +1 -0
  413. package/dist/TxSubscriptionRef.js +293 -0
  414. package/dist/TxSubscriptionRef.js.map +1 -0
  415. package/dist/Types.d.ts +83 -17
  416. package/dist/Types.d.ts.map +1 -1
  417. package/dist/Unify.d.ts +8 -2
  418. package/dist/Unify.d.ts.map +1 -1
  419. package/dist/Unify.js.map +1 -1
  420. package/dist/Utils.d.ts +137 -65
  421. package/dist/Utils.d.ts.map +1 -1
  422. package/dist/Utils.js +38 -66
  423. package/dist/Utils.js.map +1 -1
  424. package/dist/index.d.ts +888 -71
  425. package/dist/index.d.ts.map +1 -1
  426. package/dist/index.js +888 -71
  427. package/dist/index.js.map +1 -1
  428. package/dist/internal/core.js +11 -3
  429. package/dist/internal/core.js.map +1 -1
  430. package/dist/internal/dateTime.js +77 -71
  431. package/dist/internal/dateTime.js.map +1 -1
  432. package/dist/internal/effect.js +485 -325
  433. package/dist/internal/effect.js.map +1 -1
  434. package/dist/internal/hashMap.js +7 -5
  435. package/dist/internal/hashMap.js.map +1 -1
  436. package/dist/internal/layer.js +3 -3
  437. package/dist/internal/layer.js.map +1 -1
  438. package/dist/internal/option.js +6 -0
  439. package/dist/internal/option.js.map +1 -1
  440. package/dist/internal/random.d.ts +2 -0
  441. package/dist/internal/random.d.ts.map +1 -0
  442. package/dist/internal/random.js +13 -0
  443. package/dist/internal/random.js.map +1 -0
  444. package/dist/internal/rcRef.js +11 -10
  445. package/dist/internal/rcRef.js.map +1 -1
  446. package/dist/internal/references.d.ts +2 -0
  447. package/dist/internal/references.d.ts.map +1 -0
  448. package/dist/internal/references.js +51 -0
  449. package/dist/internal/references.js.map +1 -0
  450. package/dist/internal/request.js +6 -6
  451. package/dist/internal/request.js.map +1 -1
  452. package/dist/internal/schedule.js +1 -1
  453. package/dist/internal/schedule.js.map +1 -1
  454. package/dist/internal/schema/annotations.js +2 -0
  455. package/dist/internal/schema/annotations.js.map +1 -1
  456. package/dist/internal/schema/representation.js +86 -107
  457. package/dist/internal/schema/representation.js.map +1 -1
  458. package/dist/internal/schema/schema.d.ts +10 -1
  459. package/dist/internal/schema/schema.d.ts.map +1 -1
  460. package/dist/internal/schema/schema.js +22 -1
  461. package/dist/internal/schema/schema.js.map +1 -1
  462. package/dist/internal/schema/to-codec.js +7 -10
  463. package/dist/internal/schema/to-codec.js.map +1 -1
  464. package/dist/internal/trie.js +8 -7
  465. package/dist/internal/trie.js.map +1 -1
  466. package/dist/testing/TestClock.d.ts +8 -7
  467. package/dist/testing/TestClock.d.ts.map +1 -1
  468. package/dist/testing/TestClock.js +6 -4
  469. package/dist/testing/TestClock.js.map +1 -1
  470. package/dist/testing/TestSchema.d.ts +267 -33
  471. package/dist/testing/TestSchema.d.ts.map +1 -1
  472. package/dist/testing/TestSchema.js +296 -23
  473. package/dist/testing/TestSchema.js.map +1 -1
  474. package/dist/testing/index.d.ts +64 -1
  475. package/dist/testing/index.d.ts.map +1 -1
  476. package/dist/testing/index.js +64 -1
  477. package/dist/testing/index.js.map +1 -1
  478. package/dist/unstable/ai/AiError.d.ts +155 -73
  479. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  480. package/dist/unstable/ai/AiError.js +29 -23
  481. package/dist/unstable/ai/AiError.js.map +1 -1
  482. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +1 -1
  483. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  484. package/dist/unstable/ai/AnthropicStructuredOutput.js +9 -2
  485. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  486. package/dist/unstable/ai/Chat.d.ts +39 -11
  487. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  488. package/dist/unstable/ai/Chat.js +41 -47
  489. package/dist/unstable/ai/Chat.js.map +1 -1
  490. package/dist/unstable/ai/EmbeddingModel.d.ts +130 -0
  491. package/dist/unstable/ai/EmbeddingModel.d.ts.map +1 -0
  492. package/dist/unstable/ai/EmbeddingModel.js +127 -0
  493. package/dist/unstable/ai/EmbeddingModel.js.map +1 -0
  494. package/dist/unstable/ai/IdGenerator.d.ts +2 -2
  495. package/dist/unstable/ai/IdGenerator.d.ts.map +1 -1
  496. package/dist/unstable/ai/IdGenerator.js +2 -2
  497. package/dist/unstable/ai/IdGenerator.js.map +1 -1
  498. package/dist/unstable/ai/LanguageModel.d.ts +119 -49
  499. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  500. package/dist/unstable/ai/LanguageModel.js +260 -61
  501. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  502. package/dist/unstable/ai/McpSchema.d.ts +236 -141
  503. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  504. package/dist/unstable/ai/McpSchema.js +71 -19
  505. package/dist/unstable/ai/McpSchema.js.map +1 -1
  506. package/dist/unstable/ai/McpServer.d.ts +68 -15
  507. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  508. package/dist/unstable/ai/McpServer.js +218 -73
  509. package/dist/unstable/ai/McpServer.js.map +1 -1
  510. package/dist/unstable/ai/Model.d.ts +27 -9
  511. package/dist/unstable/ai/Model.d.ts.map +1 -1
  512. package/dist/unstable/ai/Model.js +25 -9
  513. package/dist/unstable/ai/Model.js.map +1 -1
  514. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +1 -1
  515. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  516. package/dist/unstable/ai/OpenAiStructuredOutput.js +9 -1
  517. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  518. package/dist/unstable/ai/Prompt.d.ts +20 -20
  519. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  520. package/dist/unstable/ai/Prompt.js +6 -9
  521. package/dist/unstable/ai/Prompt.js.map +1 -1
  522. package/dist/unstable/ai/Response.d.ts +27 -27
  523. package/dist/unstable/ai/Response.d.ts.map +1 -1
  524. package/dist/unstable/ai/Response.js +7 -8
  525. package/dist/unstable/ai/Response.js.map +1 -1
  526. package/dist/unstable/ai/ResponseIdTracker.d.ts +38 -0
  527. package/dist/unstable/ai/ResponseIdTracker.d.ts.map +1 -0
  528. package/dist/unstable/ai/ResponseIdTracker.js +68 -0
  529. package/dist/unstable/ai/ResponseIdTracker.js.map +1 -0
  530. package/dist/unstable/ai/Telemetry.d.ts +35 -2
  531. package/dist/unstable/ai/Telemetry.d.ts.map +1 -1
  532. package/dist/unstable/ai/Telemetry.js +2 -2
  533. package/dist/unstable/ai/Telemetry.js.map +1 -1
  534. package/dist/unstable/ai/Tokenizer.d.ts +2 -2
  535. package/dist/unstable/ai/Tokenizer.d.ts.map +1 -1
  536. package/dist/unstable/ai/Tokenizer.js +2 -2
  537. package/dist/unstable/ai/Tokenizer.js.map +1 -1
  538. package/dist/unstable/ai/Tool.d.ts +46 -16
  539. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  540. package/dist/unstable/ai/Tool.js +68 -22
  541. package/dist/unstable/ai/Tool.js.map +1 -1
  542. package/dist/unstable/ai/Toolkit.d.ts +4 -4
  543. package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
  544. package/dist/unstable/ai/Toolkit.js +14 -21
  545. package/dist/unstable/ai/Toolkit.js.map +1 -1
  546. package/dist/unstable/ai/index.d.ts +22 -1
  547. package/dist/unstable/ai/index.d.ts.map +1 -1
  548. package/dist/unstable/ai/index.js +22 -1
  549. package/dist/unstable/ai/index.js.map +1 -1
  550. package/dist/unstable/ai/internal/codec-transformer.js +5 -7
  551. package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
  552. package/dist/unstable/cli/Argument.d.ts +4 -7
  553. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  554. package/dist/unstable/cli/Argument.js +1 -3
  555. package/dist/unstable/cli/Argument.js.map +1 -1
  556. package/dist/unstable/cli/CliError.d.ts +55 -67
  557. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  558. package/dist/unstable/cli/CliError.js +32 -57
  559. package/dist/unstable/cli/CliError.js.map +1 -1
  560. package/dist/unstable/cli/CliOutput.d.ts +5 -4
  561. package/dist/unstable/cli/CliOutput.d.ts.map +1 -1
  562. package/dist/unstable/cli/CliOutput.js +67 -12
  563. package/dist/unstable/cli/CliOutput.js.map +1 -1
  564. package/dist/unstable/cli/Command.d.ts +372 -59
  565. package/dist/unstable/cli/Command.d.ts.map +1 -1
  566. package/dist/unstable/cli/Command.js +328 -66
  567. package/dist/unstable/cli/Command.js.map +1 -1
  568. package/dist/unstable/cli/Completions.d.ts +97 -0
  569. package/dist/unstable/cli/Completions.d.ts.map +1 -0
  570. package/dist/unstable/cli/Completions.js +25 -0
  571. package/dist/unstable/cli/Completions.js.map +1 -0
  572. package/dist/unstable/cli/Flag.d.ts +4 -5
  573. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  574. package/dist/unstable/cli/Flag.js +1 -1
  575. package/dist/unstable/cli/Flag.js.map +1 -1
  576. package/dist/unstable/cli/GlobalFlag.d.ts +125 -0
  577. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -0
  578. package/dist/unstable/cli/GlobalFlag.js +118 -0
  579. package/dist/unstable/cli/GlobalFlag.js.map +1 -0
  580. package/dist/unstable/cli/HelpDoc.d.ts +81 -11
  581. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  582. package/dist/unstable/cli/Param.d.ts +34 -6
  583. package/dist/unstable/cli/Param.d.ts.map +1 -1
  584. package/dist/unstable/cli/Param.js +24 -14
  585. package/dist/unstable/cli/Param.js.map +1 -1
  586. package/dist/unstable/cli/Primitive.d.ts +2 -2
  587. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  588. package/dist/unstable/cli/Primitive.js +1 -1
  589. package/dist/unstable/cli/Primitive.js.map +1 -1
  590. package/dist/unstable/cli/Prompt.js +266 -86
  591. package/dist/unstable/cli/Prompt.js.map +1 -1
  592. package/dist/unstable/cli/index.d.ts +8 -0
  593. package/dist/unstable/cli/index.d.ts.map +1 -1
  594. package/dist/unstable/cli/index.js +8 -0
  595. package/dist/unstable/cli/index.js.map +1 -1
  596. package/dist/unstable/cli/internal/command.d.ts +41 -15
  597. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  598. package/dist/unstable/cli/internal/command.js +84 -47
  599. package/dist/unstable/cli/internal/command.js.map +1 -1
  600. package/dist/unstable/cli/internal/completions/bash.js.map +1 -1
  601. package/dist/unstable/cli/internal/completions/descriptor.d.ts +2 -0
  602. package/dist/unstable/cli/internal/completions/descriptor.d.ts.map +1 -0
  603. package/dist/unstable/cli/internal/completions/{CommandDescriptor.js → descriptor.js} +17 -5
  604. package/dist/unstable/cli/internal/completions/descriptor.js.map +1 -0
  605. package/dist/unstable/cli/internal/completions/fish.js.map +1 -1
  606. package/dist/unstable/cli/internal/completions/zsh.js.map +1 -1
  607. package/dist/unstable/cli/internal/config.js +42 -0
  608. package/dist/unstable/cli/internal/config.js.map +1 -1
  609. package/dist/unstable/cli/internal/help.d.ts +33 -0
  610. package/dist/unstable/cli/internal/help.d.ts.map +1 -0
  611. package/dist/unstable/cli/internal/help.js +125 -0
  612. package/dist/unstable/cli/internal/help.js.map +1 -0
  613. package/dist/unstable/cli/internal/parser.js +155 -58
  614. package/dist/unstable/cli/internal/parser.js.map +1 -1
  615. package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
  616. package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
  617. package/dist/unstable/cluster/ClusterCron.js +1 -1
  618. package/dist/unstable/cluster/ClusterCron.js.map +1 -1
  619. package/dist/unstable/cluster/ClusterError.d.ts +7 -7
  620. package/dist/unstable/cluster/ClusterSchema.d.ts +28 -7
  621. package/dist/unstable/cluster/ClusterSchema.d.ts.map +1 -1
  622. package/dist/unstable/cluster/ClusterSchema.js +28 -8
  623. package/dist/unstable/cluster/ClusterSchema.js.map +1 -1
  624. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +4 -2
  625. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  626. package/dist/unstable/cluster/ClusterWorkflowEngine.js +97 -63
  627. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  628. package/dist/unstable/cluster/DeliverAt.js +1 -1
  629. package/dist/unstable/cluster/DeliverAt.js.map +1 -1
  630. package/dist/unstable/cluster/Entity.d.ts +18 -16
  631. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  632. package/dist/unstable/cluster/Entity.js +31 -25
  633. package/dist/unstable/cluster/Entity.js.map +1 -1
  634. package/dist/unstable/cluster/EntityAddress.d.ts +2 -2
  635. package/dist/unstable/cluster/EntityAddress.d.ts.map +1 -1
  636. package/dist/unstable/cluster/EntityAddress.js +1 -1
  637. package/dist/unstable/cluster/EntityAddress.js.map +1 -1
  638. package/dist/unstable/cluster/EntityProxy.js +3 -3
  639. package/dist/unstable/cluster/EntityProxy.js.map +1 -1
  640. package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
  641. package/dist/unstable/cluster/EntityProxyServer.js +4 -4
  642. package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
  643. package/dist/unstable/cluster/EntityResource.d.ts +4 -4
  644. package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
  645. package/dist/unstable/cluster/EntityResource.js +2 -2
  646. package/dist/unstable/cluster/EntityResource.js.map +1 -1
  647. package/dist/unstable/cluster/Envelope.d.ts +4 -4
  648. package/dist/unstable/cluster/HttpRunner.js +2 -2
  649. package/dist/unstable/cluster/HttpRunner.js.map +1 -1
  650. package/dist/unstable/cluster/K8sHttpClient.d.ts +5 -5
  651. package/dist/unstable/cluster/K8sHttpClient.d.ts.map +1 -1
  652. package/dist/unstable/cluster/K8sHttpClient.js +6 -6
  653. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  654. package/dist/unstable/cluster/Message.d.ts +21 -15
  655. package/dist/unstable/cluster/Message.d.ts.map +1 -1
  656. package/dist/unstable/cluster/Message.js +16 -8
  657. package/dist/unstable/cluster/Message.js.map +1 -1
  658. package/dist/unstable/cluster/MessageStorage.d.ts +46 -23
  659. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  660. package/dist/unstable/cluster/MessageStorage.js +42 -26
  661. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  662. package/dist/unstable/cluster/Reply.d.ts +10 -9
  663. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  664. package/dist/unstable/cluster/Reply.js +8 -7
  665. package/dist/unstable/cluster/Reply.js.map +1 -1
  666. package/dist/unstable/cluster/Runner.d.ts +2 -2
  667. package/dist/unstable/cluster/Runner.d.ts.map +1 -1
  668. package/dist/unstable/cluster/Runner.js +1 -1
  669. package/dist/unstable/cluster/Runner.js.map +1 -1
  670. package/dist/unstable/cluster/RunnerAddress.d.ts +1 -1
  671. package/dist/unstable/cluster/RunnerAddress.d.ts.map +1 -1
  672. package/dist/unstable/cluster/RunnerAddress.js +1 -1
  673. package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
  674. package/dist/unstable/cluster/RunnerHealth.d.ts +2 -2
  675. package/dist/unstable/cluster/RunnerHealth.d.ts.map +1 -1
  676. package/dist/unstable/cluster/RunnerHealth.js +2 -2
  677. package/dist/unstable/cluster/RunnerHealth.js.map +1 -1
  678. package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
  679. package/dist/unstable/cluster/RunnerServer.js +10 -9
  680. package/dist/unstable/cluster/RunnerServer.js.map +1 -1
  681. package/dist/unstable/cluster/RunnerStorage.d.ts +12 -12
  682. package/dist/unstable/cluster/RunnerStorage.d.ts.map +1 -1
  683. package/dist/unstable/cluster/RunnerStorage.js +3 -3
  684. package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
  685. package/dist/unstable/cluster/Runners.d.ts +5 -4
  686. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  687. package/dist/unstable/cluster/Runners.js +20 -17
  688. package/dist/unstable/cluster/Runners.js.map +1 -1
  689. package/dist/unstable/cluster/ShardId.d.ts +35 -49
  690. package/dist/unstable/cluster/ShardId.d.ts.map +1 -1
  691. package/dist/unstable/cluster/ShardId.js +65 -67
  692. package/dist/unstable/cluster/ShardId.js.map +1 -1
  693. package/dist/unstable/cluster/Sharding.d.ts +4 -4
  694. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  695. package/dist/unstable/cluster/Sharding.js +66 -54
  696. package/dist/unstable/cluster/Sharding.js.map +1 -1
  697. package/dist/unstable/cluster/ShardingConfig.d.ts +28 -27
  698. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  699. package/dist/unstable/cluster/ShardingConfig.js +27 -27
  700. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  701. package/dist/unstable/cluster/SingletonAddress.d.ts +2 -2
  702. package/dist/unstable/cluster/Snowflake.d.ts +2 -2
  703. package/dist/unstable/cluster/Snowflake.d.ts.map +1 -1
  704. package/dist/unstable/cluster/Snowflake.js +2 -2
  705. package/dist/unstable/cluster/Snowflake.js.map +1 -1
  706. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  707. package/dist/unstable/cluster/SqlMessageStorage.js +24 -20
  708. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  709. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  710. package/dist/unstable/cluster/SqlRunnerStorage.js +7 -7
  711. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  712. package/dist/unstable/cluster/internal/entityManager.js +34 -27
  713. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  714. package/dist/unstable/cluster/internal/entityReaper.js +4 -3
  715. package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
  716. package/dist/unstable/cluster/internal/resourceMap.js +3 -3
  717. package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
  718. package/dist/unstable/cluster/internal/resourceRef.js +2 -1
  719. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  720. package/dist/unstable/devtools/DevToolsClient.d.ts +2 -2
  721. package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
  722. package/dist/unstable/devtools/DevToolsClient.js +9 -8
  723. package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
  724. package/dist/unstable/devtools/DevToolsSchema.d.ts +40 -40
  725. package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
  726. package/dist/unstable/devtools/DevToolsSchema.js +9 -2
  727. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  728. package/dist/unstable/encoding/Msgpack.d.ts +1 -1
  729. package/dist/unstable/encoding/Ndjson.d.ts +9 -9
  730. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  731. package/dist/unstable/encoding/Ndjson.js.map +1 -1
  732. package/dist/unstable/encoding/Sse.d.ts +4 -4
  733. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  734. package/dist/unstable/encoding/Sse.js +1 -1
  735. package/dist/unstable/encoding/Sse.js.map +1 -1
  736. package/dist/unstable/eventlog/Event.d.ts +0 -6
  737. package/dist/unstable/eventlog/Event.d.ts.map +1 -1
  738. package/dist/unstable/eventlog/Event.js +0 -5
  739. package/dist/unstable/eventlog/Event.js.map +1 -1
  740. package/dist/unstable/eventlog/EventGroup.d.ts +0 -2
  741. package/dist/unstable/eventlog/EventGroup.d.ts.map +1 -1
  742. package/dist/unstable/eventlog/EventGroup.js +0 -2
  743. package/dist/unstable/eventlog/EventGroup.js.map +1 -1
  744. package/dist/unstable/eventlog/EventJournal.d.ts +28 -11
  745. package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
  746. package/dist/unstable/eventlog/EventJournal.js +130 -71
  747. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  748. package/dist/unstable/eventlog/EventLog.d.ts +94 -37
  749. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  750. package/dist/unstable/eventlog/EventLog.js +225 -150
  751. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  752. package/dist/unstable/eventlog/EventLogEncryption.d.ts +11 -9
  753. package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
  754. package/dist/unstable/eventlog/EventLogEncryption.js +15 -17
  755. package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
  756. package/dist/unstable/eventlog/EventLogMessage.d.ts +228 -0
  757. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -0
  758. package/dist/unstable/eventlog/EventLogMessage.js +214 -0
  759. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -0
  760. package/dist/unstable/eventlog/EventLogRemote.d.ts +112 -194
  761. package/dist/unstable/eventlog/EventLogRemote.d.ts.map +1 -1
  762. package/dist/unstable/eventlog/EventLogRemote.js +168 -322
  763. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  764. package/dist/unstable/eventlog/EventLogServer.d.ts +26 -48
  765. package/dist/unstable/eventlog/EventLogServer.d.ts.map +1 -1
  766. package/dist/unstable/eventlog/EventLogServer.js +128 -199
  767. package/dist/unstable/eventlog/EventLogServer.js.map +1 -1
  768. package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts +60 -0
  769. package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts.map +1 -0
  770. package/dist/unstable/eventlog/EventLogServerEncrypted.js +166 -0
  771. package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -0
  772. package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts +183 -0
  773. package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts.map +1 -0
  774. package/dist/unstable/eventlog/EventLogServerUnencrypted.js +461 -0
  775. package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -0
  776. package/dist/unstable/eventlog/EventLogSessionAuth.d.ts +117 -0
  777. package/dist/unstable/eventlog/EventLogSessionAuth.d.ts.map +1 -0
  778. package/dist/unstable/eventlog/EventLogSessionAuth.js +284 -0
  779. package/dist/unstable/eventlog/EventLogSessionAuth.js.map +1 -0
  780. package/dist/unstable/eventlog/{SqlEventLogJournal.d.ts → SqlEventJournal.d.ts} +2 -2
  781. package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -0
  782. package/dist/unstable/eventlog/{SqlEventLogJournal.js → SqlEventJournal.js} +28 -21
  783. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -0
  784. package/dist/unstable/eventlog/{SqlEventLogServer.d.ts → SqlEventLogServerEncrypted.d.ts} +5 -5
  785. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -0
  786. package/dist/unstable/eventlog/{SqlEventLogServer.js → SqlEventLogServerEncrypted.js} +69 -27
  787. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -0
  788. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts +25 -0
  789. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -0
  790. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +355 -0
  791. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -0
  792. package/dist/unstable/eventlog/index.d.ts +22 -2
  793. package/dist/unstable/eventlog/index.d.ts.map +1 -1
  794. package/dist/unstable/eventlog/index.js +22 -2
  795. package/dist/unstable/eventlog/index.js.map +1 -1
  796. package/dist/unstable/eventlog/internal/identityRootSecretDerivation.d.ts +2 -0
  797. package/dist/unstable/eventlog/internal/identityRootSecretDerivation.d.ts.map +1 -0
  798. package/dist/unstable/eventlog/internal/identityRootSecretDerivation.js +89 -0
  799. package/dist/unstable/eventlog/internal/identityRootSecretDerivation.js.map +1 -0
  800. package/dist/unstable/http/Cookies.d.ts +52 -7
  801. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  802. package/dist/unstable/http/Cookies.js +27 -6
  803. package/dist/unstable/http/Cookies.js.map +1 -1
  804. package/dist/unstable/http/Etag.d.ts +2 -2
  805. package/dist/unstable/http/Etag.d.ts.map +1 -1
  806. package/dist/unstable/http/Etag.js +7 -3
  807. package/dist/unstable/http/Etag.js.map +1 -1
  808. package/dist/unstable/http/FetchHttpClient.d.ts +6 -3
  809. package/dist/unstable/http/FetchHttpClient.d.ts.map +1 -1
  810. package/dist/unstable/http/FetchHttpClient.js +5 -5
  811. package/dist/unstable/http/FetchHttpClient.js.map +1 -1
  812. package/dist/unstable/http/Headers.d.ts +24 -4
  813. package/dist/unstable/http/Headers.d.ts.map +1 -1
  814. package/dist/unstable/http/Headers.js +42 -13
  815. package/dist/unstable/http/Headers.js.map +1 -1
  816. package/dist/unstable/http/HttpBody.d.ts +1 -1
  817. package/dist/unstable/http/HttpClient.d.ts +125 -21
  818. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  819. package/dist/unstable/http/HttpClient.js +197 -19
  820. package/dist/unstable/http/HttpClient.js.map +1 -1
  821. package/dist/unstable/http/HttpClientError.d.ts +8 -8
  822. package/dist/unstable/http/HttpClientRequest.d.ts +43 -15
  823. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  824. package/dist/unstable/http/HttpClientRequest.js +131 -21
  825. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  826. package/dist/unstable/http/HttpClientResponse.d.ts +2 -1
  827. package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
  828. package/dist/unstable/http/HttpClientResponse.js +6 -1
  829. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  830. package/dist/unstable/http/HttpEffect.d.ts +13 -11
  831. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  832. package/dist/unstable/http/HttpEffect.js +67 -75
  833. package/dist/unstable/http/HttpEffect.js.map +1 -1
  834. package/dist/unstable/http/HttpIncomingMessage.d.ts +5 -4
  835. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  836. package/dist/unstable/http/HttpIncomingMessage.js +2 -2
  837. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  838. package/dist/unstable/http/HttpMethod.d.ts +4 -4
  839. package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
  840. package/dist/unstable/http/HttpMethod.js +3 -3
  841. package/dist/unstable/http/HttpMethod.js.map +1 -1
  842. package/dist/unstable/http/HttpMiddleware.d.ts +4 -9
  843. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  844. package/dist/unstable/http/HttpMiddleware.js +47 -43
  845. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  846. package/dist/unstable/http/HttpPlatform.d.ts +2 -2
  847. package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
  848. package/dist/unstable/http/HttpPlatform.js +5 -4
  849. package/dist/unstable/http/HttpPlatform.js.map +1 -1
  850. package/dist/unstable/http/HttpRouter.d.ts +9 -8
  851. package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
  852. package/dist/unstable/http/HttpRouter.js +36 -36
  853. package/dist/unstable/http/HttpRouter.js.map +1 -1
  854. package/dist/unstable/http/HttpServer.d.ts +2 -2
  855. package/dist/unstable/http/HttpServer.d.ts.map +1 -1
  856. package/dist/unstable/http/HttpServer.js +4 -4
  857. package/dist/unstable/http/HttpServer.js.map +1 -1
  858. package/dist/unstable/http/HttpServerError.d.ts +22 -34
  859. package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
  860. package/dist/unstable/http/HttpServerError.js +39 -45
  861. package/dist/unstable/http/HttpServerError.js.map +1 -1
  862. package/dist/unstable/http/HttpServerRequest.d.ts +19 -7
  863. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  864. package/dist/unstable/http/HttpServerRequest.js +307 -13
  865. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  866. package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
  867. package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
  868. package/dist/unstable/http/HttpServerRespondable.js +5 -5
  869. package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
  870. package/dist/unstable/http/HttpServerResponse.d.ts +52 -5
  871. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  872. package/dist/unstable/http/HttpServerResponse.js +240 -5
  873. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  874. package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
  875. package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
  876. package/dist/unstable/http/HttpStaticServer.js +353 -0
  877. package/dist/unstable/http/HttpStaticServer.js.map +1 -0
  878. package/dist/unstable/http/HttpTraceContext.d.ts +3 -2
  879. package/dist/unstable/http/HttpTraceContext.d.ts.map +1 -1
  880. package/dist/unstable/http/HttpTraceContext.js +27 -15
  881. package/dist/unstable/http/HttpTraceContext.js.map +1 -1
  882. package/dist/unstable/http/Multipart.d.ts +9 -9
  883. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  884. package/dist/unstable/http/Multipart.js +7 -7
  885. package/dist/unstable/http/Multipart.js.map +1 -1
  886. package/dist/unstable/http/Url.d.ts +604 -0
  887. package/dist/unstable/http/Url.d.ts.map +1 -0
  888. package/dist/unstable/http/Url.js +256 -0
  889. package/dist/unstable/http/Url.js.map +1 -0
  890. package/dist/unstable/http/UrlParams.d.ts +19 -10
  891. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  892. package/dist/unstable/http/UrlParams.js +6 -7
  893. package/dist/unstable/http/UrlParams.js.map +1 -1
  894. package/dist/unstable/http/index.d.ts +8 -0
  895. package/dist/unstable/http/index.d.ts.map +1 -1
  896. package/dist/unstable/http/index.js +8 -0
  897. package/dist/unstable/http/index.js.map +1 -1
  898. package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
  899. package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
  900. package/dist/unstable/http/internal/preResponseHandler.js +10 -0
  901. package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
  902. package/dist/unstable/httpapi/HttpApi.d.ts +11 -11
  903. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  904. package/dist/unstable/httpapi/HttpApi.js +8 -8
  905. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  906. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +12 -9
  907. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  908. package/dist/unstable/httpapi/HttpApiBuilder.js +53 -39
  909. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  910. package/dist/unstable/httpapi/HttpApiClient.d.ts +83 -7
  911. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  912. package/dist/unstable/httpapi/HttpApiClient.js +79 -11
  913. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  914. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +211 -105
  915. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  916. package/dist/unstable/httpapi/HttpApiEndpoint.js +53 -47
  917. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  918. package/dist/unstable/httpapi/HttpApiError.d.ts +43 -26
  919. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  920. package/dist/unstable/httpapi/HttpApiError.js +125 -32
  921. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  922. package/dist/unstable/httpapi/HttpApiGroup.d.ts +9 -8
  923. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  924. package/dist/unstable/httpapi/HttpApiGroup.js +4 -4
  925. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  926. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +49 -18
  927. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  928. package/dist/unstable/httpapi/HttpApiMiddleware.js +38 -8
  929. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  930. package/dist/unstable/httpapi/HttpApiScalar.d.ts +6 -0
  931. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  932. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  933. package/dist/unstable/httpapi/HttpApiSchema.d.ts +88 -9
  934. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  935. package/dist/unstable/httpapi/HttpApiSchema.js +86 -11
  936. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  937. package/dist/unstable/httpapi/HttpApiSecurity.d.ts +9 -6
  938. package/dist/unstable/httpapi/HttpApiSecurity.d.ts.map +1 -1
  939. package/dist/unstable/httpapi/HttpApiSecurity.js +6 -6
  940. package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
  941. package/dist/unstable/httpapi/OpenApi.d.ts +17 -25
  942. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  943. package/dist/unstable/httpapi/OpenApi.js +59 -60
  944. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  945. package/dist/unstable/observability/Otlp.d.ts +12 -12
  946. package/dist/unstable/observability/Otlp.d.ts.map +1 -1
  947. package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
  948. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  949. package/dist/unstable/observability/OtlpExporter.js +8 -8
  950. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  951. package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
  952. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  953. package/dist/unstable/observability/OtlpLogger.js +7 -4
  954. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  955. package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
  956. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  957. package/dist/unstable/observability/OtlpMetrics.js +2 -2
  958. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  959. package/dist/unstable/observability/OtlpSerialization.d.ts +2 -2
  960. package/dist/unstable/observability/OtlpSerialization.d.ts.map +1 -1
  961. package/dist/unstable/observability/OtlpSerialization.js +2 -2
  962. package/dist/unstable/observability/OtlpSerialization.js.map +1 -1
  963. package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
  964. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  965. package/dist/unstable/observability/OtlpTracer.js +7 -3
  966. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  967. package/dist/unstable/observability/PrometheusMetrics.d.ts +3 -3
  968. package/dist/unstable/observability/PrometheusMetrics.d.ts.map +1 -1
  969. package/dist/unstable/observability/PrometheusMetrics.js +4 -33
  970. package/dist/unstable/observability/PrometheusMetrics.js.map +1 -1
  971. package/dist/unstable/observability/internal/protobuf.js +4 -4
  972. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  973. package/dist/unstable/persistence/KeyValueStore.d.ts +24 -3
  974. package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
  975. package/dist/unstable/persistence/KeyValueStore.js +148 -6
  976. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  977. package/dist/unstable/persistence/Persistable.d.ts +2 -2
  978. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  979. package/dist/unstable/persistence/Persistable.js +1 -1
  980. package/dist/unstable/persistence/Persistable.js.map +1 -1
  981. package/dist/unstable/persistence/PersistedCache.d.ts +6 -6
  982. package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
  983. package/dist/unstable/persistence/PersistedCache.js +12 -12
  984. package/dist/unstable/persistence/PersistedCache.js.map +1 -1
  985. package/dist/unstable/persistence/PersistedQueue.d.ts +16 -16
  986. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  987. package/dist/unstable/persistence/PersistedQueue.js +15 -14
  988. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  989. package/dist/unstable/persistence/Persistence.d.ts +5 -5
  990. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  991. package/dist/unstable/persistence/Persistence.js +5 -5
  992. package/dist/unstable/persistence/Persistence.js.map +1 -1
  993. package/dist/unstable/persistence/RateLimiter.d.ts +9 -9
  994. package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
  995. package/dist/unstable/persistence/RateLimiter.js +4 -4
  996. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  997. package/dist/unstable/persistence/Redis.d.ts +3 -3
  998. package/dist/unstable/persistence/Redis.d.ts.map +1 -1
  999. package/dist/unstable/persistence/Redis.js +2 -2
  1000. package/dist/unstable/persistence/Redis.js.map +1 -1
  1001. package/dist/unstable/process/ChildProcess.d.ts +5 -128
  1002. package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
  1003. package/dist/unstable/process/ChildProcess.js +1 -65
  1004. package/dist/unstable/process/ChildProcess.js.map +1 -1
  1005. package/dist/unstable/process/ChildProcessSpawner.d.ts +89 -8
  1006. package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
  1007. package/dist/unstable/process/ChildProcessSpawner.js +22 -2
  1008. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  1009. package/dist/unstable/reactivity/Atom.d.ts +108 -47
  1010. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  1011. package/dist/unstable/reactivity/Atom.js +105 -25
  1012. package/dist/unstable/reactivity/Atom.js.map +1 -1
  1013. package/dist/unstable/reactivity/AtomHttpApi.d.ts +22 -20
  1014. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  1015. package/dist/unstable/reactivity/AtomHttpApi.js +58 -26
  1016. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  1017. package/dist/unstable/reactivity/AtomRegistry.d.ts +8 -2
  1018. package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
  1019. package/dist/unstable/reactivity/AtomRegistry.js +57 -14
  1020. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  1021. package/dist/unstable/reactivity/AtomRpc.d.ts +12 -12
  1022. package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
  1023. package/dist/unstable/reactivity/AtomRpc.js +59 -31
  1024. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  1025. package/dist/unstable/reactivity/Reactivity.d.ts +2 -2
  1026. package/dist/unstable/reactivity/Reactivity.d.ts.map +1 -1
  1027. package/dist/unstable/reactivity/Reactivity.js +6 -6
  1028. package/dist/unstable/reactivity/Reactivity.js.map +1 -1
  1029. package/dist/unstable/reactivity/index.d.ts +2 -2
  1030. package/dist/unstable/reactivity/index.d.ts.map +1 -1
  1031. package/dist/unstable/reactivity/index.js +2 -2
  1032. package/dist/unstable/reactivity/index.js.map +1 -1
  1033. package/dist/unstable/rpc/Rpc.d.ts +47 -19
  1034. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  1035. package/dist/unstable/rpc/Rpc.js +39 -7
  1036. package/dist/unstable/rpc/Rpc.js.map +1 -1
  1037. package/dist/unstable/rpc/RpcClient.d.ts +26 -47
  1038. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  1039. package/dist/unstable/rpc/RpcClient.js +120 -77
  1040. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  1041. package/dist/unstable/rpc/RpcClientError.d.ts +2 -2
  1042. package/dist/unstable/rpc/RpcGroup.d.ts +15 -11
  1043. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  1044. package/dist/unstable/rpc/RpcGroup.js +30 -20
  1045. package/dist/unstable/rpc/RpcGroup.js.map +1 -1
  1046. package/dist/unstable/rpc/RpcMiddleware.d.ts +12 -12
  1047. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  1048. package/dist/unstable/rpc/RpcMiddleware.js +5 -5
  1049. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  1050. package/dist/unstable/rpc/RpcSchema.d.ts +14 -1
  1051. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  1052. package/dist/unstable/rpc/RpcSchema.js +17 -2
  1053. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  1054. package/dist/unstable/rpc/RpcSerialization.d.ts +13 -2
  1055. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  1056. package/dist/unstable/rpc/RpcSerialization.js +60 -27
  1057. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  1058. package/dist/unstable/rpc/RpcServer.d.ts +8 -12
  1059. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  1060. package/dist/unstable/rpc/RpcServer.js +78 -46
  1061. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  1062. package/dist/unstable/rpc/RpcWorker.d.ts +2 -2
  1063. package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
  1064. package/dist/unstable/rpc/RpcWorker.js +4 -4
  1065. package/dist/unstable/rpc/RpcWorker.js.map +1 -1
  1066. package/dist/unstable/rpc/Utils.d.ts +6 -3
  1067. package/dist/unstable/rpc/Utils.d.ts.map +1 -1
  1068. package/dist/unstable/rpc/Utils.js +48 -6
  1069. package/dist/unstable/rpc/Utils.js.map +1 -1
  1070. package/dist/unstable/schema/Model.d.ts +24 -3
  1071. package/dist/unstable/schema/Model.d.ts.map +1 -1
  1072. package/dist/unstable/schema/Model.js +17 -4
  1073. package/dist/unstable/schema/Model.js.map +1 -1
  1074. package/dist/unstable/schema/VariantSchema.d.ts +7 -7
  1075. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  1076. package/dist/unstable/schema/VariantSchema.js +7 -18
  1077. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  1078. package/dist/unstable/socket/Socket.d.ts +16 -15
  1079. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  1080. package/dist/unstable/socket/Socket.js +22 -19
  1081. package/dist/unstable/socket/Socket.js.map +1 -1
  1082. package/dist/unstable/socket/SocketServer.d.ts +8 -5
  1083. package/dist/unstable/socket/SocketServer.d.ts.map +1 -1
  1084. package/dist/unstable/socket/SocketServer.js +2 -2
  1085. package/dist/unstable/socket/SocketServer.js.map +1 -1
  1086. package/dist/unstable/sql/Migrator.d.ts +1 -1
  1087. package/dist/unstable/sql/Migrator.d.ts.map +1 -1
  1088. package/dist/unstable/sql/Migrator.js +2 -2
  1089. package/dist/unstable/sql/Migrator.js.map +1 -1
  1090. package/dist/unstable/sql/SqlClient.d.ts +5 -5
  1091. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  1092. package/dist/unstable/sql/SqlClient.js +7 -7
  1093. package/dist/unstable/sql/SqlClient.js.map +1 -1
  1094. package/dist/unstable/sql/SqlConnection.d.ts +2 -2
  1095. package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
  1096. package/dist/unstable/sql/SqlConnection.js +5 -2
  1097. package/dist/unstable/sql/SqlConnection.js.map +1 -1
  1098. package/dist/unstable/sql/SqlError.d.ts +237 -17
  1099. package/dist/unstable/sql/SqlError.d.ts.map +1 -1
  1100. package/dist/unstable/sql/SqlError.js +260 -4
  1101. package/dist/unstable/sql/SqlError.js.map +1 -1
  1102. package/dist/unstable/sql/SqlModel.d.ts +8 -9
  1103. package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
  1104. package/dist/unstable/sql/SqlModel.js +12 -38
  1105. package/dist/unstable/sql/SqlModel.js.map +1 -1
  1106. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  1107. package/dist/unstable/sql/SqlResolver.js +26 -17
  1108. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  1109. package/dist/unstable/sql/SqlSchema.d.ts +17 -6
  1110. package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
  1111. package/dist/unstable/sql/SqlSchema.js +17 -7
  1112. package/dist/unstable/sql/SqlSchema.js.map +1 -1
  1113. package/dist/unstable/sql/Statement.d.ts +2 -2
  1114. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  1115. package/dist/unstable/sql/Statement.js +2 -3
  1116. package/dist/unstable/sql/Statement.js.map +1 -1
  1117. package/dist/unstable/workers/Transferable.d.ts +4 -4
  1118. package/dist/unstable/workers/Transferable.d.ts.map +1 -1
  1119. package/dist/unstable/workers/Transferable.js +7 -7
  1120. package/dist/unstable/workers/Transferable.js.map +1 -1
  1121. package/dist/unstable/workers/Worker.d.ts +3 -3
  1122. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  1123. package/dist/unstable/workers/Worker.js +8 -4
  1124. package/dist/unstable/workers/Worker.js.map +1 -1
  1125. package/dist/unstable/workers/WorkerError.d.ts +5 -5
  1126. package/dist/unstable/workers/WorkerRunner.d.ts +2 -2
  1127. package/dist/unstable/workers/WorkerRunner.d.ts.map +1 -1
  1128. package/dist/unstable/workers/WorkerRunner.js +5 -2
  1129. package/dist/unstable/workers/WorkerRunner.js.map +1 -1
  1130. package/dist/unstable/workflow/Activity.d.ts +7 -2
  1131. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  1132. package/dist/unstable/workflow/Activity.js +17 -4
  1133. package/dist/unstable/workflow/Activity.js.map +1 -1
  1134. package/dist/unstable/workflow/DurableClock.d.ts +3 -6
  1135. package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
  1136. package/dist/unstable/workflow/DurableClock.js +6 -6
  1137. package/dist/unstable/workflow/DurableClock.js.map +1 -1
  1138. package/dist/unstable/workflow/DurableDeferred.d.ts +1 -1
  1139. package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
  1140. package/dist/unstable/workflow/DurableDeferred.js +15 -15
  1141. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  1142. package/dist/unstable/workflow/Workflow.d.ts +13 -12
  1143. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  1144. package/dist/unstable/workflow/Workflow.js +18 -18
  1145. package/dist/unstable/workflow/Workflow.js.map +1 -1
  1146. package/dist/unstable/workflow/WorkflowEngine.d.ts +26 -8
  1147. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  1148. package/dist/unstable/workflow/WorkflowEngine.js +167 -17
  1149. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  1150. package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
  1151. package/dist/unstable/workflow/WorkflowProxyServer.js +4 -4
  1152. package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
  1153. package/package.json +11 -11
  1154. package/src/Array.ts +304 -447
  1155. package/src/BigDecimal.ts +137 -82
  1156. package/src/BigInt.ts +53 -45
  1157. package/src/Brand.ts +3 -5
  1158. package/src/Cache.ts +27 -54
  1159. package/src/Cause.ts +58 -23
  1160. package/src/Channel.ts +693 -224
  1161. package/src/Chunk.ts +149 -331
  1162. package/src/Clock.ts +2 -2
  1163. package/src/Combiner.ts +280 -13
  1164. package/src/Config.ts +197 -27
  1165. package/src/ConfigProvider.ts +5 -5
  1166. package/src/Console.ts +2 -2
  1167. package/src/Context.ts +1454 -0
  1168. package/src/Cron.ts +155 -63
  1169. package/src/Data.ts +539 -376
  1170. package/src/DateTime.ts +77 -258
  1171. package/src/Deferred.ts +15 -6
  1172. package/src/Duration.ts +123 -67
  1173. package/src/Effect.ts +1629 -1355
  1174. package/src/Encoding.ts +879 -0
  1175. package/src/Equal.ts +295 -111
  1176. package/src/Equivalence.ts +114 -52
  1177. package/src/ErrorReporter.ts +458 -0
  1178. package/src/ExecutionPlan.ts +8 -9
  1179. package/src/Exit.ts +24 -12
  1180. package/src/Fiber.ts +17 -8
  1181. package/src/FiberHandle.ts +15 -14
  1182. package/src/FiberMap.ts +27 -27
  1183. package/src/FiberSet.ts +5 -5
  1184. package/src/FileSystem.ts +34 -30
  1185. package/src/Filter.ts +4 -62
  1186. package/src/Formatter.ts +253 -51
  1187. package/src/Function.ts +2 -10
  1188. package/src/Graph.ts +131 -117
  1189. package/src/Hash.ts +2 -2
  1190. package/src/HashMap.ts +26 -19
  1191. package/src/Iterable.ts +117 -63
  1192. package/src/JsonSchema.ts +383 -10
  1193. package/src/Latch.ts +194 -0
  1194. package/src/Layer.ts +728 -441
  1195. package/src/LayerMap.ts +38 -35
  1196. package/src/LogLevel.ts +37 -0
  1197. package/src/Logger.ts +35 -102
  1198. package/src/ManagedRuntime.ts +61 -48
  1199. package/src/Metric.ts +64 -66
  1200. package/src/MutableHashMap.ts +9 -0
  1201. package/src/MutableHashSet.ts +9 -0
  1202. package/src/MutableList.ts +3 -0
  1203. package/src/Newtype.ts +308 -0
  1204. package/src/Number.ts +98 -29
  1205. package/src/Optic.ts +948 -19
  1206. package/src/Option.ts +34 -24
  1207. package/src/Order.ts +39 -32
  1208. package/src/PartitionedSemaphore.ts +288 -56
  1209. package/src/Path.ts +2 -2
  1210. package/src/Pipeable.ts +32 -1
  1211. package/src/Pool.ts +18 -16
  1212. package/src/PubSub.ts +30 -20
  1213. package/src/Pull.ts +1 -1
  1214. package/src/Queue.ts +11 -9
  1215. package/src/Random.ts +51 -14
  1216. package/src/RcMap.ts +19 -19
  1217. package/src/RcRef.ts +1 -1
  1218. package/src/Record.ts +94 -199
  1219. package/src/Redactable.ts +146 -72
  1220. package/src/Reducer.ts +166 -7
  1221. package/src/References.ts +283 -287
  1222. package/src/Request.ts +8 -7
  1223. package/src/RequestResolver.ts +34 -55
  1224. package/src/Resource.ts +6 -5
  1225. package/src/Result.ts +2 -4
  1226. package/src/Runtime.ts +102 -6
  1227. package/src/Schedule.ts +460 -451
  1228. package/src/Scheduler.ts +52 -129
  1229. package/src/Schema.ts +4267 -752
  1230. package/src/SchemaAST.ts +480 -302
  1231. package/src/SchemaGetter.ts +92 -38
  1232. package/src/SchemaIssue.ts +28 -15
  1233. package/src/SchemaParser.ts +100 -29
  1234. package/src/SchemaRepresentation.ts +59 -32
  1235. package/src/SchemaTransformation.ts +364 -13
  1236. package/src/Scope.ts +2 -2
  1237. package/src/ScopedCache.ts +8 -8
  1238. package/src/Semaphore.ts +442 -0
  1239. package/src/Sink.ts +89 -34
  1240. package/src/Stdio.ts +29 -6
  1241. package/src/Stream.ts +898 -752
  1242. package/src/String.ts +122 -69
  1243. package/src/Struct.ts +33 -7
  1244. package/src/SubscriptionRef.ts +101 -120
  1245. package/src/SynchronizedRef.ts +3 -2
  1246. package/src/Terminal.ts +5 -4
  1247. package/src/Tracer.ts +23 -22
  1248. package/src/Trie.ts +44 -31
  1249. package/src/TxChunk.ts +26 -16
  1250. package/src/TxDeferred.ts +391 -0
  1251. package/src/TxHashMap.ts +347 -291
  1252. package/src/TxHashSet.ts +54 -61
  1253. package/src/TxPriorityQueue.ts +762 -0
  1254. package/src/TxPubSub.ts +787 -0
  1255. package/src/TxQueue.ts +221 -245
  1256. package/src/TxReentrantLock.ts +729 -0
  1257. package/src/TxRef.ts +31 -31
  1258. package/src/TxSemaphore.ts +203 -31
  1259. package/src/TxSubscriptionRef.ts +637 -0
  1260. package/src/Types.ts +78 -17
  1261. package/src/Unify.ts +26 -2
  1262. package/src/Utils.ts +137 -111
  1263. package/src/index.ts +898 -72
  1264. package/src/internal/core.ts +19 -12
  1265. package/src/internal/dateTime.ts +91 -96
  1266. package/src/internal/effect.ts +1150 -611
  1267. package/src/internal/hashMap.ts +12 -10
  1268. package/src/internal/layer.ts +7 -7
  1269. package/src/internal/option.ts +7 -0
  1270. package/src/internal/random.ts +20 -0
  1271. package/src/internal/rcRef.ts +14 -13
  1272. package/src/internal/references.ts +72 -0
  1273. package/src/internal/request.ts +8 -8
  1274. package/src/internal/schedule.ts +3 -1
  1275. package/src/internal/schema/annotations.ts +2 -0
  1276. package/src/internal/schema/representation.ts +81 -95
  1277. package/src/internal/schema/schema.ts +25 -1
  1278. package/src/internal/schema/to-codec.ts +7 -17
  1279. package/src/internal/trie.ts +21 -15
  1280. package/src/testing/TestClock.ts +13 -11
  1281. package/src/testing/TestSchema.ts +333 -36
  1282. package/src/testing/index.ts +64 -1
  1283. package/src/unstable/ai/AiError.ts +112 -54
  1284. package/src/unstable/ai/AnthropicStructuredOutput.ts +7 -3
  1285. package/src/unstable/ai/Chat.ts +137 -88
  1286. package/src/unstable/ai/EmbeddingModel.ts +209 -0
  1287. package/src/unstable/ai/IdGenerator.ts +2 -2
  1288. package/src/unstable/ai/LanguageModel.ts +685 -255
  1289. package/src/unstable/ai/McpSchema.ts +84 -22
  1290. package/src/unstable/ai/McpServer.ts +299 -87
  1291. package/src/unstable/ai/Model.ts +44 -13
  1292. package/src/unstable/ai/OpenAiStructuredOutput.ts +9 -2
  1293. package/src/unstable/ai/Prompt.ts +43 -49
  1294. package/src/unstable/ai/Response.ts +31 -33
  1295. package/src/unstable/ai/ResponseIdTracker.ts +95 -0
  1296. package/src/unstable/ai/Telemetry.ts +2 -2
  1297. package/src/unstable/ai/Tokenizer.ts +2 -2
  1298. package/src/unstable/ai/Tool.ts +62 -36
  1299. package/src/unstable/ai/Toolkit.ts +17 -26
  1300. package/src/unstable/ai/index.ts +24 -1
  1301. package/src/unstable/ai/internal/codec-transformer.ts +3 -9
  1302. package/src/unstable/cli/Argument.ts +5 -8
  1303. package/src/unstable/cli/CliError.ts +67 -66
  1304. package/src/unstable/cli/CliOutput.ts +87 -15
  1305. package/src/unstable/cli/Command.ts +808 -193
  1306. package/src/unstable/cli/Completions.ts +107 -0
  1307. package/src/unstable/cli/Flag.ts +5 -6
  1308. package/src/unstable/cli/GlobalFlag.ts +242 -0
  1309. package/src/unstable/cli/HelpDoc.ts +91 -11
  1310. package/src/unstable/cli/Param.ts +54 -27
  1311. package/src/unstable/cli/Primitive.ts +2 -2
  1312. package/src/unstable/cli/Prompt.ts +275 -104
  1313. package/src/unstable/cli/index.ts +10 -0
  1314. package/src/unstable/cli/internal/command.ts +125 -64
  1315. package/src/unstable/cli/internal/completions/bash.ts +7 -7
  1316. package/src/unstable/cli/internal/completions/{CommandDescriptor.ts → descriptor.ts} +16 -58
  1317. package/src/unstable/cli/internal/completions/fish.ts +7 -7
  1318. package/src/unstable/cli/internal/completions/zsh.ts +8 -14
  1319. package/src/unstable/cli/internal/config.ts +49 -0
  1320. package/src/unstable/cli/internal/help.ts +171 -0
  1321. package/src/unstable/cli/internal/parser.ts +201 -84
  1322. package/src/unstable/cluster/ClusterCron.ts +2 -2
  1323. package/src/unstable/cluster/ClusterSchema.ts +38 -10
  1324. package/src/unstable/cluster/ClusterWorkflowEngine.ts +144 -81
  1325. package/src/unstable/cluster/DeliverAt.ts +1 -1
  1326. package/src/unstable/cluster/Entity.ts +59 -45
  1327. package/src/unstable/cluster/EntityAddress.ts +1 -1
  1328. package/src/unstable/cluster/EntityProxy.ts +3 -3
  1329. package/src/unstable/cluster/EntityProxyServer.ts +4 -4
  1330. package/src/unstable/cluster/EntityResource.ts +6 -6
  1331. package/src/unstable/cluster/Envelope.ts +1 -1
  1332. package/src/unstable/cluster/HttpRunner.ts +2 -2
  1333. package/src/unstable/cluster/K8sHttpClient.ts +7 -7
  1334. package/src/unstable/cluster/Message.ts +30 -17
  1335. package/src/unstable/cluster/MessageStorage.ts +76 -46
  1336. package/src/unstable/cluster/Reply.ts +13 -10
  1337. package/src/unstable/cluster/Runner.ts +1 -1
  1338. package/src/unstable/cluster/RunnerAddress.ts +1 -1
  1339. package/src/unstable/cluster/RunnerHealth.ts +2 -2
  1340. package/src/unstable/cluster/RunnerServer.ts +11 -14
  1341. package/src/unstable/cluster/RunnerStorage.ts +9 -9
  1342. package/src/unstable/cluster/Runners.ts +28 -23
  1343. package/src/unstable/cluster/ShardId.ts +84 -74
  1344. package/src/unstable/cluster/Sharding.ts +83 -66
  1345. package/src/unstable/cluster/ShardingConfig.ts +39 -40
  1346. package/src/unstable/cluster/Snowflake.ts +2 -2
  1347. package/src/unstable/cluster/SqlMessageStorage.ts +29 -20
  1348. package/src/unstable/cluster/SqlRunnerStorage.ts +13 -7
  1349. package/src/unstable/cluster/internal/entityManager.ts +66 -46
  1350. package/src/unstable/cluster/internal/entityReaper.ts +4 -3
  1351. package/src/unstable/cluster/internal/resourceMap.ts +3 -3
  1352. package/src/unstable/cluster/internal/resourceRef.ts +2 -1
  1353. package/src/unstable/devtools/DevToolsClient.ts +26 -21
  1354. package/src/unstable/devtools/DevToolsSchema.ts +16 -3
  1355. package/src/unstable/encoding/Ndjson.ts +17 -17
  1356. package/src/unstable/encoding/Sse.ts +3 -5
  1357. package/src/unstable/eventlog/Event.ts +0 -8
  1358. package/src/unstable/eventlog/EventGroup.ts +0 -4
  1359. package/src/unstable/eventlog/EventJournal.ts +148 -80
  1360. package/src/unstable/eventlog/EventLog.ts +360 -233
  1361. package/src/unstable/eventlog/EventLogEncryption.ts +18 -32
  1362. package/src/unstable/eventlog/EventLogMessage.ts +277 -0
  1363. package/src/unstable/eventlog/EventLogRemote.ts +264 -410
  1364. package/src/unstable/eventlog/EventLogServer.ts +183 -275
  1365. package/src/unstable/eventlog/EventLogServerEncrypted.ts +206 -0
  1366. package/src/unstable/eventlog/EventLogServerUnencrypted.ts +749 -0
  1367. package/src/unstable/eventlog/EventLogSessionAuth.ts +437 -0
  1368. package/src/unstable/eventlog/{SqlEventLogJournal.ts → SqlEventJournal.ts} +38 -22
  1369. package/src/unstable/eventlog/{SqlEventLogServer.ts → SqlEventLogServerEncrypted.ts} +110 -43
  1370. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +506 -0
  1371. package/src/unstable/eventlog/index.ts +27 -2
  1372. package/src/unstable/eventlog/internal/identityRootSecretDerivation.ts +153 -0
  1373. package/src/unstable/http/Cookies.ts +94 -11
  1374. package/src/unstable/http/Etag.ts +7 -5
  1375. package/src/unstable/http/FetchHttpClient.ts +5 -5
  1376. package/src/unstable/http/Headers.ts +70 -20
  1377. package/src/unstable/http/HttpClient.ts +385 -42
  1378. package/src/unstable/http/HttpClientRequest.ts +151 -39
  1379. package/src/unstable/http/HttpClientResponse.ts +12 -6
  1380. package/src/unstable/http/HttpEffect.ts +86 -100
  1381. package/src/unstable/http/HttpIncomingMessage.ts +5 -4
  1382. package/src/unstable/http/HttpMethod.ts +16 -4
  1383. package/src/unstable/http/HttpMiddleware.ts +50 -50
  1384. package/src/unstable/http/HttpPlatform.ts +5 -4
  1385. package/src/unstable/http/HttpRouter.ts +46 -46
  1386. package/src/unstable/http/HttpServer.ts +5 -11
  1387. package/src/unstable/http/HttpServerError.ts +45 -47
  1388. package/src/unstable/http/HttpServerRequest.ts +414 -23
  1389. package/src/unstable/http/HttpServerRespondable.ts +6 -6
  1390. package/src/unstable/http/HttpServerResponse.ts +351 -13
  1391. package/src/unstable/http/HttpStaticServer.ts +456 -0
  1392. package/src/unstable/http/HttpTraceContext.ts +31 -17
  1393. package/src/unstable/http/Multipart.ts +10 -10
  1394. package/src/unstable/http/Url.ts +650 -0
  1395. package/src/unstable/http/UrlParams.ts +31 -19
  1396. package/src/unstable/http/index.ts +10 -0
  1397. package/src/unstable/http/internal/preResponseHandler.ts +15 -0
  1398. package/src/unstable/httpapi/HttpApi.ts +21 -21
  1399. package/src/unstable/httpapi/HttpApiBuilder.ts +128 -55
  1400. package/src/unstable/httpapi/HttpApiClient.ts +186 -34
  1401. package/src/unstable/httpapi/HttpApiEndpoint.ts +225 -113
  1402. package/src/unstable/httpapi/HttpApiError.ts +108 -30
  1403. package/src/unstable/httpapi/HttpApiGroup.ts +18 -17
  1404. package/src/unstable/httpapi/HttpApiMiddleware.ts +95 -33
  1405. package/src/unstable/httpapi/HttpApiScalar.ts +6 -0
  1406. package/src/unstable/httpapi/HttpApiSchema.ts +106 -11
  1407. package/src/unstable/httpapi/HttpApiSecurity.ts +13 -13
  1408. package/src/unstable/httpapi/OpenApi.ts +73 -72
  1409. package/src/unstable/observability/Otlp.ts +12 -12
  1410. package/src/unstable/observability/OtlpExporter.ts +14 -10
  1411. package/src/unstable/observability/OtlpLogger.ts +13 -9
  1412. package/src/unstable/observability/OtlpMetrics.ts +6 -6
  1413. package/src/unstable/observability/OtlpSerialization.ts +2 -2
  1414. package/src/unstable/observability/OtlpTracer.ts +14 -10
  1415. package/src/unstable/observability/PrometheusMetrics.ts +5 -5
  1416. package/src/unstable/observability/internal/protobuf.ts +4 -4
  1417. package/src/unstable/persistence/KeyValueStore.ts +230 -7
  1418. package/src/unstable/persistence/Persistable.ts +3 -3
  1419. package/src/unstable/persistence/PersistedCache.ts +35 -21
  1420. package/src/unstable/persistence/PersistedQueue.ts +28 -27
  1421. package/src/unstable/persistence/Persistence.ts +7 -7
  1422. package/src/unstable/persistence/RateLimiter.ts +7 -7
  1423. package/src/unstable/persistence/Redis.ts +2 -2
  1424. package/src/unstable/process/ChildProcess.ts +6 -208
  1425. package/src/unstable/process/ChildProcessSpawner.ts +120 -15
  1426. package/src/unstable/reactivity/Atom.ts +280 -124
  1427. package/src/unstable/reactivity/AtomHttpApi.ts +115 -59
  1428. package/src/unstable/reactivity/AtomRegistry.ts +70 -16
  1429. package/src/unstable/reactivity/AtomRpc.ts +82 -37
  1430. package/src/unstable/reactivity/Reactivity.ts +6 -6
  1431. package/src/unstable/reactivity/index.ts +2 -2
  1432. package/src/unstable/rpc/Rpc.ts +77 -32
  1433. package/src/unstable/rpc/RpcClient.ts +165 -145
  1434. package/src/unstable/rpc/RpcGroup.ts +51 -34
  1435. package/src/unstable/rpc/RpcMiddleware.ts +28 -22
  1436. package/src/unstable/rpc/RpcSchema.ts +24 -6
  1437. package/src/unstable/rpc/RpcSerialization.ts +97 -54
  1438. package/src/unstable/rpc/RpcServer.ts +97 -69
  1439. package/src/unstable/rpc/RpcWorker.ts +5 -5
  1440. package/src/unstable/rpc/Utils.ts +65 -5
  1441. package/src/unstable/schema/Model.ts +35 -6
  1442. package/src/unstable/schema/VariantSchema.ts +14 -27
  1443. package/src/unstable/socket/Socket.ts +42 -38
  1444. package/src/unstable/socket/SocketServer.ts +2 -2
  1445. package/src/unstable/sql/Migrator.ts +7 -5
  1446. package/src/unstable/sql/SqlClient.ts +13 -11
  1447. package/src/unstable/sql/SqlConnection.ts +2 -2
  1448. package/src/unstable/sql/SqlError.ts +365 -11
  1449. package/src/unstable/sql/SqlModel.ts +57 -85
  1450. package/src/unstable/sql/SqlResolver.ts +26 -16
  1451. package/src/unstable/sql/SqlSchema.ts +42 -26
  1452. package/src/unstable/sql/Statement.ts +2 -3
  1453. package/src/unstable/workers/Transferable.ts +17 -19
  1454. package/src/unstable/workers/Worker.ts +6 -5
  1455. package/src/unstable/workers/WorkerRunner.ts +2 -2
  1456. package/src/unstable/workflow/Activity.ts +27 -4
  1457. package/src/unstable/workflow/DurableClock.ts +11 -11
  1458. package/src/unstable/workflow/DurableDeferred.ts +16 -16
  1459. package/src/unstable/workflow/Workflow.ts +32 -25
  1460. package/src/unstable/workflow/WorkflowEngine.ts +239 -25
  1461. package/src/unstable/workflow/WorkflowProxyServer.ts +4 -4
  1462. package/dist/NullOr.d.ts +0 -149
  1463. package/dist/NullOr.d.ts.map +0 -1
  1464. package/dist/NullOr.js +0 -152
  1465. package/dist/NullOr.js.map +0 -1
  1466. package/dist/ServiceMap.d.ts +0 -1126
  1467. package/dist/ServiceMap.d.ts.map +0 -1
  1468. package/dist/ServiceMap.js.map +0 -1
  1469. package/dist/encoding/Base64.d.ts +0 -67
  1470. package/dist/encoding/Base64.d.ts.map +0 -1
  1471. package/dist/encoding/Base64.js +0 -146
  1472. package/dist/encoding/Base64.js.map +0 -1
  1473. package/dist/encoding/Base64Url.d.ts +0 -60
  1474. package/dist/encoding/Base64Url.d.ts.map +0 -1
  1475. package/dist/encoding/Base64Url.js +0 -89
  1476. package/dist/encoding/Base64Url.js.map +0 -1
  1477. package/dist/encoding/EncodingError.d.ts +0 -31
  1478. package/dist/encoding/EncodingError.d.ts.map +0 -1
  1479. package/dist/encoding/EncodingError.js +0 -22
  1480. package/dist/encoding/EncodingError.js.map +0 -1
  1481. package/dist/encoding/Hex.d.ts +0 -61
  1482. package/dist/encoding/Hex.d.ts.map +0 -1
  1483. package/dist/encoding/Hex.js +0 -115
  1484. package/dist/encoding/Hex.js.map +0 -1
  1485. package/dist/encoding/index.d.ts +0 -26
  1486. package/dist/encoding/index.d.ts.map +0 -1
  1487. package/dist/encoding/index.js +0 -27
  1488. package/dist/encoding/index.js.map +0 -1
  1489. package/dist/unstable/cli/internal/builtInFlags.d.ts +0 -7
  1490. package/dist/unstable/cli/internal/builtInFlags.d.ts.map +0 -1
  1491. package/dist/unstable/cli/internal/builtInFlags.js +0 -44
  1492. package/dist/unstable/cli/internal/builtInFlags.js.map +0 -1
  1493. package/dist/unstable/cli/internal/completions/CommandDescriptor.d.ts +0 -2
  1494. package/dist/unstable/cli/internal/completions/CommandDescriptor.d.ts.map +0 -1
  1495. package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +0 -1
  1496. package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
  1497. package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
  1498. package/dist/unstable/cli/internal/completions/Completions.js +0 -23
  1499. package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
  1500. package/dist/unstable/eventlog/SqlEventLogJournal.d.ts.map +0 -1
  1501. package/dist/unstable/eventlog/SqlEventLogJournal.js.map +0 -1
  1502. package/dist/unstable/eventlog/SqlEventLogServer.d.ts.map +0 -1
  1503. package/dist/unstable/eventlog/SqlEventLogServer.js.map +0 -1
  1504. package/src/NullOr.ts +0 -204
  1505. package/src/ServiceMap.ts +0 -1410
  1506. package/src/encoding/Base64.ts +0 -366
  1507. package/src/encoding/Base64Url.ts +0 -104
  1508. package/src/encoding/EncodingError.ts +0 -35
  1509. package/src/encoding/Hex.ts +0 -390
  1510. package/src/encoding/index.ts +0 -31
  1511. package/src/unstable/cli/internal/builtInFlags.ts +0 -78
  1512. package/src/unstable/cli/internal/completions/Completions.ts +0 -31
@@ -2,6 +2,7 @@ import * as Arr from "../Array.ts"
2
2
  import type * as Cause from "../Cause.ts"
3
3
  import type * as Clock from "../Clock.ts"
4
4
  import type * as Console from "../Console.ts"
5
+ import * as Context from "../Context.ts"
5
6
  import * as Duration from "../Duration.ts"
6
7
  import type * as Effect from "../Effect.ts"
7
8
  import * as Equal from "../Equal.ts"
@@ -14,6 +15,7 @@ import { constant, constFalse, constTrue, constUndefined, constVoid, dual, ident
14
15
  import * as Hash from "../Hash.ts"
15
16
  import { toJson, toStringUnknown } from "../Inspectable.ts"
16
17
  import * as Iterable from "../Iterable.ts"
18
+ import type * as _Latch from "../Latch.ts"
17
19
  import type * as Logger from "../Logger.ts"
18
20
  import type * as LogLevel from "../LogLevel.ts"
19
21
  import type * as Metric from "../Metric.ts"
@@ -23,23 +25,10 @@ import { pipeArguments } from "../Pipeable.ts"
23
25
  import type * as Predicate from "../Predicate.ts"
24
26
  import { hasProperty, isIterable, isString, isTagged } from "../Predicate.ts"
25
27
  import { currentFiberTypeId, redact } from "../Redactable.ts"
26
- import {
27
- CurrentConcurrency,
28
- CurrentLogAnnotations,
29
- CurrentLogLevel,
30
- CurrentLogSpans,
31
- CurrentStackFrame,
32
- MinimumLogLevel,
33
- type StackFrame,
34
- TracerEnabled,
35
- TracerSpanAnnotations,
36
- TracerSpanLinks,
37
- TracerTimingEnabled
38
- } from "../References.ts"
28
+ import type { StackFrame } from "../References.ts"
39
29
  import * as Result from "../Result.ts"
40
30
  import * as Scheduler from "../Scheduler.ts"
41
31
  import type * as Scope from "../Scope.ts"
42
- import * as ServiceMap from "../ServiceMap.ts"
43
32
  import * as Tracer from "../Tracer.ts"
44
33
  import type {
45
34
  Concurrency,
@@ -48,7 +37,9 @@ import type {
48
37
  ExcludeTag,
49
38
  ExtractReason,
50
39
  ExtractTag,
40
+ NarrowReason,
51
41
  NoInfer,
42
+ OmitReason,
52
43
  ReasonOf,
53
44
  ReasonTags,
54
45
  Simplify,
@@ -67,7 +58,6 @@ import {
67
58
  contA,
68
59
  contAll,
69
60
  contE,
70
- Die,
71
61
  evaluate,
72
62
  exitDie,
73
63
  exitFail,
@@ -93,6 +83,19 @@ import {
93
83
  } from "./core.ts"
94
84
  import * as doNotation from "./doNotation.ts"
95
85
  import * as InternalMetric from "./metric.ts"
86
+ import {
87
+ CurrentConcurrency,
88
+ CurrentErrorReporters,
89
+ CurrentLogAnnotations,
90
+ CurrentLogLevel,
91
+ CurrentLogSpans,
92
+ CurrentStackFrame,
93
+ MinimumLogLevel,
94
+ TracerEnabled,
95
+ TracerSpanAnnotations,
96
+ TracerSpanLinks,
97
+ TracerTimingEnabled
98
+ } from "./references.ts"
96
99
  import { addSpanStackTrace, type ErrorWithStackTraceLimit, makeStackCleaner } from "./tracer.ts"
97
100
  import { version } from "./version.ts"
98
101
 
@@ -212,17 +215,18 @@ export const causeInterruptors = <E>(self: Cause.Cause<E>): ReadonlySet<number>
212
215
  const emptySet = new Set<number>()
213
216
 
214
217
  /** @internal */
215
- export const hasInterruptsOnly = <E>(self: Cause.Cause<E>): boolean => self.reasons.every(isInterruptReason)
218
+ export const hasInterruptsOnly = <E>(self: Cause.Cause<E>): boolean =>
219
+ self.reasons.length > 0 && self.reasons.every(isInterruptReason)
216
220
 
217
221
  /** @internal */
218
222
  export const reasonAnnotations = <E>(
219
223
  self: Cause.Reason<E>
220
- ): ServiceMap.ServiceMap<never> => ServiceMap.makeUnsafe(self.annotations)
224
+ ): Context.Context<never> => Context.makeUnsafe(self.annotations)
221
225
 
222
226
  /** @internal */
223
227
  export const causeAnnotations = <E>(
224
228
  self: Cause.Cause<E>
225
- ): ServiceMap.ServiceMap<never> => {
229
+ ): Context.Context<never> => {
226
230
  const map = new Map<string, unknown>()
227
231
  for (const f of self.reasons) {
228
232
  if (f.annotations.size > 0) {
@@ -231,7 +235,7 @@ export const causeAnnotations = <E>(
231
235
  }
232
236
  }
233
237
  }
234
- return ServiceMap.makeUnsafe(map)
238
+ return Context.makeUnsafe(map)
235
239
  }
236
240
 
237
241
  /** @internal */
@@ -340,7 +344,8 @@ export const causePrettyErrors = <E>(self: Cause.Cause<E>): Array<Error> => {
340
344
  return errors
341
345
  }
342
346
 
343
- const causePrettyError = (
347
+ /** @internal */
348
+ export const causePrettyError = (
344
349
  original: Record<string, unknown> | Error,
345
350
  annotations?: ReadonlyMap<string, unknown>
346
351
  ): Error => {
@@ -488,32 +493,14 @@ const fiberIdStore = { id: 0 }
488
493
  /** @internal */
489
494
  export const getCurrentFiber = (): Fiber.Fiber<any, any> | undefined => (globalThis as any)[currentFiberTypeId]
490
495
 
491
- const keepAlive = (() => {
492
- let count = 0
493
- let running: ReturnType<typeof globalThis.setInterval> | undefined = undefined
494
- return ({
495
- increment() {
496
- count++
497
- running ??= globalThis.setInterval(constVoid, 2_147_483_647)
498
- },
499
- decrement() {
500
- count--
501
- if (count === 0 && running !== undefined) {
502
- globalThis.clearInterval(running)
503
- running = undefined
504
- }
505
- }
506
- })
507
- })()
508
-
509
496
  /** @internal */
510
497
  export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
511
498
  constructor(
512
- services: ServiceMap.ServiceMap<never>,
499
+ context: Context.Context<never>,
513
500
  interruptible: boolean = true
514
501
  ) {
515
502
  this[FiberTypeId] = fiberVariance as any
516
- this.setServices(services)
503
+ this.setContext(context)
517
504
  this.id = ++fiberIdStore.id
518
505
  this.currentOpCount = 0
519
506
  this.currentLoopCount = 0
@@ -540,8 +527,8 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
540
527
  _interruptedCause: Cause.Cause<never> | undefined
541
528
  _yielded: Exit.Exit<any, any> | (() => void) | undefined
542
529
 
543
- // set in setServices
544
- services!: ServiceMap.ServiceMap<never>
530
+ // set in setContext
531
+ context!: Context.Context<never>
545
532
  currentScheduler!: Scheduler.Scheduler
546
533
  currentTracerContext: Tracer.Tracer["context"]
547
534
  currentSpan: Tracer.AnySpan | undefined
@@ -550,9 +537,15 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
550
537
  currentStackFrame: StackFrame | undefined
551
538
  runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined
552
539
  maxOpsBeforeYield!: number
540
+ currentPreventYield!: boolean
541
+
542
+ _dispatcher: Scheduler.SchedulerDispatcher | undefined = undefined
543
+ get currentDispatcher(): Scheduler.SchedulerDispatcher {
544
+ return this._dispatcher ??= this.currentScheduler.makeDispatcher()
545
+ }
553
546
 
554
- getRef<X>(ref: ServiceMap.Reference<X>): X {
555
- return ServiceMap.getReferenceUnsafe(this.services, ref)
547
+ getRef<X>(ref: Context.Reference<X>): X {
548
+ return Context.getReferenceUnsafe(this.context, ref)
556
549
  }
557
550
  addObserver(cb: (exit: Exit.Exit<A, E>) => void): () => void {
558
551
  if (this._exit) {
@@ -567,13 +560,13 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
567
560
  }
568
561
  }
569
562
  }
570
- interruptUnsafe(fiberId?: number | undefined, annotations?: ServiceMap.ServiceMap<never> | undefined): void {
563
+ interruptUnsafe(fiberId?: number | undefined, annotations?: Context.Context<never> | undefined): void {
571
564
  if (this._exit) {
572
565
  return
573
566
  }
574
567
  let cause = causeInterrupt(fiberId)
575
568
  if (this.currentStackFrame) {
576
- cause = causeAnnotate(cause, ServiceMap.make(CauseStackTrace, this.currentStackFrame))
569
+ cause = causeAnnotate(cause, Context.make(CauseStackTrace, this.currentStackFrame))
577
570
  }
578
571
  if (annotations) {
579
572
  cause = causeAnnotate(cause, annotations)
@@ -589,7 +582,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
589
582
  return this._exit
590
583
  }
591
584
  evaluate(effect: Primitive): void {
592
- this.runtimeMetrics?.recordFiberStart(this.services)
585
+ this.runtimeMetrics?.recordFiberStart(this.context)
593
586
  if (this._exit) {
594
587
  return
595
588
  } else if (this._yielded !== undefined) {
@@ -610,7 +603,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
610
603
  }
611
604
 
612
605
  this._exit = exit
613
- this.runtimeMetrics?.recordFiberEnd(this.services, this._exit)
606
+ this.runtimeMetrics?.recordFiberEnd(this.context, this._exit)
614
607
  for (let i = 0; i < this._observers.length; i++) {
615
608
  this._observers[i](exit)
616
609
  }
@@ -628,6 +621,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
628
621
  this.currentOpCount++
629
622
  if (
630
623
  !yielding &&
624
+ !this.currentPreventYield &&
631
625
  this.currentScheduler.shouldYield(this as any)
632
626
  ) {
633
627
  yielding = true
@@ -683,16 +677,21 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
683
677
  pipe() {
684
678
  return pipeArguments(this, arguments)
685
679
  }
686
- setServices(services: ServiceMap.ServiceMap<never>): void {
687
- this.services = services
688
- this.currentScheduler = this.getRef(Scheduler.Scheduler)
689
- this.currentSpan = services.mapUnsafe.get(Tracer.ParentSpanKey)
680
+ setContext(context: Context.Context<never>): void {
681
+ this.context = context
682
+ const scheduler = this.getRef(Scheduler.Scheduler)
683
+ if (scheduler !== this.currentScheduler) {
684
+ this.currentScheduler = scheduler
685
+ this._dispatcher = undefined
686
+ }
687
+ this.currentSpan = context.mapUnsafe.get(Tracer.ParentSpanKey)
690
688
  this.currentLogLevel = this.getRef(CurrentLogLevel)
691
689
  this.minimumLogLevel = this.getRef(MinimumLogLevel)
692
- this.currentStackFrame = services.mapUnsafe.get(CurrentStackFrame.key)
690
+ this.currentStackFrame = context.mapUnsafe.get(CurrentStackFrame.key)
693
691
  this.maxOpsBeforeYield = this.getRef(Scheduler.MaxOpsBeforeYield)
694
- this.runtimeMetrics = services.mapUnsafe.get(InternalMetric.FiberRuntimeMetricsKey)
695
- const currentTracer = services.mapUnsafe.get(Tracer.TracerKey)
692
+ this.currentPreventYield = this.getRef(Scheduler.PreventSchedulerYield)
693
+ this.runtimeMetrics = context.mapUnsafe.get(InternalMetric.FiberRuntimeMetricsKey)
694
+ const currentTracer = context.mapUnsafe.get(Tracer.TracerKey)
696
695
  this.currentTracerContext = currentTracer ? currentTracer["context"] : undefined
697
696
  }
698
697
  get currentSpanLocal(): Tracer.Span | undefined {
@@ -710,7 +709,7 @@ const fiberStackAnnotations = (fiber: Fiber.Fiber<any, any>) => {
710
709
  if (!fiber.currentStackFrame) return undefined
711
710
  const annotations = new Map<string, unknown>()
712
711
  annotations.set(CauseStackTrace.key, fiber.currentStackFrame)
713
- return ServiceMap.makeUnsafe(annotations)
712
+ return Context.makeUnsafe(annotations)
714
713
  }
715
714
 
716
715
  const fiberInterruptChildren = (fiber: FiberImpl) => {
@@ -784,6 +783,7 @@ export const fiberJoinAll = <A extends Iterable<Fiber.Fiber<any, any>>>(self: A)
784
783
  > =>
785
784
  callback((resume) => {
786
785
  const fibers = Array.from(self)
786
+ if (fibers.length === 0) return resume(succeed(Arr.empty() as any))
787
787
  const out = new Array<any>(fibers.length) as Arr.NonEmptyArray<any>
788
788
  const cancels = Arr.empty<() => void>()
789
789
  let done = 0
@@ -812,13 +812,29 @@ export const fiberInterrupt = <A, E>(
812
812
 
813
813
  /** @internal */
814
814
  export const fiberInterruptAs: {
815
- (fiberId: number): <A, E>(self: Fiber.Fiber<A, E>) => Effect.Effect<void>
816
- <A, E>(self: Fiber.Fiber<A, E>, fiberId: number): Effect.Effect<void>
817
- } = dual(2, <A, E>(self: Fiber.Fiber<A, E>, fiberId: number): Effect.Effect<void> =>
818
- withFiber((parent) => {
819
- self.interruptUnsafe(fiberId, fiberStackAnnotations(parent))
820
- return asVoid(fiberAwait(self))
821
- }))
815
+ (
816
+ fiberId: number | undefined,
817
+ annotations?: Context.Context<never> | undefined
818
+ ): <A, E>(self: Fiber.Fiber<A, E>) => Effect.Effect<void>
819
+ <A, E>(
820
+ self: Fiber.Fiber<A, E>,
821
+ fiberId: number | undefined,
822
+ annotations?: Context.Context<never> | undefined
823
+ ): Effect.Effect<void>
824
+ } = dual(
825
+ (args) => hasProperty(args[0], FiberTypeId),
826
+ <A, E>(
827
+ self: Fiber.Fiber<A, E>,
828
+ fiberId: number | undefined,
829
+ annotations?: Context.Context<never> | undefined
830
+ ): Effect.Effect<void> =>
831
+ withFiber((parent) => {
832
+ let ann = fiberStackAnnotations(parent)
833
+ ann = ann && annotations ? Context.merge(ann, annotations) : ann ?? annotations
834
+ self.interruptUnsafe(fiberId, ann)
835
+ return asVoid(fiberAwait(self))
836
+ })
837
+ )
822
838
 
823
839
  /** @internal */
824
840
  export const fiberInterruptAll = <A extends Iterable<Fiber.Fiber<any, any>>>(
@@ -895,7 +911,7 @@ export const yieldNowWith: (priority?: number) => Effect.Effect<void> = makePrim
895
911
  op: "Yield",
896
912
  [evaluate](fiber) {
897
913
  let resumed = false
898
- fiber.currentScheduler.scheduleTask(() => {
914
+ fiber.currentDispatcher.scheduleTask(() => {
899
915
  if (resumed) return
900
916
  fiber.evaluate(exitVoid as any)
901
917
  }, this[args] ?? 0)
@@ -1018,10 +1034,8 @@ const callbackOptions: <A, E = never, R = never>(
1018
1034
  }, controller?.signal)
1019
1035
  if (yielded !== false) return yielded
1020
1036
  yielded = true
1021
- keepAlive.increment()
1022
1037
  fiber._yielded = () => {
1023
1038
  resumed = true
1024
- keepAlive.decrement()
1025
1039
  }
1026
1040
  if (controller === undefined && onCancel === undefined) {
1027
1041
  return Yield
@@ -1095,7 +1109,7 @@ export const fnUntraced: Effect.fn.Untraced = (
1095
1109
  body: Function,
1096
1110
  ...pipeables: Array<any>
1097
1111
  ) => {
1098
- return pipeables.length === 0
1112
+ const fn = pipeables.length === 0
1099
1113
  ? function(this: any) {
1100
1114
  return suspend(() => fromIteratorUnsafe(body.apply(this, arguments)))
1101
1115
  }
@@ -1106,8 +1120,15 @@ export const fnUntraced: Effect.fn.Untraced = (
1106
1120
  }
1107
1121
  return effect
1108
1122
  }
1123
+ return defineFunctionLength(body.length, fn)
1109
1124
  }
1110
1125
 
1126
+ const defineFunctionLength = <F extends Function>(length: number, fn: F): F =>
1127
+ Object.defineProperty(fn, "length", {
1128
+ value: length,
1129
+ configurable: true
1130
+ })
1131
+
1111
1132
  const fnStackCleaner = makeStackCleaner(2)
1112
1133
 
1113
1134
  /** @internal */
@@ -1148,7 +1169,7 @@ const makeFn = (
1148
1169
  ? bodyOrOptions
1149
1170
  : (pipeables.pop()!).bind(bodyOrOptions.self)
1150
1171
 
1151
- return function(this: any, ...args: Array<any>) {
1172
+ return defineFunctionLength(body.length, function(this: any, ...args: Array<any>) {
1152
1173
  let result = suspend(() => {
1153
1174
  const iter = body.apply(this, arguments)
1154
1175
  return isEffect(iter) ? iter : fromIteratorUnsafe(iter)
@@ -1178,7 +1199,7 @@ const makeFn = (
1178
1199
  }
1179
1200
  })
1180
1201
  )
1181
- }
1202
+ })
1182
1203
  }
1183
1204
 
1184
1205
  /** @internal */
@@ -1186,17 +1207,20 @@ export const fnUntracedEager: Effect.fn.Untraced = (
1186
1207
  body: Function,
1187
1208
  ...pipeables: Array<any>
1188
1209
  ) =>
1189
- pipeables.length === 0
1190
- ? function(this: any) {
1191
- return fromIteratorEagerUnsafe(() => body.apply(this, arguments))
1192
- }
1193
- : function(this: any) {
1194
- let effect = fromIteratorEagerUnsafe(() => body.apply(this, arguments))
1195
- for (const pipeable of pipeables) {
1196
- effect = pipeable(effect)
1210
+ defineFunctionLength(
1211
+ body.length,
1212
+ pipeables.length === 0
1213
+ ? function(this: any) {
1214
+ return fromIteratorEagerUnsafe(() => body.apply(this, arguments))
1197
1215
  }
1198
- return effect
1199
- }
1216
+ : function(this: any) {
1217
+ let effect = fromIteratorEagerUnsafe(() => body.apply(this, arguments))
1218
+ for (const pipeable of pipeables) {
1219
+ effect = pipeable(effect)
1220
+ }
1221
+ return effect
1222
+ }
1223
+ )
1200
1224
 
1201
1225
  const fromIteratorEagerUnsafe = (
1202
1226
  evaluate: () => Iterator<Effect.Yieldable<any, any, any, any>>
@@ -1945,61 +1969,46 @@ export const exitFindErrorOption = <A, E>(self: Exit.Exit<A, E>): Option.Option<
1945
1969
 
1946
1970
  /** @internal */
1947
1971
  export const service: {
1948
- <I, S>(service: ServiceMap.Service<I, S>): Effect.Effect<S, never, I>
1972
+ <I, S>(service: Context.Key<I, S>): Effect.Effect<S, never, I>
1949
1973
  } = fromYieldable as any
1950
1974
 
1951
1975
  /** @internal */
1952
1976
  export const serviceOption = <I, S>(
1953
- service: ServiceMap.Service<I, S>
1954
- ): Effect.Effect<Option.Option<S>> => withFiber((fiber) => succeed(ServiceMap.getOption(fiber.services, service)))
1977
+ service: Context.Key<I, S>
1978
+ ): Effect.Effect<Option.Option<S>> => withFiber((fiber) => succeed(Context.getOption(fiber.context, service)))
1955
1979
 
1956
1980
  /** @internal */
1957
1981
  export const serviceOptional = <I, S>(
1958
- service: ServiceMap.Service<I, S>
1982
+ service: Context.Key<I, S>
1959
1983
  ): Effect.Effect<S, Cause.NoSuchElementError> =>
1960
1984
  withFiber((fiber) =>
1961
- fiber.services.mapUnsafe.has(service.key)
1962
- ? succeed(ServiceMap.getUnsafe(fiber.services, service))
1985
+ fiber.context.mapUnsafe.has(service.key)
1986
+ ? succeed(Context.getUnsafe(fiber.context, service))
1963
1987
  : fail(new NoSuchElementError())
1964
1988
  )
1965
1989
 
1966
1990
  /** @internal */
1967
- export const updateServices: {
1991
+ export const updateContext: {
1968
1992
  <R2, R>(
1969
- f: (services: ServiceMap.ServiceMap<R2>) => ServiceMap.ServiceMap<NoInfer<R>>
1993
+ f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>
1970
1994
  ): <A, E>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2>
1971
1995
  <A, E, R, R2>(
1972
1996
  self: Effect.Effect<A, E, R>,
1973
- f: (services: ServiceMap.ServiceMap<R2>) => ServiceMap.ServiceMap<NoInfer<R>>
1997
+ f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>
1974
1998
  ): Effect.Effect<A, E, R2>
1975
1999
  } = dual(
1976
2000
  2,
1977
2001
  <A, E, R, R2>(
1978
2002
  self: Effect.Effect<A, E, R>,
1979
- f: (services: ServiceMap.ServiceMap<R2>) => ServiceMap.ServiceMap<NoInfer<R>>
2003
+ f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>
1980
2004
  ): Effect.Effect<A, E, R2> =>
1981
2005
  withFiber<A, E, R2>((fiber) => {
1982
- const prev = fiber.services as ServiceMap.ServiceMap<R2>
1983
- const nextServices = f(prev)
1984
- if (prev === nextServices) return self as any
1985
- fiber.setServices(nextServices)
1986
- const newServices = new Map<string, unknown>()
1987
- for (const [key, value] of fiber.services.mapUnsafe) {
1988
- if (!prev.mapUnsafe.has(key) || value !== prev.mapUnsafe.get(key)) {
1989
- newServices.set(key, value)
1990
- }
1991
- }
1992
- return onExitPrimitive(self as any, () => {
1993
- const map = new Map(fiber.services.mapUnsafe)
1994
- for (const [key, value] of newServices) {
1995
- if (value !== map.get(key)) continue
1996
- if (prev.mapUnsafe.has(key)) {
1997
- map.set(key, prev.mapUnsafe.get(key))
1998
- } else {
1999
- map.delete(key)
2000
- }
2001
- }
2002
- fiber.setServices(ServiceMap.makeUnsafe(map))
2006
+ const prevContext = fiber.context as Context.Context<R2>
2007
+ const nextContext = f(prevContext)
2008
+ if (prevContext === nextContext) return self as any
2009
+ fiber.setContext(nextContext)
2010
+ return onExitPrimitive(self, () => {
2011
+ fiber.setContext(prevContext)
2003
2012
  return undefined
2004
2013
  })
2005
2014
  })
@@ -2008,78 +2017,77 @@ export const updateServices: {
2008
2017
  /** @internal */
2009
2018
  export const updateService: {
2010
2019
  <I, A>(
2011
- service: ServiceMap.Service<I, A>,
2020
+ service: Context.Key<I, A>,
2012
2021
  f: (value: A) => A
2013
2022
  ): <XA, E, R>(self: Effect.Effect<XA, E, R>) => Effect.Effect<XA, E, R | I>
2014
2023
  <XA, E, R, I, A>(
2015
2024
  self: Effect.Effect<XA, E, R>,
2016
- service: ServiceMap.Service<I, A>,
2025
+ service: Context.Key<I, A>,
2017
2026
  f: (value: A) => A
2018
2027
  ): Effect.Effect<XA, E, R | I>
2019
2028
  } = dual(
2020
2029
  3,
2021
2030
  <XA, E, R, I, A>(
2022
2031
  self: Effect.Effect<XA, E, R>,
2023
- service: ServiceMap.Service<I, A>,
2032
+ service: Context.Key<I, A>,
2024
2033
  f: (value: A) => A
2025
2034
  ): Effect.Effect<XA, E, R | I> =>
2026
- withFiber((fiber) => {
2027
- const prev = ServiceMap.getUnsafe(fiber.services, service)
2035
+ updateContext(self, (s) => {
2036
+ const prev = Context.getUnsafe(s, service)
2028
2037
  const next = f(prev)
2029
- if (prev === next) return self
2030
- fiber.setServices(ServiceMap.add(fiber.services, service, next))
2031
- return onExit(self, () => sync(() => fiber.setServices(ServiceMap.add(fiber.services, service, prev))))
2038
+ if (prev === next) return s
2039
+ return Context.add(s, service, next)
2032
2040
  })
2033
2041
  )
2034
2042
 
2035
2043
  /** @internal */
2036
- export const services = <R = never>(): Effect.Effect<ServiceMap.ServiceMap<R>> => getServiceMap as any
2037
- const getServiceMap = withFiber((fiber) => succeed(fiber.services))
2044
+ export const context = <R = never>(): Effect.Effect<Context.Context<R>> => getContext as any
2045
+ const getContext = withFiber((fiber) => succeed(fiber.context))
2038
2046
 
2039
2047
  /** @internal */
2040
- export const servicesWith = <R, A, E, R2>(
2041
- f: (services: ServiceMap.ServiceMap<R>) => Effect.Effect<A, E, R2>
2042
- ): Effect.Effect<A, E, R | R2> => withFiber((fiber) => f(fiber.services as ServiceMap.ServiceMap<R>))
2048
+ export const contextWith = <R, A, E, R2>(
2049
+ f: (context: Context.Context<R>) => Effect.Effect<A, E, R2>
2050
+ ): Effect.Effect<A, E, R | R2> => withFiber((fiber) => f(fiber.context as Context.Context<R>))
2043
2051
 
2044
2052
  /** @internal */
2045
- export const provideServices: {
2053
+ export const provideContext: {
2046
2054
  <XR>(
2047
- services: ServiceMap.ServiceMap<XR>
2055
+ context: Context.Context<XR>
2048
2056
  ): <A, E, R>(
2049
2057
  self: Effect.Effect<A, E, R>
2050
2058
  ) => Effect.Effect<A, E, Exclude<R, XR>>
2051
2059
  <A, E, R, XR>(
2052
2060
  self: Effect.Effect<A, E, R>,
2053
- services: ServiceMap.ServiceMap<XR>
2061
+ context: Context.Context<XR>
2054
2062
  ): Effect.Effect<A, E, Exclude<R, XR>>
2055
2063
  } = dual(
2056
2064
  2,
2057
2065
  <A, E, R, XR>(
2058
2066
  self: Effect.Effect<A, E, R>,
2059
- services: ServiceMap.ServiceMap<XR>
2067
+ context: Context.Context<XR>
2060
2068
  ): Effect.Effect<A, E, Exclude<R, XR>> => {
2061
2069
  if (effectIsExit(self)) return self as any
2062
- return updateServices(self, ServiceMap.merge(services)) as any
2070
+ return updateContext(self, Context.merge(context)) as any
2063
2071
  }
2064
2072
  )
2065
2073
 
2066
2074
  /** @internal */
2067
2075
  export const provideService: {
2068
2076
  <I, S>(
2069
- service: ServiceMap.Service<I, S>
2077
+ service: Context.Key<I, S>
2070
2078
  ): {
2071
2079
  (implementation: S): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, I>>
2072
2080
  <A, E, R>(self: Effect.Effect<A, E, R>, implementation: S): Effect.Effect<A, E, Exclude<R, I>>
2073
2081
  }
2074
2082
  <I, S>(
2075
- key: ServiceMap.Service<I, S>,
2083
+ key: Context.Key<I, S>,
2076
2084
  implementation: S
2077
2085
  ): <A, E, R>(
2078
2086
  self: Effect.Effect<A, E, R>
2079
2087
  ) => Effect.Effect<A, E, Exclude<R, I>>
2080
2088
  <A, E, R, I, S>(
2081
2089
  self: Effect.Effect<A, E, R>,
2082
- service: ServiceMap.Service<I, S>,
2090
+ service: Context.Key<I, S>,
2083
2091
  implementation: S
2084
2092
  ): Effect.Effect<A, E, Exclude<R, I>>
2085
2093
  } = function(this: any) {
@@ -2092,34 +2100,33 @@ export const provideService: {
2092
2100
 
2093
2101
  const provideServiceImpl = <A, E, R, I, S>(
2094
2102
  self: Effect.Effect<A, E, R>,
2095
- service: ServiceMap.Service<I, S>,
2103
+ service: Context.Key<I, S>,
2096
2104
  implementation: S
2097
2105
  ): Effect.Effect<A, E, Exclude<R, I>> =>
2098
- withFiber((fiber) => {
2099
- const prev = ServiceMap.getOption(fiber.services, service)
2100
- if (prev._tag === "Some" && prev.value === implementation) return self
2101
- fiber.setServices(ServiceMap.add(fiber.services, service, implementation))
2102
- return onExit(self, () => sync(() => fiber.setServices(ServiceMap.addOrOmit(fiber.services, service, prev))))
2106
+ updateContext(self, (s) => {
2107
+ const prev = s.mapUnsafe.get(service.key)
2108
+ if (prev === implementation) return s
2109
+ return Context.add(s, service, implementation)
2103
2110
  }) as any
2104
2111
 
2105
2112
  /** @internal */
2106
2113
  export const provideServiceEffect: {
2107
2114
  <I, S, E2, R2>(
2108
- service: ServiceMap.Service<I, S>,
2115
+ service: Context.Key<I, S>,
2109
2116
  acquire: Effect.Effect<S, E2, R2>
2110
2117
  ): <A, E, R>(
2111
2118
  self: Effect.Effect<A, E, R>
2112
2119
  ) => Effect.Effect<A, E | E2, Exclude<R, I> | R2>
2113
2120
  <A, E, R, I, S, E2, R2>(
2114
2121
  self: Effect.Effect<A, E, R>,
2115
- service: ServiceMap.Service<I, S>,
2122
+ service: Context.Key<I, S>,
2116
2123
  acquire: Effect.Effect<S, E2, R2>
2117
2124
  ): Effect.Effect<A, E | E2, Exclude<R, I> | R2>
2118
2125
  } = dual(
2119
2126
  3,
2120
2127
  <A, E, R, I, S, E2, R2>(
2121
2128
  self: Effect.Effect<A, E, R>,
2122
- service: ServiceMap.Service<I, S>,
2129
+ service: Context.Key<I, S>,
2123
2130
  acquire: Effect.Effect<S, E2, R2>
2124
2131
  ): Effect.Effect<A, E | E2, Exclude<R, I> | R2> =>
2125
2132
  flatMap(acquire, (implementation) => provideService(self, service, implementation))
@@ -2203,19 +2210,12 @@ export const filterOrFail: {
2203
2210
  predicate: Predicate.Predicate<NoInfer<A>>,
2204
2211
  orFailWith: (a: NoInfer<A>) => E2
2205
2212
  ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E2 | E, R>
2206
- <A, B, X, E2>(
2207
- filter: Filter.Filter<NoInfer<A>, B, X>,
2208
- orFailWith: (x: X) => E2
2209
- ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E2 | E, R>
2210
2213
  <A, B extends A>(
2211
2214
  refinement: Predicate.Refinement<NoInfer<A>, B>
2212
2215
  ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, Cause.NoSuchElementError | E, R>
2213
2216
  <A>(
2214
2217
  predicate: Predicate.Predicate<NoInfer<A>>
2215
2218
  ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, Cause.NoSuchElementError | E, R>
2216
- <A, B, X>(
2217
- filter: Filter.Filter<NoInfer<A>, B, X>
2218
- ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, Cause.NoSuchElementError | E, R>
2219
2219
  <A, E, R, E2, B extends A>(
2220
2220
  self: Effect.Effect<A, E, R>,
2221
2221
  refinement: Predicate.Refinement<NoInfer<A>, B>,
@@ -2226,11 +2226,6 @@ export const filterOrFail: {
2226
2226
  predicate: Predicate.Predicate<NoInfer<A>>,
2227
2227
  orFailWith: (a: NoInfer<A>) => E2
2228
2228
  ): Effect.Effect<A, E2 | E, R>
2229
- <A, E, R, B, X, E2>(
2230
- self: Effect.Effect<A, E, R>,
2231
- filter: Filter.Filter<A, B, X>,
2232
- orFailWith: (x: X) => E2
2233
- ): Effect.Effect<B, E2 | E, R>
2234
2229
  <A, E, R, B extends A>(
2235
2230
  self: Effect.Effect<A, E, R>,
2236
2231
  refinement: Predicate.Refinement<NoInfer<A>, B>
@@ -2239,18 +2234,14 @@ export const filterOrFail: {
2239
2234
  self: Effect.Effect<A, E, R>,
2240
2235
  predicate: Predicate.Predicate<NoInfer<A>>
2241
2236
  ): Effect.Effect<A, E | Cause.NoSuchElementError, R>
2242
- <A, E, R, B, X>(
2243
- self: Effect.Effect<A, E, R>,
2244
- filter: Filter.Filter<A, B, X>
2245
- ): Effect.Effect<B, E | Cause.NoSuchElementError, R>
2246
2237
  } = dual((args) => isEffect(args[0]), <A, E, R, E2>(
2247
2238
  self: Effect.Effect<A, E, R>,
2248
- filter: Predicate.Predicate<NoInfer<A>> | Filter.Filter<A, any, any>,
2239
+ predicate: Predicate.Predicate<NoInfer<A>>,
2249
2240
  orFailWith?: (a: any) => E2
2250
2241
  ): Effect.Effect<any, E | E2 | Cause.NoSuchElementError, R> =>
2251
2242
  filterOrElse(
2252
2243
  self,
2253
- filter as any,
2244
+ predicate as any,
2254
2245
  orFailWith ? (a: any) => fail(orFailWith(a)) : () => fail(new NoSuchElementError() as E2)
2255
2246
  ))
2256
2247
 
@@ -2400,27 +2391,55 @@ const OnFailureProto = makePrimitiveProto({
2400
2391
 
2401
2392
  /** @internal */
2402
2393
  export const catchCauseIf: {
2403
- <E, Result extends Filter.ResultOrBool<Cause.Cause<any>>, B, E2, R2>(
2404
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
2405
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2394
+ <E, B, E2, R2>(
2395
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2396
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2397
+ ): <A, R>(
2398
+ self: Effect.Effect<A, E, R>
2399
+ ) => Effect.Effect<A | B, E | E2, R | R2>
2400
+ <A, E, R, B, E2, R2>(
2401
+ self: Effect.Effect<A, E, R>,
2402
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2403
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2404
+ ): Effect.Effect<A | B, E | E2, R | R2>
2405
+ } = dual(
2406
+ 3,
2407
+ <A, E, R, B, E2, R2>(
2408
+ self: Effect.Effect<A, E, R>,
2409
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2410
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2411
+ ): Effect.Effect<A | B, E | E2, R | R2> =>
2412
+ catchCause(self, (cause): Effect.Effect<B, E | E2, R2> => {
2413
+ if (!predicate(cause)) {
2414
+ return failCause(cause) as any
2415
+ }
2416
+ return internalCall(() => f(cause))
2417
+ })
2418
+ )
2419
+
2420
+ /** @internal */
2421
+ export const catchCauseFilter: {
2422
+ <E, B, E2, R2, EB, X extends Cause.Cause<any>>(
2423
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2424
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2406
2425
  ): <A, R>(
2407
2426
  self: Effect.Effect<A, E, R>
2408
- ) => Effect.Effect<A | B, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2>
2409
- <A, E, R, B, E2, R2, Result extends Filter.ResultOrBool<Cause.Cause<any>>>(
2427
+ ) => Effect.Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
2428
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2410
2429
  self: Effect.Effect<A, E, R>,
2411
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
2412
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2413
- ): Effect.Effect<A | B, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2>
2430
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2431
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2432
+ ): Effect.Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
2414
2433
  } = dual(
2415
2434
  3,
2416
- <A, E, R, B, E2, R2, Result extends Filter.ResultOrBool<Cause.Cause<any>>>(
2417
- self: Effect.Effect<A, E, R>,
2418
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
2419
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2420
- ): Effect.Effect<A | B, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2> =>
2421
- catchCause(self, (cause): Effect.Effect<B, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2> => {
2422
- const eb = Filter.apply(filter as any, cause)
2423
- return !Result.isFailure(eb) ? internalCall(() => f(eb.success as any, cause)) : failCause(eb.failure as any)
2435
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2436
+ self: Effect.Effect<A, E, R>,
2437
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2438
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2439
+ ): Effect.Effect<A | B, Cause.Cause.Error<X> | E2, R | R2> =>
2440
+ catchCause(self, (cause): Effect.Effect<B, Cause.Cause.Error<X> | E2, R2> => {
2441
+ const eb = filter(cause)
2442
+ return Result.isFailure(eb) ? failCause(eb.failure) : internalCall(() => f(eb.success, cause))
2424
2443
  })
2425
2444
  )
2426
2445
 
@@ -2438,7 +2457,7 @@ export const catch_: {
2438
2457
  <A, E, R, B, E2, R2>(
2439
2458
  self: Effect.Effect<A, E, R>,
2440
2459
  f: (a: NoInfer<E>) => Effect.Effect<B, E2, R2>
2441
- ): Effect.Effect<A | B, E2, R | R2> => catchCauseIf(self, findError as any, (e: any) => f(e)) as any
2460
+ ): Effect.Effect<A | B, E2, R | R2> => catchCauseFilter(self, findError as any, (e: any) => f(e)) as any
2442
2461
  )
2443
2462
 
2444
2463
  /** @internal */
@@ -2469,7 +2488,7 @@ export const catchDefect: {
2469
2488
  <A, E, R, B, E2, R2>(
2470
2489
  self: Effect.Effect<A, E, R>,
2471
2490
  f: (defect: unknown) => Effect.Effect<B, E2, R2>
2472
- ): Effect.Effect<A | B, E | E2, R | R2> => catchCauseIf(self, findDefect as any, f as any) as any
2491
+ ): Effect.Effect<A | B, E | E2, R | R2> => catchCauseFilter(self, findDefect as any, f as any) as any
2473
2492
  )
2474
2493
 
2475
2494
  /** @internal */
@@ -2492,32 +2511,56 @@ export const tapCause: {
2492
2511
 
2493
2512
  /** @internal */
2494
2513
  export const tapCauseIf: {
2495
- <E, Result extends Filter.ResultOrBool, B, E2, R2>(
2496
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
2497
- f: (a: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2514
+ <E, B, E2, R2>(
2515
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2516
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2498
2517
  ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2, R | R2>
2499
- <A, E, R, Result extends Filter.ResultOrBool, B, E2, R2>(
2518
+ <A, E, R, B, E2, R2>(
2500
2519
  self: Effect.Effect<A, E, R>,
2501
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
2502
- f: (a: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2520
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2521
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2503
2522
  ): Effect.Effect<A, E | E2, R | R2>
2504
2523
  } = dual(
2505
2524
  3,
2506
- <A, E, R, Result extends Filter.ResultOrBool, B, E2, R2>(
2525
+ <A, E, R, B, E2, R2>(
2507
2526
  self: Effect.Effect<A, E, R>,
2508
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
2509
- f: (a: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2527
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2528
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2510
2529
  ): Effect.Effect<A, E | E2, R | R2> =>
2511
2530
  catchCauseIf(
2512
2531
  self,
2513
- ((cause: Cause.Cause<E>) => {
2514
- const result = Filter.apply(filter as any, cause)
2515
- return Result.isFailure(result) ? Result.fail(cause) : result
2516
- }) as any,
2517
- (failure: any, cause: Cause.Cause<E>) => andThen(internalCall(() => f(failure, cause)), failCause(cause))
2532
+ predicate,
2533
+ (cause) => andThen(internalCall(() => f(cause)), failCause(cause))
2518
2534
  )
2519
2535
  )
2520
2536
 
2537
+ /** @internal */
2538
+ export const tapCauseFilter: {
2539
+ <E, B, E2, R2, EB, X extends Cause.Cause<any>>(
2540
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2541
+ f: (a: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2542
+ ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2, R | R2>
2543
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2544
+ self: Effect.Effect<A, E, R>,
2545
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2546
+ f: (a: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2547
+ ): Effect.Effect<A, E | E2, R | R2>
2548
+ } = dual(
2549
+ 3,
2550
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2551
+ self: Effect.Effect<A, E, R>,
2552
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2553
+ f: (a: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2554
+ ): Effect.Effect<A, E | E2, R | R2> =>
2555
+ catchCause(self, (cause) => {
2556
+ const result = filter(cause)
2557
+ if (Result.isFailure(result)) {
2558
+ return failCause(cause)
2559
+ }
2560
+ return andThen(internalCall(() => f(result.success, cause)), failCause(cause))
2561
+ })
2562
+ )
2563
+
2521
2564
  /** @internal */
2522
2565
  export const tapError: {
2523
2566
  <E, B, E2, R2>(
@@ -2532,7 +2575,7 @@ export const tapError: {
2532
2575
  <A, E, R, B, E2, R2>(
2533
2576
  self: Effect.Effect<A, E, R>,
2534
2577
  f: (e: NoInfer<E>) => Effect.Effect<B, E2, R2>
2535
- ): Effect.Effect<A, E | E2, R | R2> => tapCauseIf(self, findError as any, (e: any) => f(e)) as any
2578
+ ): Effect.Effect<A, E | E2, R | R2> => tapCauseFilter(self, findError as any, (e: any) => f(e)) as any
2536
2579
  )
2537
2580
 
2538
2581
  /** @internal */
@@ -2599,7 +2642,7 @@ export const tapDefect: {
2599
2642
  <A, E, R, B, E2, R2>(
2600
2643
  self: Effect.Effect<A, E, R>,
2601
2644
  f: (defect: unknown) => Effect.Effect<B, E2, R2>
2602
- ): Effect.Effect<A, E | E2, R | R2> => tapCauseIf(self, findDefect as any, (_: any) => f(_)) as any
2645
+ ): Effect.Effect<A, E | E2, R | R2> => tapCauseFilter(self, findDefect as any, (_: any) => f(_)) as any
2603
2646
  )
2604
2647
 
2605
2648
  /** @internal */
@@ -2609,10 +2652,10 @@ export const catchIf: {
2609
2652
  f: (e: EB) => Effect.Effect<A2, E2, R2>,
2610
2653
  orElse?: ((e: Exclude<E, EB>) => Effect.Effect<A3, E3, R3>) | undefined
2611
2654
  ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2612
- <E, Result extends Filter.ResultOrBool, A2, E2, R2, A3 = never, E3 = Filter.Fail<E, Result>, R3 = never>(
2613
- filter: Filter.OrPredicate<NoInfer<E>, Result>,
2614
- f: (e: Filter.Pass<E, Result>) => Effect.Effect<A2, E2, R2>,
2615
- orElse?: ((e: Filter.Fail<E, Result>) => Effect.Effect<A3, E3, R3>) | undefined
2655
+ <E, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
2656
+ predicate: Predicate.Predicate<NoInfer<E>>,
2657
+ f: (e: NoInfer<E>) => Effect.Effect<A2, E2, R2>,
2658
+ orElse?: ((e: NoInfer<E>) => Effect.Effect<A3, E3, R3>) | undefined
2616
2659
  ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2617
2660
  <A, E, R, EB extends E, A2, E2, R2, A3 = never, E3 = Exclude<E, EB>, R3 = never>(
2618
2661
  self: Effect.Effect<A, E, R>,
@@ -2620,28 +2663,59 @@ export const catchIf: {
2620
2663
  f: (e: EB) => Effect.Effect<A2, E2, R2>,
2621
2664
  orElse?: ((e: Exclude<E, EB>) => Effect.Effect<A3, E3, R3>) | undefined
2622
2665
  ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2623
- <A, E, R, Result extends Filter.ResultOrBool, A2, E2, R2, A3 = never, E3 = Filter.Fail<E, Result>, R3 = never>(
2666
+ <A, E, R, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
2667
+ self: Effect.Effect<A, E, R>,
2668
+ predicate: Predicate.Predicate<E>,
2669
+ f: (e: E) => Effect.Effect<A2, E2, R2>,
2670
+ orElse?: ((e: E) => Effect.Effect<A3, E3, R3>) | undefined
2671
+ ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2672
+ } = dual(
2673
+ (args) => isEffect(args[0]),
2674
+ <A, E, R, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
2675
+ self: Effect.Effect<A, E, R>,
2676
+ predicate: Predicate.Predicate<E>,
2677
+ f: (e: E) => Effect.Effect<A2, E2, R2>,
2678
+ orElse?: ((e: E) => Effect.Effect<A3, E3, R3>) | undefined
2679
+ ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3> =>
2680
+ catchCause(self, (cause): Effect.Effect<A2 | A3, E2 | E3, R2 | R3> => {
2681
+ const error = findError(cause)
2682
+ if (Result.isFailure(error)) return failCause(error.failure)
2683
+ if (!predicate(error.success)) {
2684
+ return orElse ? internalCall(() => orElse(error.success as any)) : failCause(cause as any as Cause.Cause<E3>)
2685
+ }
2686
+ return internalCall(() => f(error.success as any))
2687
+ })
2688
+ )
2689
+
2690
+ /** @internal */
2691
+ export const catchFilter: {
2692
+ <E, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
2693
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
2694
+ f: (e: EB) => Effect.Effect<A2, E2, R2>,
2695
+ orElse?: ((e: X) => Effect.Effect<A3, E3, R3>) | undefined
2696
+ ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2697
+ <A, E, R, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
2624
2698
  self: Effect.Effect<A, E, R>,
2625
- filter: Filter.OrPredicate<NoInfer<E>, Result>,
2626
- f: (e: Filter.Pass<E, Result>) => Effect.Effect<A2, E2, R2>,
2627
- orElse?: ((e: Filter.Fail<E, Result>) => Effect.Effect<A3, E3, R3>) | undefined
2699
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
2700
+ f: (e: EB) => Effect.Effect<A2, E2, R2>,
2701
+ orElse?: ((e: X) => Effect.Effect<A3, E3, R3>) | undefined
2628
2702
  ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2629
2703
  } = dual(
2630
2704
  (args) => isEffect(args[0]),
2631
2705
  <A, E, R, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
2632
2706
  self: Effect.Effect<A, E, R>,
2633
- filter: Filter.Filter<NoInfer<E>, EB, X> | Predicate.Predicate<NoInfer<E>>,
2707
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
2634
2708
  f: (e: EB) => Effect.Effect<A2, E2, R2>,
2635
2709
  orElse?: ((e: X) => Effect.Effect<A3, E3, R3>) | undefined
2636
2710
  ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3> =>
2637
2711
  catchCause(self, (cause): Effect.Effect<A2 | A3, E2 | E3, R2 | R3> => {
2638
2712
  const error = findError(cause)
2639
2713
  if (Result.isFailure(error)) return failCause(error.failure)
2640
- const result = Filter.apply(filter as any, error.success)
2714
+ const result = filter(error.success)
2641
2715
  if (Result.isFailure(result)) {
2642
2716
  return orElse ? internalCall(() => orElse(result.failure as any)) : failCause(cause as any as Cause.Cause<E3>)
2643
2717
  }
2644
- return internalCall(() => f(result.success as any))
2718
+ return internalCall(() => f(result.success))
2645
2719
  })
2646
2720
  )
2647
2721
 
@@ -2777,7 +2851,7 @@ export const catchTags: {
2777
2851
  >
2778
2852
  } = dual((args) => isEffect(args[0]), (self: Effect.Effect<any, any, any>, cases: Record<string, any>, orElse: any) => {
2779
2853
  let keys: Array<string>
2780
- return catchIf(
2854
+ return catchFilter(
2781
2855
  self,
2782
2856
  (e) => {
2783
2857
  keys ??= Object.keys(cases)
@@ -2787,7 +2861,7 @@ export const catchTags: {
2787
2861
  },
2788
2862
  (e: any) => internalCall(() => cases[e["_tag"] as string](e)),
2789
2863
  orElse
2790
- )
2864
+ ) as any
2791
2865
  })
2792
2866
 
2793
2867
  /** @internal */
@@ -2805,8 +2879,16 @@ export const catchReason: {
2805
2879
  >(
2806
2880
  errorTag: K,
2807
2881
  reasonTag: RK,
2808
- f: (reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>) => Effect.Effect<A2, E2, R2>,
2809
- orElse?: ((reasons: ExcludeReason<ExtractTag<NoInfer<E>, K>, RK>) => Effect.Effect<A3, E3, R3>) | undefined
2882
+ f: (
2883
+ reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
2884
+ error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
2885
+ ) => Effect.Effect<A2, E2, R2>,
2886
+ orElse?:
2887
+ | ((
2888
+ reasons: ExcludeReason<ExtractTag<NoInfer<E>, K>, RK>,
2889
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, RK>
2890
+ ) => Effect.Effect<A3, E3, R3>)
2891
+ | undefined
2810
2892
  ): <A, R>(
2811
2893
  self: Effect.Effect<A, E, R>
2812
2894
  ) => Effect.Effect<
@@ -2830,8 +2912,16 @@ export const catchReason: {
2830
2912
  self: Effect.Effect<A, E, R>,
2831
2913
  errorTag: K,
2832
2914
  reasonTag: RK,
2833
- f: (reason: ExtractReason<ExtractTag<E, K>, RK>) => Effect.Effect<A2, E2, R2>,
2834
- orElse?: ((reasons: ExcludeReason<ExtractTag<E, K>, RK>) => Effect.Effect<A3, E3, R3>) | undefined
2915
+ f: (
2916
+ reason: ExtractReason<ExtractTag<E, K>, RK>,
2917
+ error: NarrowReason<ExtractTag<E, K>, RK>
2918
+ ) => Effect.Effect<A2, E2, R2>,
2919
+ orElse?:
2920
+ | ((
2921
+ reasons: ExcludeReason<ExtractTag<E, K>, RK>,
2922
+ error: OmitReason<ExtractTag<E, K>, RK>
2923
+ ) => Effect.Effect<A3, E3, R3>)
2924
+ | undefined
2835
2925
  ): Effect.Effect<
2836
2926
  A | A2 | Exclude<A3, unassigned>,
2837
2927
  (A3 extends unassigned ? E : ExcludeTag<E, K>) | E2 | E3,
@@ -2855,8 +2945,13 @@ export const catchReason: {
2855
2945
  self: Effect.Effect<A, E, R>,
2856
2946
  errorTag: K,
2857
2947
  reasonTag: RK,
2858
- f: (reason: ExtractReason<ExtractTag<E, K>, RK>) => Effect.Effect<A2, E2, R2>,
2859
- orElse?: ((reasons: ExcludeReason<ExtractTag<E, K>, RK>) => Effect.Effect<A3, E3, R3>) | undefined
2948
+ f: (reason: ExtractReason<ExtractTag<E, K>, RK>, error: ExtractTag<E, K>) => Effect.Effect<A2, E2, R2>,
2949
+ orElse?:
2950
+ | ((
2951
+ reasons: ExcludeReason<ExtractTag<E, K>, RK>,
2952
+ error: OmitReason<ExtractTag<E, K>, RK>
2953
+ ) => Effect.Effect<A3, E3, R3>)
2954
+ | undefined
2860
2955
  ): Effect.Effect<
2861
2956
  A | A2 | Exclude<A3, unassigned>,
2862
2957
  (A3 extends unassigned ? E : ExcludeTag<E, K>) | E2 | E3,
@@ -2867,8 +2962,8 @@ export const catchReason: {
2867
2962
  ((e: any) => isTagged(e, errorTag) && hasProperty(e, "reason")) as any,
2868
2963
  (e: any): Effect.Effect<A2 | A3, E | E2 | E3, R2 | R3> => {
2869
2964
  const reason = e.reason as any
2870
- if (isTagged(reason, reasonTag)) return f(reason as any)
2871
- return orElse ? internalCall(() => orElse(reason)) : fail(e)
2965
+ if (isTagged(reason, reasonTag)) return f(reason as any, e)
2966
+ return orElse ? internalCall(() => orElse(reason, e)) : fail(e)
2872
2967
  }
2873
2968
  ) as any
2874
2969
  )
@@ -2880,7 +2975,8 @@ export const catchReasons: {
2880
2975
  E,
2881
2976
  Cases extends {
2882
2977
  [RK in ReasonTags<ExtractTag<NoInfer<E>, K>>]+?: (
2883
- reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>
2978
+ reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
2979
+ error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
2884
2980
  ) => Effect.Effect<any, any, any>
2885
2981
  },
2886
2982
  A2 = unassigned,
@@ -2891,7 +2987,8 @@ export const catchReasons: {
2891
2987
  cases: Cases,
2892
2988
  orElse?:
2893
2989
  | ((
2894
- reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
2990
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
2991
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
2895
2992
  ) => Effect.Effect<A2, E2, R2>)
2896
2993
  | undefined
2897
2994
  ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<
@@ -2918,7 +3015,8 @@ export const catchReasons: {
2918
3015
  K extends Tags<E>,
2919
3016
  Cases extends {
2920
3017
  [RK in ReasonTags<ExtractTag<E, K>>]+?: (
2921
- reason: ExtractReason<ExtractTag<E, K>, RK>
3018
+ reason: ExtractReason<ExtractTag<E, K>, RK>,
3019
+ error: NarrowReason<ExtractTag<E, K>, RK>
2922
3020
  ) => Effect.Effect<any, any, any>
2923
3021
  },
2924
3022
  A2 = unassigned,
@@ -2930,7 +3028,8 @@ export const catchReasons: {
2930
3028
  cases: Cases,
2931
3029
  orElse?:
2932
3030
  | ((
2933
- reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
3031
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
3032
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
2934
3033
  ) => Effect.Effect<A2, E2, R2>)
2935
3034
  | undefined
2936
3035
  ): Effect.Effect<
@@ -2963,9 +3062,9 @@ export const catchReasons: {
2963
3062
  const reason = e.reason
2964
3063
  keys ??= Object.keys(cases)
2965
3064
  if (keys.includes(reason._tag)) {
2966
- return internalCall(() => (cases as any)[reason._tag](reason))
3065
+ return internalCall(() => (cases as any)[reason._tag](reason, e))
2967
3066
  }
2968
- return orElse ? internalCall(() => orElse(reason)) : fail(e)
3067
+ return orElse ? internalCall(() => orElse(reason, e)) : fail(e)
2969
3068
  }
2970
3069
  )
2971
3070
  })
@@ -2998,7 +3097,7 @@ export const unwrapReason: {
2998
3097
  self: Effect.Effect<A, E, R>,
2999
3098
  errorTag: K
3000
3099
  ): Effect.Effect<A, ExcludeTag<E, K> | ReasonOf<ExtractTag<E, K>>, R> =>
3001
- catchIf(
3100
+ catchFilter(
3002
3101
  self,
3003
3102
  (e: any) => {
3004
3103
  if (isTagged(e, errorTag) && hasProperty(e, "reason")) {
@@ -3007,7 +3106,7 @@ export const unwrapReason: {
3007
3106
  return Result.fail(e)
3008
3107
  },
3009
3108
  fail as any
3010
- )
3109
+ ) as any
3011
3110
  )
3012
3111
 
3013
3112
  /** @internal */
@@ -3091,14 +3190,17 @@ export const eventually = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect
3091
3190
  /** @internal */
3092
3191
  export const ignore: <
3093
3192
  Arg extends Effect.Effect<any, any, any> | {
3094
- readonly log?: boolean | LogLevel.LogLevel | undefined
3193
+ readonly log?: boolean | LogLevel.Severity | undefined
3194
+ readonly message?: string | undefined
3095
3195
  } | undefined = {
3096
- readonly log?: boolean | LogLevel.LogLevel | undefined
3196
+ readonly log?: boolean | LogLevel.Severity | undefined
3197
+ readonly message?: string | undefined
3097
3198
  }
3098
3199
  >(
3099
3200
  effectOrOptions: Arg,
3100
3201
  options?: {
3101
- readonly log?: boolean | LogLevel.LogLevel | undefined
3202
+ readonly log?: boolean | LogLevel.Severity | undefined
3203
+ readonly message?: string | undefined
3102
3204
  } | undefined
3103
3205
  ) => [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ? Effect.Effect<void, never, _R>
3104
3206
  : <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<void, never, R> = dual(
@@ -3106,7 +3208,8 @@ export const ignore: <
3106
3208
  <A, E, R>(
3107
3209
  self: Effect.Effect<A, E, R>,
3108
3210
  options?: {
3109
- readonly log?: boolean | LogLevel.LogLevel | undefined
3211
+ readonly log?: boolean | LogLevel.Severity | undefined
3212
+ readonly message?: string | undefined
3110
3213
  } | undefined
3111
3214
  ): Effect.Effect<void, never, R> => {
3112
3215
  if (!options?.log) {
@@ -3116,7 +3219,11 @@ export const ignore: <
3116
3219
  return matchCauseEffect(self, {
3117
3220
  onFailure(cause) {
3118
3221
  const failure = findFail(cause)
3119
- return Result.isFailure(failure) ? failCause(failure.failure) : logEffect(cause)
3222
+ return Result.isFailure(failure)
3223
+ ? failCause(failure.failure)
3224
+ : options.message === undefined
3225
+ ? logEffect(cause)
3226
+ : logEffect(options.message, cause)
3120
3227
  },
3121
3228
  onSuccess: (_) => void_
3122
3229
  })
@@ -3126,14 +3233,17 @@ export const ignore: <
3126
3233
  /** @internal */
3127
3234
  export const ignoreCause: <
3128
3235
  Arg extends Effect.Effect<any, any, any> | {
3129
- readonly log?: boolean | LogLevel.LogLevel | undefined
3236
+ readonly log?: boolean | LogLevel.Severity | undefined
3237
+ readonly message?: string | undefined
3130
3238
  } | undefined = {
3131
- readonly log?: boolean | LogLevel.LogLevel | undefined
3239
+ readonly log?: boolean | LogLevel.Severity | undefined
3240
+ readonly message?: string | undefined
3132
3241
  }
3133
3242
  >(
3134
3243
  effectOrOptions: Arg,
3135
3244
  options?: {
3136
- readonly log?: boolean | LogLevel.LogLevel | undefined
3245
+ readonly log?: boolean | LogLevel.Severity | undefined
3246
+ readonly message?: string | undefined
3137
3247
  } | undefined
3138
3248
  ) => [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ? Effect.Effect<void, never, _R>
3139
3249
  : <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<void, never, R> = dual(
@@ -3141,14 +3251,18 @@ export const ignoreCause: <
3141
3251
  <A, E, R>(
3142
3252
  self: Effect.Effect<A, E, R>,
3143
3253
  options?: {
3144
- readonly log?: boolean | LogLevel.LogLevel | undefined
3254
+ readonly log?: boolean | LogLevel.Severity | undefined
3255
+ readonly message?: string | undefined
3145
3256
  } | undefined
3146
3257
  ): Effect.Effect<void, never, R> => {
3147
3258
  if (!options?.log) {
3148
3259
  return matchCauseEffect(self, { onFailure: (_) => void_, onSuccess: (_) => void_ })
3149
3260
  }
3150
3261
  const logEffect = logWithLevel(options.log === true ? undefined : options.log)
3151
- return matchCauseEffect(self, { onFailure: logEffect, onSuccess: (_) => void_ })
3262
+ return matchCauseEffect(self, {
3263
+ onFailure: (cause) => options.message === undefined ? logEffect(cause) : logEffect(options.message, cause),
3264
+ onSuccess: (_) => void_
3265
+ })
3152
3266
  }
3153
3267
  )
3154
3268
 
@@ -3403,33 +3517,33 @@ export const isSuccess: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect
3403
3517
  /** @internal */
3404
3518
  export const delay: {
3405
3519
  (
3406
- duration: Duration.DurationInput
3520
+ duration: Duration.Input
3407
3521
  ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
3408
3522
  <A, E, R>(
3409
3523
  self: Effect.Effect<A, E, R>,
3410
- duration: Duration.DurationInput
3524
+ duration: Duration.Input
3411
3525
  ): Effect.Effect<A, E, R>
3412
3526
  } = dual(
3413
3527
  2,
3414
3528
  <A, E, R>(
3415
3529
  self: Effect.Effect<A, E, R>,
3416
- duration: Duration.DurationInput
3530
+ duration: Duration.Input
3417
3531
  ): Effect.Effect<A, E, R> => andThen(sleep(duration), self)
3418
3532
  )
3419
3533
 
3420
3534
  /** @internal */
3421
3535
  export const timeoutOrElse: {
3422
3536
  <A2, E2, R2>(options: {
3423
- readonly duration: Duration.DurationInput
3424
- readonly onTimeout: LazyArg<Effect.Effect<A2, E2, R2>>
3537
+ readonly duration: Duration.Input
3538
+ readonly orElse: LazyArg<Effect.Effect<A2, E2, R2>>
3425
3539
  }): <A, E, R>(
3426
3540
  self: Effect.Effect<A, E, R>
3427
3541
  ) => Effect.Effect<A | A2, E | E2, R | R2>
3428
3542
  <A, E, R, A2, E2, R2>(
3429
3543
  self: Effect.Effect<A, E, R>,
3430
3544
  options: {
3431
- readonly duration: Duration.DurationInput
3432
- readonly onTimeout: LazyArg<Effect.Effect<A2, E2, R2>>
3545
+ readonly duration: Duration.Input
3546
+ readonly orElse: LazyArg<Effect.Effect<A2, E2, R2>>
3433
3547
  }
3434
3548
  ): Effect.Effect<A | A2, E | E2, R | R2>
3435
3549
  } = dual(
@@ -3437,55 +3551,55 @@ export const timeoutOrElse: {
3437
3551
  <A, E, R, A2, E2, R2>(
3438
3552
  self: Effect.Effect<A, E, R>,
3439
3553
  options: {
3440
- readonly duration: Duration.DurationInput
3441
- readonly onTimeout: LazyArg<Effect.Effect<A2, E2, R2>>
3554
+ readonly duration: Duration.Input
3555
+ readonly orElse: LazyArg<Effect.Effect<A2, E2, R2>>
3442
3556
  }
3443
3557
  ): Effect.Effect<A | A2, E | E2, R | R2> =>
3444
3558
  raceFirst(
3445
3559
  self,
3446
- flatMap(sleep(options.duration), options.onTimeout)
3560
+ flatMap(sleep(options.duration), options.orElse)
3447
3561
  )
3448
3562
  )
3449
3563
 
3450
3564
  /** @internal */
3451
3565
  export const timeout: {
3452
3566
  (
3453
- duration: Duration.DurationInput
3567
+ duration: Duration.Input
3454
3568
  ): <A, E, R>(
3455
3569
  self: Effect.Effect<A, E, R>
3456
3570
  ) => Effect.Effect<A, E | Cause.TimeoutError, R>
3457
3571
  <A, E, R>(
3458
3572
  self: Effect.Effect<A, E, R>,
3459
- duration: Duration.DurationInput
3573
+ duration: Duration.Input
3460
3574
  ): Effect.Effect<A, E | Cause.TimeoutError, R>
3461
3575
  } = dual(
3462
3576
  2,
3463
3577
  <A, E, R>(
3464
3578
  self: Effect.Effect<A, E, R>,
3465
- duration: Duration.DurationInput
3579
+ duration: Duration.Input
3466
3580
  ): Effect.Effect<A, E | TimeoutError, R> =>
3467
3581
  timeoutOrElse(self, {
3468
3582
  duration,
3469
- onTimeout: () => fail(new TimeoutError())
3583
+ orElse: () => fail(new TimeoutError())
3470
3584
  })
3471
3585
  )
3472
3586
 
3473
3587
  /** @internal */
3474
3588
  export const timeoutOption: {
3475
3589
  (
3476
- duration: Duration.DurationInput
3590
+ duration: Duration.Input
3477
3591
  ): <A, E, R>(
3478
3592
  self: Effect.Effect<A, E, R>
3479
3593
  ) => Effect.Effect<Option.Option<A>, E, R>
3480
3594
  <A, E, R>(
3481
3595
  self: Effect.Effect<A, E, R>,
3482
- duration: Duration.DurationInput
3596
+ duration: Duration.Input
3483
3597
  ): Effect.Effect<Option.Option<A>, E, R>
3484
3598
  } = dual(
3485
3599
  2,
3486
3600
  <A, E, R>(
3487
3601
  self: Effect.Effect<A, E, R>,
3488
- duration: Duration.DurationInput
3602
+ duration: Duration.Input
3489
3603
  ): Effect.Effect<Option.Option<A>, E, R> =>
3490
3604
  raceFirst(
3491
3605
  asSome(self),
@@ -3513,7 +3627,7 @@ export const ScopeTypeId = "~effect/Scope"
3513
3627
  export const ScopeCloseableTypeId = "~effect/Scope/Closeable"
3514
3628
 
3515
3629
  /** @internal */
3516
- export const scopeTag: ServiceMap.Service<Scope.Scope, Scope.Scope> = ServiceMap.Service<Scope.Scope>("effect/Scope")
3630
+ export const scopeTag: Context.Service<Scope.Scope, Scope.Scope> = Context.Service<Scope.Scope>("effect/Scope")
3517
3631
 
3518
3632
  /** @internal */
3519
3633
  export const scopeClose = <A, E>(self: Scope.Scope, exit_: Exit.Exit<A, E>) =>
@@ -3646,11 +3760,11 @@ export const provideScope: {
3646
3760
  /** @internal */
3647
3761
  export const scoped = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, Exclude<R, Scope.Scope>> =>
3648
3762
  withFiber((fiber) => {
3649
- const prev = ServiceMap.getOption(fiber.services, scopeTag)
3763
+ const prev = fiber.context
3650
3764
  const scope = scopeMakeUnsafe()
3651
- fiber.setServices(ServiceMap.add(fiber.services, scopeTag, scope))
3765
+ fiber.setContext(Context.add(fiber.context, scopeTag, scope))
3652
3766
  return onExitPrimitive(self, (exit) => {
3653
- fiber.setServices(ServiceMap.addOrOmit(fiber.services, scopeTag, prev))
3767
+ fiber.setContext(prev)
3654
3768
  return scopeCloseUnsafe(scope, exit)
3655
3769
  })
3656
3770
  }) as any
@@ -3677,13 +3791,22 @@ export const scopedWith = <A, E, R>(
3677
3791
  })
3678
3792
 
3679
3793
  /** @internal */
3680
- export const acquireRelease = <A, E, R>(
3794
+ export const acquireRelease = <A, E, R, R2>(
3681
3795
  acquire: Effect.Effect<A, E, R>,
3682
- release: (a: A, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<unknown>
3683
- ): Effect.Effect<A, E, R | Scope.Scope> =>
3684
- uninterruptible(
3685
- flatMap(scope, (scope) =>
3686
- tap(acquire, (a) => scopeAddFinalizerExit(scope, (exit) => internalCall(() => release(a, exit)))))
3796
+ release: (a: A, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<unknown, never, R2>,
3797
+ options?: { readonly interruptible?: boolean }
3798
+ ): Effect.Effect<A, E, R | R2 | Scope.Scope> =>
3799
+ contextWith((context: Context.Context<R2>) =>
3800
+ uninterruptibleMask((restore) =>
3801
+ flatMap(
3802
+ scope,
3803
+ (scope) =>
3804
+ tap(
3805
+ options?.interruptible ? restore(acquire) : acquire,
3806
+ (a) => scopeAddFinalizerExit(scope, (exit) => provideContext(release(a, exit), context))
3807
+ )
3808
+ )
3809
+ )
3687
3810
  )
3688
3811
 
3689
3812
  /** @internal */
@@ -3693,8 +3816,8 @@ export const addFinalizer = <R>(
3693
3816
  flatMap(
3694
3817
  scope,
3695
3818
  (scope) =>
3696
- servicesWith((services: ServiceMap.ServiceMap<R>) =>
3697
- scopeAddFinalizerExit(scope, (exit) => provideServices(finalizer(exit), services))
3819
+ contextWith((context: Context.Context<R>) =>
3820
+ scopeAddFinalizerExit(scope, (exit) => provideContext(finalizer(exit), context))
3698
3821
  )
3699
3822
  )
3700
3823
 
@@ -3758,34 +3881,51 @@ export const ensuring: {
3758
3881
 
3759
3882
  /** @internal */
3760
3883
  export const onExitIf: {
3761
- <A, E, XE, XR, Result extends Filter.ResultOrBool>(
3762
- filter: Filter.OrPredicate<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
3763
- f: (
3764
- pass: Filter.Pass<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
3765
- exit: Exit.Exit<NoInfer<A>, NoInfer<E>>
3766
- ) => Effect.Effect<void, XE, XR>
3884
+ <A, E, XE, XR>(
3885
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
3886
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3767
3887
  ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | XE, R | XR>
3768
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
3888
+ <A, E, R, XE, XR>(
3769
3889
  self: Effect.Effect<A, E, R>,
3770
- filter: Filter.OrPredicate<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
3771
- f: (
3772
- pass: Filter.Pass<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
3773
- exit: Exit.Exit<NoInfer<A>, NoInfer<E>>
3774
- ) => Effect.Effect<void, XE, XR>
3890
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
3891
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3775
3892
  ): Effect.Effect<A, E | XE, R | XR>
3776
3893
  } = dual(
3777
3894
  3,
3778
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
3895
+ <A, E, R, XE, XR>(
3779
3896
  self: Effect.Effect<A, E, R>,
3780
- filter: Filter.OrPredicate<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
3781
- f: (
3782
- pass: Filter.Pass<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
3783
- exit: Exit.Exit<NoInfer<A>, NoInfer<E>>
3784
- ) => Effect.Effect<void, XE, XR>
3897
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
3898
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3899
+ ): Effect.Effect<A, E | XE, R | XR> =>
3900
+ onExit(self, (exit) => {
3901
+ if (!predicate(exit)) {
3902
+ return void_
3903
+ }
3904
+ return f(exit)
3905
+ })
3906
+ )
3907
+
3908
+ /** @internal */
3909
+ export const onExitFilter: {
3910
+ <A, E, XE, XR, B, X>(
3911
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
3912
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3913
+ ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | XE, R | XR>
3914
+ <A, E, R, XE, XR, B, X>(
3915
+ self: Effect.Effect<A, E, R>,
3916
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
3917
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3918
+ ): Effect.Effect<A, E | XE, R | XR>
3919
+ } = dual(
3920
+ 3,
3921
+ <A, E, R, XE, XR, B, X>(
3922
+ self: Effect.Effect<A, E, R>,
3923
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
3924
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3785
3925
  ): Effect.Effect<A, E | XE, R | XR> =>
3786
3926
  onExit(self, (exit) => {
3787
- const pass = Filter.apply(filter, exit)
3788
- return Result.isFailure(pass) ? void_ : f(pass.success as any, exit)
3927
+ const b = filter(exit)
3928
+ return Result.isFailure(b) ? void_ : f(b.success, exit)
3789
3929
  })
3790
3930
  )
3791
3931
 
@@ -3803,37 +3943,66 @@ export const onError: {
3803
3943
  <A, E, R, XE, XR>(
3804
3944
  self: Effect.Effect<A, E, R>,
3805
3945
  f: (cause: Cause.Cause<NoInfer<E>>) => Effect.Effect<void, XE, XR>
3806
- ): Effect.Effect<A, E | XE, R | XR> => onExitIf(self, exitFilterCause as any, f as any) as any
3946
+ ): Effect.Effect<A, E | XE, R | XR> => onExitFilter(self, exitFilterCause as any, f as any) as any
3807
3947
  )
3808
3948
 
3809
3949
  /** @internal */
3810
3950
  export const onErrorIf: {
3811
- <E, Result extends Filter.ResultOrBool, XE, XR>(
3812
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
3813
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3951
+ <E, XE, XR>(
3952
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
3953
+ f: (cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3814
3954
  ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | XE, R | XR>
3815
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
3955
+ <A, E, R, XE, XR>(
3816
3956
  self: Effect.Effect<A, E, R>,
3817
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
3818
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3957
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
3958
+ f: (cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3819
3959
  ): Effect.Effect<A, E | XE, R | XR>
3820
3960
  } = dual(
3821
3961
  3,
3822
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
3962
+ <A, E, R, XE, XR>(
3823
3963
  self: Effect.Effect<A, E, R>,
3824
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
3825
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3964
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
3965
+ f: (cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3826
3966
  ): Effect.Effect<A, E | XE, R | XR> =>
3827
3967
  onExitIf(
3828
3968
  self,
3829
- ((exit: Exit.Exit<any, any>) => {
3830
- if (exit._tag !== "Failure") return Result.fail(exit)
3831
- return Filter.apply(filter, exit.cause)
3832
- }) as any,
3833
- (eb: any, exit: any) => f(eb, (exit as Exit.Failure<any, any>).cause)
3969
+ (exit): exit is Exit.Failure<A, E> => {
3970
+ if (exit._tag !== "Failure") {
3971
+ return false
3972
+ }
3973
+ return predicate(exit.cause)
3974
+ },
3975
+ (exit) => f((exit as Exit.Failure<A, E>).cause)
3834
3976
  ) as any
3835
3977
  )
3836
3978
 
3979
+ /** @internal */
3980
+ export const onErrorFilter: {
3981
+ <A, E, EB, X, XE, XR>(
3982
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
3983
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3984
+ ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | XE, R | XR>
3985
+ <A, E, R, EB, X, XE, XR>(
3986
+ self: Effect.Effect<A, E, R>,
3987
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
3988
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3989
+ ): Effect.Effect<A, E | XE, R | XR>
3990
+ } = dual(
3991
+ 3,
3992
+ <A, E, R, EB, X, XE, XR>(
3993
+ self: Effect.Effect<A, E, R>,
3994
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
3995
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3996
+ ): Effect.Effect<A, E | XE, R | XR> =>
3997
+ onExit(self, (exit) => {
3998
+ if (exit._tag !== "Failure") {
3999
+ return void_
4000
+ }
4001
+ const result = filter(exit.cause)
4002
+ return Result.isFailure(result) ? void_ : f(result.success, exit.cause)
4003
+ })
4004
+ )
4005
+
3837
4006
  /** @internal */
3838
4007
  export const onInterrupt: {
3839
4008
  <XE, XR>(
@@ -3848,8 +4017,7 @@ export const onInterrupt: {
3848
4017
  <A, E, R, XE, XR>(
3849
4018
  self: Effect.Effect<A, E, R>,
3850
4019
  finalizer: (interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>
3851
- ): Effect.Effect<A, E | XE, R | XR> =>
3852
- onErrorIf<E, Result.Result<Set<number>, Cause.Cause<E>>, XE, XR>(causeFilterInterruptors, finalizer)(self)
4020
+ ): Effect.Effect<A, E | XE, R | XR> => onErrorFilter(causeFilterInterruptors as any, finalizer)(self) as any
3853
4021
  )
3854
4022
 
3855
4023
  /** @internal */
@@ -3873,19 +4041,19 @@ export const acquireUseRelease = <Resource, E, R, A, E2, R2, E3, R3>(
3873
4041
 
3874
4042
  /** @internal */
3875
4043
  export const cachedInvalidateWithTTL: {
3876
- (timeToLive: Duration.DurationInput): <A, E, R>(
4044
+ (timeToLive: Duration.Input): <A, E, R>(
3877
4045
  self: Effect.Effect<A, E, R>
3878
4046
  ) => Effect.Effect<[Effect.Effect<A, E, R>, Effect.Effect<void>]>
3879
4047
  <A, E, R>(
3880
4048
  self: Effect.Effect<A, E, R>,
3881
- timeToLive: Duration.DurationInput
4049
+ timeToLive: Duration.Input
3882
4050
  ): Effect.Effect<[Effect.Effect<A, E, R>, Effect.Effect<void>]>
3883
4051
  } = dual(2, <A, E, R>(
3884
4052
  self: Effect.Effect<A, E, R>,
3885
- ttl: Duration.DurationInput
4053
+ ttl: Duration.Input
3886
4054
  ): Effect.Effect<[Effect.Effect<A, E, R>, Effect.Effect<void>]> =>
3887
4055
  sync(() => {
3888
- const ttlMillis = Duration.toMillis(Duration.fromDurationInputUnsafe(ttl))
4056
+ const ttlMillis = Duration.toMillis(Duration.fromInputUnsafe(ttl))
3889
4057
  const isFinite = Number.isFinite(ttlMillis)
3890
4058
  const latch = makeLatchUnsafe(false)
3891
4059
  let expiresAt = 0
@@ -3894,7 +4062,8 @@ export const cachedInvalidateWithTTL: {
3894
4062
  const wait = flatMap(latch.await, () => exit!)
3895
4063
  return [
3896
4064
  withFiber((fiber) => {
3897
- const now = isFinite ? fiber.getRef(ClockRef).currentTimeMillisUnsafe() : 0
4065
+ const clock = fiber.getRef(ClockRef)
4066
+ const now = isFinite ? clock.currentTimeMillisUnsafe() : 0
3898
4067
  if (running || now < expiresAt) return exit ?? wait
3899
4068
  running = true
3900
4069
  latch.closeUnsafe()
@@ -3902,7 +4071,7 @@ export const cachedInvalidateWithTTL: {
3902
4071
  return onExit(self, (exit_) =>
3903
4072
  sync(() => {
3904
4073
  running = false
3905
- expiresAt = now + ttlMillis
4074
+ expiresAt = clock.currentTimeMillisUnsafe() + ttlMillis
3906
4075
  exit = exit_
3907
4076
  latch.openUnsafe()
3908
4077
  }))
@@ -3918,17 +4087,17 @@ export const cachedInvalidateWithTTL: {
3918
4087
  /** @internal */
3919
4088
  export const cachedWithTTL: {
3920
4089
  (
3921
- timeToLive: Duration.DurationInput
4090
+ timeToLive: Duration.Input
3922
4091
  ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Effect.Effect<A, E, R>>
3923
4092
  <A, E, R>(
3924
4093
  self: Effect.Effect<A, E, R>,
3925
- timeToLive: Duration.DurationInput
4094
+ timeToLive: Duration.Input
3926
4095
  ): Effect.Effect<Effect.Effect<A, E, R>>
3927
4096
  } = dual(
3928
4097
  2,
3929
4098
  <A, E, R>(
3930
4099
  self: Effect.Effect<A, E, R>,
3931
- timeToLive: Duration.DurationInput
4100
+ timeToLive: Duration.Input
3932
4101
  ): Effect.Effect<Effect.Effect<A, E, R>> => map(cachedInvalidateWithTTL(self, timeToLive), (tuple) => tuple[0])
3933
4102
  )
3934
4103
 
@@ -4074,54 +4243,191 @@ export const partition: {
4074
4243
  ): Effect.Effect<[excluded: Array<E>, satisfying: Array<B>], never, R> =>
4075
4244
  map(
4076
4245
  forEach(elements, (a, i) => result(f(a, i)), options),
4077
- (results) => Arr.partitionMap(results, identity)
4246
+ (results) => Arr.partition(results, identity)
4078
4247
  )
4079
4248
  )
4080
4249
 
4081
4250
  /** @internal */
4082
- export const whileLoop: <A, E, R>(options: {
4083
- readonly while: LazyArg<boolean>
4084
- readonly body: LazyArg<Effect.Effect<A, E, R>>
4085
- readonly step: (a: A) => void
4086
- }) => Effect.Effect<void, E, R> = makePrimitive({
4087
- op: "While",
4088
- [contA](value, fiber) {
4089
- this[args].step(value)
4090
- if (this[args].while()) {
4091
- fiber._stack.push(this)
4092
- return this[args].body()
4093
- }
4094
- return exitVoid
4095
- },
4096
- [evaluate](fiber) {
4097
- if (this[args].while()) {
4098
- fiber._stack.push(this)
4099
- return this[args].body()
4251
+ export const validate: {
4252
+ <A, B, E, R>(
4253
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4254
+ options?: {
4255
+ readonly concurrency?: Concurrency | undefined
4256
+ readonly discard?: false | undefined
4257
+ } | undefined
4258
+ ): (elements: Iterable<A>) => Effect.Effect<Array<B>, Arr.NonEmptyArray<E>, R>
4259
+ <A, B, E, R>(
4260
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4261
+ options: {
4262
+ readonly concurrency?: Concurrency | undefined
4263
+ readonly discard: true
4100
4264
  }
4101
- return exitVoid
4102
- }
4103
- })
4104
-
4105
- /** @internal */
4106
- export const forEach: {
4107
- <B, E, R, S extends Iterable<any>, const Discard extends boolean = false>(
4108
- f: (a: Arr.ReadonlyArray.Infer<S>, i: number) => Effect.Effect<B, E, R>,
4265
+ ): (elements: Iterable<A>) => Effect.Effect<void, Arr.NonEmptyArray<E>, R>
4266
+ <A, B, E, R>(
4267
+ elements: Iterable<A>,
4268
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4109
4269
  options?: {
4110
4270
  readonly concurrency?: Concurrency | undefined
4111
- readonly discard?: Discard | undefined
4271
+ readonly discard?: false | undefined
4112
4272
  } | undefined
4113
- ): (
4114
- self: S
4115
- ) => Effect.Effect<Discard extends false ? Arr.ReadonlyArray.With<S, B> : void, E, R>
4116
- <B, E, R, S extends Iterable<any>, const Discard extends boolean = false>(
4117
- self: S,
4118
- f: (a: Arr.ReadonlyArray.Infer<S>, i: number) => Effect.Effect<B, E, R>,
4273
+ ): Effect.Effect<Array<B>, Arr.NonEmptyArray<E>, R>
4274
+ <A, B, E, R>(
4275
+ elements: Iterable<A>,
4276
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4277
+ options: {
4278
+ readonly concurrency?: Concurrency | undefined
4279
+ readonly discard: true
4280
+ }
4281
+ ): Effect.Effect<void, Arr.NonEmptyArray<E>, R>
4282
+ } = dual(
4283
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4284
+ <A, B, E, R>(
4285
+ elements: Iterable<A>,
4286
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4119
4287
  options?: {
4120
4288
  readonly concurrency?: Concurrency | undefined
4121
- readonly discard?: Discard | undefined
4289
+ readonly discard?: boolean | undefined
4122
4290
  } | undefined
4123
- ): Effect.Effect<Discard extends false ? Arr.ReadonlyArray.With<S, B> : void, E, R>
4124
- } = dual((args) => typeof args[1] === "function", <A, B, E, R>(
4291
+ ): Effect.Effect<Array<B> | void, Arr.NonEmptyArray<E>, R> =>
4292
+ flatMap(
4293
+ partition(elements, f, { concurrency: options?.concurrency }),
4294
+ ([excluded, satisfying]) => {
4295
+ if (Arr.isArrayNonEmpty(excluded)) {
4296
+ return fail(excluded)
4297
+ }
4298
+ return options?.discard ? void_ : succeed(satisfying)
4299
+ }
4300
+ )
4301
+ )
4302
+
4303
+ /** @internal */
4304
+ export const findFirst: {
4305
+ <A, E, R>(
4306
+ predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
4307
+ ): (elements: Iterable<A>) => Effect.Effect<Option.Option<A>, E, R>
4308
+ <A, E, R>(
4309
+ elements: Iterable<A>,
4310
+ predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
4311
+ ): Effect.Effect<Option.Option<A>, E, R>
4312
+ } = dual(
4313
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4314
+ <A, E, R>(
4315
+ elements: Iterable<A>,
4316
+ predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>
4317
+ ): Effect.Effect<Option.Option<A>, E, R> =>
4318
+ suspend(() => {
4319
+ const iterator = elements[Symbol.iterator]()
4320
+ const next = iterator.next()
4321
+ if (!next.done) {
4322
+ return findFirstLoop(iterator, 0, predicate, next.value)
4323
+ }
4324
+ return succeed(Option.none())
4325
+ })
4326
+ )
4327
+
4328
+ const findFirstLoop = <A, E, R>(
4329
+ iterator: Iterator<A>,
4330
+ index: number,
4331
+ predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>,
4332
+ value: A
4333
+ ): Effect.Effect<Option.Option<A>, E, R> =>
4334
+ flatMap(predicate(value, index), (keep) => {
4335
+ if (keep) {
4336
+ return succeed(Option.some(value))
4337
+ }
4338
+ const next = iterator.next()
4339
+ if (!next.done) {
4340
+ return findFirstLoop(iterator, index + 1, predicate, next.value)
4341
+ }
4342
+ return succeed(Option.none())
4343
+ })
4344
+
4345
+ /** @internal */
4346
+ export const findFirstFilter: {
4347
+ <A, B, X, E, R>(
4348
+ filter: (input: NoInfer<A>, i: number) => Effect.Effect<Result.Result<B, X>, E, R>
4349
+ ): (elements: Iterable<A>) => Effect.Effect<Option.Option<B>, E, R>
4350
+ <A, B, X, E, R>(
4351
+ elements: Iterable<A>,
4352
+ filter: (input: NoInfer<A>, i: number) => Effect.Effect<Result.Result<B, X>, E, R>
4353
+ ): Effect.Effect<Option.Option<B>, E, R>
4354
+ } = dual(
4355
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4356
+ <A, B, X, E, R>(
4357
+ elements: Iterable<A>,
4358
+ filter: (input: A, i: number) => Effect.Effect<Result.Result<B, X>, E, R>
4359
+ ): Effect.Effect<Option.Option<B>, E, R> =>
4360
+ suspend(() => {
4361
+ const iterator = elements[Symbol.iterator]()
4362
+ const next = iterator.next()
4363
+ if (!next.done) {
4364
+ return findFirstFilterLoop(iterator, 0, filter, next.value)
4365
+ }
4366
+ return succeed(Option.none())
4367
+ })
4368
+ )
4369
+
4370
+ const findFirstFilterLoop = <A, B, X, E, R>(
4371
+ iterator: Iterator<A>,
4372
+ index: number,
4373
+ filter: (input: A, i: number) => Effect.Effect<Result.Result<B, X>, E, R>,
4374
+ value: A
4375
+ ): Effect.Effect<Option.Option<B>, E, R> =>
4376
+ flatMap(filter(value, index), (result) => {
4377
+ if (Result.isSuccess(result)) {
4378
+ return succeed(Option.some(result.success))
4379
+ }
4380
+ const next = iterator.next()
4381
+ if (!next.done) {
4382
+ return findFirstFilterLoop(iterator, index + 1, filter, next.value)
4383
+ }
4384
+ return succeed(Option.none())
4385
+ })
4386
+
4387
+ /** @internal */
4388
+ export const whileLoop: <A, E, R>(options: {
4389
+ readonly while: LazyArg<boolean>
4390
+ readonly body: LazyArg<Effect.Effect<A, E, R>>
4391
+ readonly step: (a: A) => void
4392
+ }) => Effect.Effect<void, E, R> = makePrimitive({
4393
+ op: "While",
4394
+ [contA](value, fiber) {
4395
+ this[args].step(value)
4396
+ if (this[args].while()) {
4397
+ fiber._stack.push(this)
4398
+ return this[args].body()
4399
+ }
4400
+ return exitVoid
4401
+ },
4402
+ [evaluate](fiber) {
4403
+ if (this[args].while()) {
4404
+ fiber._stack.push(this)
4405
+ return this[args].body()
4406
+ }
4407
+ return exitVoid
4408
+ }
4409
+ })
4410
+
4411
+ /** @internal */
4412
+ export const forEach: {
4413
+ <B, E, R, S extends Iterable<any>, const Discard extends boolean = false>(
4414
+ f: (a: Arr.ReadonlyArray.Infer<S>, i: number) => Effect.Effect<B, E, R>,
4415
+ options?: {
4416
+ readonly concurrency?: Concurrency | undefined
4417
+ readonly discard?: Discard | undefined
4418
+ } | undefined
4419
+ ): (
4420
+ self: S
4421
+ ) => Effect.Effect<Discard extends false ? Arr.ReadonlyArray.With<S, B> : void, E, R>
4422
+ <B, E, R, S extends Iterable<any>, const Discard extends boolean = false>(
4423
+ self: S,
4424
+ f: (a: Arr.ReadonlyArray.Infer<S>, i: number) => Effect.Effect<B, E, R>,
4425
+ options?: {
4426
+ readonly concurrency?: Concurrency | undefined
4427
+ readonly discard?: Discard | undefined
4428
+ } | undefined
4429
+ ): Effect.Effect<Discard extends false ? Arr.ReadonlyArray.With<S, B> : void, E, R>
4430
+ } = dual((args) => typeof args[1] === "function", <A, B, E, R>(
4125
4431
  iterable: Iterable<A>,
4126
4432
  f: (a: A, index: number) => Effect.Effect<B, E, R>,
4127
4433
  options?: {
@@ -4150,72 +4456,8 @@ export const forEach: {
4150
4456
  const out: Array<B> | undefined = options?.discard
4151
4457
  ? undefined
4152
4458
  : new Array(length)
4153
- let index = 0
4154
- const annotations = fiberStackAnnotations(parent)
4155
-
4156
- return callback((resume) => {
4157
- const fibers = new Set<Fiber.Fiber<unknown, unknown>>()
4158
- const failures: Array<Cause.Reason<E>> = []
4159
- let failed = false
4160
- let inProgress = 0
4161
- let doneCount = 0
4162
- let pumping = false
4163
- let interrupted = false
4164
- function pump() {
4165
- pumping = true
4166
- while (inProgress < concurrency && index < length) {
4167
- const currentIndex = index
4168
- const item = items[currentIndex]
4169
- index++
4170
- inProgress++
4171
- try {
4172
- const child = forkUnsafe(parent, f(item, currentIndex), true, true, "inherit")
4173
- fibers.add(child)
4174
- child.addObserver((exit) => {
4175
- if (interrupted) {
4176
- return
4177
- }
4178
- fibers.delete(child)
4179
- if (exit._tag === "Failure") {
4180
- if (!failed) {
4181
- failed = true
4182
- length = index
4183
- failures.push(...exit.cause.reasons)
4184
- fibers.forEach((fiber) => fiber.interruptUnsafe(parent.id, annotations))
4185
- } else {
4186
- for (const f of exit.cause.reasons) {
4187
- if (f._tag === "Interrupt") continue
4188
- failures.push(f)
4189
- }
4190
- }
4191
- } else if (out !== undefined) {
4192
- out[currentIndex] = exit.value
4193
- }
4194
- doneCount++
4195
- inProgress--
4196
- if (doneCount === length) {
4197
- resume(failures.length > 0 ? exitFailCause(causeFromReasons(failures)) : succeed(out))
4198
- } else if (!pumping && !failed && inProgress < concurrency) {
4199
- pump()
4200
- }
4201
- })
4202
- } catch (err) {
4203
- failed = true
4204
- length = index
4205
- failures.push(new Die(err))
4206
- fibers.forEach((fiber) => fiber.interruptUnsafe(parent.id, annotations))
4207
- }
4208
- }
4209
- pumping = false
4210
- }
4211
- pump()
4212
-
4213
- return suspend(() => {
4214
- interrupted = true
4215
- index = length
4216
- return fiberInterruptAll(fibers)
4217
- })
4218
- })
4459
+ const eff = forEachConcurrent({ f, out }, items, { concurrency })
4460
+ return eff ? as(eff, out as any) : succeed(out as any)
4219
4461
  }))
4220
4462
 
4221
4463
  const forEachSequential = <A, B, E, R>(
@@ -4243,39 +4485,273 @@ const forEachSequential = <A, B, E, R>(
4243
4485
  )
4244
4486
  })
4245
4487
 
4488
+ const iterateEagerImpl = <S, A, X, E, R, E2>(options: {
4489
+ readonly onItem: (state: S, item: A, index: number) => Effect.Effect<X, E, R>
4490
+ readonly step: (state: NoInfer<S>, item: A, exit: Exit.Exit<X, E>, index: number) => Exit.Exit<void, E2> | void
4491
+ }): (
4492
+ initialState: S,
4493
+ items: ReadonlyArray<A>,
4494
+ options?: {
4495
+ readonly concurrency?: number | undefined
4496
+ readonly start?: number | undefined
4497
+ readonly end?: number | undefined
4498
+ }
4499
+ ) => Effect.Effect<void, E | E2, R> | undefined => {
4500
+ const onItem = options.onItem
4501
+ const step = options.step
4502
+
4503
+ return (
4504
+ state: S,
4505
+ items: ReadonlyArray<A>,
4506
+ opts: {
4507
+ readonly concurrency?: number | undefined
4508
+ readonly start?: number | undefined
4509
+ readonly end?: number | undefined
4510
+ } | undefined
4511
+ ): Effect.Effect<void, E | E2, R> | undefined => {
4512
+ let index = opts?.start ?? 0
4513
+ const end = opts?.end ?? items.length
4514
+ const concurrency = opts?.concurrency ?? 1
4515
+ let done = false
4516
+ let parentFiber: Fiber.Fiber<any, any> | undefined
4517
+ let fibers: Set<Fiber.Fiber<any, any>> | undefined
4518
+ let resume: ((effect: Effect.Effect<void, E | E2, R>) => void) | undefined
4519
+ let interrupted = false
4520
+ let terminal: Exit.Exit<void, E | E2> | void
4521
+ let effect: Effect.Effect<X, E, R> | undefined
4522
+
4523
+ const go = (): Effect.Effect<void, E | E2, R> | undefined => {
4524
+ let paused = false
4525
+ for (; !terminal && index < end; index++) {
4526
+ const item = items[index]
4527
+ const eff = effect ?? onItem(state, item, index)
4528
+
4529
+ // fast case (already an exit)
4530
+ if (effectIsExit(eff)) {
4531
+ terminal = step(state, item, eff, index)
4532
+ if (terminal) break
4533
+
4534
+ // Use flatMap for concurrency of 1
4535
+ } else if (concurrency === 1) {
4536
+ return flatMap(exit(eff), (exit) => {
4537
+ terminal = step(state, item, exit, index)
4538
+ index++
4539
+ return terminal ?? go() ?? void_
4540
+ })
4541
+
4542
+ // We have an effect, so enter "async" mode
4543
+ } else if (!parentFiber) {
4544
+ return callback((cb) => {
4545
+ parentFiber = getCurrentFiber()!
4546
+ effect = eff
4547
+ resume = cb
4548
+ const result = go()
4549
+ if (result) return cb(result)
4550
+ return suspend(() => {
4551
+ terminal = exitVoid
4552
+ interrupted = true
4553
+ return fibers ? fiberInterruptAll(fibers) : void_
4554
+ })
4555
+ })
4556
+
4557
+ // Fork the effect with concurrency > 1
4558
+ } else {
4559
+ // Clear the temporary effect from capturing the parentFiber
4560
+ effect = undefined
4561
+
4562
+ const fiber = forkUnsafe(parentFiber, eff, true, true, "inherit")
4563
+ if (fiber._exit) {
4564
+ terminal = step(state, item, fiber._exit, index)
4565
+ if (terminal) break
4566
+ continue
4567
+ }
4568
+
4569
+ // Add the fiber to the Set
4570
+ if (fibers) fibers.add(fiber)
4571
+ else fibers = new Set([fiber])
4572
+
4573
+ const currentIndex = index
4574
+ fiber.addObserver((exit) => {
4575
+ fibers!.delete(fiber)
4576
+ if (terminal) {
4577
+ if (!interrupted && exit._tag === "Failure") {
4578
+ for (const reason of exit.cause.reasons) {
4579
+ if (reason._tag === "Interrupt") continue
4580
+ else if (terminal._tag === "Failure") {
4581
+ ;(terminal.cause.reasons as Array<any>).push(reason)
4582
+ } else {
4583
+ terminal = exitFailCause(causeFromReasons([reason]))
4584
+ }
4585
+ }
4586
+ }
4587
+ } else {
4588
+ const result = step(state, item, exit, currentIndex)
4589
+ if (result) {
4590
+ terminal = result._tag === "Failure"
4591
+ ? exitFailCause(causeFromReasons(result.cause.reasons.slice()))
4592
+ : result
4593
+ go()
4594
+ }
4595
+ }
4596
+
4597
+ if (paused) {
4598
+ const eff = go()
4599
+ if (eff) resume!(eff)
4600
+ } else if (done && fibers!.size === 0) {
4601
+ resume!(terminal ?? void_)
4602
+ }
4603
+ })
4604
+
4605
+ // Check if we have reached the concurrency limit
4606
+ if (fibers.size < concurrency) continue
4607
+ paused = true
4608
+ index++
4609
+ return
4610
+ }
4611
+ }
4612
+
4613
+ done = true
4614
+
4615
+ if (terminal) {
4616
+ if (fibers && fibers.size > 0) {
4617
+ const annotations = fiberStackAnnotations(parentFiber!)
4618
+ fibers.forEach((f) => f.interruptUnsafe(parentFiber!.id, annotations))
4619
+ return
4620
+ }
4621
+ if (resume || terminal._tag === "Failure") {
4622
+ return terminal
4623
+ }
4624
+ } else if (resume) {
4625
+ if (!fibers) {
4626
+ return exitVoid
4627
+ } else if (fibers.size === 0) {
4628
+ resume(void_)
4629
+ }
4630
+ }
4631
+ }
4632
+
4633
+ return go()
4634
+ }
4635
+ }
4636
+
4637
+ /** @internal */
4638
+ export const iterateEager = <S, A>(): <X, E, R, E2>(options: {
4639
+ readonly onItem: (state: S, item: A, index: number) => Effect.Effect<X, E, R>
4640
+ readonly step: (state: NoInfer<S>, item: A, exit: Exit.Exit<X, E>, index: number) => Exit.Exit<void, E2> | void
4641
+ }) => (
4642
+ initialState: S,
4643
+ items: ReadonlyArray<A>,
4644
+ options?: {
4645
+ readonly concurrency?: number | undefined
4646
+ readonly start?: number | undefined
4647
+ readonly end?: number | undefined
4648
+ }
4649
+ ) => Effect.Effect<void, E | E2, R> | undefined => iterateEagerImpl
4650
+
4651
+ const forEachConcurrent = iterateEagerImpl({
4652
+ onItem(
4653
+ state: {
4654
+ readonly f: (a: any, i: number) => Effect.Effect<any, any, any>
4655
+ readonly out: Array<any> | undefined
4656
+ },
4657
+ item,
4658
+ index
4659
+ ) {
4660
+ return state.f(item, index)
4661
+ },
4662
+ step(state, _, exit, index) {
4663
+ if (exit._tag === "Failure") return exit
4664
+ else if (state.out) {
4665
+ state.out[index] = exit.value
4666
+ }
4667
+ }
4668
+ })
4669
+
4246
4670
  /* @internal */
4247
4671
  export const filterOrElse: {
4248
4672
  <A, C, E2, R2, B extends A>(
4249
4673
  refinement: Predicate.Refinement<NoInfer<A>, B>,
4250
4674
  orElse: (a: EqualsWith<A, B, NoInfer<A>, Exclude<NoInfer<A>, B>>) => Effect.Effect<C, E2, R2>
4251
4675
  ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B | C, E2 | E, R2 | R>
4252
- <A, Result extends Filter.ResultOrBool, C, E2, R2>(
4253
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
4254
- orElse: (a: Filter.Fail<A, Result>) => Effect.Effect<C, E2, R2>
4255
- ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Filter.Pass<A, Result> | C, E2 | E, R2 | R>
4676
+ <A, C, E2, R2>(
4677
+ predicate: Predicate.Predicate<NoInfer<A>>,
4678
+ orElse: (a: NoInfer<A>) => Effect.Effect<C, E2, R2>
4679
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | C, E2 | E, R2 | R>
4256
4680
  <A, E, R, C, E2, R2, B extends A>(
4257
4681
  self: Effect.Effect<A, E, R>,
4258
4682
  refinement: Predicate.Refinement<A, B>,
4259
4683
  orElse: (a: EqualsWith<A, B, A, Exclude<A, B>>) => Effect.Effect<C, E2, R2>
4260
4684
  ): Effect.Effect<B | C, E | E2, R | R2>
4261
- <A, E, R, Result extends Filter.ResultOrBool, C, E2, R2>(
4685
+ <A, E, R, C, E2, R2>(
4262
4686
  self: Effect.Effect<A, E, R>,
4263
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
4264
- orElse: (a: Filter.Fail<A, Result>) => Effect.Effect<C, E2, R2>
4265
- ): Effect.Effect<Filter.Pass<A, Result> | C, E | E2, R | R2>
4266
- } = dual(3, <A, E, R, Result extends Filter.ResultOrBool, C, E2, R2>(
4687
+ predicate: Predicate.Predicate<NoInfer<A>>,
4688
+ orElse: (a: NoInfer<A>) => Effect.Effect<C, E2, R2>
4689
+ ): Effect.Effect<A | C, E | E2, R | R2>
4690
+ } = dual(3, <A, E, R, B, E2, R2>(
4267
4691
  self: Effect.Effect<A, E, R>,
4268
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
4269
- orElse: (a: Filter.Fail<A, Result>) => Effect.Effect<C, E2, R2>
4270
- ): Effect.Effect<Filter.Pass<A, Result> | C, E | E2, R | R2> =>
4692
+ predicate: Predicate.Predicate<A>,
4693
+ orElse: (a: A) => Effect.Effect<B, E2, R2>
4694
+ ): Effect.Effect<A | B, E | E2, R | R2> =>
4695
+ flatMap(
4696
+ self,
4697
+ (a) => predicate(a) ? succeed<A | B>(a) : orElse(a)
4698
+ ))
4699
+
4700
+ /** @internal */
4701
+ export const filterMapOrElse: {
4702
+ <A, B, X, C, E2, R2>(
4703
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4704
+ orElse: (x: X) => Effect.Effect<C, E2, R2>
4705
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B | C, E2 | E, R2 | R>
4706
+ <A, E, R, B, X, C, E2, R2>(
4707
+ self: Effect.Effect<A, E, R>,
4708
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4709
+ orElse: (x: X) => Effect.Effect<C, E2, R2>
4710
+ ): Effect.Effect<B | C, E | E2, R | R2>
4711
+ } = dual(3, <A, E, R, B, X, C, E2, R2>(
4712
+ self: Effect.Effect<A, E, R>,
4713
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4714
+ orElse: (x: X) => Effect.Effect<C, E2, R2>
4715
+ ): Effect.Effect<B | C, E | E2, R | R2> =>
4271
4716
  flatMap(
4272
4717
  self,
4273
4718
  (a) => {
4274
- const result = Filter.apply(filter, a)
4275
- return Result.isFailure(result) ? orElse(result.failure) : succeed(result.success) as any
4719
+ const result = filter(a)
4720
+ return (Result.isFailure(result)
4721
+ ? orElse(result.failure)
4722
+ : succeed(result.success)) as Effect.Effect<B | C, E2, R2>
4276
4723
  }
4277
4724
  ))
4278
4725
 
4726
+ /* @internal */
4727
+ export const filterMapOrFail: {
4728
+ <A, B, X, E2>(
4729
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4730
+ orFailWith: (x: X) => E2
4731
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E2 | E, R>
4732
+ <A, B, X>(
4733
+ filter: Filter.Filter<NoInfer<A>, B, X>
4734
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, Cause.NoSuchElementError | E, R>
4735
+ <A, E, R, B, X, E2>(
4736
+ self: Effect.Effect<A, E, R>,
4737
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4738
+ orFailWith: (x: X) => E2
4739
+ ): Effect.Effect<B, E2 | E, R>
4740
+ <A, E, R, B, X>(
4741
+ self: Effect.Effect<A, E, R>,
4742
+ filter: Filter.Filter<NoInfer<A>, B, X>
4743
+ ): Effect.Effect<B, Cause.NoSuchElementError | E, R>
4744
+ } = dual((args) => isEffect(args[0]), <A, E, R, B, X, E2>(
4745
+ self: Effect.Effect<A, E, R>,
4746
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4747
+ orFailWith?: (x: X) => E2
4748
+ ): Effect.Effect<B, E2 | Cause.NoSuchElementError | E, R> =>
4749
+ filterMapOrElse(
4750
+ self,
4751
+ filter,
4752
+ orFailWith ? (x: X) => fail(orFailWith(x)) : () => fail(new NoSuchElementError() as E2)
4753
+ ))
4754
+
4279
4755
  /** @internal */
4280
4756
  export const filter: {
4281
4757
  <A, B extends A>(
@@ -4284,13 +4760,6 @@ export const filter: {
4284
4760
  <A>(
4285
4761
  predicate: Predicate.Predicate<NoInfer<A>>
4286
4762
  ): (elements: Iterable<A>) => Effect.Effect<Array<A>>
4287
- <A, B, X>(
4288
- filter: Filter.Filter<NoInfer<A>, B, X>
4289
- ): (elements: Iterable<A>) => Effect.Effect<Array<B>>
4290
- <A, B, X, E, R>(
4291
- filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
4292
- options?: { readonly concurrency?: Concurrency | undefined }
4293
- ): (elements: Iterable<A>) => Effect.Effect<Array<B>, E, R>
4294
4763
  <A, E, R>(
4295
4764
  predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>,
4296
4765
  options?: { readonly concurrency?: Concurrency | undefined }
@@ -4303,15 +4772,6 @@ export const filter: {
4303
4772
  elements: Iterable<A>,
4304
4773
  predicate: Predicate.Predicate<A>
4305
4774
  ): Effect.Effect<Array<A>>
4306
- <A, B, X>(
4307
- elements: Iterable<A>,
4308
- filter: Filter.Filter<NoInfer<A>, B, X>
4309
- ): Effect.Effect<Array<B>>
4310
- <A, B, X, E, R>(
4311
- elements: Iterable<A>,
4312
- filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
4313
- options?: { readonly concurrency?: Concurrency | undefined }
4314
- ): Effect.Effect<Array<B>, E, R>
4315
4775
  <A, E, R>(
4316
4776
  iterable: Iterable<A>,
4317
4777
  predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>,
@@ -4319,36 +4779,27 @@ export const filter: {
4319
4779
  ): Effect.Effect<Array<A>, E, R>
4320
4780
  } = dual(
4321
4781
  (args) => isIterable(args[0]) && !isEffect(args[0]),
4322
- <A, B, X, E, R>(
4782
+ <A, E, R>(
4323
4783
  elements: Iterable<A>,
4324
- filter:
4325
- | Filter.FilterEffect<A, B, X, E, R>
4784
+ predicate:
4326
4785
  | Predicate.Predicate<A>
4327
4786
  | ((a: A, i: number) => Effect.Effect<boolean, E, R>),
4328
4787
  options?: { readonly concurrency?: Concurrency | undefined }
4329
- ): Effect.Effect<Array<B>, E, R> =>
4788
+ ): Effect.Effect<Array<A>, E, R> =>
4330
4789
  suspend(() => {
4331
- const out: Array<any> = []
4790
+ const out: Array<A> = []
4332
4791
  return as(
4333
4792
  forEach(
4334
4793
  elements,
4335
4794
  (a, i) => {
4336
- const result = (filter as Function)(a, i)
4795
+ const result = (predicate as Function)(a, i)
4337
4796
  if (typeof result === "boolean") {
4338
4797
  if (result) out.push(a)
4339
4798
  return void_ as any
4340
4799
  }
4341
- if (!isEffect(result)) {
4342
- if (!Result.isFailure(result)) {
4343
- out.push(result.success)
4344
- }
4345
- return void_ as any
4346
- }
4347
- return map(result, (r: any) => {
4348
- if (typeof r === "boolean") {
4349
- if (r) out.push(a)
4350
- } else if (!Result.isFailure(r)) {
4351
- out.push(r.success)
4800
+ return map(result, (keep) => {
4801
+ if (keep) {
4802
+ out.push(a)
4352
4803
  }
4353
4804
  })
4354
4805
  },
@@ -4362,6 +4813,72 @@ export const filter: {
4362
4813
  })
4363
4814
  )
4364
4815
 
4816
+ /** @internal */
4817
+ export const filterMap: {
4818
+ <A, B, X>(
4819
+ filter: Filter.Filter<NoInfer<A>, B, X>
4820
+ ): (elements: Iterable<A>) => Effect.Effect<Array<B>>
4821
+ <A, B, X>(
4822
+ elements: Iterable<A>,
4823
+ filter: Filter.Filter<NoInfer<A>, B, X>
4824
+ ): Effect.Effect<Array<B>>
4825
+ } = dual(
4826
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4827
+ <A, B, X>(
4828
+ elements: Iterable<A>,
4829
+ filter: Filter.Filter<A, B, X>
4830
+ ): Effect.Effect<Array<B>> =>
4831
+ suspend(() => {
4832
+ const out: Array<B> = []
4833
+ for (const a of elements) {
4834
+ const result = filter(a)
4835
+ if (Result.isSuccess(result)) {
4836
+ out.push(result.success)
4837
+ }
4838
+ }
4839
+ return succeed(out)
4840
+ })
4841
+ )
4842
+
4843
+ /** @internal */
4844
+ export const filterMapEffect: {
4845
+ <A, B, X, E, R>(
4846
+ filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
4847
+ options?: { readonly concurrency?: Concurrency | undefined }
4848
+ ): (elements: Iterable<A>) => Effect.Effect<Array<B>, E, R>
4849
+ <A, B, X, E, R>(
4850
+ elements: Iterable<A>,
4851
+ filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
4852
+ options?: { readonly concurrency?: Concurrency | undefined }
4853
+ ): Effect.Effect<Array<B>, E, R>
4854
+ } = dual(
4855
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4856
+ <A, B, X, E, R>(
4857
+ elements: Iterable<A>,
4858
+ filter: Filter.FilterEffect<A, B, X, E, R>,
4859
+ options?: { readonly concurrency?: Concurrency | undefined }
4860
+ ): Effect.Effect<Array<B>, E, R> =>
4861
+ suspend(() => {
4862
+ const out: Array<B> = []
4863
+ return as(
4864
+ forEach(
4865
+ elements,
4866
+ (a) =>
4867
+ map(filter(a), (result) => {
4868
+ if (Result.isSuccess(result)) {
4869
+ out.push(result.success)
4870
+ }
4871
+ }),
4872
+ {
4873
+ discard: true,
4874
+ concurrency: options?.concurrency
4875
+ }
4876
+ ),
4877
+ out
4878
+ )
4879
+ })
4880
+ )
4881
+
4365
4882
  // ----------------------------------------------------------------------------
4366
4883
  // do notation
4367
4884
  // ----------------------------------------------------------------------------
@@ -4462,13 +4979,13 @@ export const forkUnsafe = <FA, FE, A, E, R>(
4462
4979
  immediate = false,
4463
4980
  daemon = false,
4464
4981
  uninterruptible: boolean | "inherit" = false
4465
- ): Fiber.Fiber<A, E> => {
4982
+ ): FiberImpl<A, E> => {
4466
4983
  const interruptible = uninterruptible === "inherit" ? parent.interruptible : !uninterruptible
4467
- const child = new FiberImpl<A, E>(parent.services, interruptible)
4984
+ const child = new FiberImpl<A, E>(parent.context, interruptible)
4468
4985
  if (immediate) {
4469
4986
  child.evaluate(effect as any)
4470
4987
  } else {
4471
- parent.currentScheduler.scheduleTask(() => child.evaluate(effect as any), 0)
4988
+ parent.currentDispatcher.scheduleTask(() => child.evaluate(effect as any), 0)
4472
4989
  }
4473
4990
  if (!daemon && !child._exit) {
4474
4991
  parent.children().add(child)
@@ -4588,7 +5105,8 @@ export const forkScoped: {
4588
5105
  readonly startImmediately?: boolean | undefined
4589
5106
  readonly uninterruptible?: boolean | "inherit" | undefined
4590
5107
  } | undefined
4591
- ): [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ? Effect.Effect<Fiber.Fiber<_A, _E>, never, _R>
5108
+ ): [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ?
5109
+ Effect.Effect<Fiber.Fiber<_A, _E>, never, _R | Scope.Scope>
4592
5110
  : <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.Fiber<A, E>, never, R | Scope.Scope>
4593
5111
  } = dual((args) => isEffect(args[0]), <A, E, R>(
4594
5112
  self: Effect.Effect<A, E, R>,
@@ -4603,15 +5121,13 @@ export const forkScoped: {
4603
5121
  // ----------------------------------------------------------------------------
4604
5122
 
4605
5123
  /** @internal */
4606
- export const runForkWith = <R>(services: ServiceMap.ServiceMap<R>) =>
5124
+ export const runForkWith = <R>(context: Context.Context<R>) =>
4607
5125
  <A, E>(
4608
5126
  effect: Effect.Effect<A, E, R>,
4609
5127
  options?: Effect.RunOptions | undefined
4610
5128
  ): Fiber.Fiber<A, E> => {
4611
- const scheduler = options?.scheduler ||
4612
- (!services.mapUnsafe.has(Scheduler.Scheduler.key) && new Scheduler.MixedScheduler())
4613
5129
  const fiber = new FiberImpl<A, E>(
4614
- scheduler ? ServiceMap.add(services, Scheduler.Scheduler, scheduler) : services,
5130
+ options?.scheduler ? Context.add(context, Scheduler.Scheduler, options.scheduler) : context,
4615
5131
  options?.uninterruptible !== true
4616
5132
  )
4617
5133
  fiber.evaluate(effect as any)
@@ -4626,6 +5142,9 @@ export const runForkWith = <R>(services: ServiceMap.ServiceMap<R>) =>
4626
5142
  fiber.addObserver(() => options.signal!.removeEventListener("abort", abort))
4627
5143
  }
4628
5144
  }
5145
+ if (options?.onFiberStart) {
5146
+ options.onFiberStart(fiber)
5147
+ }
4629
5148
  return fiber
4630
5149
  }
4631
5150
 
@@ -4656,11 +5175,11 @@ export const fiberRunIn: {
4656
5175
  export const runFork: <A, E>(
4657
5176
  effect: Effect.Effect<A, E, never>,
4658
5177
  options?: Effect.RunOptions | undefined
4659
- ) => Fiber.Fiber<A, E> = runForkWith(ServiceMap.empty())
5178
+ ) => Fiber.Fiber<A, E> = runForkWith(Context.empty())
4660
5179
 
4661
5180
  /** @internal */
4662
- export const runCallbackWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4663
- const runFork = runForkWith(services)
5181
+ export const runCallbackWith = <R>(context: Context.Context<R>) => {
5182
+ const runFork = runForkWith(context)
4664
5183
  return <A, E>(
4665
5184
  effect: Effect.Effect<A, E, R>,
4666
5185
  options?:
@@ -4680,11 +5199,11 @@ export const runCallbackWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4680
5199
  }
4681
5200
 
4682
5201
  /** @internal */
4683
- export const runCallback = runCallbackWith(ServiceMap.empty())
5202
+ export const runCallback = runCallbackWith(Context.empty())
4684
5203
 
4685
5204
  /** @internal */
4686
- export const runPromiseExitWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4687
- const runFork = runForkWith(services)
5205
+ export const runPromiseExitWith = <R>(context: Context.Context<R>) => {
5206
+ const runFork = runForkWith(context)
4688
5207
  return <A, E>(
4689
5208
  effect: Effect.Effect<A, E, R>,
4690
5209
  options?: Effect.RunOptions | undefined
@@ -4697,11 +5216,11 @@ export const runPromiseExitWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4697
5216
  }
4698
5217
 
4699
5218
  /** @internal */
4700
- export const runPromiseExit = runPromiseExitWith(ServiceMap.empty())
5219
+ export const runPromiseExit = runPromiseExitWith(Context.empty())
4701
5220
 
4702
5221
  /** @internal */
4703
- export const runPromiseWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4704
- const runPromiseExit = runPromiseExitWith(services)
5222
+ export const runPromiseWith = <R>(context: Context.Context<R>) => {
5223
+ const runPromiseExit = runPromiseExitWith(context)
4705
5224
  return <A, E>(
4706
5225
  effect: Effect.Effect<A, E, R>,
4707
5226
  options?:
@@ -4722,28 +5241,28 @@ export const runPromise: <A, E>(
4722
5241
  options?:
4723
5242
  | Effect.RunOptions
4724
5243
  | undefined
4725
- ) => Promise<A> = runPromiseWith(ServiceMap.empty())
5244
+ ) => Promise<A> = runPromiseWith(Context.empty())
4726
5245
 
4727
5246
  /** @internal */
4728
- export const runSyncExitWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4729
- const runFork = runForkWith(services)
5247
+ export const runSyncExitWith = <R>(context: Context.Context<R>) => {
5248
+ const runFork = runForkWith(context)
4730
5249
  return <A, E>(effect: Effect.Effect<A, E, R>): Exit.Exit<A, E> => {
4731
5250
  if (effectIsExit(effect)) return effect
4732
5251
  const scheduler = new Scheduler.MixedScheduler("sync")
4733
5252
  const fiber = runFork(effect, { scheduler })
4734
- scheduler.flush()
4735
- return (fiber as FiberImpl<A, E>)._exit ?? exitDie(fiber)
5253
+ fiber.currentDispatcher?.flush()
5254
+ return (fiber as FiberImpl<A, E>)._exit ?? exitDie(new AsyncFiberError(fiber))
4736
5255
  }
4737
5256
  }
4738
5257
 
4739
5258
  /** @internal */
4740
5259
  export const runSyncExit: <A, E>(effect: Effect.Effect<A, E>) => Exit.Exit<A, E> = runSyncExitWith(
4741
- ServiceMap.empty()
5260
+ Context.empty()
4742
5261
  )
4743
5262
 
4744
5263
  /** @internal */
4745
- export const runSyncWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4746
- const runSyncExit = runSyncExitWith(services)
5264
+ export const runSyncWith = <R>(context: Context.Context<R>) => {
5265
+ const runSyncExit = runSyncExitWith(context)
4747
5266
  return <A, E>(effect: Effect.Effect<A, E, R>): A => {
4748
5267
  const exit = runSyncExit(effect)
4749
5268
  if (exit._tag === "Failure") throw causeSquash(exit.cause)
@@ -4752,109 +5271,12 @@ export const runSyncWith = <R>(services: ServiceMap.ServiceMap<R>) => {
4752
5271
  }
4753
5272
 
4754
5273
  /** @internal */
4755
- export const runSync: <A, E>(effect: Effect.Effect<A, E>) => A = runSyncWith(ServiceMap.empty())
4756
-
4757
- // ----------------------------------------------------------------------------
4758
- // Semaphore
4759
- // ----------------------------------------------------------------------------
4760
-
4761
- /** @internal */
4762
- class Semaphore {
4763
- public waiters = new Set<() => void>()
4764
- public taken = 0
4765
- public permits: number
4766
-
4767
- constructor(permits: number) {
4768
- this.permits = permits
4769
- }
4770
-
4771
- get free() {
4772
- return this.permits - this.taken
4773
- }
4774
-
4775
- readonly take = (n: number): Effect.Effect<number> =>
4776
- callback<number>((resume) => {
4777
- if (this.free < n) {
4778
- const observer = () => {
4779
- if (this.free < n) {
4780
- return
4781
- }
4782
- this.waiters.delete(observer)
4783
- this.taken += n
4784
- resume(succeed(n))
4785
- }
4786
- this.waiters.add(observer)
4787
- return sync(() => {
4788
- this.waiters.delete(observer)
4789
- })
4790
- }
4791
- this.taken += n
4792
- return resume(succeed(n))
4793
- })
4794
-
4795
- updateTakenUnsafe(fiber: Fiber.Fiber<any, any>, f: (n: number) => number): Effect.Effect<number> {
4796
- this.taken = f(this.taken)
4797
- if (this.waiters.size > 0) {
4798
- fiber.currentScheduler.scheduleTask(() => {
4799
- const iter = this.waiters.values()
4800
- let item = iter.next()
4801
- while (item.done === false && this.free > 0) {
4802
- item.value()
4803
- item = iter.next()
4804
- }
4805
- }, 0)
4806
- }
4807
- return succeed(this.free)
4808
- }
4809
-
4810
- updateTaken(f: (n: number) => number): Effect.Effect<number> {
4811
- return withFiber((fiber) => this.updateTakenUnsafe(fiber, f))
4812
- }
4813
-
4814
- readonly resize = (permits: number) =>
4815
- asVoid(
4816
- withFiber((fiber) => {
4817
- this.permits = permits
4818
- if (this.free < 0) {
4819
- return void_
4820
- }
4821
- return this.updateTakenUnsafe(fiber, (taken) => taken)
4822
- })
4823
- )
4824
-
4825
- readonly release = (n: number): Effect.Effect<number> => this.updateTaken((taken) => taken - n)
4826
-
4827
- readonly releaseAll: Effect.Effect<number> = this.updateTaken((_) => 0)
4828
-
4829
- readonly withPermits = (n: number) => <A, E, R>(self: Effect.Effect<A, E, R>) =>
4830
- uninterruptibleMask((restore) =>
4831
- flatMap(restore(this.take(n)), (permits) => ensuring(restore(self), this.release(permits)))
4832
- )
4833
-
4834
- readonly withPermit = this.withPermits(1)
4835
-
4836
- readonly withPermitsIfAvailable = (n: number) => <A, E, R>(self: Effect.Effect<A, E, R>) =>
4837
- uninterruptibleMask((restore) =>
4838
- suspend(() => {
4839
- if (this.free < n) {
4840
- return succeedNone
4841
- }
4842
- this.taken += n
4843
- return ensuring(restore(asSome(self)), this.release(n))
4844
- })
4845
- )
4846
- }
4847
-
4848
- /** @internal */
4849
- export const makeSemaphoreUnsafe = (permits: number): Semaphore => new Semaphore(permits)
4850
-
4851
- /** @internal */
4852
- export const makeSemaphore = (permits: number) => sync(() => makeSemaphoreUnsafe(permits))
5274
+ export const runSync: <A, E>(effect: Effect.Effect<A, E>) => A = runSyncWith(Context.empty())
4853
5275
 
4854
5276
  const succeedTrue = succeed(true)
4855
5277
  const succeedFalse = succeed(false)
4856
5278
 
4857
- class Latch implements Effect.Latch {
5279
+ class Latch implements _Latch.Latch {
4858
5280
  waiters: Array<(_: Effect.Effect<void>) => void> = []
4859
5281
  scheduled = false
4860
5282
  private isOpen: boolean
@@ -4868,7 +5290,7 @@ class Latch implements Effect.Latch {
4868
5290
  return succeedTrue
4869
5291
  }
4870
5292
  this.scheduled = true
4871
- fiber.currentScheduler.scheduleTask(this.flushWaiters, 0)
5293
+ fiber.currentDispatcher.scheduleTask(this.flushWaiters, 0)
4872
5294
  return succeedTrue
4873
5295
  }
4874
5296
  private flushWaiters = () => {
@@ -4910,11 +5332,11 @@ class Latch implements Effect.Latch {
4910
5332
  return true
4911
5333
  }
4912
5334
  close = sync(() => this.closeUnsafe())
4913
- whenOpen = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => andThen(this.await, self)
5335
+ whenOpen = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => flatMap(this.await, () => self)
4914
5336
  }
4915
5337
 
4916
5338
  /** @internal */
4917
- export const makeLatchUnsafe = (open?: boolean | undefined): Effect.Latch => new Latch(open ?? false)
5339
+ export const makeLatchUnsafe = (open?: boolean | undefined): _Latch.Latch => new Latch(open ?? false)
4918
5340
 
4919
5341
  /** @internal */
4920
5342
  export const makeLatch = (open?: boolean | undefined) => sync(() => makeLatchUnsafe(open))
@@ -4973,16 +5395,15 @@ const NoopSpanProto: Omit<Tracer.Span, "parent" | "name" | "annotations" | "leve
4973
5395
  /** @internal */
4974
5396
  export const noopSpan = (options: {
4975
5397
  readonly name: string
4976
- readonly parent: Tracer.AnySpan | undefined
4977
- readonly annotations: ServiceMap.ServiceMap<never>
5398
+ readonly parent: Option.Option<Tracer.AnySpan>
5399
+ readonly annotations: Context.Context<never>
4978
5400
  }): Tracer.Span => Object.assign(Object.create(NoopSpanProto), options)
4979
5401
 
4980
- const filterDisablePropagation = (span: Tracer.AnySpan | undefined): Tracer.AnySpan | undefined => {
4981
- if (span) {
4982
- return ServiceMap.get(span.annotations, Tracer.DisablePropagation)
4983
- ? span._tag === "Span" ? filterDisablePropagation(span.parent) : undefined
4984
- : span
4985
- }
5402
+ const filterDisablePropagation = (span: Tracer.AnySpan | undefined): Option.Option<Tracer.AnySpan> => {
5403
+ if (!span) return Option.none()
5404
+ return Context.get(span.annotations, Tracer.DisablePropagation)
5405
+ ? span._tag === "Span" ? filterDisablePropagation(Option.getOrUndefined(span.parent)) : Option.none()
5406
+ : Option.some(span)
4986
5407
  }
4987
5408
 
4988
5409
  /** @internal */
@@ -4992,8 +5413,12 @@ export const makeSpanUnsafe = <XA, XE>(
4992
5413
  options: Tracer.SpanOptionsNoTrace | undefined
4993
5414
  ) => {
4994
5415
  const disablePropagation = !fiber.getRef(TracerEnabled) ||
4995
- (options?.annotations && ServiceMap.get(options.annotations, Tracer.DisablePropagation))
4996
- const parent = options?.parent ?? (options?.root ? undefined : filterDisablePropagation(fiber.currentSpan))
5416
+ (options?.annotations && Context.get(options.annotations, Tracer.DisablePropagation))
5417
+ const parent = options?.parent !== undefined
5418
+ ? Option.some(options.parent)
5419
+ : options?.root
5420
+ ? Option.none<Tracer.AnySpan>()
5421
+ : filterDisablePropagation(fiber.currentSpan)
4997
5422
 
4998
5423
  let span: Tracer.Span
4999
5424
 
@@ -5001,8 +5426,8 @@ export const makeSpanUnsafe = <XA, XE>(
5001
5426
  span = noopSpan({
5002
5427
  name,
5003
5428
  parent,
5004
- annotations: ServiceMap.add(
5005
- options?.annotations ?? ServiceMap.empty(),
5429
+ annotations: Context.add(
5430
+ options?.annotations ?? Context.empty(),
5006
5431
  Tracer.DisablePropagation,
5007
5432
  true
5008
5433
  )
@@ -5022,13 +5447,13 @@ export const makeSpanUnsafe = <XA, XE>(
5022
5447
  span = tracer.span({
5023
5448
  name,
5024
5449
  parent,
5025
- annotations: options?.annotations ?? ServiceMap.empty(),
5450
+ annotations: options?.annotations ?? Context.empty(),
5026
5451
  links,
5027
- startTime: timingEnabled ? clock.currentTimeNanosUnsafe() : 0n,
5452
+ startTime: timingEnabled ? clock.currentTimeNanosUnsafe() : BigInt(0),
5028
5453
  kind: options?.kind ?? "internal",
5029
- root: options?.root ?? options?.parent === undefined,
5454
+ root: options?.root ?? Option.isNone(parent),
5030
5455
  sampled: options?.sampled ??
5031
- (parent?.sampled === false
5456
+ (Option.isSome(parent) && parent.value.sampled === false
5032
5457
  ? false
5033
5458
  : !isLogLevelGreaterThan(fiber.getRef(Tracer.MinimumTraceLevel), level))
5034
5459
  })
@@ -5059,7 +5484,7 @@ export const makeSpanScoped = (
5059
5484
  ): Effect.Effect<Tracer.Span, never, Scope.Scope> =>
5060
5485
  uninterruptible(
5061
5486
  withFiber((fiber) => {
5062
- const scope = ServiceMap.getUnsafe(fiber.services, scopeTag)
5487
+ const scope = Context.getUnsafe(fiber.context, scopeTag)
5063
5488
  const span = makeSpanUnsafe(fiber, name, options ?? {})
5064
5489
  const clock = fiber.getRef(ClockRef)
5065
5490
  const timingEnabled = fiber.getRef(TracerTimingEnabled)
@@ -5291,7 +5716,7 @@ export const currentParentSpan: Effect.Effect<Tracer.AnySpan, Cause.NoSuchElemen
5291
5716
  // ----------------------------------------------------------------------------
5292
5717
 
5293
5718
  /** @internal */
5294
- export const ClockRef = ServiceMap.Reference<Clock.Clock>("effect/Clock", {
5719
+ export const ClockRef = Context.Reference<Clock.Clock>("effect/Clock", {
5295
5720
  defaultValue: (): Clock.Clock => new ClockImpl()
5296
5721
  })
5297
5722
 
@@ -5344,8 +5769,8 @@ export const clockWith = <A, E, R>(f: (clock: Clock.Clock) => Effect.Effect<A, E
5344
5769
  withFiber((fiber) => f(fiber.getRef(ClockRef)))
5345
5770
 
5346
5771
  /** @internal */
5347
- export const sleep = (duration: Duration.DurationInput): Effect.Effect<void> =>
5348
- clockWith((clock) => clock.sleep(Duration.fromDurationInputUnsafe(duration)))
5772
+ export const sleep = (duration: Duration.Input): Effect.Effect<void> =>
5773
+ clockWith((clock) => clock.sleep(Duration.fromInputUnsafe(duration)))
5349
5774
 
5350
5775
  /** @internal */
5351
5776
  export const currentTimeMillis: Effect.Effect<number> = clockWith((clock) => clock.currentTimeMillis)
@@ -5403,6 +5828,28 @@ export class ExceededCapacityError extends TaggedError("ExceededCapacityError")
5403
5828
  }
5404
5829
  }
5405
5830
 
5831
+ /** @internal */
5832
+ export const AsyncFiberErrorTypeId = "~effect/Cause/AsyncFiberError"
5833
+
5834
+ /** @internal */
5835
+ export const isAsyncFiberError = (
5836
+ u: unknown
5837
+ ): u is Cause.AsyncFiberError => hasProperty(u, AsyncFiberErrorTypeId)
5838
+
5839
+ /** @internal */
5840
+ export class AsyncFiberError extends TaggedError("AsyncFiberError")<{
5841
+ fiber: Fiber.Fiber<unknown, unknown>
5842
+ message: string
5843
+ }> {
5844
+ readonly [AsyncFiberErrorTypeId] = AsyncFiberErrorTypeId
5845
+ constructor(fiber: Fiber.Fiber<unknown, unknown>) {
5846
+ super({
5847
+ message: "An asynchronous Effect was executed with Effect.runSync",
5848
+ fiber
5849
+ })
5850
+ }
5851
+ }
5852
+
5406
5853
  /** @internal */
5407
5854
  export const UnknownErrorTypeId = "~effect/Cause/UnknownError"
5408
5855
 
@@ -5412,7 +5859,10 @@ export const isUnknownError = (
5412
5859
  ): u is Cause.UnknownError => hasProperty(u, UnknownErrorTypeId)
5413
5860
 
5414
5861
  /** @internal */
5415
- export class UnknownError extends TaggedError("UnknownError") {
5862
+ export class UnknownError extends TaggedError("UnknownError")<{
5863
+ cause: unknown
5864
+ message?: string | undefined
5865
+ }> {
5416
5866
  readonly [UnknownErrorTypeId] = UnknownErrorTypeId
5417
5867
  constructor(cause: unknown, message?: string) {
5418
5868
  super({ message, cause } as any)
@@ -5424,7 +5874,7 @@ export class UnknownError extends TaggedError("UnknownError") {
5424
5874
  // ----------------------------------------------------------------------------
5425
5875
 
5426
5876
  /** @internal */
5427
- export const ConsoleRef = ServiceMap.Reference<Console.Console>(
5877
+ export const ConsoleRef = Context.Reference<Console.Console>(
5428
5878
  "effect/Console/CurrentConsole",
5429
5879
  { defaultValue: (): Console.Console => globalThis.console }
5430
5880
  )
@@ -5466,17 +5916,51 @@ export const isLogLevelGreaterThan = Order.isGreaterThan(LogLevelOrder)
5466
5916
  // ----------------------------------------------------------------------------
5467
5917
 
5468
5918
  /** @internal */
5469
- export const CurrentLoggers = ServiceMap.Reference<
5919
+ export const CurrentLoggers = Context.Reference<
5470
5920
  ReadonlySet<Logger.Logger<unknown, any>>
5471
5921
  >("effect/Loggers/CurrentLoggers", {
5472
5922
  defaultValue: () => new Set([defaultLogger, tracerLogger])
5473
5923
  })
5474
5924
 
5475
5925
  /** @internal */
5476
- export const LogToStderr = ServiceMap.Reference<boolean>("effect/Logger/LogToStderr", {
5926
+ export const LogToStderr = Context.Reference<boolean>("effect/Logger/LogToStderr", {
5477
5927
  defaultValue: constFalse
5478
5928
  })
5479
5929
 
5930
+ /** @internal */
5931
+ export const annotateLogsScoped: {
5932
+ (key: string, value: unknown): Effect.Effect<void, never, Scope.Scope>
5933
+ (values: Record<string, unknown>): Effect.Effect<void, never, Scope.Scope>
5934
+ } = function() {
5935
+ const entries = typeof arguments[0] === "string" ?
5936
+ [[arguments[0], arguments[1]]] :
5937
+ Object.entries(arguments[0])
5938
+ return uninterruptible(withFiber((fiber) => {
5939
+ const prev = fiber.getRef(CurrentLogAnnotations)
5940
+ const next = { ...prev }
5941
+ for (let i = 0; i < entries.length; i++) {
5942
+ const [key, value] = entries[i]
5943
+ next[key] = value
5944
+ }
5945
+ fiber.setContext(Context.add(fiber.context, CurrentLogAnnotations, next))
5946
+ return scopeAddFinalizerExit(Context.getUnsafe(fiber.context, scopeTag), (_) => {
5947
+ const current = fiber.getRef(CurrentLogAnnotations)
5948
+ const next = { ...current }
5949
+ for (let i = 0; i < entries.length; i++) {
5950
+ const [key, value] = entries[i]
5951
+ if (current[key] !== value) continue
5952
+ if (key in prev) {
5953
+ next[key] = prev[key]
5954
+ } else {
5955
+ delete next[key]
5956
+ }
5957
+ }
5958
+ fiber.setContext(Context.add(fiber.context, CurrentLogAnnotations, next))
5959
+ return void_
5960
+ })
5961
+ }))
5962
+ }
5963
+
5480
5964
  /** @internal */
5481
5965
  export const LoggerTypeId = "~effect/Logger"
5482
5966
 
@@ -5492,7 +5976,7 @@ const LoggerProto = {
5492
5976
 
5493
5977
  /** @internal */
5494
5978
  export const loggerMake = <Message, Output>(
5495
- log: (options: Logger.Logger.Options<Message>) => Output
5979
+ log: (options: Logger.Options<Message>) => Output
5496
5980
  ): Logger.Logger<Message, Output> => {
5497
5981
  const self = Object.create(LoggerProto)
5498
5982
  self.log = log
@@ -5532,7 +6016,7 @@ export const structuredMessage = (u: unknown): unknown => {
5532
6016
  }
5533
6017
 
5534
6018
  /** @internal */
5535
- export const logWithLevel = (level?: LogLevel.LogLevel) =>
6019
+ export const logWithLevel = (level?: LogLevel.Severity) =>
5536
6020
  (
5537
6021
  ...message: ReadonlyArray<any>
5538
6022
  ): Effect.Effect<void> => {
@@ -5651,10 +6135,11 @@ const prettyLoggerTty = (options: {
5651
6135
  readonly formatDate: (date: Date) => string
5652
6136
  }) => {
5653
6137
  const processIsBun = typeof process === "object" && "isBun" in process && process.isBun === true
5654
- const color = options.colors && processStdoutIsTTY ? withColor : withColorNoop
6138
+ const color = options.colors ? withColor : withColorNoop
5655
6139
  return loggerMake<unknown, void>(
5656
6140
  ({ cause, date, fiber, logLevel, message: message_ }) => {
5657
6141
  const console = fiber.getRef(ConsoleRef)
6142
+ // oxlint-disable-next-line no-console
5658
6143
  const log = fiber.getRef(LogToStderr) ? console.error : console.log
5659
6144
 
5660
6145
  const message = Array.isArray(message_) ? message_.slice() : [message_]
@@ -5680,6 +6165,7 @@ const prettyLoggerTty = (options: {
5680
6165
  }
5681
6166
 
5682
6167
  log(firstLine)
6168
+ // oxlint-disable-next-line no-console
5683
6169
  if (!processIsBun) console.group()
5684
6170
 
5685
6171
  if (cause.reasons.length > 0) {
@@ -5697,6 +6183,7 @@ const prettyLoggerTty = (options: {
5697
6183
  log(color(`${key}:`, colors.bold, colors.white), redact(value))
5698
6184
  }
5699
6185
 
6186
+ // oxlint-disable-next-line no-console
5700
6187
  if (!processIsBun) console.groupEnd()
5701
6188
  }
5702
6189
  )
@@ -5743,14 +6230,17 @@ const prettyLoggerBrowser = (options: {
5743
6230
  }
5744
6231
  }
5745
6232
 
6233
+ // oxlint-disable-next-line no-console
5746
6234
  console.groupCollapsed(firstLine, ...firstParams)
5747
6235
 
5748
6236
  if (cause.reasons.length > 0) {
6237
+ // oxlint-disable-next-line no-console
5749
6238
  console.error(causePretty(cause))
5750
6239
  }
5751
6240
 
5752
6241
  if (messageIndex < message.length) {
5753
6242
  for (; messageIndex < message.length; messageIndex++) {
6243
+ // oxlint-disable-next-line no-console
5754
6244
  console.log(redact(message[messageIndex]))
5755
6245
  }
5756
6246
  }
@@ -5759,12 +6249,15 @@ const prettyLoggerBrowser = (options: {
5759
6249
  for (const [key, value] of Object.entries(annotations)) {
5760
6250
  const redacted = redact(value)
5761
6251
  if (options.colors) {
6252
+ // oxlint-disable-next-line no-console
5762
6253
  console.log(`%c${key}:`, "color:gray", redacted)
5763
6254
  } else {
6255
+ // oxlint-disable-next-line no-console
5764
6256
  console.log(`${key}:`, redacted)
5765
6257
  }
5766
6258
  }
5767
6259
 
6260
+ // oxlint-disable-next-line no-console
5768
6261
  console.groupEnd()
5769
6262
  }
5770
6263
  )
@@ -5774,7 +6267,7 @@ const prettyLoggerBrowser = (options: {
5774
6267
  export const defaultLogger = loggerMake<unknown, void>(({ cause, date, fiber, logLevel, message }) => {
5775
6268
  const message_ = Array.isArray(message) ? message.slice() : [message]
5776
6269
  if (cause.reasons.length > 0) {
5777
- message_.unshift(causePretty(cause))
6270
+ message_.push(causePretty(cause))
5778
6271
  }
5779
6272
  const now = date.getTime()
5780
6273
  const spans = fiber.getRef(CurrentLogSpans)
@@ -5787,6 +6280,7 @@ export const defaultLogger = loggerMake<unknown, void>(({ cause, date, fiber, lo
5787
6280
  message_.push(annotations)
5788
6281
  }
5789
6282
  const console = fiber.getRef(ConsoleRef)
6283
+ // oxlint-disable-next-line no-console
5790
6284
  const log = fiber.getRef(LogToStderr) ? console.error : console.log
5791
6285
  log(`[${defaultDateFormat(date)}] ${logLevel.toUpperCase()} (#${fiber.id})${spanString}:`, ...message_)
5792
6286
  })
@@ -5823,3 +6317,48 @@ const undefined_ = succeed(undefined)
5823
6317
 
5824
6318
  /** @internal */
5825
6319
  export { undefined_ as undefined }
6320
+
6321
+ // ----------------------------------------------------------------------------
6322
+ // ErrorReporter
6323
+ // ----------------------------------------------------------------------------
6324
+
6325
+ /** @internal */
6326
+ export const withErrorReporting: <
6327
+ Arg extends Effect.Effect<any, any, any> | {
6328
+ readonly defectsOnly?: boolean | undefined
6329
+ } | undefined = {
6330
+ readonly defectsOnly?: boolean | undefined
6331
+ }
6332
+ >(
6333
+ effectOrOptions: Arg,
6334
+ options?: {
6335
+ readonly defectsOnly?: boolean | undefined
6336
+ } | undefined
6337
+ ) => [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ? Arg
6338
+ : <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> = dual(
6339
+ (args) => isEffect(args[0]),
6340
+ <A, E, R>(
6341
+ self: Effect.Effect<A, E, R>,
6342
+ options?: {
6343
+ readonly defectsOnly?: boolean | undefined
6344
+ } | undefined
6345
+ ): Effect.Effect<A, E, R> =>
6346
+ onError(self, (cause) =>
6347
+ withFiber((fiber) => {
6348
+ reportCauseUnsafe(fiber, cause, options?.defectsOnly)
6349
+ return void_
6350
+ }))
6351
+ )
6352
+
6353
+ /** @internal */
6354
+ export const reportCauseUnsafe = (
6355
+ fiber: Fiber.Fiber<unknown, unknown>,
6356
+ cause: Cause.Cause<unknown>,
6357
+ defectsOnly?: boolean
6358
+ ) => {
6359
+ const reporters = fiber.getRef(CurrentErrorReporters)
6360
+ if (reporters.size === 0) return
6361
+ if (defectsOnly && !hasDies(cause)) return
6362
+ const opts = { cause, fiber, timestamp: fiber.getRef(ClockRef).currentTimeNanosUnsafe() }
6363
+ reporters.forEach((reporter) => reporter.report(opts))
6364
+ }