effect 4.0.0-beta.2 → 4.0.0-beta.21

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 (881) hide show
  1. package/dist/Array.d.ts +127 -299
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +102 -62
  4. package/dist/Array.js.map +1 -1
  5. package/dist/Cache.d.ts +2 -2
  6. package/dist/Cache.d.ts.map +1 -1
  7. package/dist/Cache.js +6 -5
  8. package/dist/Cache.js.map +1 -1
  9. package/dist/Cause.d.ts +1 -1
  10. package/dist/Cause.d.ts.map +1 -1
  11. package/dist/Channel.d.ts +116 -30
  12. package/dist/Channel.d.ts.map +1 -1
  13. package/dist/Channel.js +82 -37
  14. package/dist/Channel.js.map +1 -1
  15. package/dist/Chunk.d.ts +54 -247
  16. package/dist/Chunk.d.ts.map +1 -1
  17. package/dist/Chunk.js +36 -67
  18. package/dist/Chunk.js.map +1 -1
  19. package/dist/Combiner.d.ts +280 -13
  20. package/dist/Combiner.d.ts.map +1 -1
  21. package/dist/Combiner.js +198 -7
  22. package/dist/Combiner.js.map +1 -1
  23. package/dist/Config.d.ts +165 -9
  24. package/dist/Config.d.ts.map +1 -1
  25. package/dist/Config.js +62 -7
  26. package/dist/Config.js.map +1 -1
  27. package/dist/ConfigProvider.d.ts +1 -1
  28. package/dist/Cron.d.ts +1 -1
  29. package/dist/Data.d.ts +534 -365
  30. package/dist/Data.d.ts.map +1 -1
  31. package/dist/Data.js +132 -79
  32. package/dist/Data.js.map +1 -1
  33. package/dist/DateTime.d.ts +23 -161
  34. package/dist/DateTime.d.ts.map +1 -1
  35. package/dist/DateTime.js +6 -51
  36. package/dist/DateTime.js.map +1 -1
  37. package/dist/Duration.d.ts +12 -12
  38. package/dist/Duration.d.ts.map +1 -1
  39. package/dist/Duration.js +12 -12
  40. package/dist/Duration.js.map +1 -1
  41. package/dist/Effect.d.ts +829 -692
  42. package/dist/Effect.d.ts.map +1 -1
  43. package/dist/Effect.js +263 -251
  44. package/dist/Effect.js.map +1 -1
  45. package/dist/Encoding.d.ts +194 -0
  46. package/dist/Encoding.d.ts.map +1 -0
  47. package/dist/Encoding.js +352 -0
  48. package/dist/Encoding.js.map +1 -0
  49. package/dist/Equal.d.ts +276 -109
  50. package/dist/Equal.d.ts.map +1 -1
  51. package/dist/Equal.js +124 -48
  52. package/dist/Equal.js.map +1 -1
  53. package/dist/ErrorReporter.d.ts +376 -0
  54. package/dist/ErrorReporter.d.ts.map +1 -0
  55. package/dist/ErrorReporter.js +246 -0
  56. package/dist/ErrorReporter.js.map +1 -0
  57. package/dist/Fiber.d.ts +2 -2
  58. package/dist/Fiber.d.ts.map +1 -1
  59. package/dist/Fiber.js.map +1 -1
  60. package/dist/FileSystem.d.ts +1 -1
  61. package/dist/FileSystem.d.ts.map +1 -1
  62. package/dist/FileSystem.js +5 -5
  63. package/dist/FileSystem.js.map +1 -1
  64. package/dist/Filter.d.ts +30 -34
  65. package/dist/Filter.d.ts.map +1 -1
  66. package/dist/Filter.js +15 -13
  67. package/dist/Filter.js.map +1 -1
  68. package/dist/Formatter.d.ts +131 -47
  69. package/dist/Formatter.d.ts.map +1 -1
  70. package/dist/Formatter.js +229 -51
  71. package/dist/Formatter.js.map +1 -1
  72. package/dist/Graph.d.ts +1 -1
  73. package/dist/Graph.d.ts.map +1 -1
  74. package/dist/Graph.js +5 -8
  75. package/dist/Graph.js.map +1 -1
  76. package/dist/HashMap.d.ts +15 -14
  77. package/dist/HashMap.d.ts.map +1 -1
  78. package/dist/HashMap.js +4 -4
  79. package/dist/HashMap.js.map +1 -1
  80. package/dist/Iterable.d.ts +40 -39
  81. package/dist/Iterable.d.ts.map +1 -1
  82. package/dist/Iterable.js +94 -22
  83. package/dist/Iterable.js.map +1 -1
  84. package/dist/JsonSchema.d.ts +299 -10
  85. package/dist/JsonSchema.d.ts.map +1 -1
  86. package/dist/JsonSchema.js +323 -4
  87. package/dist/JsonSchema.js.map +1 -1
  88. package/dist/Latch.d.ts +109 -0
  89. package/dist/Latch.d.ts.map +1 -0
  90. package/dist/Latch.js +72 -0
  91. package/dist/Latch.js.map +1 -0
  92. package/dist/Layer.d.ts +9 -9
  93. package/dist/Layer.d.ts.map +1 -1
  94. package/dist/Layer.js.map +1 -1
  95. package/dist/LayerMap.d.ts +4 -4
  96. package/dist/LayerMap.d.ts.map +1 -1
  97. package/dist/LogLevel.d.ts +32 -0
  98. package/dist/LogLevel.d.ts.map +1 -1
  99. package/dist/LogLevel.js +28 -100
  100. package/dist/LogLevel.js.map +1 -1
  101. package/dist/Logger.d.ts +29 -95
  102. package/dist/Logger.d.ts.map +1 -1
  103. package/dist/Logger.js +2 -3
  104. package/dist/Logger.js.map +1 -1
  105. package/dist/ManagedRuntime.d.ts +1 -1
  106. package/dist/ManagedRuntime.js +1 -1
  107. package/dist/Metric.d.ts +2 -2
  108. package/dist/Metric.d.ts.map +1 -1
  109. package/dist/Metric.js +1 -1
  110. package/dist/Metric.js.map +1 -1
  111. package/dist/Optic.d.ts +947 -18
  112. package/dist/Optic.d.ts.map +1 -1
  113. package/dist/Optic.js +454 -5
  114. package/dist/Optic.js.map +1 -1
  115. package/dist/Option.d.ts +22 -15
  116. package/dist/Option.d.ts.map +1 -1
  117. package/dist/Option.js +14 -7
  118. package/dist/Option.js.map +1 -1
  119. package/dist/Pipeable.d.ts +17 -0
  120. package/dist/Pipeable.d.ts.map +1 -1
  121. package/dist/Pipeable.js +19 -1
  122. package/dist/Pipeable.js.map +1 -1
  123. package/dist/PlatformError.d.ts +10 -9
  124. package/dist/PlatformError.d.ts.map +1 -1
  125. package/dist/PlatformError.js +2 -2
  126. package/dist/PlatformError.js.map +1 -1
  127. package/dist/Pool.d.ts +6 -4
  128. package/dist/Pool.d.ts.map +1 -1
  129. package/dist/Pool.js +7 -5
  130. package/dist/Pool.js.map +1 -1
  131. package/dist/PubSub.d.ts +3 -2
  132. package/dist/PubSub.d.ts.map +1 -1
  133. package/dist/PubSub.js +3 -2
  134. package/dist/PubSub.js.map +1 -1
  135. package/dist/Pull.d.ts.map +1 -1
  136. package/dist/Pull.js +1 -1
  137. package/dist/Pull.js.map +1 -1
  138. package/dist/Queue.d.ts.map +1 -1
  139. package/dist/Queue.js +0 -1
  140. package/dist/Queue.js.map +1 -1
  141. package/dist/Random.d.ts +35 -1
  142. package/dist/Random.d.ts.map +1 -1
  143. package/dist/Random.js +46 -12
  144. package/dist/Random.js.map +1 -1
  145. package/dist/RcMap.d.ts +2 -2
  146. package/dist/RcMap.d.ts.map +1 -1
  147. package/dist/RcMap.js +1 -1
  148. package/dist/RcMap.js.map +1 -1
  149. package/dist/RcRef.d.ts +1 -1
  150. package/dist/RcRef.d.ts.map +1 -1
  151. package/dist/Record.d.ts +24 -120
  152. package/dist/Record.d.ts.map +1 -1
  153. package/dist/Record.js +21 -41
  154. package/dist/Record.js.map +1 -1
  155. package/dist/Reducer.d.ts +166 -7
  156. package/dist/Reducer.d.ts.map +1 -1
  157. package/dist/Reducer.js +135 -1
  158. package/dist/Reducer.js.map +1 -1
  159. package/dist/References.d.ts +3 -3
  160. package/dist/References.d.ts.map +1 -1
  161. package/dist/Request.d.ts +1 -1
  162. package/dist/Request.d.ts.map +1 -1
  163. package/dist/Request.js +2 -1
  164. package/dist/Request.js.map +1 -1
  165. package/dist/RequestResolver.d.ts +6 -26
  166. package/dist/RequestResolver.d.ts.map +1 -1
  167. package/dist/RequestResolver.js +0 -20
  168. package/dist/RequestResolver.js.map +1 -1
  169. package/dist/Result.d.ts +12 -0
  170. package/dist/Result.d.ts.map +1 -1
  171. package/dist/Result.js +12 -0
  172. package/dist/Result.js.map +1 -1
  173. package/dist/Schedule.d.ts +47 -20
  174. package/dist/Schedule.d.ts.map +1 -1
  175. package/dist/Schedule.js +94 -34
  176. package/dist/Schedule.js.map +1 -1
  177. package/dist/Schema.d.ts +266 -50
  178. package/dist/Schema.d.ts.map +1 -1
  179. package/dist/Schema.js +426 -74
  180. package/dist/Schema.js.map +1 -1
  181. package/dist/SchemaAST.d.ts.map +1 -1
  182. package/dist/SchemaAST.js +7 -6
  183. package/dist/SchemaAST.js.map +1 -1
  184. package/dist/SchemaGetter.d.ts +2 -2
  185. package/dist/SchemaGetter.d.ts.map +1 -1
  186. package/dist/SchemaGetter.js +12 -14
  187. package/dist/SchemaGetter.js.map +1 -1
  188. package/dist/SchemaParser.d.ts +5 -0
  189. package/dist/SchemaParser.d.ts.map +1 -1
  190. package/dist/SchemaParser.js +10 -0
  191. package/dist/SchemaParser.js.map +1 -1
  192. package/dist/SchemaRepresentation.d.ts +44 -43
  193. package/dist/SchemaRepresentation.d.ts.map +1 -1
  194. package/dist/SchemaRepresentation.js +43 -24
  195. package/dist/SchemaRepresentation.js.map +1 -1
  196. package/dist/SchemaTransformation.d.ts +107 -3
  197. package/dist/SchemaTransformation.d.ts.map +1 -1
  198. package/dist/SchemaTransformation.js +159 -4
  199. package/dist/SchemaTransformation.js.map +1 -1
  200. package/dist/ScopedCache.d.ts +2 -2
  201. package/dist/ScopedCache.d.ts.map +1 -1
  202. package/dist/ScopedCache.js +1 -1
  203. package/dist/ScopedCache.js.map +1 -1
  204. package/dist/Semaphore.d.ts +211 -0
  205. package/dist/Semaphore.d.ts.map +1 -0
  206. package/dist/{PartitionedSemaphore.js → Semaphore.js} +97 -13
  207. package/dist/Semaphore.js.map +1 -0
  208. package/dist/ServiceMap.d.ts +39 -30
  209. package/dist/ServiceMap.d.ts.map +1 -1
  210. package/dist/ServiceMap.js +3 -3
  211. package/dist/ServiceMap.js.map +1 -1
  212. package/dist/Sink.d.ts +13 -13
  213. package/dist/Sink.d.ts.map +1 -1
  214. package/dist/Sink.js +53 -6
  215. package/dist/Sink.js.map +1 -1
  216. package/dist/Stream.d.ts +235 -423
  217. package/dist/Stream.d.ts.map +1 -1
  218. package/dist/Stream.js +124 -77
  219. package/dist/Stream.js.map +1 -1
  220. package/dist/Struct.d.ts +16 -0
  221. package/dist/Struct.d.ts.map +1 -1
  222. package/dist/Struct.js +22 -0
  223. package/dist/Struct.js.map +1 -1
  224. package/dist/SubscriptionRef.d.ts +2 -1
  225. package/dist/SubscriptionRef.d.ts.map +1 -1
  226. package/dist/SubscriptionRef.js +2 -1
  227. package/dist/SubscriptionRef.js.map +1 -1
  228. package/dist/SynchronizedRef.d.ts +2 -1
  229. package/dist/SynchronizedRef.d.ts.map +1 -1
  230. package/dist/SynchronizedRef.js +2 -1
  231. package/dist/SynchronizedRef.js.map +1 -1
  232. package/dist/Trie.d.ts +18 -17
  233. package/dist/Trie.d.ts.map +1 -1
  234. package/dist/Trie.js +5 -5
  235. package/dist/Trie.js.map +1 -1
  236. package/dist/TxChunk.d.ts +37 -37
  237. package/dist/TxChunk.d.ts.map +1 -1
  238. package/dist/TxChunk.js +3 -3
  239. package/dist/TxChunk.js.map +1 -1
  240. package/dist/TxDeferred.d.ts +328 -0
  241. package/dist/TxDeferred.d.ts.map +1 -0
  242. package/dist/TxDeferred.js +196 -0
  243. package/dist/TxDeferred.js.map +1 -0
  244. package/dist/TxHashMap.d.ts +84 -83
  245. package/dist/TxHashMap.d.ts.map +1 -1
  246. package/dist/TxHashMap.js +24 -24
  247. package/dist/TxHashMap.js.map +1 -1
  248. package/dist/TxHashSet.d.ts +35 -35
  249. package/dist/TxHashSet.d.ts.map +1 -1
  250. package/dist/TxHashSet.js +14 -14
  251. package/dist/TxHashSet.js.map +1 -1
  252. package/dist/TxPriorityQueue.d.ts +609 -0
  253. package/dist/TxPriorityQueue.d.ts.map +1 -0
  254. package/dist/TxPriorityQueue.js +415 -0
  255. package/dist/TxPriorityQueue.js.map +1 -0
  256. package/dist/TxPubSub.d.ts +585 -0
  257. package/dist/TxPubSub.d.ts.map +1 -0
  258. package/dist/TxPubSub.js +521 -0
  259. package/dist/TxPubSub.js.map +1 -0
  260. package/dist/TxQueue.d.ts +32 -32
  261. package/dist/TxQueue.d.ts.map +1 -1
  262. package/dist/TxQueue.js +26 -26
  263. package/dist/TxQueue.js.map +1 -1
  264. package/dist/TxReentrantLock.d.ts +523 -0
  265. package/dist/TxReentrantLock.d.ts.map +1 -0
  266. package/dist/TxReentrantLock.js +504 -0
  267. package/dist/TxReentrantLock.js.map +1 -0
  268. package/dist/TxRef.d.ts +34 -34
  269. package/dist/TxRef.d.ts.map +1 -1
  270. package/dist/TxRef.js +21 -14
  271. package/dist/TxRef.js.map +1 -1
  272. package/dist/TxSemaphore.d.ts +8 -8
  273. package/dist/TxSemaphore.d.ts.map +1 -1
  274. package/dist/TxSemaphore.js +7 -7
  275. package/dist/TxSemaphore.js.map +1 -1
  276. package/dist/TxSubscriptionRef.d.ts +508 -0
  277. package/dist/TxSubscriptionRef.d.ts.map +1 -0
  278. package/dist/TxSubscriptionRef.js +293 -0
  279. package/dist/TxSubscriptionRef.js.map +1 -0
  280. package/dist/Types.d.ts +84 -6
  281. package/dist/Types.d.ts.map +1 -1
  282. package/dist/index.d.ts +591 -20
  283. package/dist/index.d.ts.map +1 -1
  284. package/dist/index.js +591 -20
  285. package/dist/index.js.map +1 -1
  286. package/dist/internal/core.js +11 -3
  287. package/dist/internal/core.js.map +1 -1
  288. package/dist/internal/dateTime.js +3 -11
  289. package/dist/internal/dateTime.js.map +1 -1
  290. package/dist/internal/effect.js +263 -99
  291. package/dist/internal/effect.js.map +1 -1
  292. package/dist/internal/hashMap.js +5 -4
  293. package/dist/internal/hashMap.js.map +1 -1
  294. package/dist/internal/random.d.ts +2 -0
  295. package/dist/internal/random.d.ts.map +1 -0
  296. package/dist/internal/random.js +13 -0
  297. package/dist/internal/random.js.map +1 -0
  298. package/dist/internal/rcRef.js +3 -2
  299. package/dist/internal/rcRef.js.map +1 -1
  300. package/dist/internal/request.js +2 -2
  301. package/dist/internal/request.js.map +1 -1
  302. package/dist/internal/schema/annotations.js +2 -0
  303. package/dist/internal/schema/annotations.js.map +1 -1
  304. package/dist/internal/schema/schema.js +1 -0
  305. package/dist/internal/schema/schema.js.map +1 -1
  306. package/dist/internal/trie.js +5 -4
  307. package/dist/internal/trie.js.map +1 -1
  308. package/dist/testing/TestClock.d.ts +7 -6
  309. package/dist/testing/TestClock.d.ts.map +1 -1
  310. package/dist/testing/TestClock.js +6 -4
  311. package/dist/testing/TestClock.js.map +1 -1
  312. package/dist/testing/TestSchema.d.ts +8 -8
  313. package/dist/testing/TestSchema.d.ts.map +1 -1
  314. package/dist/testing/TestSchema.js.map +1 -1
  315. package/dist/unstable/ai/AiError.d.ts +128 -48
  316. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  317. package/dist/unstable/ai/AiError.js +11 -12
  318. package/dist/unstable/ai/AiError.js.map +1 -1
  319. package/dist/unstable/ai/Chat.d.ts +3 -3
  320. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  321. package/dist/unstable/ai/Chat.js +4 -3
  322. package/dist/unstable/ai/Chat.js.map +1 -1
  323. package/dist/unstable/ai/LanguageModel.d.ts +4 -2
  324. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  325. package/dist/unstable/ai/LanguageModel.js +86 -14
  326. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  327. package/dist/unstable/ai/McpSchema.d.ts +163 -87
  328. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  329. package/dist/unstable/ai/McpSchema.js +49 -12
  330. package/dist/unstable/ai/McpSchema.js.map +1 -1
  331. package/dist/unstable/ai/McpServer.d.ts +1 -1
  332. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  333. package/dist/unstable/ai/McpServer.js +35 -7
  334. package/dist/unstable/ai/McpServer.js.map +1 -1
  335. package/dist/unstable/ai/Model.d.ts +25 -7
  336. package/dist/unstable/ai/Model.d.ts.map +1 -1
  337. package/dist/unstable/ai/Model.js +22 -6
  338. package/dist/unstable/ai/Model.js.map +1 -1
  339. package/dist/unstable/ai/Prompt.d.ts +20 -20
  340. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  341. package/dist/unstable/ai/Response.d.ts +26 -26
  342. package/dist/unstable/ai/Response.d.ts.map +1 -1
  343. package/dist/unstable/ai/Response.js +1 -1
  344. package/dist/unstable/ai/Response.js.map +1 -1
  345. package/dist/unstable/ai/Tool.d.ts +19 -3
  346. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  347. package/dist/unstable/ai/Tool.js +14 -9
  348. package/dist/unstable/ai/Tool.js.map +1 -1
  349. package/dist/unstable/ai/index.d.ts +1 -1
  350. package/dist/unstable/ai/index.js +1 -1
  351. package/dist/unstable/cli/CliError.d.ts +5 -5
  352. package/dist/unstable/cli/CliOutput.js +59 -6
  353. package/dist/unstable/cli/CliOutput.js.map +1 -1
  354. package/dist/unstable/cli/Command.d.ts +276 -19
  355. package/dist/unstable/cli/Command.d.ts.map +1 -1
  356. package/dist/unstable/cli/Command.js +234 -36
  357. package/dist/unstable/cli/Command.js.map +1 -1
  358. package/dist/unstable/cli/GlobalFlag.d.ts +125 -0
  359. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -0
  360. package/dist/unstable/cli/GlobalFlag.js +118 -0
  361. package/dist/unstable/cli/GlobalFlag.js.map +1 -0
  362. package/dist/unstable/cli/HelpDoc.d.ts +70 -2
  363. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  364. package/dist/unstable/cli/index.d.ts +4 -0
  365. package/dist/unstable/cli/index.d.ts.map +1 -1
  366. package/dist/unstable/cli/index.js +4 -0
  367. package/dist/unstable/cli/index.js.map +1 -1
  368. package/dist/unstable/cli/internal/command.d.ts +17 -8
  369. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  370. package/dist/unstable/cli/internal/command.js +32 -23
  371. package/dist/unstable/cli/internal/command.js.map +1 -1
  372. package/dist/unstable/cli/internal/completions/CommandDescriptor.js +7 -2
  373. package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
  374. package/dist/unstable/cli/internal/help.d.ts +33 -0
  375. package/dist/unstable/cli/internal/help.d.ts.map +1 -0
  376. package/dist/unstable/cli/internal/help.js +107 -0
  377. package/dist/unstable/cli/internal/help.js.map +1 -0
  378. package/dist/unstable/cli/internal/parser.js +29 -36
  379. package/dist/unstable/cli/internal/parser.js.map +1 -1
  380. package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
  381. package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
  382. package/dist/unstable/cluster/ClusterCron.js +1 -1
  383. package/dist/unstable/cluster/ClusterCron.js.map +1 -1
  384. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  385. package/dist/unstable/cluster/ClusterWorkflowEngine.js +4 -3
  386. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  387. package/dist/unstable/cluster/Entity.d.ts +7 -6
  388. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  389. package/dist/unstable/cluster/Entity.js.map +1 -1
  390. package/dist/unstable/cluster/EntityResource.d.ts +2 -2
  391. package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
  392. package/dist/unstable/cluster/Envelope.d.ts +1 -1
  393. package/dist/unstable/cluster/K8sHttpClient.d.ts +1 -1
  394. package/dist/unstable/cluster/K8sHttpClient.js +4 -4
  395. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  396. package/dist/unstable/cluster/Message.d.ts +10 -10
  397. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  398. package/dist/unstable/cluster/MessageStorage.js +2 -1
  399. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  400. package/dist/unstable/cluster/Reply.d.ts +6 -6
  401. package/dist/unstable/cluster/Runner.d.ts +1 -1
  402. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  403. package/dist/unstable/cluster/Runners.js +4 -3
  404. package/dist/unstable/cluster/Runners.js.map +1 -1
  405. package/dist/unstable/cluster/Sharding.d.ts +2 -2
  406. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  407. package/dist/unstable/cluster/Sharding.js +9 -7
  408. package/dist/unstable/cluster/Sharding.js.map +1 -1
  409. package/dist/unstable/cluster/ShardingConfig.d.ts +21 -21
  410. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  411. package/dist/unstable/cluster/ShardingConfig.js +20 -20
  412. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  413. package/dist/unstable/cluster/SqlRunnerStorage.js +1 -1
  414. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  415. package/dist/unstable/cluster/internal/entityManager.js +5 -4
  416. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  417. package/dist/unstable/cluster/internal/entityReaper.js +2 -1
  418. package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
  419. package/dist/unstable/cluster/internal/resourceRef.js +2 -1
  420. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  421. package/dist/unstable/devtools/DevToolsSchema.d.ts +36 -36
  422. package/dist/unstable/encoding/Msgpack.d.ts +1 -1
  423. package/dist/unstable/encoding/Ndjson.d.ts +1 -1
  424. package/dist/unstable/encoding/Sse.d.ts +4 -4
  425. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  426. package/dist/unstable/encoding/Sse.js +1 -1
  427. package/dist/unstable/encoding/Sse.js.map +1 -1
  428. package/dist/unstable/eventlog/EventJournal.d.ts +2 -2
  429. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  430. package/dist/unstable/eventlog/EventLog.js +2 -1
  431. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  432. package/dist/unstable/eventlog/EventLogRemote.d.ts +6 -6
  433. package/dist/unstable/http/Cookies.d.ts +3 -3
  434. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  435. package/dist/unstable/http/Cookies.js +2 -2
  436. package/dist/unstable/http/Cookies.js.map +1 -1
  437. package/dist/unstable/http/Headers.d.ts.map +1 -1
  438. package/dist/unstable/http/Headers.js +27 -10
  439. package/dist/unstable/http/Headers.js.map +1 -1
  440. package/dist/unstable/http/HttpBody.d.ts +17 -2
  441. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  442. package/dist/unstable/http/HttpBody.js +28 -1
  443. package/dist/unstable/http/HttpBody.js.map +1 -1
  444. package/dist/unstable/http/HttpClient.d.ts +37 -13
  445. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  446. package/dist/unstable/http/HttpClient.js +4 -4
  447. package/dist/unstable/http/HttpClient.js.map +1 -1
  448. package/dist/unstable/http/HttpClientError.d.ts +7 -7
  449. package/dist/unstable/http/HttpClientRequest.d.ts +27 -11
  450. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  451. package/dist/unstable/http/HttpClientRequest.js +15 -3
  452. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  453. package/dist/unstable/http/HttpEffect.d.ts +3 -8
  454. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  455. package/dist/unstable/http/HttpEffect.js +42 -56
  456. package/dist/unstable/http/HttpEffect.js.map +1 -1
  457. package/dist/unstable/http/HttpMethod.d.ts +4 -4
  458. package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
  459. package/dist/unstable/http/HttpMethod.js +3 -3
  460. package/dist/unstable/http/HttpMethod.js.map +1 -1
  461. package/dist/unstable/http/HttpMiddleware.d.ts +1 -6
  462. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  463. package/dist/unstable/http/HttpMiddleware.js +8 -17
  464. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  465. package/dist/unstable/http/HttpServerError.d.ts +20 -33
  466. package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
  467. package/dist/unstable/http/HttpServerError.js +37 -44
  468. package/dist/unstable/http/HttpServerError.js.map +1 -1
  469. package/dist/unstable/http/HttpServerRequest.d.ts +1 -1
  470. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  471. package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
  472. package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
  473. package/dist/unstable/http/HttpServerRespondable.js +5 -5
  474. package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
  475. package/dist/unstable/http/HttpServerResponse.d.ts +2 -1
  476. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  477. package/dist/unstable/http/HttpServerResponse.js +3 -1
  478. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  479. package/dist/unstable/http/Multipart.d.ts +3 -3
  480. package/dist/unstable/http/UrlParams.d.ts +14 -6
  481. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  482. package/dist/unstable/http/UrlParams.js +1 -1
  483. package/dist/unstable/http/UrlParams.js.map +1 -1
  484. package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
  485. package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
  486. package/dist/unstable/http/internal/preResponseHandler.js +10 -0
  487. package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
  488. package/dist/unstable/httpapi/HttpApi.d.ts +3 -3
  489. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  490. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  491. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +11 -5
  492. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  493. package/dist/unstable/httpapi/HttpApiBuilder.js +23 -12
  494. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  495. package/dist/unstable/httpapi/HttpApiClient.d.ts +7 -2
  496. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  497. package/dist/unstable/httpapi/HttpApiClient.js +3 -3
  498. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  499. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +31 -44
  500. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  501. package/dist/unstable/httpapi/HttpApiEndpoint.js +15 -24
  502. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  503. package/dist/unstable/httpapi/HttpApiError.d.ts +11 -0
  504. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  505. package/dist/unstable/httpapi/HttpApiError.js +29 -9
  506. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  507. package/dist/unstable/httpapi/HttpApiGroup.d.ts +3 -3
  508. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  509. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  510. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -4
  511. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  512. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  513. package/dist/unstable/httpapi/HttpApiScalar.d.ts +6 -0
  514. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  515. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  516. package/dist/unstable/httpapi/HttpApiSecurity.d.ts +2 -2
  517. package/dist/unstable/httpapi/HttpApiSecurity.d.ts.map +1 -1
  518. package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
  519. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  520. package/dist/unstable/httpapi/OpenApi.js +32 -21
  521. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  522. package/dist/unstable/observability/Otlp.d.ts +12 -12
  523. package/dist/unstable/observability/Otlp.d.ts.map +1 -1
  524. package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
  525. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  526. package/dist/unstable/observability/OtlpExporter.js +1 -1
  527. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  528. package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
  529. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  530. package/dist/unstable/observability/OtlpLogger.js +7 -4
  531. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  532. package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
  533. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  534. package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
  535. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  536. package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
  537. package/dist/unstable/persistence/KeyValueStore.js +6 -6
  538. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  539. package/dist/unstable/persistence/Persistable.d.ts +2 -2
  540. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  541. package/dist/unstable/persistence/PersistedCache.d.ts +6 -5
  542. package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
  543. package/dist/unstable/persistence/PersistedCache.js +2 -1
  544. package/dist/unstable/persistence/PersistedCache.js.map +1 -1
  545. package/dist/unstable/persistence/PersistedQueue.d.ts +12 -12
  546. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  547. package/dist/unstable/persistence/PersistedQueue.js +12 -11
  548. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  549. package/dist/unstable/persistence/Persistence.d.ts +1 -1
  550. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  551. package/dist/unstable/persistence/Persistence.js +2 -2
  552. package/dist/unstable/persistence/Persistence.js.map +1 -1
  553. package/dist/unstable/persistence/RateLimiter.d.ts +3 -3
  554. package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
  555. package/dist/unstable/persistence/RateLimiter.js +1 -1
  556. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  557. package/dist/unstable/process/ChildProcess.d.ts +5 -128
  558. package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
  559. package/dist/unstable/process/ChildProcess.js +1 -65
  560. package/dist/unstable/process/ChildProcess.js.map +1 -1
  561. package/dist/unstable/process/ChildProcessSpawner.d.ts +45 -7
  562. package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
  563. package/dist/unstable/process/ChildProcessSpawner.js +21 -1
  564. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  565. package/dist/unstable/reactivity/Atom.d.ts +10 -10
  566. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  567. package/dist/unstable/reactivity/Atom.js +16 -13
  568. package/dist/unstable/reactivity/Atom.js.map +1 -1
  569. package/dist/unstable/reactivity/AtomHttpApi.d.ts +8 -8
  570. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  571. package/dist/unstable/reactivity/AtomHttpApi.js +3 -3
  572. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  573. package/dist/unstable/reactivity/AtomRegistry.d.ts +6 -0
  574. package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
  575. package/dist/unstable/reactivity/AtomRegistry.js +24 -7
  576. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  577. package/dist/unstable/reactivity/AtomRpc.d.ts +1 -1
  578. package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
  579. package/dist/unstable/reactivity/AtomRpc.js +1 -1
  580. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  581. package/dist/unstable/reactivity/Hydration.d.ts +39 -0
  582. package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
  583. package/dist/unstable/reactivity/Hydration.js +76 -0
  584. package/dist/unstable/reactivity/Hydration.js.map +1 -0
  585. package/dist/unstable/reactivity/index.d.ts +4 -0
  586. package/dist/unstable/reactivity/index.d.ts.map +1 -1
  587. package/dist/unstable/reactivity/index.js +4 -0
  588. package/dist/unstable/reactivity/index.js.map +1 -1
  589. package/dist/unstable/rpc/Rpc.d.ts +4 -4
  590. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  591. package/dist/unstable/rpc/Rpc.js.map +1 -1
  592. package/dist/unstable/rpc/RpcClient.d.ts +5 -26
  593. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  594. package/dist/unstable/rpc/RpcClient.js +6 -13
  595. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  596. package/dist/unstable/rpc/RpcGroup.d.ts +2 -2
  597. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  598. package/dist/unstable/rpc/RpcGroup.js.map +1 -1
  599. package/dist/unstable/rpc/RpcMiddleware.d.ts +3 -3
  600. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  601. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  602. package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
  603. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  604. package/dist/unstable/rpc/RpcSchema.js +14 -0
  605. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  606. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  607. package/dist/unstable/rpc/RpcSerialization.js +34 -9
  608. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  609. package/dist/unstable/rpc/RpcServer.d.ts +0 -7
  610. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  611. package/dist/unstable/rpc/RpcServer.js +15 -15
  612. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  613. package/dist/unstable/rpc/Utils.d.ts.map +1 -1
  614. package/dist/unstable/rpc/Utils.js +2 -1
  615. package/dist/unstable/rpc/Utils.js.map +1 -1
  616. package/dist/unstable/schema/Model.d.ts +1 -1
  617. package/dist/unstable/schema/Model.d.ts.map +1 -1
  618. package/dist/unstable/schema/VariantSchema.d.ts +3 -3
  619. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  620. package/dist/unstable/schema/VariantSchema.js +3 -3
  621. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  622. package/dist/unstable/socket/Socket.d.ts +4 -4
  623. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  624. package/dist/unstable/socket/Socket.js +6 -5
  625. package/dist/unstable/socket/Socket.js.map +1 -1
  626. package/dist/unstable/socket/SocketServer.d.ts +3 -3
  627. package/dist/unstable/sql/Migrator.d.ts +1 -1
  628. package/dist/unstable/sql/SqlClient.d.ts +1 -1
  629. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  630. package/dist/unstable/sql/SqlError.d.ts +14 -14
  631. package/dist/unstable/sql/SqlError.d.ts.map +1 -1
  632. package/dist/unstable/sql/SqlError.js +9 -3
  633. package/dist/unstable/sql/SqlError.js.map +1 -1
  634. package/dist/unstable/sql/SqlModel.d.ts +2 -2
  635. package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
  636. package/dist/unstable/sql/SqlModel.js +3 -3
  637. package/dist/unstable/sql/SqlModel.js.map +1 -1
  638. package/dist/unstable/sql/SqlSchema.d.ts +16 -5
  639. package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
  640. package/dist/unstable/sql/SqlSchema.js +17 -7
  641. package/dist/unstable/sql/SqlSchema.js.map +1 -1
  642. package/dist/unstable/sql/Statement.js +0 -1
  643. package/dist/unstable/sql/Statement.js.map +1 -1
  644. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  645. package/dist/unstable/workers/Worker.js +2 -1
  646. package/dist/unstable/workers/Worker.js.map +1 -1
  647. package/dist/unstable/workflow/DurableClock.d.ts +3 -3
  648. package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
  649. package/dist/unstable/workflow/DurableClock.js +3 -3
  650. package/dist/unstable/workflow/DurableClock.js.map +1 -1
  651. package/dist/unstable/workflow/DurableDeferred.js +2 -2
  652. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  653. package/dist/unstable/workflow/Workflow.d.ts +3 -3
  654. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  655. package/dist/unstable/workflow/Workflow.js +1 -1
  656. package/dist/unstable/workflow/Workflow.js.map +1 -1
  657. package/dist/unstable/workflow/WorkflowEngine.d.ts +12 -1
  658. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  659. package/dist/unstable/workflow/WorkflowEngine.js +137 -1
  660. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  661. package/package.json +2 -2
  662. package/src/Array.ts +190 -342
  663. package/src/Cache.ts +9 -8
  664. package/src/Cause.ts +1 -1
  665. package/src/Channel.ts +554 -138
  666. package/src/Chunk.ts +81 -268
  667. package/src/Combiner.ts +280 -13
  668. package/src/Config.ts +183 -21
  669. package/src/Data.ts +538 -374
  670. package/src/DateTime.ts +24 -164
  671. package/src/Duration.ts +15 -15
  672. package/src/Effect.ts +991 -800
  673. package/src/Encoding.ts +879 -0
  674. package/src/Equal.ts +278 -111
  675. package/src/ErrorReporter.ts +459 -0
  676. package/src/Fiber.ts +9 -2
  677. package/src/FileSystem.ts +7 -8
  678. package/src/Filter.ts +48 -58
  679. package/src/Formatter.ts +253 -51
  680. package/src/Graph.ts +24 -11
  681. package/src/HashMap.ts +15 -14
  682. package/src/Iterable.ts +105 -50
  683. package/src/JsonSchema.ts +383 -10
  684. package/src/Latch.ts +112 -0
  685. package/src/Layer.ts +11 -15
  686. package/src/LayerMap.ts +5 -5
  687. package/src/LogLevel.ts +37 -0
  688. package/src/Logger.ts +33 -100
  689. package/src/ManagedRuntime.ts +1 -1
  690. package/src/Metric.ts +4 -4
  691. package/src/Optic.ts +948 -19
  692. package/src/Option.ts +30 -20
  693. package/src/Pipeable.ts +32 -1
  694. package/src/PlatformError.ts +5 -5
  695. package/src/Pool.ts +13 -11
  696. package/src/PubSub.ts +10 -9
  697. package/src/Pull.ts +1 -1
  698. package/src/Queue.ts +0 -1
  699. package/src/Random.ts +51 -14
  700. package/src/RcMap.ts +5 -5
  701. package/src/RcRef.ts +1 -1
  702. package/src/Record.ts +43 -152
  703. package/src/Reducer.ts +166 -7
  704. package/src/References.ts +4 -4
  705. package/src/Request.ts +3 -2
  706. package/src/RequestResolver.ts +9 -29
  707. package/src/Result.ts +13 -0
  708. package/src/Schedule.ts +318 -160
  709. package/src/Schema.ts +661 -116
  710. package/src/SchemaAST.ts +7 -6
  711. package/src/SchemaGetter.ts +12 -14
  712. package/src/SchemaParser.ts +11 -0
  713. package/src/SchemaRepresentation.ts +43 -24
  714. package/src/SchemaTransformation.ts +189 -4
  715. package/src/ScopedCache.ts +3 -3
  716. package/src/Semaphore.ts +356 -0
  717. package/src/ServiceMap.ts +47 -38
  718. package/src/Sink.ts +78 -26
  719. package/src/Stream.ts +566 -601
  720. package/src/Struct.ts +26 -0
  721. package/src/SubscriptionRef.ts +3 -2
  722. package/src/SynchronizedRef.ts +3 -2
  723. package/src/Trie.ts +18 -17
  724. package/src/TxChunk.ts +72 -53
  725. package/src/TxDeferred.ts +394 -0
  726. package/src/TxHashMap.ts +332 -285
  727. package/src/TxHashSet.ts +111 -116
  728. package/src/TxPriorityQueue.ts +767 -0
  729. package/src/TxPubSub.ts +789 -0
  730. package/src/TxQueue.ts +241 -251
  731. package/src/TxReentrantLock.ts +753 -0
  732. package/src/TxRef.ts +50 -38
  733. package/src/TxSemaphore.ts +29 -32
  734. package/src/TxSubscriptionRef.ts +639 -0
  735. package/src/Types.ts +78 -2
  736. package/src/index.ts +600 -21
  737. package/src/internal/core.ts +12 -5
  738. package/src/internal/dateTime.ts +9 -30
  739. package/src/internal/effect.ts +744 -265
  740. package/src/internal/hashMap.ts +9 -7
  741. package/src/internal/random.ts +20 -0
  742. package/src/internal/rcRef.ts +4 -3
  743. package/src/internal/request.ts +2 -2
  744. package/src/internal/schema/annotations.ts +2 -0
  745. package/src/internal/schema/schema.ts +1 -0
  746. package/src/internal/trie.ts +16 -9
  747. package/src/testing/TestClock.ts +13 -11
  748. package/src/testing/TestSchema.ts +10 -10
  749. package/src/unstable/ai/AiError.ts +97 -44
  750. package/src/unstable/ai/Chat.ts +12 -11
  751. package/src/unstable/ai/LanguageModel.ts +129 -25
  752. package/src/unstable/ai/McpSchema.ts +59 -13
  753. package/src/unstable/ai/McpServer.ts +48 -9
  754. package/src/unstable/ai/Model.ts +40 -9
  755. package/src/unstable/ai/Prompt.ts +37 -37
  756. package/src/unstable/ai/Response.ts +25 -25
  757. package/src/unstable/ai/Tool.ts +19 -13
  758. package/src/unstable/ai/index.ts +1 -1
  759. package/src/unstable/cli/CliOutput.ts +75 -6
  760. package/src/unstable/cli/Command.ts +501 -60
  761. package/src/unstable/cli/GlobalFlag.ts +243 -0
  762. package/src/unstable/cli/HelpDoc.ts +80 -2
  763. package/src/unstable/cli/index.ts +5 -0
  764. package/src/unstable/cli/internal/command.ts +50 -34
  765. package/src/unstable/cli/internal/completions/CommandDescriptor.ts +7 -2
  766. package/src/unstable/cli/internal/help.ts +146 -0
  767. package/src/unstable/cli/internal/parser.ts +33 -54
  768. package/src/unstable/cluster/ClusterCron.ts +2 -2
  769. package/src/unstable/cluster/ClusterWorkflowEngine.ts +5 -4
  770. package/src/unstable/cluster/Entity.ts +11 -10
  771. package/src/unstable/cluster/EntityResource.ts +4 -4
  772. package/src/unstable/cluster/Envelope.ts +1 -1
  773. package/src/unstable/cluster/K8sHttpClient.ts +5 -5
  774. package/src/unstable/cluster/MessageStorage.ts +3 -5
  775. package/src/unstable/cluster/Runners.ts +6 -5
  776. package/src/unstable/cluster/Sharding.ts +12 -10
  777. package/src/unstable/cluster/ShardingConfig.ts +30 -31
  778. package/src/unstable/cluster/SqlRunnerStorage.ts +1 -1
  779. package/src/unstable/cluster/internal/entityManager.ts +9 -8
  780. package/src/unstable/cluster/internal/entityReaper.ts +2 -1
  781. package/src/unstable/cluster/internal/resourceRef.ts +2 -1
  782. package/src/unstable/encoding/Sse.ts +3 -5
  783. package/src/unstable/eventlog/EventLog.ts +2 -1
  784. package/src/unstable/http/Cookies.ts +3 -3
  785. package/src/unstable/http/Headers.ts +28 -13
  786. package/src/unstable/http/HttpBody.ts +42 -1
  787. package/src/unstable/http/HttpClient.ts +58 -23
  788. package/src/unstable/http/HttpClientRequest.ts +38 -13
  789. package/src/unstable/http/HttpEffect.ts +46 -68
  790. package/src/unstable/http/HttpMethod.ts +16 -4
  791. package/src/unstable/http/HttpMiddleware.ts +9 -24
  792. package/src/unstable/http/HttpServerError.ts +42 -45
  793. package/src/unstable/http/HttpServerRequest.ts +1 -1
  794. package/src/unstable/http/HttpServerRespondable.ts +6 -6
  795. package/src/unstable/http/HttpServerResponse.ts +4 -2
  796. package/src/unstable/http/Multipart.ts +2 -2
  797. package/src/unstable/http/UrlParams.ts +20 -5
  798. package/src/unstable/http/internal/preResponseHandler.ts +15 -0
  799. package/src/unstable/httpapi/HttpApi.ts +5 -5
  800. package/src/unstable/httpapi/HttpApiBuilder.ts +77 -21
  801. package/src/unstable/httpapi/HttpApiClient.ts +14 -6
  802. package/src/unstable/httpapi/HttpApiEndpoint.ts +67 -83
  803. package/src/unstable/httpapi/HttpApiError.ts +30 -9
  804. package/src/unstable/httpapi/HttpApiGroup.ts +6 -6
  805. package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -4
  806. package/src/unstable/httpapi/HttpApiScalar.ts +6 -0
  807. package/src/unstable/httpapi/HttpApiSecurity.ts +3 -3
  808. package/src/unstable/httpapi/OpenApi.ts +41 -23
  809. package/src/unstable/observability/Otlp.ts +12 -12
  810. package/src/unstable/observability/OtlpExporter.ts +3 -3
  811. package/src/unstable/observability/OtlpLogger.ts +13 -9
  812. package/src/unstable/observability/OtlpMetrics.ts +4 -4
  813. package/src/unstable/observability/OtlpTracer.ts +4 -4
  814. package/src/unstable/persistence/KeyValueStore.ts +6 -6
  815. package/src/unstable/persistence/Persistable.ts +2 -2
  816. package/src/unstable/persistence/PersistedCache.ts +20 -9
  817. package/src/unstable/persistence/PersistedQueue.ts +25 -24
  818. package/src/unstable/persistence/Persistence.ts +3 -3
  819. package/src/unstable/persistence/RateLimiter.ts +4 -4
  820. package/src/unstable/process/ChildProcess.ts +6 -208
  821. package/src/unstable/process/ChildProcessSpawner.ts +75 -14
  822. package/src/unstable/reactivity/Atom.ts +27 -25
  823. package/src/unstable/reactivity/AtomHttpApi.ts +21 -20
  824. package/src/unstable/reactivity/AtomRegistry.ts +31 -7
  825. package/src/unstable/reactivity/AtomRpc.ts +3 -3
  826. package/src/unstable/reactivity/Hydration.ts +112 -0
  827. package/src/unstable/reactivity/index.ts +5 -0
  828. package/src/unstable/rpc/Rpc.ts +6 -6
  829. package/src/unstable/rpc/RpcClient.ts +12 -54
  830. package/src/unstable/rpc/RpcGroup.ts +4 -4
  831. package/src/unstable/rpc/RpcMiddleware.ts +3 -3
  832. package/src/unstable/rpc/RpcSchema.ts +17 -0
  833. package/src/unstable/rpc/RpcSerialization.ts +44 -9
  834. package/src/unstable/rpc/RpcServer.ts +21 -30
  835. package/src/unstable/rpc/Utils.ts +2 -1
  836. package/src/unstable/schema/VariantSchema.ts +6 -6
  837. package/src/unstable/socket/Socket.ts +16 -17
  838. package/src/unstable/sql/SqlClient.ts +1 -1
  839. package/src/unstable/sql/SqlError.ts +11 -9
  840. package/src/unstable/sql/SqlModel.ts +5 -5
  841. package/src/unstable/sql/SqlSchema.ts +41 -25
  842. package/src/unstable/sql/Statement.ts +0 -1
  843. package/src/unstable/workers/Worker.ts +2 -1
  844. package/src/unstable/workflow/DurableClock.ts +8 -8
  845. package/src/unstable/workflow/DurableDeferred.ts +2 -2
  846. package/src/unstable/workflow/Workflow.ts +6 -2
  847. package/src/unstable/workflow/WorkflowEngine.ts +185 -2
  848. package/dist/PartitionedSemaphore.d.ts +0 -52
  849. package/dist/PartitionedSemaphore.d.ts.map +0 -1
  850. package/dist/PartitionedSemaphore.js.map +0 -1
  851. package/dist/encoding/Base64.d.ts +0 -67
  852. package/dist/encoding/Base64.d.ts.map +0 -1
  853. package/dist/encoding/Base64.js +0 -146
  854. package/dist/encoding/Base64.js.map +0 -1
  855. package/dist/encoding/Base64Url.d.ts +0 -60
  856. package/dist/encoding/Base64Url.d.ts.map +0 -1
  857. package/dist/encoding/Base64Url.js +0 -89
  858. package/dist/encoding/Base64Url.js.map +0 -1
  859. package/dist/encoding/EncodingError.d.ts +0 -31
  860. package/dist/encoding/EncodingError.d.ts.map +0 -1
  861. package/dist/encoding/EncodingError.js +0 -22
  862. package/dist/encoding/EncodingError.js.map +0 -1
  863. package/dist/encoding/Hex.d.ts +0 -61
  864. package/dist/encoding/Hex.d.ts.map +0 -1
  865. package/dist/encoding/Hex.js +0 -115
  866. package/dist/encoding/Hex.js.map +0 -1
  867. package/dist/encoding/index.d.ts +0 -26
  868. package/dist/encoding/index.d.ts.map +0 -1
  869. package/dist/encoding/index.js +0 -27
  870. package/dist/encoding/index.js.map +0 -1
  871. package/dist/unstable/cli/internal/builtInFlags.d.ts +0 -7
  872. package/dist/unstable/cli/internal/builtInFlags.d.ts.map +0 -1
  873. package/dist/unstable/cli/internal/builtInFlags.js +0 -44
  874. package/dist/unstable/cli/internal/builtInFlags.js.map +0 -1
  875. package/src/PartitionedSemaphore.ts +0 -182
  876. package/src/encoding/Base64.ts +0 -366
  877. package/src/encoding/Base64Url.ts +0 -104
  878. package/src/encoding/EncodingError.ts +0 -35
  879. package/src/encoding/Hex.ts +0 -390
  880. package/src/encoding/index.ts +0 -31
  881. package/src/unstable/cli/internal/builtInFlags.ts +0 -78
@@ -5,6 +5,7 @@ import type * as Console from "../Console.ts"
5
5
  import * as Duration from "../Duration.ts"
6
6
  import type * as Effect from "../Effect.ts"
7
7
  import * as Equal from "../Equal.ts"
8
+ import type { ErrorReporter } from "../ErrorReporter.ts"
8
9
  import type * as Exit from "../Exit.ts"
9
10
  import type * as Fiber from "../Fiber.ts"
10
11
  import * as Filter from "../Filter.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"
@@ -48,7 +50,9 @@ import type {
48
50
  ExcludeTag,
49
51
  ExtractReason,
50
52
  ExtractTag,
53
+ NarrowReason,
51
54
  NoInfer,
55
+ OmitReason,
52
56
  ReasonOf,
53
57
  ReasonTags,
54
58
  Simplify,
@@ -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 => {
@@ -489,17 +494,33 @@ const fiberIdStore = { id: 0 }
489
494
  export const getCurrentFiber = (): Fiber.Fiber<any, any> | undefined => (globalThis as any)[currentFiberTypeId]
490
495
 
491
496
  const keepAlive = (() => {
497
+ let isAvailable: boolean | undefined
498
+ const start = () => {
499
+ if (isAvailable === true) return setInterval(constVoid, 2_147_483_647)
500
+ else if (isAvailable === false) return undefined
501
+
502
+ try {
503
+ const running = setInterval(constVoid, 2_147_483_647)
504
+ isAvailable = true
505
+ return running
506
+ } catch {
507
+ isAvailable = false
508
+ return undefined
509
+ }
510
+ }
492
511
  let count = 0
493
512
  let running: ReturnType<typeof globalThis.setInterval> | undefined = undefined
494
513
  return ({
495
514
  increment() {
496
515
  count++
497
- running ??= globalThis.setInterval(constVoid, 2_147_483_647)
516
+ if (running === undefined) {
517
+ running = start()
518
+ }
498
519
  },
499
520
  decrement() {
500
521
  count--
501
522
  if (count === 0 && running !== undefined) {
502
- globalThis.clearInterval(running)
523
+ clearInterval(running)
503
524
  running = undefined
504
525
  }
505
526
  }
@@ -784,6 +805,7 @@ export const fiberJoinAll = <A extends Iterable<Fiber.Fiber<any, any>>>(self: A)
784
805
  > =>
785
806
  callback((resume) => {
786
807
  const fibers = Array.from(self)
808
+ if (fibers.length === 0) return resume(succeed(Arr.empty() as any))
787
809
  const out = new Array<any>(fibers.length) as Arr.NonEmptyArray<any>
788
810
  const cancels = Arr.empty<() => void>()
789
811
  let done = 0
@@ -812,13 +834,29 @@ export const fiberInterrupt = <A, E>(
812
834
 
813
835
  /** @internal */
814
836
  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
- }))
837
+ (
838
+ fiberId: number | undefined,
839
+ annotations?: ServiceMap.ServiceMap<never> | undefined
840
+ ): <A, E>(self: Fiber.Fiber<A, E>) => Effect.Effect<void>
841
+ <A, E>(
842
+ self: Fiber.Fiber<A, E>,
843
+ fiberId: number | undefined,
844
+ annotations?: ServiceMap.ServiceMap<never> | undefined
845
+ ): Effect.Effect<void>
846
+ } = dual(
847
+ (args) => hasProperty(args[0], FiberTypeId),
848
+ <A, E>(
849
+ self: Fiber.Fiber<A, E>,
850
+ fiberId: number | undefined,
851
+ annotations?: ServiceMap.ServiceMap<never> | undefined
852
+ ): Effect.Effect<void> =>
853
+ withFiber((parent) => {
854
+ let ann = fiberStackAnnotations(parent)
855
+ ann = ann && annotations ? ServiceMap.merge(ann, annotations) : ann ?? annotations
856
+ self.interruptUnsafe(fiberId, ann)
857
+ return asVoid(fiberAwait(self))
858
+ })
859
+ )
822
860
 
823
861
  /** @internal */
824
862
  export const fiberInterruptAll = <A extends Iterable<Fiber.Fiber<any, any>>>(
@@ -1945,17 +1983,17 @@ export const exitFindErrorOption = <A, E>(self: Exit.Exit<A, E>): Option.Option<
1945
1983
 
1946
1984
  /** @internal */
1947
1985
  export const service: {
1948
- <I, S>(service: ServiceMap.Service<I, S>): Effect.Effect<S, never, I>
1986
+ <I, S>(service: ServiceMap.Key<I, S>): Effect.Effect<S, never, I>
1949
1987
  } = fromYieldable as any
1950
1988
 
1951
1989
  /** @internal */
1952
1990
  export const serviceOption = <I, S>(
1953
- service: ServiceMap.Service<I, S>
1991
+ service: ServiceMap.Key<I, S>
1954
1992
  ): Effect.Effect<Option.Option<S>> => withFiber((fiber) => succeed(ServiceMap.getOption(fiber.services, service)))
1955
1993
 
1956
1994
  /** @internal */
1957
1995
  export const serviceOptional = <I, S>(
1958
- service: ServiceMap.Service<I, S>
1996
+ service: ServiceMap.Key<I, S>
1959
1997
  ): Effect.Effect<S, Cause.NoSuchElementError> =>
1960
1998
  withFiber((fiber) =>
1961
1999
  fiber.services.mapUnsafe.has(service.key)
@@ -1983,23 +2021,8 @@ export const updateServices: {
1983
2021
  const nextServices = f(prev)
1984
2022
  if (prev === nextServices) return self as any
1985
2023
  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))
2024
+ return onExitPrimitive(self, () => {
2025
+ fiber.setServices(prev)
2003
2026
  return undefined
2004
2027
  })
2005
2028
  })
@@ -2008,27 +2031,26 @@ export const updateServices: {
2008
2031
  /** @internal */
2009
2032
  export const updateService: {
2010
2033
  <I, A>(
2011
- service: ServiceMap.Service<I, A>,
2034
+ service: ServiceMap.Key<I, A>,
2012
2035
  f: (value: A) => A
2013
2036
  ): <XA, E, R>(self: Effect.Effect<XA, E, R>) => Effect.Effect<XA, E, R | I>
2014
2037
  <XA, E, R, I, A>(
2015
2038
  self: Effect.Effect<XA, E, R>,
2016
- service: ServiceMap.Service<I, A>,
2039
+ service: ServiceMap.Key<I, A>,
2017
2040
  f: (value: A) => A
2018
2041
  ): Effect.Effect<XA, E, R | I>
2019
2042
  } = dual(
2020
2043
  3,
2021
2044
  <XA, E, R, I, A>(
2022
2045
  self: Effect.Effect<XA, E, R>,
2023
- service: ServiceMap.Service<I, A>,
2046
+ service: ServiceMap.Key<I, A>,
2024
2047
  f: (value: A) => A
2025
2048
  ): Effect.Effect<XA, E, R | I> =>
2026
- withFiber((fiber) => {
2027
- const prev = ServiceMap.getUnsafe(fiber.services, service)
2049
+ updateServices(self, (s) => {
2050
+ const prev = ServiceMap.getUnsafe(s, service)
2028
2051
  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))))
2052
+ if (prev === next) return s
2053
+ return ServiceMap.add(s, service, next)
2032
2054
  })
2033
2055
  )
2034
2056
 
@@ -2066,20 +2088,20 @@ export const provideServices: {
2066
2088
  /** @internal */
2067
2089
  export const provideService: {
2068
2090
  <I, S>(
2069
- service: ServiceMap.Service<I, S>
2091
+ service: ServiceMap.Key<I, S>
2070
2092
  ): {
2071
2093
  (implementation: S): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, I>>
2072
2094
  <A, E, R>(self: Effect.Effect<A, E, R>, implementation: S): Effect.Effect<A, E, Exclude<R, I>>
2073
2095
  }
2074
2096
  <I, S>(
2075
- key: ServiceMap.Service<I, S>,
2097
+ key: ServiceMap.Key<I, S>,
2076
2098
  implementation: S
2077
2099
  ): <A, E, R>(
2078
2100
  self: Effect.Effect<A, E, R>
2079
2101
  ) => Effect.Effect<A, E, Exclude<R, I>>
2080
2102
  <A, E, R, I, S>(
2081
2103
  self: Effect.Effect<A, E, R>,
2082
- service: ServiceMap.Service<I, S>,
2104
+ service: ServiceMap.Key<I, S>,
2083
2105
  implementation: S
2084
2106
  ): Effect.Effect<A, E, Exclude<R, I>>
2085
2107
  } = function(this: any) {
@@ -2092,34 +2114,33 @@ export const provideService: {
2092
2114
 
2093
2115
  const provideServiceImpl = <A, E, R, I, S>(
2094
2116
  self: Effect.Effect<A, E, R>,
2095
- service: ServiceMap.Service<I, S>,
2117
+ service: ServiceMap.Key<I, S>,
2096
2118
  implementation: S
2097
2119
  ): 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))))
2120
+ updateServices(self, (s) => {
2121
+ const prev = s.mapUnsafe.get(service.key)
2122
+ if (prev === implementation) return s
2123
+ return ServiceMap.add(s, service, implementation)
2103
2124
  }) as any
2104
2125
 
2105
2126
  /** @internal */
2106
2127
  export const provideServiceEffect: {
2107
2128
  <I, S, E2, R2>(
2108
- service: ServiceMap.Service<I, S>,
2129
+ service: ServiceMap.Key<I, S>,
2109
2130
  acquire: Effect.Effect<S, E2, R2>
2110
2131
  ): <A, E, R>(
2111
2132
  self: Effect.Effect<A, E, R>
2112
2133
  ) => Effect.Effect<A, E | E2, Exclude<R, I> | R2>
2113
2134
  <A, E, R, I, S, E2, R2>(
2114
2135
  self: Effect.Effect<A, E, R>,
2115
- service: ServiceMap.Service<I, S>,
2136
+ service: ServiceMap.Key<I, S>,
2116
2137
  acquire: Effect.Effect<S, E2, R2>
2117
2138
  ): Effect.Effect<A, E | E2, Exclude<R, I> | R2>
2118
2139
  } = dual(
2119
2140
  3,
2120
2141
  <A, E, R, I, S, E2, R2>(
2121
2142
  self: Effect.Effect<A, E, R>,
2122
- service: ServiceMap.Service<I, S>,
2143
+ service: ServiceMap.Key<I, S>,
2123
2144
  acquire: Effect.Effect<S, E2, R2>
2124
2145
  ): Effect.Effect<A, E | E2, Exclude<R, I> | R2> =>
2125
2146
  flatMap(acquire, (implementation) => provideService(self, service, implementation))
@@ -2203,19 +2224,12 @@ export const filterOrFail: {
2203
2224
  predicate: Predicate.Predicate<NoInfer<A>>,
2204
2225
  orFailWith: (a: NoInfer<A>) => E2
2205
2226
  ): <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
2227
  <A, B extends A>(
2211
2228
  refinement: Predicate.Refinement<NoInfer<A>, B>
2212
2229
  ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, Cause.NoSuchElementError | E, R>
2213
2230
  <A>(
2214
2231
  predicate: Predicate.Predicate<NoInfer<A>>
2215
2232
  ): <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
2233
  <A, E, R, E2, B extends A>(
2220
2234
  self: Effect.Effect<A, E, R>,
2221
2235
  refinement: Predicate.Refinement<NoInfer<A>, B>,
@@ -2226,11 +2240,6 @@ export const filterOrFail: {
2226
2240
  predicate: Predicate.Predicate<NoInfer<A>>,
2227
2241
  orFailWith: (a: NoInfer<A>) => E2
2228
2242
  ): 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
2243
  <A, E, R, B extends A>(
2235
2244
  self: Effect.Effect<A, E, R>,
2236
2245
  refinement: Predicate.Refinement<NoInfer<A>, B>
@@ -2239,18 +2248,14 @@ export const filterOrFail: {
2239
2248
  self: Effect.Effect<A, E, R>,
2240
2249
  predicate: Predicate.Predicate<NoInfer<A>>
2241
2250
  ): 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
2251
  } = dual((args) => isEffect(args[0]), <A, E, R, E2>(
2247
2252
  self: Effect.Effect<A, E, R>,
2248
- filter: Predicate.Predicate<NoInfer<A>> | Filter.Filter<A, any, any>,
2253
+ predicate: Predicate.Predicate<NoInfer<A>>,
2249
2254
  orFailWith?: (a: any) => E2
2250
2255
  ): Effect.Effect<any, E | E2 | Cause.NoSuchElementError, R> =>
2251
2256
  filterOrElse(
2252
2257
  self,
2253
- filter as any,
2258
+ predicate as any,
2254
2259
  orFailWith ? (a: any) => fail(orFailWith(a)) : () => fail(new NoSuchElementError() as E2)
2255
2260
  ))
2256
2261
 
@@ -2400,27 +2405,55 @@ const OnFailureProto = makePrimitiveProto({
2400
2405
 
2401
2406
  /** @internal */
2402
2407
  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>
2408
+ <E, B, E2, R2>(
2409
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2410
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2406
2411
  ): <A, R>(
2407
2412
  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>>>(
2413
+ ) => Effect.Effect<A | B, E | E2, R | R2>
2414
+ <A, E, R, B, E2, R2>(
2410
2415
  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>
2416
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2417
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2418
+ ): Effect.Effect<A | B, E | E2, R | R2>
2414
2419
  } = dual(
2415
2420
  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)
2421
+ <A, E, R, B, E2, R2>(
2422
+ self: Effect.Effect<A, E, R>,
2423
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2424
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2425
+ ): Effect.Effect<A | B, E | E2, R | R2> =>
2426
+ catchCause(self, (cause): Effect.Effect<B, E | E2, R2> => {
2427
+ if (!predicate(cause)) {
2428
+ return failCause(cause) as any
2429
+ }
2430
+ return internalCall(() => f(cause))
2431
+ })
2432
+ )
2433
+
2434
+ /** @internal */
2435
+ export const catchCauseFilter: {
2436
+ <E, B, E2, R2, EB, X extends Cause.Cause<any>>(
2437
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2438
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2439
+ ): <A, R>(
2440
+ self: Effect.Effect<A, E, R>
2441
+ ) => Effect.Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
2442
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2443
+ self: Effect.Effect<A, E, R>,
2444
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2445
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2446
+ ): Effect.Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
2447
+ } = dual(
2448
+ 3,
2449
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2450
+ self: Effect.Effect<A, E, R>,
2451
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2452
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2453
+ ): Effect.Effect<A | B, Cause.Cause.Error<X> | E2, R | R2> =>
2454
+ catchCause(self, (cause): Effect.Effect<B, Cause.Cause.Error<X> | E2, R2> => {
2455
+ const eb = filter(cause)
2456
+ return Result.isFailure(eb) ? failCause(eb.failure) : internalCall(() => f(eb.success, cause))
2424
2457
  })
2425
2458
  )
2426
2459
 
@@ -2438,7 +2471,7 @@ export const catch_: {
2438
2471
  <A, E, R, B, E2, R2>(
2439
2472
  self: Effect.Effect<A, E, R>,
2440
2473
  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
2474
+ ): Effect.Effect<A | B, E2, R | R2> => catchCauseFilter(self, findError as any, (e: any) => f(e)) as any
2442
2475
  )
2443
2476
 
2444
2477
  /** @internal */
@@ -2469,7 +2502,7 @@ export const catchDefect: {
2469
2502
  <A, E, R, B, E2, R2>(
2470
2503
  self: Effect.Effect<A, E, R>,
2471
2504
  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
2505
+ ): Effect.Effect<A | B, E | E2, R | R2> => catchCauseFilter(self, findDefect as any, f as any) as any
2473
2506
  )
2474
2507
 
2475
2508
  /** @internal */
@@ -2492,32 +2525,56 @@ export const tapCause: {
2492
2525
 
2493
2526
  /** @internal */
2494
2527
  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>
2528
+ <E, B, E2, R2>(
2529
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2530
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2498
2531
  ): <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>(
2532
+ <A, E, R, B, E2, R2>(
2500
2533
  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>
2534
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2535
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2503
2536
  ): Effect.Effect<A, E | E2, R | R2>
2504
2537
  } = dual(
2505
2538
  3,
2506
- <A, E, R, Result extends Filter.ResultOrBool, B, E2, R2>(
2539
+ <A, E, R, B, E2, R2>(
2507
2540
  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>
2541
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
2542
+ f: (cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2510
2543
  ): Effect.Effect<A, E | E2, R | R2> =>
2511
2544
  catchCauseIf(
2512
2545
  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))
2546
+ predicate,
2547
+ (cause) => andThen(internalCall(() => f(cause)), failCause(cause))
2518
2548
  )
2519
2549
  )
2520
2550
 
2551
+ /** @internal */
2552
+ export const tapCauseFilter: {
2553
+ <E, B, E2, R2, EB, X extends Cause.Cause<any>>(
2554
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2555
+ f: (a: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2556
+ ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2, R | R2>
2557
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2558
+ self: Effect.Effect<A, E, R>,
2559
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2560
+ f: (a: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2561
+ ): Effect.Effect<A, E | E2, R | R2>
2562
+ } = dual(
2563
+ 3,
2564
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
2565
+ self: Effect.Effect<A, E, R>,
2566
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
2567
+ f: (a: EB, cause: Cause.Cause<E>) => Effect.Effect<B, E2, R2>
2568
+ ): Effect.Effect<A, E | E2, R | R2> =>
2569
+ catchCause(self, (cause) => {
2570
+ const result = filter(cause)
2571
+ if (Result.isFailure(result)) {
2572
+ return failCause(cause)
2573
+ }
2574
+ return andThen(internalCall(() => f(result.success, cause)), failCause(cause))
2575
+ })
2576
+ )
2577
+
2521
2578
  /** @internal */
2522
2579
  export const tapError: {
2523
2580
  <E, B, E2, R2>(
@@ -2532,7 +2589,7 @@ export const tapError: {
2532
2589
  <A, E, R, B, E2, R2>(
2533
2590
  self: Effect.Effect<A, E, R>,
2534
2591
  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
2592
+ ): Effect.Effect<A, E | E2, R | R2> => tapCauseFilter(self, findError as any, (e: any) => f(e)) as any
2536
2593
  )
2537
2594
 
2538
2595
  /** @internal */
@@ -2599,7 +2656,7 @@ export const tapDefect: {
2599
2656
  <A, E, R, B, E2, R2>(
2600
2657
  self: Effect.Effect<A, E, R>,
2601
2658
  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
2659
+ ): Effect.Effect<A, E | E2, R | R2> => tapCauseFilter(self, findDefect as any, (_: any) => f(_)) as any
2603
2660
  )
2604
2661
 
2605
2662
  /** @internal */
@@ -2609,10 +2666,10 @@ export const catchIf: {
2609
2666
  f: (e: EB) => Effect.Effect<A2, E2, R2>,
2610
2667
  orElse?: ((e: Exclude<E, EB>) => Effect.Effect<A3, E3, R3>) | undefined
2611
2668
  ): <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
2669
+ <E, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
2670
+ predicate: Predicate.Predicate<NoInfer<E>>,
2671
+ f: (e: NoInfer<E>) => Effect.Effect<A2, E2, R2>,
2672
+ orElse?: ((e: NoInfer<E>) => Effect.Effect<A3, E3, R3>) | undefined
2616
2673
  ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2617
2674
  <A, E, R, EB extends E, A2, E2, R2, A3 = never, E3 = Exclude<E, EB>, R3 = never>(
2618
2675
  self: Effect.Effect<A, E, R>,
@@ -2620,28 +2677,59 @@ export const catchIf: {
2620
2677
  f: (e: EB) => Effect.Effect<A2, E2, R2>,
2621
2678
  orElse?: ((e: Exclude<E, EB>) => Effect.Effect<A3, E3, R3>) | undefined
2622
2679
  ): 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>(
2680
+ <A, E, R, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
2681
+ self: Effect.Effect<A, E, R>,
2682
+ predicate: Predicate.Predicate<E>,
2683
+ f: (e: E) => Effect.Effect<A2, E2, R2>,
2684
+ orElse?: ((e: E) => Effect.Effect<A3, E3, R3>) | undefined
2685
+ ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2686
+ } = dual(
2687
+ (args) => isEffect(args[0]),
2688
+ <A, E, R, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
2689
+ self: Effect.Effect<A, E, R>,
2690
+ predicate: Predicate.Predicate<E>,
2691
+ f: (e: E) => Effect.Effect<A2, E2, R2>,
2692
+ orElse?: ((e: E) => Effect.Effect<A3, E3, R3>) | undefined
2693
+ ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3> =>
2694
+ catchCause(self, (cause): Effect.Effect<A2 | A3, E2 | E3, R2 | R3> => {
2695
+ const error = findError(cause)
2696
+ if (Result.isFailure(error)) return failCause(error.failure)
2697
+ if (!predicate(error.success)) {
2698
+ return orElse ? internalCall(() => orElse(error.success as any)) : failCause(cause as any as Cause.Cause<E3>)
2699
+ }
2700
+ return internalCall(() => f(error.success as any))
2701
+ })
2702
+ )
2703
+
2704
+ /** @internal */
2705
+ export const catchFilter: {
2706
+ <E, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
2707
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
2708
+ f: (e: EB) => Effect.Effect<A2, E2, R2>,
2709
+ orElse?: ((e: X) => Effect.Effect<A3, E3, R3>) | undefined
2710
+ ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2711
+ <A, E, R, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
2624
2712
  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
2713
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
2714
+ f: (e: EB) => Effect.Effect<A2, E2, R2>,
2715
+ orElse?: ((e: X) => Effect.Effect<A3, E3, R3>) | undefined
2628
2716
  ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
2629
2717
  } = dual(
2630
2718
  (args) => isEffect(args[0]),
2631
2719
  <A, E, R, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
2632
2720
  self: Effect.Effect<A, E, R>,
2633
- filter: Filter.Filter<NoInfer<E>, EB, X> | Predicate.Predicate<NoInfer<E>>,
2721
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
2634
2722
  f: (e: EB) => Effect.Effect<A2, E2, R2>,
2635
2723
  orElse?: ((e: X) => Effect.Effect<A3, E3, R3>) | undefined
2636
2724
  ): Effect.Effect<A | A2 | A3, E2 | E3, R | R2 | R3> =>
2637
2725
  catchCause(self, (cause): Effect.Effect<A2 | A3, E2 | E3, R2 | R3> => {
2638
2726
  const error = findError(cause)
2639
2727
  if (Result.isFailure(error)) return failCause(error.failure)
2640
- const result = Filter.apply(filter as any, error.success)
2728
+ const result = filter(error.success)
2641
2729
  if (Result.isFailure(result)) {
2642
2730
  return orElse ? internalCall(() => orElse(result.failure as any)) : failCause(cause as any as Cause.Cause<E3>)
2643
2731
  }
2644
- return internalCall(() => f(result.success as any))
2732
+ return internalCall(() => f(result.success))
2645
2733
  })
2646
2734
  )
2647
2735
 
@@ -2777,7 +2865,7 @@ export const catchTags: {
2777
2865
  >
2778
2866
  } = dual((args) => isEffect(args[0]), (self: Effect.Effect<any, any, any>, cases: Record<string, any>, orElse: any) => {
2779
2867
  let keys: Array<string>
2780
- return catchIf(
2868
+ return catchFilter(
2781
2869
  self,
2782
2870
  (e) => {
2783
2871
  keys ??= Object.keys(cases)
@@ -2787,7 +2875,7 @@ export const catchTags: {
2787
2875
  },
2788
2876
  (e: any) => internalCall(() => cases[e["_tag"] as string](e)),
2789
2877
  orElse
2790
- )
2878
+ ) as any
2791
2879
  })
2792
2880
 
2793
2881
  /** @internal */
@@ -2805,8 +2893,16 @@ export const catchReason: {
2805
2893
  >(
2806
2894
  errorTag: K,
2807
2895
  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
2896
+ f: (
2897
+ reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
2898
+ error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
2899
+ ) => Effect.Effect<A2, E2, R2>,
2900
+ orElse?:
2901
+ | ((
2902
+ reasons: ExcludeReason<ExtractTag<NoInfer<E>, K>, RK>,
2903
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, RK>
2904
+ ) => Effect.Effect<A3, E3, R3>)
2905
+ | undefined
2810
2906
  ): <A, R>(
2811
2907
  self: Effect.Effect<A, E, R>
2812
2908
  ) => Effect.Effect<
@@ -2830,8 +2926,16 @@ export const catchReason: {
2830
2926
  self: Effect.Effect<A, E, R>,
2831
2927
  errorTag: K,
2832
2928
  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
2929
+ f: (
2930
+ reason: ExtractReason<ExtractTag<E, K>, RK>,
2931
+ error: NarrowReason<ExtractTag<E, K>, RK>
2932
+ ) => Effect.Effect<A2, E2, R2>,
2933
+ orElse?:
2934
+ | ((
2935
+ reasons: ExcludeReason<ExtractTag<E, K>, RK>,
2936
+ error: OmitReason<ExtractTag<E, K>, RK>
2937
+ ) => Effect.Effect<A3, E3, R3>)
2938
+ | undefined
2835
2939
  ): Effect.Effect<
2836
2940
  A | A2 | Exclude<A3, unassigned>,
2837
2941
  (A3 extends unassigned ? E : ExcludeTag<E, K>) | E2 | E3,
@@ -2855,8 +2959,13 @@ export const catchReason: {
2855
2959
  self: Effect.Effect<A, E, R>,
2856
2960
  errorTag: K,
2857
2961
  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
2962
+ f: (reason: ExtractReason<ExtractTag<E, K>, RK>, error: ExtractTag<E, K>) => Effect.Effect<A2, E2, R2>,
2963
+ orElse?:
2964
+ | ((
2965
+ reasons: ExcludeReason<ExtractTag<E, K>, RK>,
2966
+ error: OmitReason<ExtractTag<E, K>, RK>
2967
+ ) => Effect.Effect<A3, E3, R3>)
2968
+ | undefined
2860
2969
  ): Effect.Effect<
2861
2970
  A | A2 | Exclude<A3, unassigned>,
2862
2971
  (A3 extends unassigned ? E : ExcludeTag<E, K>) | E2 | E3,
@@ -2867,8 +2976,8 @@ export const catchReason: {
2867
2976
  ((e: any) => isTagged(e, errorTag) && hasProperty(e, "reason")) as any,
2868
2977
  (e: any): Effect.Effect<A2 | A3, E | E2 | E3, R2 | R3> => {
2869
2978
  const reason = e.reason as any
2870
- if (isTagged(reason, reasonTag)) return f(reason as any)
2871
- return orElse ? internalCall(() => orElse(reason)) : fail(e)
2979
+ if (isTagged(reason, reasonTag)) return f(reason as any, e)
2980
+ return orElse ? internalCall(() => orElse(reason, e)) : fail(e)
2872
2981
  }
2873
2982
  ) as any
2874
2983
  )
@@ -2880,7 +2989,8 @@ export const catchReasons: {
2880
2989
  E,
2881
2990
  Cases extends {
2882
2991
  [RK in ReasonTags<ExtractTag<NoInfer<E>, K>>]+?: (
2883
- reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>
2992
+ reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
2993
+ error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
2884
2994
  ) => Effect.Effect<any, any, any>
2885
2995
  },
2886
2996
  A2 = unassigned,
@@ -2891,7 +3001,8 @@ export const catchReasons: {
2891
3001
  cases: Cases,
2892
3002
  orElse?:
2893
3003
  | ((
2894
- reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
3004
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
3005
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
2895
3006
  ) => Effect.Effect<A2, E2, R2>)
2896
3007
  | undefined
2897
3008
  ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<
@@ -2918,7 +3029,8 @@ export const catchReasons: {
2918
3029
  K extends Tags<E>,
2919
3030
  Cases extends {
2920
3031
  [RK in ReasonTags<ExtractTag<E, K>>]+?: (
2921
- reason: ExtractReason<ExtractTag<E, K>, RK>
3032
+ reason: ExtractReason<ExtractTag<E, K>, RK>,
3033
+ error: NarrowReason<ExtractTag<E, K>, RK>
2922
3034
  ) => Effect.Effect<any, any, any>
2923
3035
  },
2924
3036
  A2 = unassigned,
@@ -2930,7 +3042,8 @@ export const catchReasons: {
2930
3042
  cases: Cases,
2931
3043
  orElse?:
2932
3044
  | ((
2933
- reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
3045
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
3046
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
2934
3047
  ) => Effect.Effect<A2, E2, R2>)
2935
3048
  | undefined
2936
3049
  ): Effect.Effect<
@@ -2963,9 +3076,9 @@ export const catchReasons: {
2963
3076
  const reason = e.reason
2964
3077
  keys ??= Object.keys(cases)
2965
3078
  if (keys.includes(reason._tag)) {
2966
- return internalCall(() => (cases as any)[reason._tag](reason))
3079
+ return internalCall(() => (cases as any)[reason._tag](reason, e))
2967
3080
  }
2968
- return orElse ? internalCall(() => orElse(reason)) : fail(e)
3081
+ return orElse ? internalCall(() => orElse(reason, e)) : fail(e)
2969
3082
  }
2970
3083
  )
2971
3084
  })
@@ -2998,7 +3111,7 @@ export const unwrapReason: {
2998
3111
  self: Effect.Effect<A, E, R>,
2999
3112
  errorTag: K
3000
3113
  ): Effect.Effect<A, ExcludeTag<E, K> | ReasonOf<ExtractTag<E, K>>, R> =>
3001
- catchIf(
3114
+ catchFilter(
3002
3115
  self,
3003
3116
  (e: any) => {
3004
3117
  if (isTagged(e, errorTag) && hasProperty(e, "reason")) {
@@ -3007,7 +3120,7 @@ export const unwrapReason: {
3007
3120
  return Result.fail(e)
3008
3121
  },
3009
3122
  fail as any
3010
- )
3123
+ ) as any
3011
3124
  )
3012
3125
 
3013
3126
  /** @internal */
@@ -3091,14 +3204,14 @@ export const eventually = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect
3091
3204
  /** @internal */
3092
3205
  export const ignore: <
3093
3206
  Arg extends Effect.Effect<any, any, any> | {
3094
- readonly log?: boolean | LogLevel.LogLevel | undefined
3207
+ readonly log?: boolean | LogLevel.Severity | undefined
3095
3208
  } | undefined = {
3096
- readonly log?: boolean | LogLevel.LogLevel | undefined
3209
+ readonly log?: boolean | LogLevel.Severity | undefined
3097
3210
  }
3098
3211
  >(
3099
3212
  effectOrOptions: Arg,
3100
3213
  options?: {
3101
- readonly log?: boolean | LogLevel.LogLevel | undefined
3214
+ readonly log?: boolean | LogLevel.Severity | undefined
3102
3215
  } | undefined
3103
3216
  ) => [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ? Effect.Effect<void, never, _R>
3104
3217
  : <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<void, never, R> = dual(
@@ -3106,7 +3219,7 @@ export const ignore: <
3106
3219
  <A, E, R>(
3107
3220
  self: Effect.Effect<A, E, R>,
3108
3221
  options?: {
3109
- readonly log?: boolean | LogLevel.LogLevel | undefined
3222
+ readonly log?: boolean | LogLevel.Severity | undefined
3110
3223
  } | undefined
3111
3224
  ): Effect.Effect<void, never, R> => {
3112
3225
  if (!options?.log) {
@@ -3126,14 +3239,14 @@ export const ignore: <
3126
3239
  /** @internal */
3127
3240
  export const ignoreCause: <
3128
3241
  Arg extends Effect.Effect<any, any, any> | {
3129
- readonly log?: boolean | LogLevel.LogLevel | undefined
3242
+ readonly log?: boolean | LogLevel.Severity | undefined
3130
3243
  } | undefined = {
3131
- readonly log?: boolean | LogLevel.LogLevel | undefined
3244
+ readonly log?: boolean | LogLevel.Severity | undefined
3132
3245
  }
3133
3246
  >(
3134
3247
  effectOrOptions: Arg,
3135
3248
  options?: {
3136
- readonly log?: boolean | LogLevel.LogLevel | undefined
3249
+ readonly log?: boolean | LogLevel.Severity | undefined
3137
3250
  } | undefined
3138
3251
  ) => [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ? Effect.Effect<void, never, _R>
3139
3252
  : <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<void, never, R> = dual(
@@ -3141,7 +3254,7 @@ export const ignoreCause: <
3141
3254
  <A, E, R>(
3142
3255
  self: Effect.Effect<A, E, R>,
3143
3256
  options?: {
3144
- readonly log?: boolean | LogLevel.LogLevel | undefined
3257
+ readonly log?: boolean | LogLevel.Severity | undefined
3145
3258
  } | undefined
3146
3259
  ): Effect.Effect<void, never, R> => {
3147
3260
  if (!options?.log) {
@@ -3403,24 +3516,24 @@ export const isSuccess: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect
3403
3516
  /** @internal */
3404
3517
  export const delay: {
3405
3518
  (
3406
- duration: Duration.DurationInput
3519
+ duration: Duration.Input
3407
3520
  ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
3408
3521
  <A, E, R>(
3409
3522
  self: Effect.Effect<A, E, R>,
3410
- duration: Duration.DurationInput
3523
+ duration: Duration.Input
3411
3524
  ): Effect.Effect<A, E, R>
3412
3525
  } = dual(
3413
3526
  2,
3414
3527
  <A, E, R>(
3415
3528
  self: Effect.Effect<A, E, R>,
3416
- duration: Duration.DurationInput
3529
+ duration: Duration.Input
3417
3530
  ): Effect.Effect<A, E, R> => andThen(sleep(duration), self)
3418
3531
  )
3419
3532
 
3420
3533
  /** @internal */
3421
3534
  export const timeoutOrElse: {
3422
3535
  <A2, E2, R2>(options: {
3423
- readonly duration: Duration.DurationInput
3536
+ readonly duration: Duration.Input
3424
3537
  readonly onTimeout: LazyArg<Effect.Effect<A2, E2, R2>>
3425
3538
  }): <A, E, R>(
3426
3539
  self: Effect.Effect<A, E, R>
@@ -3428,7 +3541,7 @@ export const timeoutOrElse: {
3428
3541
  <A, E, R, A2, E2, R2>(
3429
3542
  self: Effect.Effect<A, E, R>,
3430
3543
  options: {
3431
- readonly duration: Duration.DurationInput
3544
+ readonly duration: Duration.Input
3432
3545
  readonly onTimeout: LazyArg<Effect.Effect<A2, E2, R2>>
3433
3546
  }
3434
3547
  ): Effect.Effect<A | A2, E | E2, R | R2>
@@ -3437,7 +3550,7 @@ export const timeoutOrElse: {
3437
3550
  <A, E, R, A2, E2, R2>(
3438
3551
  self: Effect.Effect<A, E, R>,
3439
3552
  options: {
3440
- readonly duration: Duration.DurationInput
3553
+ readonly duration: Duration.Input
3441
3554
  readonly onTimeout: LazyArg<Effect.Effect<A2, E2, R2>>
3442
3555
  }
3443
3556
  ): Effect.Effect<A | A2, E | E2, R | R2> =>
@@ -3450,19 +3563,19 @@ export const timeoutOrElse: {
3450
3563
  /** @internal */
3451
3564
  export const timeout: {
3452
3565
  (
3453
- duration: Duration.DurationInput
3566
+ duration: Duration.Input
3454
3567
  ): <A, E, R>(
3455
3568
  self: Effect.Effect<A, E, R>
3456
3569
  ) => Effect.Effect<A, E | Cause.TimeoutError, R>
3457
3570
  <A, E, R>(
3458
3571
  self: Effect.Effect<A, E, R>,
3459
- duration: Duration.DurationInput
3572
+ duration: Duration.Input
3460
3573
  ): Effect.Effect<A, E | Cause.TimeoutError, R>
3461
3574
  } = dual(
3462
3575
  2,
3463
3576
  <A, E, R>(
3464
3577
  self: Effect.Effect<A, E, R>,
3465
- duration: Duration.DurationInput
3578
+ duration: Duration.Input
3466
3579
  ): Effect.Effect<A, E | TimeoutError, R> =>
3467
3580
  timeoutOrElse(self, {
3468
3581
  duration,
@@ -3473,19 +3586,19 @@ export const timeout: {
3473
3586
  /** @internal */
3474
3587
  export const timeoutOption: {
3475
3588
  (
3476
- duration: Duration.DurationInput
3589
+ duration: Duration.Input
3477
3590
  ): <A, E, R>(
3478
3591
  self: Effect.Effect<A, E, R>
3479
3592
  ) => Effect.Effect<Option.Option<A>, E, R>
3480
3593
  <A, E, R>(
3481
3594
  self: Effect.Effect<A, E, R>,
3482
- duration: Duration.DurationInput
3595
+ duration: Duration.Input
3483
3596
  ): Effect.Effect<Option.Option<A>, E, R>
3484
3597
  } = dual(
3485
3598
  2,
3486
3599
  <A, E, R>(
3487
3600
  self: Effect.Effect<A, E, R>,
3488
- duration: Duration.DurationInput
3601
+ duration: Duration.Input
3489
3602
  ): Effect.Effect<Option.Option<A>, E, R> =>
3490
3603
  raceFirst(
3491
3604
  asSome(self),
@@ -3646,11 +3759,11 @@ export const provideScope: {
3646
3759
  /** @internal */
3647
3760
  export const scoped = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, Exclude<R, Scope.Scope>> =>
3648
3761
  withFiber((fiber) => {
3649
- const prev = ServiceMap.getOption(fiber.services, scopeTag)
3762
+ const prev = fiber.services
3650
3763
  const scope = scopeMakeUnsafe()
3651
3764
  fiber.setServices(ServiceMap.add(fiber.services, scopeTag, scope))
3652
3765
  return onExitPrimitive(self, (exit) => {
3653
- fiber.setServices(ServiceMap.addOrOmit(fiber.services, scopeTag, prev))
3766
+ fiber.setServices(prev)
3654
3767
  return scopeCloseUnsafe(scope, exit)
3655
3768
  })
3656
3769
  }) as any
@@ -3758,34 +3871,51 @@ export const ensuring: {
3758
3871
 
3759
3872
  /** @internal */
3760
3873
  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>
3874
+ <A, E, XE, XR>(
3875
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
3876
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3767
3877
  ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | XE, R | XR>
3768
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
3878
+ <A, E, R, XE, XR>(
3769
3879
  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>
3880
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
3881
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3775
3882
  ): Effect.Effect<A, E | XE, R | XR>
3776
3883
  } = dual(
3777
3884
  3,
3778
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
3885
+ <A, E, R, XE, XR>(
3779
3886
  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>
3887
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
3888
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3785
3889
  ): Effect.Effect<A, E | XE, R | XR> =>
3786
3890
  onExit(self, (exit) => {
3787
- const pass = Filter.apply(filter, exit)
3788
- return Result.isFailure(pass) ? void_ : f(pass.success as any, exit)
3891
+ if (!predicate(exit)) {
3892
+ return void_
3893
+ }
3894
+ return f(exit)
3895
+ })
3896
+ )
3897
+
3898
+ /** @internal */
3899
+ export const onExitFilter: {
3900
+ <A, E, XE, XR, B, X>(
3901
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
3902
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3903
+ ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | XE, R | XR>
3904
+ <A, E, R, XE, XR, B, X>(
3905
+ self: Effect.Effect<A, E, R>,
3906
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
3907
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3908
+ ): Effect.Effect<A, E | XE, R | XR>
3909
+ } = dual(
3910
+ 3,
3911
+ <A, E, R, XE, XR, B, X>(
3912
+ self: Effect.Effect<A, E, R>,
3913
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
3914
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect.Effect<void, XE, XR>
3915
+ ): Effect.Effect<A, E | XE, R | XR> =>
3916
+ onExit(self, (exit) => {
3917
+ const b = filter(exit)
3918
+ return Result.isFailure(b) ? void_ : f(b.success, exit)
3789
3919
  })
3790
3920
  )
3791
3921
 
@@ -3803,37 +3933,66 @@ export const onError: {
3803
3933
  <A, E, R, XE, XR>(
3804
3934
  self: Effect.Effect<A, E, R>,
3805
3935
  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
3936
+ ): Effect.Effect<A, E | XE, R | XR> => onExitFilter(self, exitFilterCause as any, f as any) as any
3807
3937
  )
3808
3938
 
3809
3939
  /** @internal */
3810
3940
  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>
3941
+ <E, XE, XR>(
3942
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
3943
+ f: (cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3814
3944
  ): <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>(
3945
+ <A, E, R, XE, XR>(
3816
3946
  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>
3947
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
3948
+ f: (cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3819
3949
  ): Effect.Effect<A, E | XE, R | XR>
3820
3950
  } = dual(
3821
3951
  3,
3822
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
3952
+ <A, E, R, XE, XR>(
3823
3953
  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>
3954
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
3955
+ f: (cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3826
3956
  ): Effect.Effect<A, E | XE, R | XR> =>
3827
3957
  onExitIf(
3828
3958
  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)
3959
+ (exit): exit is Exit.Failure<A, E> => {
3960
+ if (exit._tag !== "Failure") {
3961
+ return false
3962
+ }
3963
+ return predicate(exit.cause)
3964
+ },
3965
+ (exit) => f((exit as Exit.Failure<A, E>).cause)
3834
3966
  ) as any
3835
3967
  )
3836
3968
 
3969
+ /** @internal */
3970
+ export const onErrorFilter: {
3971
+ <A, E, EB, X, XE, XR>(
3972
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
3973
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3974
+ ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | XE, R | XR>
3975
+ <A, E, R, EB, X, XE, XR>(
3976
+ self: Effect.Effect<A, E, R>,
3977
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
3978
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3979
+ ): Effect.Effect<A, E | XE, R | XR>
3980
+ } = dual(
3981
+ 3,
3982
+ <A, E, R, EB, X, XE, XR>(
3983
+ self: Effect.Effect<A, E, R>,
3984
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
3985
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect.Effect<void, XE, XR>
3986
+ ): Effect.Effect<A, E | XE, R | XR> =>
3987
+ onExit(self, (exit) => {
3988
+ if (exit._tag !== "Failure") {
3989
+ return void_
3990
+ }
3991
+ const result = filter(exit.cause)
3992
+ return Result.isFailure(result) ? void_ : f(result.success, exit.cause)
3993
+ })
3994
+ )
3995
+
3837
3996
  /** @internal */
3838
3997
  export const onInterrupt: {
3839
3998
  <XE, XR>(
@@ -3848,8 +4007,7 @@ export const onInterrupt: {
3848
4007
  <A, E, R, XE, XR>(
3849
4008
  self: Effect.Effect<A, E, R>,
3850
4009
  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)
4010
+ ): Effect.Effect<A, E | XE, R | XR> => onErrorFilter(causeFilterInterruptors as any, finalizer)(self) as any
3853
4011
  )
3854
4012
 
3855
4013
  /** @internal */
@@ -3873,19 +4031,19 @@ export const acquireUseRelease = <Resource, E, R, A, E2, R2, E3, R3>(
3873
4031
 
3874
4032
  /** @internal */
3875
4033
  export const cachedInvalidateWithTTL: {
3876
- (timeToLive: Duration.DurationInput): <A, E, R>(
4034
+ (timeToLive: Duration.Input): <A, E, R>(
3877
4035
  self: Effect.Effect<A, E, R>
3878
4036
  ) => Effect.Effect<[Effect.Effect<A, E, R>, Effect.Effect<void>]>
3879
4037
  <A, E, R>(
3880
4038
  self: Effect.Effect<A, E, R>,
3881
- timeToLive: Duration.DurationInput
4039
+ timeToLive: Duration.Input
3882
4040
  ): Effect.Effect<[Effect.Effect<A, E, R>, Effect.Effect<void>]>
3883
4041
  } = dual(2, <A, E, R>(
3884
4042
  self: Effect.Effect<A, E, R>,
3885
- ttl: Duration.DurationInput
4043
+ ttl: Duration.Input
3886
4044
  ): Effect.Effect<[Effect.Effect<A, E, R>, Effect.Effect<void>]> =>
3887
4045
  sync(() => {
3888
- const ttlMillis = Duration.toMillis(Duration.fromDurationInputUnsafe(ttl))
4046
+ const ttlMillis = Duration.toMillis(Duration.fromInputUnsafe(ttl))
3889
4047
  const isFinite = Number.isFinite(ttlMillis)
3890
4048
  const latch = makeLatchUnsafe(false)
3891
4049
  let expiresAt = 0
@@ -3918,17 +4076,17 @@ export const cachedInvalidateWithTTL: {
3918
4076
  /** @internal */
3919
4077
  export const cachedWithTTL: {
3920
4078
  (
3921
- timeToLive: Duration.DurationInput
4079
+ timeToLive: Duration.Input
3922
4080
  ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Effect.Effect<A, E, R>>
3923
4081
  <A, E, R>(
3924
4082
  self: Effect.Effect<A, E, R>,
3925
- timeToLive: Duration.DurationInput
4083
+ timeToLive: Duration.Input
3926
4084
  ): Effect.Effect<Effect.Effect<A, E, R>>
3927
4085
  } = dual(
3928
4086
  2,
3929
4087
  <A, E, R>(
3930
4088
  self: Effect.Effect<A, E, R>,
3931
- timeToLive: Duration.DurationInput
4089
+ timeToLive: Duration.Input
3932
4090
  ): Effect.Effect<Effect.Effect<A, E, R>> => map(cachedInvalidateWithTTL(self, timeToLive), (tuple) => tuple[0])
3933
4091
  )
3934
4092
 
@@ -4074,10 +4232,147 @@ export const partition: {
4074
4232
  ): Effect.Effect<[excluded: Array<E>, satisfying: Array<B>], never, R> =>
4075
4233
  map(
4076
4234
  forEach(elements, (a, i) => result(f(a, i)), options),
4077
- (results) => Arr.partitionMap(results, identity)
4235
+ (results) => Arr.partition(results, identity)
4236
+ )
4237
+ )
4238
+
4239
+ /** @internal */
4240
+ export const validate: {
4241
+ <A, B, E, R>(
4242
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4243
+ options?: {
4244
+ readonly concurrency?: Concurrency | undefined
4245
+ readonly discard?: false | undefined
4246
+ } | undefined
4247
+ ): (elements: Iterable<A>) => Effect.Effect<Array<B>, Arr.NonEmptyArray<E>, R>
4248
+ <A, B, E, R>(
4249
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4250
+ options: {
4251
+ readonly concurrency?: Concurrency | undefined
4252
+ readonly discard: true
4253
+ }
4254
+ ): (elements: Iterable<A>) => Effect.Effect<void, Arr.NonEmptyArray<E>, R>
4255
+ <A, B, E, R>(
4256
+ elements: Iterable<A>,
4257
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4258
+ options?: {
4259
+ readonly concurrency?: Concurrency | undefined
4260
+ readonly discard?: false | undefined
4261
+ } | undefined
4262
+ ): Effect.Effect<Array<B>, Arr.NonEmptyArray<E>, R>
4263
+ <A, B, E, R>(
4264
+ elements: Iterable<A>,
4265
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4266
+ options: {
4267
+ readonly concurrency?: Concurrency | undefined
4268
+ readonly discard: true
4269
+ }
4270
+ ): Effect.Effect<void, Arr.NonEmptyArray<E>, R>
4271
+ } = dual(
4272
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4273
+ <A, B, E, R>(
4274
+ elements: Iterable<A>,
4275
+ f: (a: A, i: number) => Effect.Effect<B, E, R>,
4276
+ options?: {
4277
+ readonly concurrency?: Concurrency | undefined
4278
+ readonly discard?: boolean | undefined
4279
+ } | undefined
4280
+ ): Effect.Effect<Array<B> | void, Arr.NonEmptyArray<E>, R> =>
4281
+ flatMap(
4282
+ partition(elements, f, { concurrency: options?.concurrency }),
4283
+ ([excluded, satisfying]) => {
4284
+ if (Arr.isArrayNonEmpty(excluded)) {
4285
+ return fail(excluded)
4286
+ }
4287
+ return options?.discard ? void_ : succeed(satisfying)
4288
+ }
4078
4289
  )
4079
4290
  )
4080
4291
 
4292
+ /** @internal */
4293
+ export const findFirst: {
4294
+ <A, E, R>(
4295
+ predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
4296
+ ): (elements: Iterable<A>) => Effect.Effect<Option.Option<A>, E, R>
4297
+ <A, E, R>(
4298
+ elements: Iterable<A>,
4299
+ predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
4300
+ ): Effect.Effect<Option.Option<A>, E, R>
4301
+ } = dual(
4302
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4303
+ <A, E, R>(
4304
+ elements: Iterable<A>,
4305
+ predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>
4306
+ ): Effect.Effect<Option.Option<A>, E, R> =>
4307
+ suspend(() => {
4308
+ const iterator = elements[Symbol.iterator]()
4309
+ const next = iterator.next()
4310
+ if (!next.done) {
4311
+ return findFirstLoop(iterator, 0, predicate, next.value)
4312
+ }
4313
+ return succeed(Option.none())
4314
+ })
4315
+ )
4316
+
4317
+ const findFirstLoop = <A, E, R>(
4318
+ iterator: Iterator<A>,
4319
+ index: number,
4320
+ predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>,
4321
+ value: A
4322
+ ): Effect.Effect<Option.Option<A>, E, R> =>
4323
+ flatMap(predicate(value, index), (keep) => {
4324
+ if (keep) {
4325
+ return succeed(Option.some(value))
4326
+ }
4327
+ const next = iterator.next()
4328
+ if (!next.done) {
4329
+ return findFirstLoop(iterator, index + 1, predicate, next.value)
4330
+ }
4331
+ return succeed(Option.none())
4332
+ })
4333
+
4334
+ /** @internal */
4335
+ export const findFirstFilter: {
4336
+ <A, B, X, E, R>(
4337
+ filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R, [i: number]>
4338
+ ): (elements: Iterable<A>) => Effect.Effect<Option.Option<B>, E, R>
4339
+ <A, B, X, E, R>(
4340
+ elements: Iterable<A>,
4341
+ filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R, [i: number]>
4342
+ ): Effect.Effect<Option.Option<B>, E, R>
4343
+ } = dual(
4344
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4345
+ <A, B, X, E, R>(
4346
+ elements: Iterable<A>,
4347
+ filter: Filter.FilterEffect<A, B, X, E, R, [i: number]>
4348
+ ): Effect.Effect<Option.Option<B>, E, R> =>
4349
+ suspend(() => {
4350
+ const iterator = elements[Symbol.iterator]()
4351
+ const next = iterator.next()
4352
+ if (!next.done) {
4353
+ return findFirstFilterLoop(iterator, 0, filter, next.value)
4354
+ }
4355
+ return succeed(Option.none())
4356
+ })
4357
+ )
4358
+
4359
+ const findFirstFilterLoop = <A, B, X, E, R>(
4360
+ iterator: Iterator<A>,
4361
+ index: number,
4362
+ filter: Filter.FilterEffect<A, B, X, E, R, [i: number]>,
4363
+ value: A
4364
+ ): Effect.Effect<Option.Option<B>, E, R> =>
4365
+ flatMap(filter(value, index), (result) => {
4366
+ if (Result.isSuccess(result)) {
4367
+ return succeed(Option.some(result.success))
4368
+ }
4369
+ const next = iterator.next()
4370
+ if (!next.done) {
4371
+ return findFirstFilterLoop(iterator, index + 1, filter, next.value)
4372
+ }
4373
+ return succeed(Option.none())
4374
+ })
4375
+
4081
4376
  /** @internal */
4082
4377
  export const whileLoop: <A, E, R>(options: {
4083
4378
  readonly while: LazyArg<boolean>
@@ -4249,33 +4544,85 @@ export const filterOrElse: {
4249
4544
  refinement: Predicate.Refinement<NoInfer<A>, B>,
4250
4545
  orElse: (a: EqualsWith<A, B, NoInfer<A>, Exclude<NoInfer<A>, B>>) => Effect.Effect<C, E2, R2>
4251
4546
  ): <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>
4547
+ <A, C, E2, R2>(
4548
+ predicate: Predicate.Predicate<NoInfer<A>>,
4549
+ orElse: (a: NoInfer<A>) => Effect.Effect<C, E2, R2>
4550
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | C, E2 | E, R2 | R>
4256
4551
  <A, E, R, C, E2, R2, B extends A>(
4257
4552
  self: Effect.Effect<A, E, R>,
4258
4553
  refinement: Predicate.Refinement<A, B>,
4259
4554
  orElse: (a: EqualsWith<A, B, A, Exclude<A, B>>) => Effect.Effect<C, E2, R2>
4260
4555
  ): Effect.Effect<B | C, E | E2, R | R2>
4261
- <A, E, R, Result extends Filter.ResultOrBool, C, E2, R2>(
4556
+ <A, E, R, C, E2, R2>(
4262
4557
  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>(
4558
+ predicate: Predicate.Predicate<NoInfer<A>>,
4559
+ orElse: (a: NoInfer<A>) => Effect.Effect<C, E2, R2>
4560
+ ): Effect.Effect<A | C, E | E2, R | R2>
4561
+ } = dual(3, <A, E, R, B, E2, R2>(
4267
4562
  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> =>
4563
+ predicate: Predicate.Predicate<A>,
4564
+ orElse: (a: A) => Effect.Effect<B, E2, R2>
4565
+ ): Effect.Effect<A | B, E | E2, R | R2> =>
4566
+ flatMap(
4567
+ self,
4568
+ (a) => predicate(a) ? succeed<A | B>(a) : orElse(a)
4569
+ ))
4570
+
4571
+ /** @internal */
4572
+ export const filterMapOrElse: {
4573
+ <A, B, X, C, E2, R2>(
4574
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4575
+ orElse: (x: X) => Effect.Effect<C, E2, R2>
4576
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B | C, E2 | E, R2 | R>
4577
+ <A, E, R, B, X, C, E2, R2>(
4578
+ self: Effect.Effect<A, E, R>,
4579
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4580
+ orElse: (x: X) => Effect.Effect<C, E2, R2>
4581
+ ): Effect.Effect<B | C, E | E2, R | R2>
4582
+ } = dual(3, <A, E, R, B, X, C, E2, R2>(
4583
+ self: Effect.Effect<A, E, R>,
4584
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4585
+ orElse: (x: X) => Effect.Effect<C, E2, R2>
4586
+ ): Effect.Effect<B | C, E | E2, R | R2> =>
4271
4587
  flatMap(
4272
4588
  self,
4273
4589
  (a) => {
4274
- const result = Filter.apply(filter, a)
4275
- return Result.isFailure(result) ? orElse(result.failure) : succeed(result.success) as any
4590
+ const result = filter(a)
4591
+ return (Result.isFailure(result)
4592
+ ? orElse(result.failure)
4593
+ : succeed(result.success)) as Effect.Effect<B | C, E2, R2>
4276
4594
  }
4277
4595
  ))
4278
4596
 
4597
+ /* @internal */
4598
+ export const filterMapOrFail: {
4599
+ <A, B, X, E2>(
4600
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4601
+ orFailWith: (x: X) => E2
4602
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E2 | E, R>
4603
+ <A, B, X>(
4604
+ filter: Filter.Filter<NoInfer<A>, B, X>
4605
+ ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, Cause.NoSuchElementError | E, R>
4606
+ <A, E, R, B, X, E2>(
4607
+ self: Effect.Effect<A, E, R>,
4608
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4609
+ orFailWith: (x: X) => E2
4610
+ ): Effect.Effect<B, E2 | E, R>
4611
+ <A, E, R, B, X>(
4612
+ self: Effect.Effect<A, E, R>,
4613
+ filter: Filter.Filter<NoInfer<A>, B, X>
4614
+ ): Effect.Effect<B, Cause.NoSuchElementError | E, R>
4615
+ } = dual((args) => isEffect(args[0]), <A, E, R, B, X, E2>(
4616
+ self: Effect.Effect<A, E, R>,
4617
+ filter: Filter.Filter<NoInfer<A>, B, X>,
4618
+ orFailWith?: (x: X) => E2
4619
+ ): Effect.Effect<B, E2 | Cause.NoSuchElementError | E, R> =>
4620
+ filterMapOrElse(
4621
+ self,
4622
+ filter,
4623
+ orFailWith ? (x: X) => fail(orFailWith(x)) : () => fail(new NoSuchElementError() as E2)
4624
+ ))
4625
+
4279
4626
  /** @internal */
4280
4627
  export const filter: {
4281
4628
  <A, B extends A>(
@@ -4284,13 +4631,6 @@ export const filter: {
4284
4631
  <A>(
4285
4632
  predicate: Predicate.Predicate<NoInfer<A>>
4286
4633
  ): (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
4634
  <A, E, R>(
4295
4635
  predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>,
4296
4636
  options?: { readonly concurrency?: Concurrency | undefined }
@@ -4303,15 +4643,6 @@ export const filter: {
4303
4643
  elements: Iterable<A>,
4304
4644
  predicate: Predicate.Predicate<A>
4305
4645
  ): 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
4646
  <A, E, R>(
4316
4647
  iterable: Iterable<A>,
4317
4648
  predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>,
@@ -4319,36 +4650,27 @@ export const filter: {
4319
4650
  ): Effect.Effect<Array<A>, E, R>
4320
4651
  } = dual(
4321
4652
  (args) => isIterable(args[0]) && !isEffect(args[0]),
4322
- <A, B, X, E, R>(
4653
+ <A, E, R>(
4323
4654
  elements: Iterable<A>,
4324
- filter:
4325
- | Filter.FilterEffect<A, B, X, E, R>
4655
+ predicate:
4326
4656
  | Predicate.Predicate<A>
4327
4657
  | ((a: A, i: number) => Effect.Effect<boolean, E, R>),
4328
4658
  options?: { readonly concurrency?: Concurrency | undefined }
4329
- ): Effect.Effect<Array<B>, E, R> =>
4659
+ ): Effect.Effect<Array<A>, E, R> =>
4330
4660
  suspend(() => {
4331
- const out: Array<any> = []
4661
+ const out: Array<A> = []
4332
4662
  return as(
4333
4663
  forEach(
4334
4664
  elements,
4335
4665
  (a, i) => {
4336
- const result = (filter as Function)(a, i)
4666
+ const result = (predicate as Function)(a, i)
4337
4667
  if (typeof result === "boolean") {
4338
4668
  if (result) out.push(a)
4339
4669
  return void_ as any
4340
4670
  }
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)
4671
+ return map(result, (keep) => {
4672
+ if (keep) {
4673
+ out.push(a)
4352
4674
  }
4353
4675
  })
4354
4676
  },
@@ -4362,6 +4684,72 @@ export const filter: {
4362
4684
  })
4363
4685
  )
4364
4686
 
4687
+ /** @internal */
4688
+ export const filterMap: {
4689
+ <A, B, X>(
4690
+ filter: Filter.Filter<NoInfer<A>, B, X>
4691
+ ): (elements: Iterable<A>) => Effect.Effect<Array<B>>
4692
+ <A, B, X>(
4693
+ elements: Iterable<A>,
4694
+ filter: Filter.Filter<NoInfer<A>, B, X>
4695
+ ): Effect.Effect<Array<B>>
4696
+ } = dual(
4697
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4698
+ <A, B, X>(
4699
+ elements: Iterable<A>,
4700
+ filter: Filter.Filter<A, B, X>
4701
+ ): Effect.Effect<Array<B>> =>
4702
+ suspend(() => {
4703
+ const out: Array<B> = []
4704
+ for (const a of elements) {
4705
+ const result = filter(a)
4706
+ if (Result.isSuccess(result)) {
4707
+ out.push(result.success)
4708
+ }
4709
+ }
4710
+ return succeed(out)
4711
+ })
4712
+ )
4713
+
4714
+ /** @internal */
4715
+ export const filterMapEffect: {
4716
+ <A, B, X, E, R>(
4717
+ filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
4718
+ options?: { readonly concurrency?: Concurrency | undefined }
4719
+ ): (elements: Iterable<A>) => Effect.Effect<Array<B>, E, R>
4720
+ <A, B, X, E, R>(
4721
+ elements: Iterable<A>,
4722
+ filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
4723
+ options?: { readonly concurrency?: Concurrency | undefined }
4724
+ ): Effect.Effect<Array<B>, E, R>
4725
+ } = dual(
4726
+ (args) => isIterable(args[0]) && !isEffect(args[0]),
4727
+ <A, B, X, E, R>(
4728
+ elements: Iterable<A>,
4729
+ filter: Filter.FilterEffect<A, B, X, E, R>,
4730
+ options?: { readonly concurrency?: Concurrency | undefined }
4731
+ ): Effect.Effect<Array<B>, E, R> =>
4732
+ suspend(() => {
4733
+ const out: Array<B> = []
4734
+ return as(
4735
+ forEach(
4736
+ elements,
4737
+ (a) =>
4738
+ map(filter(a), (result) => {
4739
+ if (Result.isSuccess(result)) {
4740
+ out.push(result.success)
4741
+ }
4742
+ }),
4743
+ {
4744
+ discard: true,
4745
+ concurrency: options?.concurrency
4746
+ }
4747
+ ),
4748
+ out
4749
+ )
4750
+ })
4751
+ )
4752
+
4365
4753
  // ----------------------------------------------------------------------------
4366
4754
  // do notation
4367
4755
  // ----------------------------------------------------------------------------
@@ -4772,25 +5160,27 @@ class Semaphore {
4772
5160
  return this.permits - this.taken
4773
5161
  }
4774
5162
 
4775
- readonly take = (n: number): Effect.Effect<number> =>
4776
- callback<number>((resume) => {
5163
+ readonly take = (n: number): Effect.Effect<number> => {
5164
+ const take: Effect.Effect<number> = suspend(() => {
4777
5165
  if (this.free < n) {
4778
- const observer = () => {
4779
- if (this.free < n) {
4780
- return
5166
+ return callback((resume) => {
5167
+ if (this.free >= n) return resume(take)
5168
+ const observer = () => {
5169
+ if (this.free < n) return
5170
+ this.waiters.delete(observer)
5171
+ resume(take)
4781
5172
  }
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)
5173
+ this.waiters.add(observer)
5174
+ return sync(() => {
5175
+ this.waiters.delete(observer)
5176
+ })
4789
5177
  })
4790
5178
  }
4791
5179
  this.taken += n
4792
- return resume(succeed(n))
5180
+ return succeed(n)
4793
5181
  })
5182
+ return take
5183
+ }
4794
5184
 
4795
5185
  updateTakenUnsafe(fiber: Fiber.Fiber<any, any>, f: (n: number) => number): Effect.Effect<number> {
4796
5186
  this.taken = f(this.taken)
@@ -4828,7 +5218,10 @@ class Semaphore {
4828
5218
 
4829
5219
  readonly withPermits = (n: number) => <A, E, R>(self: Effect.Effect<A, E, R>) =>
4830
5220
  uninterruptibleMask((restore) =>
4831
- flatMap(restore(this.take(n)), (permits) => ensuring(restore(self), this.release(permits)))
5221
+ flatMap(
5222
+ restore(this.take(n)),
5223
+ (permits) => onExitPrimitive(restore(self), () => this.release(permits), true)
5224
+ )
4832
5225
  )
4833
5226
 
4834
5227
  readonly withPermit = this.withPermits(1)
@@ -4854,7 +5247,7 @@ export const makeSemaphore = (permits: number) => sync(() => makeSemaphoreUnsafe
4854
5247
  const succeedTrue = succeed(true)
4855
5248
  const succeedFalse = succeed(false)
4856
5249
 
4857
- class Latch implements Effect.Latch {
5250
+ class Latch implements _Latch.Latch {
4858
5251
  waiters: Array<(_: Effect.Effect<void>) => void> = []
4859
5252
  scheduled = false
4860
5253
  private isOpen: boolean
@@ -4914,7 +5307,7 @@ class Latch implements Effect.Latch {
4914
5307
  }
4915
5308
 
4916
5309
  /** @internal */
4917
- export const makeLatchUnsafe = (open?: boolean | undefined): Effect.Latch => new Latch(open ?? false)
5310
+ export const makeLatchUnsafe = (open?: boolean | undefined): _Latch.Latch => new Latch(open ?? false)
4918
5311
 
4919
5312
  /** @internal */
4920
5313
  export const makeLatch = (open?: boolean | undefined) => sync(() => makeLatchUnsafe(open))
@@ -5344,8 +5737,8 @@ export const clockWith = <A, E, R>(f: (clock: Clock.Clock) => Effect.Effect<A, E
5344
5737
  withFiber((fiber) => f(fiber.getRef(ClockRef)))
5345
5738
 
5346
5739
  /** @internal */
5347
- export const sleep = (duration: Duration.DurationInput): Effect.Effect<void> =>
5348
- clockWith((clock) => clock.sleep(Duration.fromDurationInputUnsafe(duration)))
5740
+ export const sleep = (duration: Duration.Input): Effect.Effect<void> =>
5741
+ clockWith((clock) => clock.sleep(Duration.fromInputUnsafe(duration)))
5349
5742
 
5350
5743
  /** @internal */
5351
5744
  export const currentTimeMillis: Effect.Effect<number> = clockWith((clock) => clock.currentTimeMillis)
@@ -5477,6 +5870,40 @@ export const LogToStderr = ServiceMap.Reference<boolean>("effect/Logger/LogToStd
5477
5870
  defaultValue: constFalse
5478
5871
  })
5479
5872
 
5873
+ /** @internal */
5874
+ export const annotateLogsScoped: {
5875
+ (key: string, value: unknown): Effect.Effect<void, never, Scope.Scope>
5876
+ (values: Record<string, unknown>): Effect.Effect<void, never, Scope.Scope>
5877
+ } = function() {
5878
+ const entries = typeof arguments[0] === "string" ?
5879
+ [[arguments[0], arguments[1]]] :
5880
+ Object.entries(arguments[0])
5881
+ return uninterruptible(withFiber((fiber) => {
5882
+ const prev = fiber.getRef(CurrentLogAnnotations)
5883
+ const next = { ...prev }
5884
+ for (let i = 0; i < entries.length; i++) {
5885
+ const [key, value] = entries[i]
5886
+ next[key] = value
5887
+ }
5888
+ fiber.setServices(ServiceMap.add(fiber.services, CurrentLogAnnotations, next))
5889
+ return scopeAddFinalizerExit(ServiceMap.getUnsafe(fiber.services, scopeTag), (_) => {
5890
+ const current = fiber.getRef(CurrentLogAnnotations)
5891
+ const next = { ...current }
5892
+ for (let i = 0; i < entries.length; i++) {
5893
+ const [key, value] = entries[i]
5894
+ if (current[key] !== value) continue
5895
+ if (key in prev) {
5896
+ next[key] = prev[key]
5897
+ } else {
5898
+ delete next[key]
5899
+ }
5900
+ }
5901
+ fiber.setServices(ServiceMap.add(fiber.services, CurrentLogAnnotations, next))
5902
+ return void_
5903
+ })
5904
+ }))
5905
+ }
5906
+
5480
5907
  /** @internal */
5481
5908
  export const LoggerTypeId = "~effect/Logger"
5482
5909
 
@@ -5492,7 +5919,7 @@ const LoggerProto = {
5492
5919
 
5493
5920
  /** @internal */
5494
5921
  export const loggerMake = <Message, Output>(
5495
- log: (options: Logger.Logger.Options<Message>) => Output
5922
+ log: (options: Logger.Options<Message>) => Output
5496
5923
  ): Logger.Logger<Message, Output> => {
5497
5924
  const self = Object.create(LoggerProto)
5498
5925
  self.log = log
@@ -5532,7 +5959,7 @@ export const structuredMessage = (u: unknown): unknown => {
5532
5959
  }
5533
5960
 
5534
5961
  /** @internal */
5535
- export const logWithLevel = (level?: LogLevel.LogLevel) =>
5962
+ export const logWithLevel = (level?: LogLevel.Severity) =>
5536
5963
  (
5537
5964
  ...message: ReadonlyArray<any>
5538
5965
  ): Effect.Effect<void> => {
@@ -5823,3 +6250,55 @@ const undefined_ = succeed(undefined)
5823
6250
 
5824
6251
  /** @internal */
5825
6252
  export { undefined_ as undefined }
6253
+
6254
+ // ----------------------------------------------------------------------------
6255
+ // ErrorReporter
6256
+ // ----------------------------------------------------------------------------
6257
+
6258
+ /** @internal */
6259
+ export const CurrentErrorReporters = ServiceMap.Reference<
6260
+ ReadonlySet<ErrorReporter>
6261
+ >("effect/ErrorReporter/CurrentErrorReporters", {
6262
+ defaultValue: () => new Set()
6263
+ })
6264
+
6265
+ /** @internal */
6266
+ export const withErrorReporting: <
6267
+ Arg extends Effect.Effect<any, any, any> | {
6268
+ readonly defectsOnly?: boolean | undefined
6269
+ } | undefined = {
6270
+ readonly defectsOnly?: boolean | undefined
6271
+ }
6272
+ >(
6273
+ effectOrOptions: Arg,
6274
+ options?: {
6275
+ readonly defectsOnly?: boolean | undefined
6276
+ } | undefined
6277
+ ) => [Arg] extends [Effect.Effect<infer _A, infer _E, infer _R>] ? Arg
6278
+ : <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> = dual(
6279
+ (args) => isEffect(args[0]),
6280
+ <A, E, R>(
6281
+ self: Effect.Effect<A, E, R>,
6282
+ options?: {
6283
+ readonly defectsOnly?: boolean | undefined
6284
+ } | undefined
6285
+ ): Effect.Effect<A, E, R> =>
6286
+ onError(self, (cause) =>
6287
+ withFiber((fiber) => {
6288
+ reportCauseUnsafe(fiber, cause, options?.defectsOnly)
6289
+ return void_
6290
+ }))
6291
+ )
6292
+
6293
+ /** @internal */
6294
+ export const reportCauseUnsafe = (
6295
+ fiber: Fiber.Fiber<unknown, unknown>,
6296
+ cause: Cause.Cause<unknown>,
6297
+ defectsOnly?: boolean
6298
+ ) => {
6299
+ const reporters = fiber.getRef(CurrentErrorReporters)
6300
+ if (reporters.size === 0) return
6301
+ if (defectsOnly && !hasDies(cause)) return
6302
+ const opts = { cause, fiber, timestamp: fiber.getRef(ClockRef).currentTimeNanosUnsafe() }
6303
+ reporters.forEach((reporter) => reporter.report(opts))
6304
+ }