effect 4.0.0-beta.30 → 4.0.0-beta.32

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 (514) hide show
  1. package/dist/Array.d.ts +87 -86
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +47 -40
  4. package/dist/Array.js.map +1 -1
  5. package/dist/BigDecimal.d.ts +46 -45
  6. package/dist/BigDecimal.d.ts.map +1 -1
  7. package/dist/BigDecimal.js +35 -38
  8. package/dist/BigDecimal.js.map +1 -1
  9. package/dist/BigInt.d.ts +39 -32
  10. package/dist/BigInt.d.ts.map +1 -1
  11. package/dist/BigInt.js +32 -29
  12. package/dist/BigInt.js.map +1 -1
  13. package/dist/Channel.d.ts +2 -2
  14. package/dist/Channel.d.ts.map +1 -1
  15. package/dist/Channel.js.map +1 -1
  16. package/dist/Chunk.d.ts +58 -57
  17. package/dist/Chunk.d.ts.map +1 -1
  18. package/dist/Chunk.js +20 -21
  19. package/dist/Chunk.js.map +1 -1
  20. package/dist/Config.d.ts.map +1 -1
  21. package/dist/Config.js +4 -1
  22. package/dist/Config.js.map +1 -1
  23. package/dist/Cron.d.ts +3 -6
  24. package/dist/Cron.d.ts.map +1 -1
  25. package/dist/Cron.js +11 -18
  26. package/dist/Cron.js.map +1 -1
  27. package/dist/DateTime.d.ts +49 -92
  28. package/dist/DateTime.d.ts.map +1 -1
  29. package/dist/DateTime.js +9 -9
  30. package/dist/DateTime.js.map +1 -1
  31. package/dist/Deferred.d.ts +7 -5
  32. package/dist/Deferred.d.ts.map +1 -1
  33. package/dist/Deferred.js +7 -5
  34. package/dist/Deferred.js.map +1 -1
  35. package/dist/Duration.d.ts +55 -25
  36. package/dist/Duration.d.ts.map +1 -1
  37. package/dist/Duration.js +100 -70
  38. package/dist/Duration.js.map +1 -1
  39. package/dist/Effect.d.ts.map +1 -1
  40. package/dist/Effect.js +3 -4
  41. package/dist/Effect.js.map +1 -1
  42. package/dist/Fiber.d.ts +2 -1
  43. package/dist/Fiber.d.ts.map +1 -1
  44. package/dist/Fiber.js.map +1 -1
  45. package/dist/FiberHandle.d.ts +9 -8
  46. package/dist/FiberHandle.d.ts.map +1 -1
  47. package/dist/FiberHandle.js +8 -7
  48. package/dist/FiberHandle.js.map +1 -1
  49. package/dist/FiberMap.d.ts +20 -19
  50. package/dist/FiberMap.d.ts.map +1 -1
  51. package/dist/FiberMap.js +6 -6
  52. package/dist/FiberMap.js.map +1 -1
  53. package/dist/FileSystem.d.ts +17 -16
  54. package/dist/FileSystem.d.ts.map +1 -1
  55. package/dist/FileSystem.js +10 -7
  56. package/dist/FileSystem.js.map +1 -1
  57. package/dist/Graph.d.ts +64 -64
  58. package/dist/Graph.d.ts.map +1 -1
  59. package/dist/Graph.js +53 -53
  60. package/dist/Graph.js.map +1 -1
  61. package/dist/HashMap.d.ts +11 -5
  62. package/dist/HashMap.d.ts.map +1 -1
  63. package/dist/HashMap.js +3 -1
  64. package/dist/HashMap.js.map +1 -1
  65. package/dist/Iterable.d.ts +11 -11
  66. package/dist/Iterable.d.ts.map +1 -1
  67. package/dist/Iterable.js +12 -12
  68. package/dist/Iterable.js.map +1 -1
  69. package/dist/Latch.d.ts +69 -3
  70. package/dist/Latch.d.ts.map +1 -1
  71. package/dist/Latch.js +58 -0
  72. package/dist/Latch.js.map +1 -1
  73. package/dist/Layer.d.ts +181 -2
  74. package/dist/Layer.d.ts.map +1 -1
  75. package/dist/Layer.js +35 -2
  76. package/dist/Layer.js.map +1 -1
  77. package/dist/Number.d.ts +74 -18
  78. package/dist/Number.d.ts.map +1 -1
  79. package/dist/Number.js +34 -15
  80. package/dist/Number.js.map +1 -1
  81. package/dist/Option.d.ts +2 -0
  82. package/dist/Option.d.ts.map +1 -1
  83. package/dist/Option.js.map +1 -1
  84. package/dist/PartitionedSemaphore.d.ts +183 -0
  85. package/dist/PartitionedSemaphore.d.ts.map +1 -0
  86. package/dist/PartitionedSemaphore.js +231 -0
  87. package/dist/PartitionedSemaphore.js.map +1 -0
  88. package/dist/PubSub.d.ts +5 -4
  89. package/dist/PubSub.d.ts.map +1 -1
  90. package/dist/PubSub.js +6 -5
  91. package/dist/PubSub.js.map +1 -1
  92. package/dist/Queue.d.ts +3 -3
  93. package/dist/Queue.d.ts.map +1 -1
  94. package/dist/Queue.js +2 -2
  95. package/dist/Queue.js.map +1 -1
  96. package/dist/Record.d.ts +40 -40
  97. package/dist/Record.d.ts.map +1 -1
  98. package/dist/Record.js +16 -15
  99. package/dist/Record.js.map +1 -1
  100. package/dist/Scheduler.d.ts +25 -123
  101. package/dist/Scheduler.d.ts.map +1 -1
  102. package/dist/Scheduler.js +20 -123
  103. package/dist/Scheduler.js.map +1 -1
  104. package/dist/Schema.d.ts +2346 -114
  105. package/dist/Schema.d.ts.map +1 -1
  106. package/dist/Schema.js +1359 -68
  107. package/dist/Schema.js.map +1 -1
  108. package/dist/SchemaAST.d.ts +2 -2
  109. package/dist/SchemaAST.js +2 -2
  110. package/dist/SchemaGetter.js +6 -4
  111. package/dist/SchemaGetter.js.map +1 -1
  112. package/dist/SchemaRepresentation.d.ts +2 -2
  113. package/dist/SchemaRepresentation.d.ts.map +1 -1
  114. package/dist/SchemaRepresentation.js.map +1 -1
  115. package/dist/SchemaTransformation.d.ts.map +1 -1
  116. package/dist/SchemaTransformation.js +32 -27
  117. package/dist/SchemaTransformation.js.map +1 -1
  118. package/dist/Semaphore.d.ts +149 -53
  119. package/dist/Semaphore.d.ts.map +1 -1
  120. package/dist/Semaphore.js +137 -117
  121. package/dist/Semaphore.js.map +1 -1
  122. package/dist/ServiceMap.d.ts +26 -0
  123. package/dist/ServiceMap.d.ts.map +1 -1
  124. package/dist/ServiceMap.js +36 -21
  125. package/dist/ServiceMap.js.map +1 -1
  126. package/dist/Stream.js +1 -1
  127. package/dist/Stream.js.map +1 -1
  128. package/dist/String.d.ts +114 -47
  129. package/dist/String.d.ts.map +1 -1
  130. package/dist/String.js +29 -47
  131. package/dist/String.js.map +1 -1
  132. package/dist/SubscriptionRef.d.ts +1 -2
  133. package/dist/SubscriptionRef.d.ts.map +1 -1
  134. package/dist/SubscriptionRef.js +81 -115
  135. package/dist/SubscriptionRef.js.map +1 -1
  136. package/dist/Terminal.d.ts +2 -1
  137. package/dist/Terminal.d.ts.map +1 -1
  138. package/dist/Terminal.js.map +1 -1
  139. package/dist/Tracer.d.ts +5 -4
  140. package/dist/Tracer.d.ts.map +1 -1
  141. package/dist/Tracer.js +2 -1
  142. package/dist/Tracer.js.map +1 -1
  143. package/dist/Trie.d.ts +26 -14
  144. package/dist/Trie.d.ts.map +1 -1
  145. package/dist/Trie.js +8 -4
  146. package/dist/Trie.js.map +1 -1
  147. package/dist/TxHashMap.d.ts +77 -59
  148. package/dist/TxHashMap.d.ts.map +1 -1
  149. package/dist/TxHashMap.js +25 -19
  150. package/dist/TxHashMap.js.map +1 -1
  151. package/dist/TxSemaphore.d.ts +162 -2
  152. package/dist/TxSemaphore.d.ts.map +1 -1
  153. package/dist/TxSemaphore.js +16 -2
  154. package/dist/TxSemaphore.js.map +1 -1
  155. package/dist/index.d.ts +88 -32
  156. package/dist/index.d.ts.map +1 -1
  157. package/dist/index.js +88 -32
  158. package/dist/index.js.map +1 -1
  159. package/dist/internal/dateTime.js +66 -59
  160. package/dist/internal/dateTime.js.map +1 -1
  161. package/dist/internal/effect.js +21 -90
  162. package/dist/internal/effect.js.map +1 -1
  163. package/dist/internal/hashMap.js +2 -1
  164. package/dist/internal/hashMap.js.map +1 -1
  165. package/dist/internal/option.js +6 -0
  166. package/dist/internal/option.js.map +1 -1
  167. package/dist/internal/trie.js +3 -3
  168. package/dist/internal/trie.js.map +1 -1
  169. package/dist/unstable/ai/AiError.js +1 -1
  170. package/dist/unstable/ai/AiError.js.map +1 -1
  171. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  172. package/dist/unstable/ai/AnthropicStructuredOutput.js +4 -0
  173. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  174. package/dist/unstable/ai/Chat.d.ts +3 -4
  175. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  176. package/dist/unstable/ai/Chat.js +2 -2
  177. package/dist/unstable/ai/Chat.js.map +1 -1
  178. package/dist/unstable/ai/LanguageModel.d.ts +30 -16
  179. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  180. package/dist/unstable/ai/LanguageModel.js +10 -87
  181. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  182. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  183. package/dist/unstable/ai/OpenAiStructuredOutput.js +4 -0
  184. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  185. package/dist/unstable/ai/Tool.d.ts +14 -0
  186. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  187. package/dist/unstable/ai/Tool.js +13 -0
  188. package/dist/unstable/ai/Tool.js.map +1 -1
  189. package/dist/unstable/cli/Argument.d.ts +2 -4
  190. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  191. package/dist/unstable/cli/Argument.js +1 -3
  192. package/dist/unstable/cli/Argument.js.map +1 -1
  193. package/dist/unstable/cli/CliOutput.d.ts +3 -2
  194. package/dist/unstable/cli/CliOutput.d.ts.map +1 -1
  195. package/dist/unstable/cli/CliOutput.js +4 -3
  196. package/dist/unstable/cli/CliOutput.js.map +1 -1
  197. package/dist/unstable/cli/Command.d.ts +3 -2
  198. package/dist/unstable/cli/Command.d.ts.map +1 -1
  199. package/dist/unstable/cli/Command.js +3 -3
  200. package/dist/unstable/cli/Command.js.map +1 -1
  201. package/dist/unstable/cli/Completions.d.ts +16 -0
  202. package/dist/unstable/cli/Completions.d.ts.map +1 -0
  203. package/dist/unstable/cli/Completions.js +23 -0
  204. package/dist/unstable/cli/Completions.js.map +1 -0
  205. package/dist/unstable/cli/Flag.d.ts +2 -2
  206. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  207. package/dist/unstable/cli/Flag.js +1 -1
  208. package/dist/unstable/cli/Flag.js.map +1 -1
  209. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  210. package/dist/unstable/cli/GlobalFlag.js +4 -4
  211. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  212. package/dist/unstable/cli/HelpDoc.d.ts +14 -12
  213. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  214. package/dist/unstable/cli/Param.d.ts +4 -4
  215. package/dist/unstable/cli/Param.d.ts.map +1 -1
  216. package/dist/unstable/cli/Param.js +7 -7
  217. package/dist/unstable/cli/Param.js.map +1 -1
  218. package/dist/unstable/cli/Primitive.d.ts +1 -1
  219. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  220. package/dist/unstable/cli/Primitive.js.map +1 -1
  221. package/dist/unstable/cli/Prompt.js +71 -67
  222. package/dist/unstable/cli/Prompt.js.map +1 -1
  223. package/dist/unstable/cli/index.d.ts +4 -0
  224. package/dist/unstable/cli/index.d.ts.map +1 -1
  225. package/dist/unstable/cli/index.js +4 -0
  226. package/dist/unstable/cli/index.js.map +1 -1
  227. package/dist/unstable/cli/internal/completions/CommandDescriptor.js +9 -2
  228. package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
  229. package/dist/unstable/cli/internal/parser.js +8 -3
  230. package/dist/unstable/cli/internal/parser.js.map +1 -1
  231. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -2
  232. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  233. package/dist/unstable/cluster/ClusterWorkflowEngine.js +25 -23
  234. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  235. package/dist/unstable/cluster/DeliverAt.js +1 -1
  236. package/dist/unstable/cluster/DeliverAt.js.map +1 -1
  237. package/dist/unstable/cluster/Entity.d.ts +3 -2
  238. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  239. package/dist/unstable/cluster/Entity.js +7 -7
  240. package/dist/unstable/cluster/Entity.js.map +1 -1
  241. package/dist/unstable/cluster/Message.d.ts +4 -3
  242. package/dist/unstable/cluster/Message.d.ts.map +1 -1
  243. package/dist/unstable/cluster/Message.js +3 -2
  244. package/dist/unstable/cluster/Message.js.map +1 -1
  245. package/dist/unstable/cluster/MessageStorage.d.ts +10 -10
  246. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  247. package/dist/unstable/cluster/MessageStorage.js +12 -12
  248. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  249. package/dist/unstable/cluster/Reply.d.ts +2 -1
  250. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  251. package/dist/unstable/cluster/Reply.js +4 -3
  252. package/dist/unstable/cluster/Reply.js.map +1 -1
  253. package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
  254. package/dist/unstable/cluster/RunnerServer.js +9 -8
  255. package/dist/unstable/cluster/RunnerServer.js.map +1 -1
  256. package/dist/unstable/cluster/Runners.d.ts +2 -1
  257. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  258. package/dist/unstable/cluster/Runners.js +7 -6
  259. package/dist/unstable/cluster/Runners.js.map +1 -1
  260. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  261. package/dist/unstable/cluster/Sharding.js +19 -13
  262. package/dist/unstable/cluster/Sharding.js.map +1 -1
  263. package/dist/unstable/cluster/ShardingConfig.d.ts +5 -4
  264. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  265. package/dist/unstable/cluster/ShardingConfig.js +4 -4
  266. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  267. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  268. package/dist/unstable/cluster/SqlMessageStorage.js +19 -18
  269. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  270. package/dist/unstable/cluster/internal/entityManager.js +9 -10
  271. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  272. package/dist/unstable/devtools/DevToolsSchema.d.ts +2 -1
  273. package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
  274. package/dist/unstable/devtools/DevToolsSchema.js +1 -4
  275. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  276. package/dist/unstable/encoding/Ndjson.d.ts +8 -8
  277. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  278. package/dist/unstable/encoding/Ndjson.js.map +1 -1
  279. package/dist/unstable/http/Cookies.d.ts +5 -4
  280. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  281. package/dist/unstable/http/Cookies.js +3 -4
  282. package/dist/unstable/http/Cookies.js.map +1 -1
  283. package/dist/unstable/http/Etag.d.ts.map +1 -1
  284. package/dist/unstable/http/Etag.js +5 -1
  285. package/dist/unstable/http/Etag.js.map +1 -1
  286. package/dist/unstable/http/Headers.d.ts +3 -2
  287. package/dist/unstable/http/Headers.d.ts.map +1 -1
  288. package/dist/unstable/http/Headers.js +2 -1
  289. package/dist/unstable/http/Headers.js.map +1 -1
  290. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  291. package/dist/unstable/http/HttpClient.js +2 -1
  292. package/dist/unstable/http/HttpClient.js.map +1 -1
  293. package/dist/unstable/http/HttpClientRequest.d.ts +4 -3
  294. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  295. package/dist/unstable/http/HttpClientRequest.js +8 -6
  296. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  297. package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
  298. package/dist/unstable/http/HttpClientResponse.js +2 -1
  299. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  300. package/dist/unstable/http/HttpIncomingMessage.d.ts +3 -2
  301. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  302. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  303. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  304. package/dist/unstable/http/HttpMiddleware.js +16 -15
  305. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  306. package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
  307. package/dist/unstable/http/HttpPlatform.js +3 -2
  308. package/dist/unstable/http/HttpPlatform.js.map +1 -1
  309. package/dist/unstable/http/HttpRouter.d.ts +2 -1
  310. package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
  311. package/dist/unstable/http/HttpRouter.js +7 -7
  312. package/dist/unstable/http/HttpRouter.js.map +1 -1
  313. package/dist/unstable/http/HttpServer.d.ts.map +1 -1
  314. package/dist/unstable/http/HttpServer.js +2 -2
  315. package/dist/unstable/http/HttpServer.js.map +1 -1
  316. package/dist/unstable/http/HttpServerError.d.ts +2 -1
  317. package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
  318. package/dist/unstable/http/HttpServerError.js +2 -1
  319. package/dist/unstable/http/HttpServerError.js.map +1 -1
  320. package/dist/unstable/http/HttpServerRequest.d.ts +3 -2
  321. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  322. package/dist/unstable/http/HttpServerRequest.js +14 -10
  323. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  324. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  325. package/dist/unstable/http/HttpServerResponse.js +4 -3
  326. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  327. package/dist/unstable/http/HttpTraceContext.d.ts +3 -2
  328. package/dist/unstable/http/HttpTraceContext.d.ts.map +1 -1
  329. package/dist/unstable/http/HttpTraceContext.js +27 -15
  330. package/dist/unstable/http/HttpTraceContext.js.map +1 -1
  331. package/dist/unstable/http/UrlParams.d.ts +5 -4
  332. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  333. package/dist/unstable/http/UrlParams.js +5 -6
  334. package/dist/unstable/http/UrlParams.js.map +1 -1
  335. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +2 -2
  336. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  337. package/dist/unstable/httpapi/HttpApiBuilder.js +4 -2
  338. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  339. package/dist/unstable/httpapi/HttpApiError.d.ts +15 -0
  340. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  341. package/dist/unstable/httpapi/HttpApiError.js +81 -3
  342. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  343. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  344. package/dist/unstable/observability/OtlpExporter.js +2 -2
  345. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  346. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  347. package/dist/unstable/observability/OtlpTracer.js +7 -3
  348. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  349. package/dist/unstable/persistence/Persistable.js +1 -1
  350. package/dist/unstable/persistence/Persistable.js.map +1 -1
  351. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  352. package/dist/unstable/reactivity/Atom.js +1 -5
  353. package/dist/unstable/reactivity/Atom.js.map +1 -1
  354. package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
  355. package/dist/unstable/reactivity/AtomRegistry.js +4 -2
  356. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  357. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  358. package/dist/unstable/rpc/Rpc.js +4 -3
  359. package/dist/unstable/rpc/Rpc.js.map +1 -1
  360. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  361. package/dist/unstable/rpc/RpcClient.js +4 -4
  362. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  363. package/dist/unstable/rpc/RpcGroup.d.ts +1 -3
  364. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  365. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  366. package/dist/unstable/rpc/RpcSchema.js +3 -2
  367. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  368. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  369. package/dist/unstable/rpc/RpcSerialization.js +4 -1
  370. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  371. package/dist/unstable/rpc/RpcServer.d.ts +1 -1
  372. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  373. package/dist/unstable/rpc/RpcServer.js +3 -2
  374. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  375. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  376. package/dist/unstable/socket/Socket.js +2 -1
  377. package/dist/unstable/socket/Socket.js.map +1 -1
  378. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  379. package/dist/unstable/sql/SqlClient.js +1 -1
  380. package/dist/unstable/sql/SqlClient.js.map +1 -1
  381. package/dist/unstable/workflow/DurableDeferred.js +6 -6
  382. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  383. package/dist/unstable/workflow/Workflow.d.ts +2 -1
  384. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  385. package/dist/unstable/workflow/WorkflowEngine.d.ts +5 -4
  386. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  387. package/dist/unstable/workflow/WorkflowEngine.js +19 -14
  388. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  389. package/package.json +1 -1
  390. package/src/Array.ts +112 -105
  391. package/src/BigDecimal.ts +63 -66
  392. package/src/BigInt.ts +49 -41
  393. package/src/Channel.ts +3 -3
  394. package/src/Chunk.ts +68 -63
  395. package/src/Config.ts +4 -1
  396. package/src/Cron.ts +13 -18
  397. package/src/DateTime.ts +51 -92
  398. package/src/Deferred.ts +8 -6
  399. package/src/Duration.ts +112 -56
  400. package/src/Effect.ts +3 -4
  401. package/src/Fiber.ts +2 -1
  402. package/src/FiberHandle.ts +10 -9
  403. package/src/FiberMap.ts +22 -22
  404. package/src/FileSystem.ts +25 -22
  405. package/src/Graph.ts +105 -105
  406. package/src/HashMap.ts +11 -5
  407. package/src/Iterable.ts +13 -13
  408. package/src/Latch.ts +85 -3
  409. package/src/Layer.ts +244 -19
  410. package/src/Number.ts +85 -26
  411. package/src/Option.ts +2 -0
  412. package/src/PartitionedSemaphore.ts +414 -0
  413. package/src/PubSub.ts +7 -6
  414. package/src/Queue.ts +5 -5
  415. package/src/Record.ts +52 -47
  416. package/src/Scheduler.ts +37 -126
  417. package/src/Schema.ts +2366 -116
  418. package/src/SchemaAST.ts +2 -2
  419. package/src/SchemaGetter.ts +4 -4
  420. package/src/SchemaRepresentation.ts +2 -2
  421. package/src/SchemaTransformation.ts +27 -27
  422. package/src/Semaphore.ts +271 -183
  423. package/src/ServiceMap.ts +83 -31
  424. package/src/Stream.ts +1 -1
  425. package/src/String.ts +122 -69
  426. package/src/SubscriptionRef.ts +96 -117
  427. package/src/Terminal.ts +2 -1
  428. package/src/Tracer.ts +6 -5
  429. package/src/Trie.ts +26 -14
  430. package/src/TxHashMap.ts +78 -60
  431. package/src/TxSemaphore.ts +186 -11
  432. package/src/index.ts +89 -33
  433. package/src/internal/dateTime.ts +74 -65
  434. package/src/internal/effect.ts +30 -122
  435. package/src/internal/hashMap.ts +4 -3
  436. package/src/internal/option.ts +7 -0
  437. package/src/internal/trie.ts +6 -6
  438. package/src/unstable/ai/AiError.ts +1 -1
  439. package/src/unstable/ai/AnthropicStructuredOutput.ts +4 -0
  440. package/src/unstable/ai/Chat.ts +17 -15
  441. package/src/unstable/ai/LanguageModel.ts +148 -97
  442. package/src/unstable/ai/OpenAiStructuredOutput.ts +4 -0
  443. package/src/unstable/ai/Tool.ts +20 -0
  444. package/src/unstable/cli/Argument.ts +2 -4
  445. package/src/unstable/cli/CliOutput.ts +7 -5
  446. package/src/unstable/cli/Command.ts +5 -5
  447. package/src/unstable/cli/Completions.ts +36 -0
  448. package/src/unstable/cli/Flag.ts +2 -2
  449. package/src/unstable/cli/GlobalFlag.ts +4 -5
  450. package/src/unstable/cli/HelpDoc.ts +14 -12
  451. package/src/unstable/cli/Param.ts +15 -11
  452. package/src/unstable/cli/Primitive.ts +1 -1
  453. package/src/unstable/cli/Prompt.ts +81 -83
  454. package/src/unstable/cli/index.ts +5 -0
  455. package/src/unstable/cli/internal/completions/CommandDescriptor.ts +3 -2
  456. package/src/unstable/cli/internal/parser.ts +7 -4
  457. package/src/unstable/cluster/ClusterWorkflowEngine.ts +35 -30
  458. package/src/unstable/cluster/DeliverAt.ts +1 -1
  459. package/src/unstable/cluster/Entity.ts +13 -12
  460. package/src/unstable/cluster/Message.ts +6 -5
  461. package/src/unstable/cluster/MessageStorage.ts +26 -25
  462. package/src/unstable/cluster/Reply.ts +7 -4
  463. package/src/unstable/cluster/RunnerServer.ts +10 -13
  464. package/src/unstable/cluster/Runners.ts +8 -7
  465. package/src/unstable/cluster/Sharding.ts +24 -17
  466. package/src/unstable/cluster/ShardingConfig.ts +6 -6
  467. package/src/unstable/cluster/SqlMessageStorage.ts +21 -18
  468. package/src/unstable/cluster/internal/entityManager.ts +27 -21
  469. package/src/unstable/devtools/DevToolsSchema.ts +3 -2
  470. package/src/unstable/encoding/Ndjson.ts +17 -17
  471. package/src/unstable/http/Cookies.ts +7 -8
  472. package/src/unstable/http/Etag.ts +5 -3
  473. package/src/unstable/http/Headers.ts +6 -5
  474. package/src/unstable/http/HttpClient.ts +2 -1
  475. package/src/unstable/http/HttpClientRequest.ts +11 -9
  476. package/src/unstable/http/HttpClientResponse.ts +5 -4
  477. package/src/unstable/http/HttpIncomingMessage.ts +3 -2
  478. package/src/unstable/http/HttpMiddleware.ts +16 -15
  479. package/src/unstable/http/HttpPlatform.ts +3 -2
  480. package/src/unstable/http/HttpRouter.ts +9 -9
  481. package/src/unstable/http/HttpServer.ts +3 -9
  482. package/src/unstable/http/HttpServerError.ts +3 -2
  483. package/src/unstable/http/HttpServerRequest.ts +29 -25
  484. package/src/unstable/http/HttpServerResponse.ts +7 -6
  485. package/src/unstable/http/HttpTraceContext.ts +31 -17
  486. package/src/unstable/http/UrlParams.ts +11 -14
  487. package/src/unstable/httpapi/HttpApiBuilder.ts +13 -7
  488. package/src/unstable/httpapi/HttpApiError.ts +67 -12
  489. package/src/unstable/observability/OtlpExporter.ts +5 -2
  490. package/src/unstable/observability/OtlpTracer.ts +8 -4
  491. package/src/unstable/persistence/Persistable.ts +1 -1
  492. package/src/unstable/reactivity/Atom.ts +1 -4
  493. package/src/unstable/reactivity/AtomRegistry.ts +5 -3
  494. package/src/unstable/rpc/Rpc.ts +4 -3
  495. package/src/unstable/rpc/RpcClient.ts +10 -9
  496. package/src/unstable/rpc/RpcGroup.ts +3 -3
  497. package/src/unstable/rpc/RpcSchema.ts +6 -5
  498. package/src/unstable/rpc/RpcSerialization.ts +4 -1
  499. package/src/unstable/rpc/RpcServer.ts +3 -3
  500. package/src/unstable/socket/Socket.ts +2 -1
  501. package/src/unstable/sql/SqlClient.ts +5 -3
  502. package/src/unstable/workflow/DurableDeferred.ts +6 -6
  503. package/src/unstable/workflow/Workflow.ts +1 -1
  504. package/src/unstable/workflow/WorkflowEngine.ts +29 -20
  505. package/dist/NullOr.d.ts +0 -149
  506. package/dist/NullOr.d.ts.map +0 -1
  507. package/dist/NullOr.js +0 -152
  508. package/dist/NullOr.js.map +0 -1
  509. package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
  510. package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
  511. package/dist/unstable/cli/internal/completions/Completions.js +0 -23
  512. package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
  513. package/src/NullOr.ts +0 -204
  514. package/src/unstable/cli/internal/completions/Completions.ts +0 -31
package/src/SchemaAST.ts CHANGED
@@ -2394,9 +2394,9 @@ export function memoizeThunk<A>(f: () => A): () => A {
2394
2394
  * readonly children: ReadonlyArray<Category>
2395
2395
  * }
2396
2396
  *
2397
- * const Category: Schema.Schema<Category> = Schema.Struct({
2397
+ * const Category = Schema.Struct({
2398
2398
  * name: Schema.String,
2399
- * children: Schema.Array(Schema.suspend(() => Category))
2399
+ * children: Schema.Array(Schema.suspend((): Schema.Codec<Category> => Category))
2400
2400
  * })
2401
2401
  *
2402
2402
  * // The recursive branch is a Suspend node
@@ -1482,10 +1482,10 @@ export function decodeHexString<E extends string>(): Getter<string, E> {
1482
1482
  */
1483
1483
  export function dateTimeUtcFromInput<E extends DateTime.DateTime.Input>(): Getter<DateTime.Utc, E> {
1484
1484
  return transformOrFail((input) => {
1485
- const dt = DateTime.make(input)
1486
- return dt
1487
- ? Effect.succeed(DateTime.toUtc(dt))
1488
- : Effect.fail(new Issue.InvalidValue(Option.some(input), { message: "Invalid DateTime input" }))
1485
+ return Option.match(DateTime.make(input), {
1486
+ onNone: () => Effect.fail(new Issue.InvalidValue(Option.some(input), { message: "Invalid DateTime input" })),
1487
+ onSome: (dt) => Effect.succeed(DateTime.toUtc(dt))
1488
+ })
1489
1489
  })
1490
1490
  }
1491
1491
 
@@ -1646,7 +1646,7 @@ export const fromASTs: (asts: readonly [AST.AST, ...Array<AST.AST>]) => MultiDoc
1646
1646
  *
1647
1647
  * @since 4.0.0
1648
1648
  */
1649
- export const DocumentFromJson: Schema.Codec<Document, unknown> = Schema.toCodecJson($Document)
1649
+ export const DocumentFromJson: Schema.Codec<Document, Schema.Json> = Schema.toCodecJson($Document)
1650
1650
 
1651
1651
  /**
1652
1652
  * Schema codec that decodes a {@link MultiDocument} from JSON and encodes it
@@ -1657,7 +1657,7 @@ export const DocumentFromJson: Schema.Codec<Document, unknown> = Schema.toCodecJ
1657
1657
  *
1658
1658
  * @since 4.0.0
1659
1659
  */
1660
- export const MultiDocumentFromJson: Schema.Codec<MultiDocument, unknown> = Schema.toCodecJson($MultiDocument)
1660
+ export const MultiDocumentFromJson: Schema.Codec<MultiDocument, Schema.Json> = Schema.toCodecJson($MultiDocument)
1661
1661
 
1662
1662
  /**
1663
1663
  * Wraps a single {@link Document} as a {@link MultiDocument} with one
@@ -907,15 +907,14 @@ export const bigintFromString = new Transformation(
907
907
  */
908
908
  export const durationFromNanos: Transformation<Duration.Duration, bigint> = transformOrFail({
909
909
  decode: (i) => Effect.succeed(Duration.nanos(i)),
910
- encode: (a) => {
911
- const nanos = Duration.toNanos(a)
912
- if (Predicate.isUndefined(nanos)) {
913
- return Effect.fail(
914
- new Issue.InvalidValue(Option.some(a), { message: `Unable to encode ${a} into a bigint` })
915
- )
916
- }
917
- return Effect.succeed(nanos)
918
- }
910
+ encode: (a) =>
911
+ Option.match(Duration.toNanos(a), {
912
+ onNone: () =>
913
+ Effect.fail(
914
+ new Issue.InvalidValue(Option.some(a), { message: `Unable to encode ${a} into a bigint` })
915
+ ),
916
+ onSome: (nanos) => Effect.succeed(nanos)
917
+ })
919
918
  })
920
919
 
921
920
  /**
@@ -1239,9 +1238,9 @@ export const bigDecimalFromString: Transformation<BigDecimal.BigDecimal, string>
1239
1238
  >({
1240
1239
  decode: (s) => {
1241
1240
  const result = BigDecimal.fromString(s)
1242
- return result === undefined
1241
+ return Option.isNone(result)
1243
1242
  ? Effect.fail(new Issue.InvalidValue(Option.some(s), { message: `Invalid BigDecimal string: ${s}` }))
1244
- : Effect.succeed(result)
1243
+ : Effect.succeed(result.value)
1245
1244
  },
1246
1245
  encode: (bd) => Effect.succeed(BigDecimal.format(bd))
1247
1246
  })
@@ -1394,10 +1393,10 @@ export const timeZoneNamedFromString: Transformation<DateTime.TimeZone.Named, st
1394
1393
  string
1395
1394
  >({
1396
1395
  decode: (s) => {
1397
- const result = DateTime.zoneMakeNamed(s)
1398
- return result === undefined
1399
- ? Effect.fail(new Issue.InvalidValue(Option.some(s), { message: `Invalid IANA time zone: ${s}` }))
1400
- : Effect.succeed(result)
1396
+ return Option.match(DateTime.zoneMakeNamed(s), {
1397
+ onNone: () => Effect.fail(new Issue.InvalidValue(Option.some(s), { message: `Invalid IANA time zone: ${s}` })),
1398
+ onSome: Effect.succeed
1399
+ })
1401
1400
  },
1402
1401
  encode: (tz) => Effect.succeed(tz.id)
1403
1402
  })
@@ -1410,10 +1409,10 @@ export const timeZoneFromString: Transformation<DateTime.TimeZone, string> = tra
1410
1409
  string
1411
1410
  >({
1412
1411
  decode: (s) => {
1413
- const result = DateTime.zoneFromString(s)
1414
- return result === undefined
1415
- ? Effect.fail(new Issue.InvalidValue(Option.some(s), { message: `Invalid time zone: ${s}` }))
1416
- : Effect.succeed(result)
1412
+ return Option.match(DateTime.zoneFromString(s), {
1413
+ onNone: () => Effect.fail(new Issue.InvalidValue(Option.some(s), { message: `Invalid time zone: ${s}` })),
1414
+ onSome: Effect.succeed
1415
+ })
1417
1416
  },
1418
1417
  encode: (tz) => Effect.succeed(DateTime.zoneToString(tz))
1419
1418
  })
@@ -1426,10 +1425,10 @@ export const dateTimeUtcFromString: Transformation<DateTime.Utc, string> = trans
1426
1425
  string
1427
1426
  >({
1428
1427
  decode: (s) => {
1429
- const result = DateTime.make(s)
1430
- return result === undefined
1431
- ? Effect.fail(new Issue.InvalidValue(Option.some(s), { message: "Invalid DateTime input" }))
1432
- : Effect.succeed(DateTime.toUtc(result))
1428
+ return Option.match(DateTime.make(s), {
1429
+ onNone: () => Effect.fail(new Issue.InvalidValue(Option.some(s), { message: "Invalid DateTime input" })),
1430
+ onSome: (result) => Effect.succeed(DateTime.toUtc(result))
1431
+ })
1433
1432
  },
1434
1433
  encode: (utc) => Effect.succeed(DateTime.formatIso(utc))
1435
1434
  })
@@ -1442,10 +1441,11 @@ export const dateTimeZonedFromString: Transformation<DateTime.Zoned, string> = t
1442
1441
  string
1443
1442
  >({
1444
1443
  decode: (s) => {
1445
- const result = DateTime.makeZonedFromString(s)
1446
- return result === undefined
1447
- ? Effect.fail(new Issue.InvalidValue(Option.some(s), { message: `Invalid zoned DateTime string: ${s}` }))
1448
- : Effect.succeed(result)
1444
+ return Option.match(DateTime.makeZonedFromString(s), {
1445
+ onNone: () =>
1446
+ Effect.fail(new Issue.InvalidValue(Option.some(s), { message: `Invalid zoned DateTime string: ${s}` })),
1447
+ onSome: Effect.succeed
1448
+ })
1449
1449
  },
1450
1450
  encode: (zoned) => Effect.succeed(DateTime.formatIsoZoned(zoned))
1451
1451
  })
package/src/Semaphore.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * @since 2.0.0
3
3
  */
4
- import * as Effect from "./Effect.ts"
4
+ import type * as Effect from "./Effect.ts"
5
+ import type { Fiber } from "./Fiber.ts"
6
+ import { dual } from "./Function.ts"
7
+ import * as core from "./internal/core.ts"
5
8
  import * as internal from "./internal/effect.ts"
6
- import * as MutableHashMap from "./MutableHashMap.ts"
7
- import * as Option from "./Option.ts"
9
+ import type * as Option from "./Option.ts"
8
10
 
9
11
  /**
10
12
  * @category models
@@ -27,7 +29,7 @@ export interface Semaphore {
27
29
  /**
28
30
  * Adjusts the number of permits available in the semaphore.
29
31
  */
30
- resize(permits: number): Effect.Effect<void>
32
+ resize(this: Semaphore, permits: number): Effect.Effect<void>
31
33
 
32
34
  /**
33
35
  * Runs an effect with the given number of permits and releases the permits
@@ -40,7 +42,7 @@ export interface Semaphore {
40
42
  * If insufficient permits are available, the function will wait until they
41
43
  * are released by other tasks.
42
44
  */
43
- withPermits(permits: number): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
45
+ withPermits(this: Semaphore, permits: number): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
44
46
 
45
47
  /**
46
48
  * Runs an effect with the given number of permits and releases the permits
@@ -53,7 +55,7 @@ export interface Semaphore {
53
55
  * If insufficient permits are available, the function will wait until they
54
56
  * are released by other tasks.
55
57
  */
56
- withPermit<A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
58
+ withPermit<A, E, R>(this: Semaphore, self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
57
59
 
58
60
  /**
59
61
  * Runs an effect only if the specified number of permits are immediately
@@ -67,6 +69,7 @@ export interface Semaphore {
67
69
  * the result is `Option.none`.
68
70
  */
69
71
  withPermitsIfAvailable(
72
+ this: Semaphore,
70
73
  permits: number
71
74
  ): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>
72
75
 
@@ -75,18 +78,18 @@ export interface Semaphore {
75
78
  * available permits, suspending the task if they are not yet available.
76
79
  * Concurrent pending `take` calls are processed in a first-in, first-out manner.
77
80
  */
78
- take(permits: number): Effect.Effect<number>
81
+ take(this: Semaphore, permits: number): Effect.Effect<number>
79
82
 
80
83
  /**
81
84
  * Releases the specified number of permits and returns the resulting
82
85
  * available permits.
83
86
  */
84
- release(permits: number): Effect.Effect<number>
87
+ release(this: Semaphore, permits: number): Effect.Effect<number>
85
88
 
86
89
  /**
87
90
  * Releases all permits held by this semaphore and returns the resulting available permits.
88
91
  */
89
- releaseAll: Effect.Effect<number>
92
+ readonly releaseAll: Effect.Effect<number>
90
93
  }
91
94
 
92
95
  /**
@@ -126,7 +129,113 @@ export interface Semaphore {
126
129
  * @since 2.0.0
127
130
  * @category constructors
128
131
  */
129
- export const makeUnsafe: (permits: number) => Semaphore = internal.makeSemaphoreUnsafe
132
+ export const makeUnsafe = (permits: number): Semaphore => new SemaphoreImpl(permits)
133
+
134
+ class SemaphoreImpl implements Semaphore {
135
+ public waiters = new Set<() => void>()
136
+ public taken = 0
137
+ public permits: number
138
+
139
+ constructor(permits: number) {
140
+ this.permits = permits
141
+ }
142
+
143
+ get free() {
144
+ return this.permits - this.taken
145
+ }
146
+
147
+ take(n: number): Effect.Effect<number> {
148
+ const take: Effect.Effect<number> = internal.suspend(() => {
149
+ if (this.free < n) {
150
+ return internal.callback((resume) => {
151
+ if (this.free >= n) return resume(take)
152
+ const observer = () => {
153
+ if (this.free < n) return
154
+ this.waiters.delete(observer)
155
+ resume(take)
156
+ }
157
+ this.waiters.add(observer)
158
+ return internal.sync(() => {
159
+ this.waiters.delete(observer)
160
+ })
161
+ })
162
+ }
163
+ this.taken += n
164
+ return internal.succeed(n)
165
+ })
166
+ return take
167
+ }
168
+
169
+ updateTakenUnsafe(fiber: Fiber<any, any>, f: (n: number) => number): number {
170
+ this.taken = f(this.taken)
171
+ if (this.waiters.size > 0) {
172
+ fiber.currentDispatcher.scheduleTask(() => {
173
+ const iter = this.waiters.values()
174
+ let item = iter.next()
175
+ while (item.done === false && this.free > 0) {
176
+ item.value()
177
+ item = iter.next()
178
+ }
179
+ }, 0)
180
+ }
181
+ return this.free
182
+ }
183
+
184
+ updateTaken(f: (n: number) => number): Effect.Effect<number> {
185
+ return core.withFiber((fiber) => internal.succeed(this.updateTakenUnsafe(fiber, f)))
186
+ }
187
+
188
+ resize(permits: number) {
189
+ return core.withFiber((fiber) => {
190
+ this.permits = permits
191
+ if (this.free < 0) return internal.void
192
+ this.updateTakenUnsafe(fiber, (taken) => taken)
193
+ return internal.void
194
+ })
195
+ }
196
+
197
+ release(n: number): Effect.Effect<number> {
198
+ return this.updateTaken((taken) => taken - n)
199
+ }
200
+
201
+ get releaseAll(): Effect.Effect<number> {
202
+ return this.updateTaken((_) => 0)
203
+ }
204
+
205
+ withPermits(n: number) {
206
+ return <A, E, R>(self: Effect.Effect<A, E, R>) =>
207
+ internal.uninterruptibleMask((restore) =>
208
+ internal.flatMap(
209
+ restore(this.take(n)),
210
+ (permits) =>
211
+ internal.onExitPrimitive(
212
+ restore(self),
213
+ () => {
214
+ this.updateTakenUnsafe(internal.getCurrentFiber()!, (taken) => taken - permits)
215
+ return undefined
216
+ },
217
+ true
218
+ )
219
+ )
220
+ )
221
+ }
222
+
223
+ get withPermit(): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> {
224
+ return this.withPermits(1)
225
+ }
226
+
227
+ withPermitsIfAvailable(n: number) {
228
+ return <A, E, R>(self: Effect.Effect<A, E, R>) =>
229
+ internal.uninterruptibleMask((restore) => {
230
+ if (this.free < n) return internal.succeedNone
231
+ this.taken += n
232
+ return internal.onExitPrimitive(restore(internal.asSome(self)), () => {
233
+ this.updateTakenUnsafe(internal.getCurrentFiber()!, (taken) => taken - n)
234
+ return undefined
235
+ }, true)
236
+ })
237
+ }
238
+ }
130
239
 
131
240
  /**
132
241
  * Creates a new Semaphore.
@@ -161,196 +270,175 @@ export const makeUnsafe: (permits: number) => Semaphore = internal.makeSemaphore
161
270
  * @since 2.0.0
162
271
  * @category constructors
163
272
  */
164
- export const make: (permits: number) => Effect.Effect<Semaphore> = internal.makeSemaphore
165
-
166
- // -----------------------------------------------------------------------------
167
- // Partitioned
168
- // -----------------------------------------------------------------------------
273
+ export const make = (permits: number): Effect.Effect<Semaphore> => internal.sync(() => new SemaphoreImpl(permits))
169
274
 
170
275
  /**
171
- * @since 3.19.4
172
- * @category models
276
+ * Adjusts the number of permits available in the semaphore.
277
+ *
278
+ * @since 4.0.0
279
+ * @category combinators
173
280
  */
174
- export const PartitionedTypeId: PartitionedTypeId = "~effect/PartitionedSemaphore"
281
+ export const resize: {
282
+ /**
283
+ * Adjusts the number of permits available in the semaphore.
284
+ *
285
+ * @since 4.0.0
286
+ * @category combinators
287
+ */
288
+ (permits: number): (self: Semaphore) => Effect.Effect<void>
289
+ /**
290
+ * Adjusts the number of permits available in the semaphore.
291
+ *
292
+ * @since 4.0.0
293
+ * @category combinators
294
+ */
295
+ (self: Semaphore, permits: number): Effect.Effect<void>
296
+ } = dual(2, (self: Semaphore, permits: number) => self.resize(permits))
175
297
 
176
298
  /**
177
- * @since 3.19.4
178
- * @category models
299
+ * Runs an effect with the given number of permits and releases the permits when
300
+ * the effect completes.
301
+ *
302
+ * @since 4.0.0
303
+ * @category combinators
179
304
  */
180
- export type PartitionedTypeId = "~effect/PartitionedSemaphore"
305
+ export const withPermits: {
306
+ /**
307
+ * Runs an effect with the given number of permits and releases the permits when
308
+ * the effect completes.
309
+ *
310
+ * @since 4.0.0
311
+ * @category combinators
312
+ */
313
+ (self: Semaphore, permits: number): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
314
+ /**
315
+ * Runs an effect with the given number of permits and releases the permits when
316
+ * the effect completes.
317
+ *
318
+ * @since 4.0.0
319
+ * @category combinators
320
+ */
321
+ <A, E, R>(self: Semaphore, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
322
+ } = ((self: Semaphore, permits: number, effect?: Effect.Effect<any, any, any>) => {
323
+ const withPermits = self.withPermits(permits)
324
+ return effect ? withPermits(effect) : withPermits
325
+ }) as any
181
326
 
182
327
  /**
183
- * A `Partitioned` semaphore controls access to a shared permit pool while
184
- * tracking waiters by partition key.
185
- *
186
- * Waiting permits are distributed across partitions in round-robin order.
187
- *
188
- * **Previously Known As**
189
- *
190
- * This API replaces the following from Effect 3.x:
191
- *
192
- * - `PartitionedSemaphore.PartitionedSemaphore`
328
+ * Runs an effect with a single permit and releases the permit when the effect
329
+ * completes.
193
330
  *
194
- * @since 3.19.4
195
- * @category models
331
+ * @since 4.0.0
332
+ * @category combinators
196
333
  */
197
- export interface Partitioned<in K> {
198
- readonly [PartitionedTypeId]: PartitionedTypeId
199
- readonly withPermits: (
200
- key: K,
201
- permits: number
202
- ) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
203
- }
334
+ export const withPermit: {
335
+ /**
336
+ * Runs an effect with a single permit and releases the permit when the effect
337
+ * completes.
338
+ *
339
+ * @since 4.0.0
340
+ * @category combinators
341
+ */
342
+ (self: Semaphore): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
343
+ /**
344
+ * Runs an effect with a single permit and releases the permit when the effect
345
+ * completes.
346
+ *
347
+ * @since 4.0.0
348
+ * @category combinators
349
+ */
350
+ <A, E, R>(self: Semaphore, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
351
+ } = ((self: Semaphore, effect?: Effect.Effect<any, any, any>) => {
352
+ if (!effect) return self.withPermit
353
+ return self.withPermit(effect)
354
+ }) as any
204
355
 
205
356
  /**
206
- * Creates a `Partitioned` semaphore unsafely.
357
+ * Runs an effect only if the specified number of permits are immediately
358
+ * available.
207
359
  *
208
- * **Previously Known As**
209
- *
210
- * This API replaces the following from Effect 3.x:
211
- *
212
- * - `PartitionedSemaphore.makeUnsafe`
213
- *
214
- * @since 3.19.4
215
- * @category constructors
360
+ * @since 4.0.0
361
+ * @category combinators
216
362
  */
217
- export const makePartitionedUnsafe = <K = unknown>(options: {
218
- readonly permits: number
219
- }): Partitioned<K> => {
220
- const maxPermits = Math.max(0, options.permits)
221
-
222
- if (!Number.isFinite(maxPermits)) {
223
- return {
224
- [PartitionedTypeId]: PartitionedTypeId,
225
- withPermits: () => (effect) => effect
226
- }
227
- }
228
-
229
- let totalPermits = maxPermits
230
- let waitingPermits = 0
231
-
232
- type Waiter = {
233
- permits: number
234
- readonly resume: () => void
235
- }
236
- const partitions = MutableHashMap.empty<K, Set<Waiter>>()
237
-
238
- const take = (key: K, permits: number) =>
239
- Effect.callback<void>((resume) => {
240
- if (maxPermits < permits) {
241
- resume(Effect.never)
242
- return
243
- }
244
-
245
- if (totalPermits >= permits) {
246
- totalPermits -= permits
247
- resume(Effect.void)
248
- return
249
- }
250
-
251
- const needed = permits - totalPermits
252
- const taken = permits - needed
253
- if (totalPermits > 0) {
254
- totalPermits = 0
255
- }
256
- waitingPermits += needed
257
-
258
- const waiters = Option.getOrElse(
259
- MutableHashMap.get(partitions, key),
260
- () => {
261
- const set = new Set<Waiter>()
262
- MutableHashMap.set(partitions, key, set)
263
- return set
264
- }
265
- )
266
-
267
- const entry: Waiter = {
268
- permits: needed,
269
- resume: () => {
270
- cleanup()
271
- resume(Effect.void)
272
- }
273
- }
274
-
275
- const cleanup = () => {
276
- waiters.delete(entry)
277
- if (waiters.size === 0) {
278
- MutableHashMap.remove(partitions, key)
279
- }
280
- }
281
-
282
- waiters.add(entry)
283
-
284
- return Effect.sync(() => {
285
- cleanup()
286
- waitingPermits -= entry.permits
287
- if (taken > 0) {
288
- releaseUnsafe(taken)
289
- }
290
- })
291
- })
292
-
293
- let iterator = partitions[Symbol.iterator]()
294
-
295
- const releaseUnsafe = (permits: number): void => {
296
- while (permits > 0) {
297
- if (waitingPermits === 0) {
298
- totalPermits += permits
299
- return
300
- }
301
-
302
- let state = iterator.next()
303
- if (state.done) {
304
- iterator = partitions[Symbol.iterator]()
305
- state = iterator.next()
306
- if (state.done) {
307
- return
308
- }
309
- }
310
-
311
- const waiter = state.value[1].values().next().value
312
- if (waiter === undefined) {
313
- continue
314
- }
315
-
316
- waiter.permits -= 1
317
- waitingPermits -= 1
318
-
319
- if (waiter.permits === 0) {
320
- waiter.resume()
321
- }
322
-
323
- permits -= 1
324
- }
325
- }
326
-
327
- return {
328
- [PartitionedTypeId]: PartitionedTypeId,
329
- withPermits: (key, permits) => {
330
- const takePermits = take(key, permits)
331
- return (effect) =>
332
- Effect.uninterruptibleMask((restore) =>
333
- Effect.flatMap(
334
- restore(takePermits),
335
- () => Effect.ensuring(restore(effect), Effect.sync(() => releaseUnsafe(permits)))
336
- )
337
- )
338
- }
339
- }
340
- }
363
+ export const withPermitsIfAvailable: {
364
+ /**
365
+ * Runs an effect only if the specified number of permits are immediately
366
+ * available.
367
+ *
368
+ * @since 4.0.0
369
+ * @category combinators
370
+ */
371
+ (self: Semaphore, permits: number): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>
372
+ /**
373
+ * Runs an effect only if the specified number of permits are immediately
374
+ * available.
375
+ *
376
+ * @since 4.0.0
377
+ * @category combinators
378
+ */
379
+ <A, E, R>(self: Semaphore, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<Option.Option<A>, E, R>
380
+ } = ((self: Semaphore, permits: number, effect?: Effect.Effect<any, any, any>) => {
381
+ const withPermits = self.withPermitsIfAvailable(permits)
382
+ return effect ? withPermits(effect) : withPermits
383
+ }) as any
341
384
 
342
385
  /**
343
- * Creates a `Partitioned` semaphore.
386
+ * Acquires the specified number of permits and returns the resulting available
387
+ * permits, suspending the task if they are not yet available.
344
388
  *
345
- * **Previously Known As**
346
- *
347
- * This API replaces the following from Effect 3.x:
389
+ * @since 4.0.0
390
+ * @category combinators
391
+ */
392
+ export const take: {
393
+ /**
394
+ * Acquires the specified number of permits and returns the resulting available
395
+ * permits, suspending the task if they are not yet available.
396
+ *
397
+ * @since 4.0.0
398
+ * @category combinators
399
+ */
400
+ (permits: number): (self: Semaphore) => Effect.Effect<number>
401
+ /**
402
+ * Acquires the specified number of permits and returns the resulting available
403
+ * permits, suspending the task if they are not yet available.
404
+ *
405
+ * @since 4.0.0
406
+ * @category combinators
407
+ */
408
+ (self: Semaphore, permits: number): Effect.Effect<number>
409
+ } = dual(2, (self: Semaphore, permits: number) => self.take(permits))
410
+
411
+ /**
412
+ * Releases the specified number of permits and returns the resulting available
413
+ * permits.
348
414
  *
349
- * - `PartitionedSemaphore.make`
415
+ * @since 4.0.0
416
+ * @category combinators
417
+ */
418
+ export const release: {
419
+ /**
420
+ * Releases the specified number of permits and returns the resulting available
421
+ * permits.
422
+ *
423
+ * @since 4.0.0
424
+ * @category combinators
425
+ */
426
+ (permits: number): (self: Semaphore) => Effect.Effect<number>
427
+ /**
428
+ * Releases the specified number of permits and returns the resulting available
429
+ * permits.
430
+ *
431
+ * @since 4.0.0
432
+ * @category combinators
433
+ */
434
+ (self: Semaphore, permits: number): Effect.Effect<number>
435
+ } = dual(2, (self: Semaphore, permits: number) => self.release(permits))
436
+
437
+ /**
438
+ * Releases all permits held by this semaphore and returns the resulting
439
+ * available permits.
350
440
  *
351
- * @since 3.19.4
352
- * @category constructors
441
+ * @since 4.0.0
442
+ * @category combinators
353
443
  */
354
- export const makePartitioned = <K = unknown>(options: {
355
- readonly permits: number
356
- }): Effect.Effect<Partitioned<K>> => Effect.sync(() => makePartitionedUnsafe<K>(options))
444
+ export const releaseAll = (self: Semaphore): Effect.Effect<number> => self.releaseAll