effect 4.1.5 → 4.1.7

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 (441) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/dist/Channel.d.ts +104 -7
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +73 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Codegen.d.ts +7 -2
  7. package/dist/Codegen.d.ts.map +1 -1
  8. package/dist/Codegen.js +7 -2
  9. package/dist/Codegen.js.map +1 -1
  10. package/dist/Config.d.ts +1 -1
  11. package/dist/Config.d.ts.map +1 -1
  12. package/dist/Config.js +5 -3
  13. package/dist/Config.js.map +1 -1
  14. package/dist/Context.d.ts.map +1 -1
  15. package/dist/Context.js +79 -31
  16. package/dist/Context.js.map +1 -1
  17. package/dist/Cron.d.ts.map +1 -1
  18. package/dist/Cron.js +10 -9
  19. package/dist/Cron.js.map +1 -1
  20. package/dist/Effect.d.ts +139 -18
  21. package/dist/Effect.d.ts.map +1 -1
  22. package/dist/Effect.js +10 -2
  23. package/dist/Effect.js.map +1 -1
  24. package/dist/Equal.d.ts +4 -4
  25. package/dist/Equal.d.ts.map +1 -1
  26. package/dist/Equal.js +78 -66
  27. package/dist/Equal.js.map +1 -1
  28. package/dist/Formatter.js +4 -4
  29. package/dist/Formatter.js.map +1 -1
  30. package/dist/Hash.d.ts.map +1 -1
  31. package/dist/Hash.js +34 -41
  32. package/dist/Hash.js.map +1 -1
  33. package/dist/LayerRef.d.ts +1 -1
  34. package/dist/LayerRef.d.ts.map +1 -1
  35. package/dist/LayerRef.js +3 -3
  36. package/dist/LayerRef.js.map +1 -1
  37. package/dist/Logger.d.ts +37 -13
  38. package/dist/Logger.d.ts.map +1 -1
  39. package/dist/Logger.js +39 -10
  40. package/dist/Logger.js.map +1 -1
  41. package/dist/Match.d.ts +23 -23
  42. package/dist/Match.d.ts.map +1 -1
  43. package/dist/Match.js.map +1 -1
  44. package/dist/Metric.d.ts.map +1 -1
  45. package/dist/Metric.js +3 -4
  46. package/dist/Metric.js.map +1 -1
  47. package/dist/Order.js +1 -1
  48. package/dist/Order.js.map +1 -1
  49. package/dist/Pool.d.ts.map +1 -1
  50. package/dist/Pool.js +49 -21
  51. package/dist/Pool.js.map +1 -1
  52. package/dist/Predicate.d.ts.map +1 -1
  53. package/dist/Predicate.js +2 -1
  54. package/dist/Predicate.js.map +1 -1
  55. package/dist/Scheduler.d.ts.map +1 -1
  56. package/dist/Scheduler.js +15 -9
  57. package/dist/Scheduler.js.map +1 -1
  58. package/dist/Schema.d.ts +41 -0
  59. package/dist/Schema.d.ts.map +1 -1
  60. package/dist/Schema.js +51 -390
  61. package/dist/Schema.js.map +1 -1
  62. package/dist/SchemaAST.d.ts +2 -2
  63. package/dist/SchemaAST.d.ts.map +1 -1
  64. package/dist/SchemaAST.js +199 -98
  65. package/dist/SchemaAST.js.map +1 -1
  66. package/dist/SchemaParser.d.ts.map +1 -1
  67. package/dist/SchemaParser.js +29 -50
  68. package/dist/SchemaParser.js.map +1 -1
  69. package/dist/ScopedCache.d.ts.map +1 -1
  70. package/dist/ScopedCache.js +6 -4
  71. package/dist/ScopedCache.js.map +1 -1
  72. package/dist/Stream.d.ts +128 -5
  73. package/dist/Stream.d.ts.map +1 -1
  74. package/dist/Stream.js +124 -29
  75. package/dist/Stream.js.map +1 -1
  76. package/dist/String.js +1 -1
  77. package/dist/String.js.map +1 -1
  78. package/dist/Tracer.d.ts +10 -0
  79. package/dist/Tracer.d.ts.map +1 -1
  80. package/dist/Tracer.js +3 -4
  81. package/dist/Tracer.js.map +1 -1
  82. package/dist/ai/McpClient.d.ts +68 -4
  83. package/dist/ai/McpClient.d.ts.map +1 -1
  84. package/dist/ai/McpClient.js +100 -17
  85. package/dist/ai/McpClient.js.map +1 -1
  86. package/dist/ai/McpClientError.d.ts +46 -4
  87. package/dist/ai/McpClientError.d.ts.map +1 -1
  88. package/dist/ai/McpClientError.js +38 -3
  89. package/dist/ai/McpClientError.js.map +1 -1
  90. package/dist/ai/McpServer.d.ts +158 -7
  91. package/dist/ai/McpServer.d.ts.map +1 -1
  92. package/dist/ai/McpServer.js +103 -49
  93. package/dist/ai/McpServer.js.map +1 -1
  94. package/dist/ai/Prompt.d.ts +3 -1
  95. package/dist/ai/Prompt.d.ts.map +1 -1
  96. package/dist/ai/Prompt.js +17 -3
  97. package/dist/ai/Prompt.js.map +1 -1
  98. package/dist/ai/Skill.d.ts +172 -0
  99. package/dist/ai/Skill.d.ts.map +1 -0
  100. package/dist/ai/Skill.js +209 -0
  101. package/dist/ai/Skill.js.map +1 -0
  102. package/dist/ai/index.d.ts +5 -0
  103. package/dist/ai/index.d.ts.map +1 -1
  104. package/dist/ai/index.js +5 -0
  105. package/dist/ai/index.js.map +1 -1
  106. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +9 -7
  107. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  108. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +12 -11
  109. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  110. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +18 -17
  111. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  112. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +19 -18
  113. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  114. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +1 -1
  115. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  116. package/dist/ai/internal/mcpProtocol.js +11 -0
  117. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  118. package/dist/ai/internal/mcpRuntime.js +29 -17
  119. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  120. package/dist/ai/internal/mcpSchema/v2024_11_05.js +2 -1
  121. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  122. package/dist/ai/internal/mcpSchema/v2025_03_26.js +1 -8
  123. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  124. package/dist/ai/internal/mcpSchema/v2025_06_18.js +5 -9
  125. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  126. package/dist/ai/internal/mcpSchema/v2025_11_25.js +1 -8
  127. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  128. package/dist/ai/internal/mcpSchema/v2026_07_28.js +4 -3
  129. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  130. package/dist/cluster/ClusterCron.d.ts +5 -20
  131. package/dist/cluster/ClusterCron.d.ts.map +1 -1
  132. package/dist/cluster/ClusterCron.js +16 -4
  133. package/dist/cluster/ClusterCron.js.map +1 -1
  134. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  135. package/dist/cluster/ClusterWorkflowEngine.js +155 -83
  136. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  137. package/dist/cluster/MessageStorage.d.ts +56 -0
  138. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  139. package/dist/cluster/MessageStorage.js +18 -2
  140. package/dist/cluster/MessageStorage.js.map +1 -1
  141. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  142. package/dist/cluster/SqlMessageStorage.js +48 -23
  143. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  144. package/dist/cluster/internal/entityActivation.js +2 -0
  145. package/dist/cluster/internal/entityActivation.js.map +1 -1
  146. package/dist/cluster/internal/entityManager.js +8 -5
  147. package/dist/cluster/internal/entityManager.js.map +1 -1
  148. package/dist/encoding/Base64.js +5 -1
  149. package/dist/encoding/Base64.js.map +1 -1
  150. package/dist/encoding/Base64Url.d.ts.map +1 -1
  151. package/dist/encoding/Base64Url.js +6 -1
  152. package/dist/encoding/Base64Url.js.map +1 -1
  153. package/dist/encoding/Hex.js +7 -5
  154. package/dist/encoding/Hex.js.map +1 -1
  155. package/dist/encoding/Xml.d.ts +38 -9
  156. package/dist/encoding/Xml.d.ts.map +1 -1
  157. package/dist/encoding/Xml.js +63 -31
  158. package/dist/encoding/Xml.js.map +1 -1
  159. package/dist/http/FetchHttpClient.d.ts +2 -1
  160. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  161. package/dist/http/FetchHttpClient.js +14 -10
  162. package/dist/http/FetchHttpClient.js.map +1 -1
  163. package/dist/http/Headers.d.ts +201 -3
  164. package/dist/http/Headers.d.ts.map +1 -1
  165. package/dist/http/Headers.js +205 -3
  166. package/dist/http/Headers.js.map +1 -1
  167. package/dist/http/HttpClient.d.ts.map +1 -1
  168. package/dist/http/HttpClient.js +11 -7
  169. package/dist/http/HttpClient.js.map +1 -1
  170. package/dist/http/HttpClientError.d.ts +1 -0
  171. package/dist/http/HttpClientError.d.ts.map +1 -1
  172. package/dist/http/HttpClientError.js +32 -9
  173. package/dist/http/HttpClientError.js.map +1 -1
  174. package/dist/http/HttpClientRequest.d.ts +46 -0
  175. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  176. package/dist/http/HttpClientRequest.js +15 -0
  177. package/dist/http/HttpClientRequest.js.map +1 -1
  178. package/dist/http/HttpClientResponse.d.ts +132 -0
  179. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  180. package/dist/http/HttpClientResponse.js +83 -0
  181. package/dist/http/HttpClientResponse.js.map +1 -1
  182. package/dist/http/HttpEffect.d.ts.map +1 -1
  183. package/dist/http/HttpEffect.js +31 -2
  184. package/dist/http/HttpEffect.js.map +1 -1
  185. package/dist/http/HttpMiddleware.js +1 -1
  186. package/dist/http/HttpMiddleware.js.map +1 -1
  187. package/dist/http/HttpServerError.d.ts +1 -1
  188. package/dist/http/HttpServerError.js +1 -1
  189. package/dist/http/HttpServerResponse.d.ts +118 -0
  190. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  191. package/dist/http/HttpServerResponse.js +43 -0
  192. package/dist/http/HttpServerResponse.js.map +1 -1
  193. package/dist/http/Multipart.d.ts.map +1 -1
  194. package/dist/http/Multipart.js +0 -5
  195. package/dist/http/Multipart.js.map +1 -1
  196. package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
  197. package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
  198. package/dist/http/MultipartParser/internal/contentType.js +1 -1
  199. package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
  200. package/dist/http/internal/clientPath.d.ts +2 -0
  201. package/dist/http/internal/clientPath.d.ts.map +1 -0
  202. package/dist/http/internal/clientPath.js +24 -0
  203. package/dist/http/internal/clientPath.js.map +1 -0
  204. package/dist/http/internal/redactedPath.js +2 -0
  205. package/dist/http/internal/redactedPath.js.map +1 -1
  206. package/dist/http/internal/tracing.js +5 -3
  207. package/dist/http/internal/tracing.js.map +1 -1
  208. package/dist/http-api/HttpApi.d.ts +2 -2
  209. package/dist/http-api/HttpApi.d.ts.map +1 -1
  210. package/dist/http-api/HttpApi.js +30 -7
  211. package/dist/http-api/HttpApi.js.map +1 -1
  212. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  213. package/dist/http-api/HttpApiBuilder.js +5 -2
  214. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  215. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  216. package/dist/http-api/HttpApiClient.js +23 -6
  217. package/dist/http-api/HttpApiClient.js.map +1 -1
  218. package/dist/http-api/internal/redactedKeys.d.ts +2 -0
  219. package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
  220. package/dist/http-api/internal/redactedKeys.js +37 -0
  221. package/dist/http-api/internal/redactedKeys.js.map +1 -0
  222. package/dist/internal/base64.js +34 -2
  223. package/dist/internal/base64.js.map +1 -1
  224. package/dist/internal/core.js +60 -43
  225. package/dist/internal/core.js.map +1 -1
  226. package/dist/internal/dateTime.js +35 -17
  227. package/dist/internal/dateTime.js.map +1 -1
  228. package/dist/internal/effect.js +60 -52
  229. package/dist/internal/effect.js.map +1 -1
  230. package/dist/internal/equal.js +44 -13
  231. package/dist/internal/equal.js.map +1 -1
  232. package/dist/internal/fiberCachedKeys.d.ts +2 -0
  233. package/dist/internal/fiberCachedKeys.d.ts.map +1 -0
  234. package/dist/internal/fiberCachedKeys.js +48 -0
  235. package/dist/internal/fiberCachedKeys.js.map +1 -0
  236. package/dist/internal/hashMap.js +1 -1
  237. package/dist/internal/hashMap.js.map +1 -1
  238. package/dist/internal/matcher.js +17 -17
  239. package/dist/internal/matcher.js.map +1 -1
  240. package/dist/internal/predicate.d.ts +2 -0
  241. package/dist/internal/predicate.d.ts.map +1 -0
  242. package/dist/internal/predicate.js +10 -0
  243. package/dist/internal/predicate.js.map +1 -0
  244. package/dist/internal/references.js +8 -11
  245. package/dist/internal/references.js.map +1 -1
  246. package/dist/internal/schema/schemaCodegen.js +3 -2
  247. package/dist/internal/schema/schemaCodegen.js.map +1 -1
  248. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
  249. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
  250. package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
  251. package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
  252. package/dist/internal/schema/toEquivalence.js +3 -4
  253. package/dist/internal/schema/toEquivalence.js.map +1 -1
  254. package/dist/internal/version.js +1 -1
  255. package/dist/jose/JoseError.d.ts +51 -1
  256. package/dist/jose/JoseError.d.ts.map +1 -1
  257. package/dist/jose/JoseError.js +25 -18
  258. package/dist/jose/JoseError.js.map +1 -1
  259. package/dist/jose/internal/compact.js +10 -5
  260. package/dist/jose/internal/compact.js.map +1 -1
  261. package/dist/observability/Otlp.d.ts +19 -0
  262. package/dist/observability/Otlp.d.ts.map +1 -1
  263. package/dist/observability/Otlp.js +10 -0
  264. package/dist/observability/Otlp.js.map +1 -1
  265. package/dist/observability/OtlpExporter.d.ts +49 -13
  266. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  267. package/dist/observability/OtlpExporter.js +135 -54
  268. package/dist/observability/OtlpExporter.js.map +1 -1
  269. package/dist/observability/OtlpLogger.d.ts +14 -0
  270. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  271. package/dist/observability/OtlpLogger.js +10 -2
  272. package/dist/observability/OtlpLogger.js.map +1 -1
  273. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  274. package/dist/observability/OtlpMetrics.js +2 -0
  275. package/dist/observability/OtlpMetrics.js.map +1 -1
  276. package/dist/observability/OtlpTracer.d.ts +14 -0
  277. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  278. package/dist/observability/OtlpTracer.js +10 -2
  279. package/dist/observability/OtlpTracer.js.map +1 -1
  280. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  281. package/dist/persistence/KeyValueStore.js +6 -4
  282. package/dist/persistence/KeyValueStore.js.map +1 -1
  283. package/dist/reactivity/Atom.d.ts.map +1 -1
  284. package/dist/reactivity/Atom.js +10 -9
  285. package/dist/reactivity/Atom.js.map +1 -1
  286. package/dist/rpc/RpcClient.d.ts.map +1 -1
  287. package/dist/rpc/RpcClient.js +32 -1
  288. package/dist/rpc/RpcClient.js.map +1 -1
  289. package/dist/rpc/RpcGroup.d.ts +1 -1
  290. package/dist/rpc/RpcGroup.d.ts.map +1 -1
  291. package/dist/rpc/RpcGroup.js +4 -0
  292. package/dist/rpc/RpcGroup.js.map +1 -1
  293. package/dist/sql/Migrator.d.ts.map +1 -1
  294. package/dist/sql/Migrator.js +2 -5
  295. package/dist/sql/Migrator.js.map +1 -1
  296. package/dist/sql/SqlClient.d.ts.map +1 -1
  297. package/dist/sql/SqlClient.js +5 -1
  298. package/dist/sql/SqlClient.js.map +1 -1
  299. package/dist/sql/Statement.d.ts +23 -0
  300. package/dist/sql/Statement.d.ts.map +1 -1
  301. package/dist/sql/Statement.js +30 -5
  302. package/dist/sql/Statement.js.map +1 -1
  303. package/dist/workers/Worker.d.ts +21 -0
  304. package/dist/workers/Worker.d.ts.map +1 -1
  305. package/dist/workers/Worker.js +23 -0
  306. package/dist/workers/Worker.js.map +1 -1
  307. package/dist/workflow/Activity.d.ts +18 -0
  308. package/dist/workflow/Activity.d.ts.map +1 -1
  309. package/dist/workflow/Activity.js +13 -4
  310. package/dist/workflow/Activity.js.map +1 -1
  311. package/dist/workflow/Workflow.d.ts +10 -9
  312. package/dist/workflow/Workflow.d.ts.map +1 -1
  313. package/dist/workflow/Workflow.js +33 -22
  314. package/dist/workflow/Workflow.js.map +1 -1
  315. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  316. package/dist/workflow/WorkflowEngine.js +26 -12
  317. package/dist/workflow/WorkflowEngine.js.map +1 -1
  318. package/dist/workflow/internal/retry.d.ts +2 -0
  319. package/dist/workflow/internal/retry.d.ts.map +1 -0
  320. package/dist/workflow/internal/retry.js +11 -0
  321. package/dist/workflow/internal/retry.js.map +1 -0
  322. package/dist/workflow/internal/scope.d.ts +2 -0
  323. package/dist/workflow/internal/scope.d.ts.map +1 -0
  324. package/dist/workflow/internal/scope.js +26 -0
  325. package/dist/workflow/internal/scope.js.map +1 -0
  326. package/package.json +3 -3
  327. package/src/Channel.ts +105 -8
  328. package/src/Codegen.ts +7 -2
  329. package/src/Config.ts +6 -3
  330. package/src/Context.ts +108 -50
  331. package/src/Cron.ts +11 -10
  332. package/src/Effect.ts +224 -48
  333. package/src/Equal.ts +93 -80
  334. package/src/Formatter.ts +4 -4
  335. package/src/Hash.ts +49 -48
  336. package/src/LayerRef.ts +6 -4
  337. package/src/Logger.ts +68 -25
  338. package/src/Match.ts +78 -50
  339. package/src/Metric.ts +4 -4
  340. package/src/Order.ts +1 -1
  341. package/src/Pool.ts +62 -33
  342. package/src/Predicate.ts +2 -5
  343. package/src/Scheduler.ts +27 -10
  344. package/src/Schema.ts +79 -296
  345. package/src/SchemaAST.ts +231 -157
  346. package/src/SchemaParser.ts +40 -57
  347. package/src/ScopedCache.ts +6 -4
  348. package/src/Stream.ts +167 -33
  349. package/src/String.ts +1 -1
  350. package/src/Tracer.ts +11 -2
  351. package/src/ai/McpClient.ts +157 -15
  352. package/src/ai/McpClientError.ts +55 -4
  353. package/src/ai/McpServer.ts +318 -91
  354. package/src/ai/Prompt.ts +20 -3
  355. package/src/ai/Skill.ts +236 -0
  356. package/src/ai/index.ts +6 -0
  357. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -13
  358. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +13 -15
  359. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +21 -23
  360. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +22 -24
  361. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +1 -1
  362. package/src/ai/internal/mcpProtocol.ts +15 -0
  363. package/src/ai/internal/mcpRuntime.ts +36 -13
  364. package/src/ai/internal/mcpSchema/v2024_11_05.ts +2 -1
  365. package/src/ai/internal/mcpSchema/v2025_03_26.ts +1 -9
  366. package/src/ai/internal/mcpSchema/v2025_06_18.ts +3 -10
  367. package/src/ai/internal/mcpSchema/v2025_11_25.ts +1 -9
  368. package/src/ai/internal/mcpSchema/v2026_07_28.ts +6 -8
  369. package/src/cluster/ClusterCron.ts +31 -20
  370. package/src/cluster/ClusterWorkflowEngine.ts +172 -96
  371. package/src/cluster/MessageStorage.ts +51 -2
  372. package/src/cluster/SqlMessageStorage.ts +88 -36
  373. package/src/cluster/internal/entityActivation.ts +6 -0
  374. package/src/cluster/internal/entityManager.ts +8 -4
  375. package/src/encoding/Base64.ts +5 -1
  376. package/src/encoding/Base64Url.ts +6 -1
  377. package/src/encoding/Hex.ts +5 -5
  378. package/src/encoding/Xml.ts +96 -26
  379. package/src/http/FetchHttpClient.ts +8 -5
  380. package/src/http/Headers.ts +309 -3
  381. package/src/http/HttpClient.ts +19 -7
  382. package/src/http/HttpClientError.ts +42 -9
  383. package/src/http/HttpClientRequest.ts +51 -0
  384. package/src/http/HttpClientResponse.ts +156 -0
  385. package/src/http/HttpEffect.ts +23 -3
  386. package/src/http/HttpMiddleware.ts +1 -1
  387. package/src/http/HttpServerError.ts +1 -1
  388. package/src/http/HttpServerResponse.ts +126 -0
  389. package/src/http/Multipart.ts +0 -5
  390. package/src/http/MultipartParser/internal/contentType.ts +1 -1
  391. package/src/http/internal/clientPath.ts +39 -0
  392. package/src/http/internal/redactedPath.ts +4 -0
  393. package/src/http/internal/tracing.ts +6 -3
  394. package/src/http-api/HttpApi.ts +29 -8
  395. package/src/http-api/HttpApiBuilder.ts +7 -2
  396. package/src/http-api/HttpApiClient.ts +30 -7
  397. package/src/http-api/internal/redactedKeys.ts +40 -0
  398. package/src/internal/base64.ts +57 -2
  399. package/src/internal/core.ts +80 -44
  400. package/src/internal/dateTime.ts +43 -24
  401. package/src/internal/effect.ts +115 -157
  402. package/src/internal/equal.ts +73 -17
  403. package/src/internal/fiberCachedKeys.ts +81 -0
  404. package/src/internal/hashMap.ts +1 -1
  405. package/src/internal/matcher.ts +34 -113
  406. package/src/internal/predicate.ts +10 -0
  407. package/src/internal/references.ts +21 -14
  408. package/src/internal/schema/schemaCodegen.ts +5 -4
  409. package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
  410. package/src/internal/schema/toEquivalence.ts +3 -5
  411. package/src/internal/version.ts +1 -1
  412. package/src/jose/JoseError.ts +34 -0
  413. package/src/jose/internal/compact.ts +14 -5
  414. package/src/observability/Otlp.ts +29 -0
  415. package/src/observability/OtlpExporter.ts +206 -75
  416. package/src/observability/OtlpLogger.ts +24 -2
  417. package/src/observability/OtlpMetrics.ts +2 -0
  418. package/src/observability/OtlpTracer.ts +24 -3
  419. package/src/persistence/KeyValueStore.ts +17 -14
  420. package/src/reactivity/Atom.ts +12 -18
  421. package/src/rpc/RpcClient.ts +26 -1
  422. package/src/rpc/RpcGroup.ts +4 -1
  423. package/src/sql/Migrator.ts +2 -11
  424. package/src/sql/SqlClient.ts +14 -8
  425. package/src/sql/Statement.ts +48 -12
  426. package/src/workers/Worker.ts +25 -0
  427. package/src/workflow/Activity.ts +28 -4
  428. package/src/workflow/Workflow.ts +68 -44
  429. package/src/workflow/WorkflowEngine.ts +38 -15
  430. package/src/workflow/internal/retry.ts +12 -0
  431. package/src/workflow/internal/scope.ts +36 -0
  432. package/dist/internal/hash.d.ts +0 -2
  433. package/dist/internal/hash.d.ts.map +0 -1
  434. package/dist/internal/hash.js +0 -11
  435. package/dist/internal/hash.js.map +0 -1
  436. package/dist/internal/metric.d.ts +0 -2
  437. package/dist/internal/metric.d.ts.map +0 -1
  438. package/dist/internal/metric.js +0 -3
  439. package/dist/internal/metric.js.map +0 -1
  440. package/src/internal/hash.ts +0 -11
  441. package/src/internal/metric.ts +0 -2
@@ -44,15 +44,13 @@ import * as SchemaIssue from "./SchemaIssue.ts"
44
44
  */
45
45
  export function makeEffect<S extends Schema.Constraint>(schema: S) {
46
46
  const ast = schema.ast
47
- let parser: ReturnType<typeof runWithCompiler<S["Type"], never>>
48
- return (input: S["~type.make.in"], options?: Schema.MakeOptions): Effect.Effect<S["Type"], SchemaIssue.Issue> => {
49
- return (parser ??= runWithCompiler<S["Type"], never>(constructorCompiler, SchemaAST.toType(ast)))(
47
+ let entry: CompilerRegistry.Entry | undefined
48
+ return (input: S["~type.make.in"], options?: Schema.MakeOptions): Effect.Effect<S["Type"], SchemaIssue.Issue> =>
49
+ constructEffect<S["Type"]>(
50
+ entry ??= CompilerRegistry.resolve(SchemaAST.toType(ast)),
50
51
  input,
51
- options?.disableChecks
52
- ? options?.parseOptions ? { ...options.parseOptions, disableChecks: true } : { disableChecks: true }
53
- : options?.parseOptions
52
+ constructorParseOptions(options)
54
53
  )
55
- }
56
54
  }
57
55
 
58
56
  /**
@@ -76,14 +74,8 @@ export function makeEffect<S extends Schema.Constraint>(schema: S) {
76
74
  */
77
75
  export function makeOption<S extends Schema.Constraint>(schema: S) {
78
76
  const parser = makeEffect(schema)
79
- return (input: S["~type.make.in"], options?: Schema.MakeOptions): Option.Option<S["Type"]> => {
80
- const exit = Effect.runSyncExit(parser(input, options))
81
- if (Exit.isSuccess(exit)) {
82
- return Option.some(exit.value)
83
- }
84
- InternalSchemaCause.getSchemaIssueOrThrow(exit.cause, "Option adapter can only return none for schema issues")
85
- return Option.none()
86
- }
77
+ return (input: S["~type.make.in"], options?: Schema.MakeOptions): Option.Option<S["Type"]> =>
78
+ exitToOption(Effect.runSyncExit(parser(input, options)))
87
79
  }
88
80
 
89
81
  /**
@@ -275,9 +267,7 @@ export function decodeUnknownEffect<S extends Schema.Constraint>(
275
267
  options?: SchemaAST.ParseOptions
276
268
  ) => Effect.Effect<S["Type"], SchemaIssue.Issue, S["DecodingServices"]> {
277
269
  const parser = run<S["Type"], S["DecodingServices"]>(schema.ast)
278
- return options === undefined
279
- ? parser
280
- : (input, overrideOptions) => parser(input, mergeParseOptions(options, overrideOptions))
270
+ return withParseOptions(parser, options)
281
271
  }
282
272
 
283
273
  /**
@@ -638,9 +628,7 @@ export function encodeUnknownEffect<S extends Schema.Constraint>(
638
628
  options?: SchemaAST.ParseOptions
639
629
  ) => Effect.Effect<S["Encoded"], SchemaIssue.Issue, S["EncodingServices"]> {
640
630
  const parser = run<S["Encoded"], S["EncodingServices"]>(SchemaAST.flip(schema.ast))
641
- return options === undefined
642
- ? parser
643
- : (input, overrideOptions) => parser(input, mergeParseOptions(options, overrideOptions))
631
+ return withParseOptions(parser, options)
644
632
  }
645
633
 
646
634
  /**
@@ -965,10 +953,15 @@ export const encodeSync: <S extends Schema.ConstraintEncoder<unknown>>(
965
953
  options?: SchemaAST.ParseOptions
966
954
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"] = encodeUnknownSync
967
955
 
968
- const mergeParseOptions = (
969
- options: SchemaAST.ParseOptions,
970
- overrideOptions: SchemaAST.ParseOptions | undefined
971
- ): SchemaAST.ParseOptions => overrideOptions ? { ...options, ...overrideOptions } : options
956
+ function withParseOptions<T>(
957
+ parse: (input: unknown, options?: SchemaAST.ParseOptions) => T,
958
+ options?: SchemaAST.ParseOptions
959
+ ) {
960
+ return options === undefined ?
961
+ parse :
962
+ (input: unknown, overrides?: SchemaAST.ParseOptions) =>
963
+ parse(input, overrides ? { ...options, ...overrides } : options)
964
+ }
972
965
 
973
966
  const getValue = (value: unknown): Effect.Effect<any, SchemaIssue.Issue> => {
974
967
  if (value === InternalParser.missing) {
@@ -1001,20 +994,7 @@ function parserResult<T, R>(
1001
994
  function runWithCompiler<T, R>(compiler: Compiler, ast: SchemaAST.AST) {
1002
995
  let parser: Parser
1003
996
  return (input: unknown, options?: SchemaAST.ParseOptions): Effect.Effect<T, SchemaIssue.Issue, R> => {
1004
- const result = (parser ??= compiler(ast))(
1005
- input,
1006
- options ?? SchemaAST.defaultParseOptions
1007
- )
1008
- if (InternalParser.isSameExit(result)) {
1009
- return Effect.succeed(input) as Effect.Effect<T, SchemaIssue.Issue, R>
1010
- }
1011
- if (!effectIsExit(result)) {
1012
- return Effect.flatMapEager(result, getValue)
1013
- }
1014
- return (result as InternalParser.Success<unknown, SchemaIssue.Issue>)[InternalParser.args] ===
1015
- InternalParser.missing
1016
- ? getValue(InternalParser.missing)
1017
- : result as Effect.Effect<T, SchemaIssue.Issue, R>
997
+ return parserResult<T, R>((parser ??= compiler(ast))(input, options ?? SchemaAST.defaultParseOptions), input)
1018
998
  }
1019
999
  }
1020
1000
 
@@ -1055,6 +1035,12 @@ export function asOption<T, E, R>(
1055
1035
  }
1056
1036
  }
1057
1037
 
1038
+ function exitToOption<T>(exit: Exit.Exit<T, SchemaIssue.Issue>): Option.Option<T> {
1039
+ if (Exit.isSuccess(exit)) return Option.some(exit.value)
1040
+ InternalSchemaCause.getSchemaIssueOrThrow(exit.cause, "Option adapter can only return none for schema issues")
1041
+ return Option.none()
1042
+ }
1043
+
1058
1044
  function asResult<T, E, R>(
1059
1045
  parser: (input: E, options?: SchemaAST.ParseOptions) => Effect.Effect<T, SchemaIssue.Issue, R>
1060
1046
  ): (input: E, options?: SchemaAST.ParseOptions) => Result.Result<T, SchemaIssue.Issue> {
@@ -1102,9 +1088,7 @@ function makeSyncEntry<T>(
1102
1088
  if (output !== CompilerRegistry.invalid) return output as T
1103
1089
  return (detailed ??= makeDetailedSync<T>(entry))(input, parseOptions)
1104
1090
  }
1105
- return options === undefined
1106
- ? run
1107
- : (input, overrideOptions) => run(input, mergeParseOptions(options, overrideOptions))
1091
+ return withParseOptions(run, options)
1108
1092
  }
1109
1093
 
1110
1094
  function makeDetailedSync<T>(
@@ -1116,15 +1100,7 @@ function makeDetailedSync<T>(
1116
1100
  function asSync<T, E>(
1117
1101
  parser: (input: E, options?: SchemaAST.ParseOptions) => Effect.Effect<T, SchemaIssue.Issue>
1118
1102
  ): (input: E, options?: SchemaAST.ParseOptions) => T {
1119
- const parserExit = asExit(parser)
1120
- return (input: E, options?: SchemaAST.ParseOptions) => {
1121
- const exit = parserExit(input, options)
1122
- if (Exit.isSuccess(exit)) {
1123
- return exit.value
1124
- }
1125
- const issue = InternalSchemaCause.getSchemaIssueOrThrow(exit.cause, "Sync adapter can only throw schema issues")
1126
- throw new Error("Schema validation failed", { cause: issue })
1127
- }
1103
+ return (input, options) => runSync(parser(input, options), "Sync adapter can only throw schema issues")
1128
1104
  }
1129
1105
 
1130
1106
  function runSync<T>(effect: Effect.Effect<T, SchemaIssue.Issue>, message: string): T {
@@ -1149,11 +1125,19 @@ function makeConstructorSync<T, E>(
1149
1125
  return (input, options) => constructSync(entry ??= CompilerRegistry.resolve(ast), input, options)
1150
1126
  }
1151
1127
 
1152
- function constructSync<T>(entry: CompilerRegistry.Entry, input: unknown, options: Schema.MakeOptions | undefined): T {
1153
- const parseOptions = options?.disableChecks
1154
- ? options.parseOptions ? { ...options.parseOptions, disableChecks: true } : { disableChecks: true }
1128
+ function constructorParseOptions(options: Schema.MakeOptions | undefined): SchemaAST.ParseOptions {
1129
+ return options?.disableChecks
1130
+ ? { ...options.parseOptions, disableChecks: true }
1155
1131
  : options?.parseOptions ?? SchemaAST.defaultParseOptions
1156
- const make = entry.make
1132
+ }
1133
+
1134
+ function constructEffect<T>(entry: CompilerRegistry.Entry, input: unknown, options: SchemaAST.ParseOptions) {
1135
+ return parserResult<T, never>(entry.makeEffect(input, options), input)
1136
+ }
1137
+
1138
+ function constructSync<T>(entry: CompilerRegistry.Entry, input: unknown, options: Schema.MakeOptions | undefined): T {
1139
+ const parseOptions = constructorParseOptions(options)
1140
+ const make = CompilerRegistry.compilerAdaptersEnabled ? entry.make : undefined
1157
1141
  if (make !== undefined && input !== InternalParser.missing) {
1158
1142
  let output: unknown
1159
1143
  try {
@@ -1163,7 +1147,7 @@ function constructSync<T>(entry: CompilerRegistry.Entry, input: unknown, options
1163
1147
  }
1164
1148
  if (output !== CompilerRegistry.invalid && output !== InternalParser.missing) return output as T
1165
1149
  }
1166
- return runSync(parserResult<T, never>(entry.makeEffect(input, parseOptions), input), constructorDefectMessage)
1150
+ return runSync(constructEffect<T>(entry, input, parseOptions), constructorDefectMessage)
1167
1151
  }
1168
1152
 
1169
1153
  /**
@@ -1209,4 +1193,3 @@ export interface Compiler {
1209
1193
  }
1210
1194
 
1211
1195
  const normalCompiler: Compiler = (ast) => CompilerRegistry.resolve(ast).parser
1212
- const constructorCompiler: Compiler = (ast) => CompilerRegistry.resolve(ast).makeEffect
@@ -339,11 +339,13 @@ export const get: {
339
339
  return effect.interrupt
340
340
  }
341
341
  const oentry = MutableHashMap.get(state.map, key)
342
- if (Option.isSome(oentry) && !hasExpired(oentry.value, fiber)) {
343
- // Move the entry to the end of the map to keep it fresh
342
+ if (Option.isSome(oentry)) {
344
343
  MutableHashMap.remove(state.map, key)
345
- MutableHashMap.set(state.map, key, oentry.value)
346
- return awaitEntry(self, key, oentry.value, restore)
344
+ if (!hasExpired(oentry.value, fiber)) {
345
+ // Move the entry to the end of the map to keep it fresh
346
+ MutableHashMap.set(state.map, key, oentry.value)
347
+ return awaitEntry(self, key, oentry.value, restore)
348
+ }
347
349
  }
348
350
  const clock = fiber.getRef(effect.ClockRef)
349
351
  const scope = Scope.makeUnsafe()
package/src/Stream.ts CHANGED
@@ -8,6 +8,26 @@
8
8
  * stream lifecycle: create a stream, transform or combine it, control buffering
9
9
  * and timing, handle failures, and finally consume it.
10
10
  *
11
+ * Every stream runs in a scope supplied by its consumer, called the stream's
12
+ * scope. The run functions create that scope and close it before they return,
13
+ * however the stream ends: completion, failure, defect, an early stop by a
14
+ * downstream operator such as `take`, or interruption. `toPull` uses the scope
15
+ * it is given and leaves closing it to its owner. Operators that run inner
16
+ * streams, such as `flatMap` and `concat`, may give each inner stream a child
17
+ * scope that closes sooner.
18
+ *
19
+ * `ensuring`, `onExit`, and `scoped` finalize when their stream ends on its own
20
+ * (completion, failure, or defect), before downstream observes that end.
21
+ * `callback` and `unwrap` register finalizers in the stream's scope, so they
22
+ * run when that scope closes. A stream that is abandoned because a downstream
23
+ * operator such as `take` stopped pulling from it is finalized no later than
24
+ * when its scope closes. Under `toPull`, that can be after the pull has
25
+ * returned its final result, so close the scope to release what the stream
26
+ * still holds. `toQueue` and `toPubSub` use the given scope for the queue or
27
+ * pubsub and for the fiber that feeds it. That fiber runs the stream like a run
28
+ * function, so the stream's resources are released when it ends, without
29
+ * waiting for the scope to close.
30
+ *
11
31
  * @stability stable
12
32
  * @since 2.0.0
13
33
  */
@@ -695,9 +715,15 @@ export const toChannel = <A, E, R>(
695
715
  * Use when you need callback-based code to emit stream values by offering to a
696
716
  * `Queue`, or signal stream completion through the `Queue` module APIs.
697
717
  *
698
- * By default it uses an "unbounded" buffer size.
699
- * You can customize the buffer size and strategy by passing an object as the
700
- * second argument with the `bufferSize` and `strategy` fields.
718
+ * **Details**
719
+ *
720
+ * The callback effect runs in the stream's scope. Finalizers it registers, for
721
+ * example with `Effect.acquireRelease`, run when that scope closes, not when
722
+ * the queue ends.
723
+ *
724
+ * By default it uses an "unbounded" buffer size. You can customize the buffer
725
+ * size and strategy by passing an object as the second argument with the
726
+ * `bufferSize` and `strategy` fields.
701
727
  *
702
728
  * **Example** (Creating a stream from a callback that can emit values into a queue)
703
729
  *
@@ -718,6 +744,29 @@ export const toChannel = <A, E, R>(
718
744
  * await Effect.runPromise(Stream.runCollect(stream)) // => [1, 2, 3]
719
745
  * ```
720
746
  *
747
+ * **Example** (Unregistering a listener when the stream scope closes)
748
+ *
749
+ * ```ts import.meta.vitest
750
+ * import { Effect, Queue, Stream } from "effect"
751
+ *
752
+ * const listeners = new Set<(value: number) => void>()
753
+ *
754
+ * const stream = Stream.callback<number>(Effect.fnUntraced(function*(queue) {
755
+ * const listener = (value: number) => {
756
+ * Queue.offerUnsafe(queue, value)
757
+ * }
758
+ * yield* Effect.acquireRelease(
759
+ * Effect.sync(() => listeners.add(listener)),
760
+ * () => Effect.sync(() => listeners.delete(listener))
761
+ * )
762
+ * listeners.forEach((notify) => notify(1))
763
+ * }))
764
+ *
765
+ * const values = await Effect.runPromise(Stream.runCollect(stream.pipe(Stream.take(1))))
766
+ * values // => [1]
767
+ * listeners.size // => 0
768
+ * ```
769
+ *
721
770
  * @stability stable
722
771
  * @category constructors
723
772
  * @since 4.0.0
@@ -1692,6 +1741,11 @@ export const never: Stream<never> = fromChannel(Channel.never)
1692
1741
  /**
1693
1742
  * Creates a stream produced from an `Effect`.
1694
1743
  *
1744
+ * **Details**
1745
+ *
1746
+ * The effect runs in the stream's scope, so finalizers it registers run when
1747
+ * that scope closes.
1748
+ *
1695
1749
  * **Example** (Unwrapping a stream effect)
1696
1750
  *
1697
1751
  * ```ts import.meta.vitest
@@ -1720,6 +1774,14 @@ export const unwrap = <A, E2, R2, E, R>(
1720
1774
  * Runs a stream that requires `Scope` in a managed scope, ensuring its
1721
1775
  * finalizers are run when the stream completes.
1722
1776
  *
1777
+ * **Details**
1778
+ *
1779
+ * The provided scope closes when the stream ends on its own (completion,
1780
+ * failure, or defect), before downstream observes that end. If a downstream
1781
+ * operator stops pulling first, it closes no later than when the stream's scope
1782
+ * closes. It satisfies the `Scope` service requirement only; constructors that
1783
+ * register finalizers in the stream's scope, such as `callback`, keep using it.
1784
+ *
1723
1785
  * **Example** (Scoping a stream)
1724
1786
  *
1725
1787
  * ```ts import.meta.vitest
@@ -17677,6 +17739,12 @@ export const haltWhen: {
17677
17739
  /**
17678
17740
  * Runs the provided finalizer when the stream exits, passing the exit value.
17679
17741
  *
17742
+ * **Details**
17743
+ *
17744
+ * The finalizer runs when the stream ends on its own (completion, failure, or
17745
+ * defect), before downstream observes that end. If a downstream operator stops
17746
+ * pulling first, it runs no later than when the stream's scope closes.
17747
+ *
17680
17748
  * **Example** (Running a finalizer on exit)
17681
17749
  *
17682
17750
  * ```ts import.meta.vitest
@@ -17705,6 +17773,12 @@ export const onExit: {
17705
17773
  /**
17706
17774
  * Runs the provided finalizer when the stream exits, passing the exit value.
17707
17775
  *
17776
+ * **Details**
17777
+ *
17778
+ * The finalizer runs when the stream ends on its own (completion, failure, or
17779
+ * defect), before downstream observes that end. If a downstream operator stops
17780
+ * pulling first, it runs no later than when the stream's scope closes.
17781
+ *
17708
17782
  * **Example** (Running a finalizer on exit)
17709
17783
  *
17710
17784
  * ```ts import.meta.vitest
@@ -17735,6 +17809,12 @@ export const onExit: {
17735
17809
  /**
17736
17810
  * Runs the provided finalizer when the stream exits, passing the exit value.
17737
17811
  *
17812
+ * **Details**
17813
+ *
17814
+ * The finalizer runs when the stream ends on its own (completion, failure, or
17815
+ * defect), before downstream observes that end. If a downstream operator stops
17816
+ * pulling first, it runs no later than when the stream's scope closes.
17817
+ *
17738
17818
  * **Example** (Running a finalizer on exit)
17739
17819
  *
17740
17820
  * ```ts import.meta.vitest
@@ -18121,6 +18201,12 @@ export const onEnd: {
18121
18201
  /**
18122
18202
  * Executes the provided finalizer after this stream's finalizers run.
18123
18203
  *
18204
+ * **Details**
18205
+ *
18206
+ * The finalizer runs when the stream ends on its own (completion, failure, or
18207
+ * defect), before downstream observes that end. If a downstream operator stops
18208
+ * pulling first, it runs no later than when the stream's scope closes.
18209
+ *
18124
18210
  * **Example** (Ensuring finalization)
18125
18211
  *
18126
18212
  * ```ts import.meta.vitest
@@ -18148,6 +18234,12 @@ export const ensuring: {
18148
18234
  /**
18149
18235
  * Executes the provided finalizer after this stream's finalizers run.
18150
18236
  *
18237
+ * **Details**
18238
+ *
18239
+ * The finalizer runs when the stream ends on its own (completion, failure, or
18240
+ * defect), before downstream observes that end. If a downstream operator stops
18241
+ * pulling first, it runs no later than when the stream's scope closes.
18242
+ *
18151
18243
  * **Example** (Ensuring finalization)
18152
18244
  *
18153
18245
  * ```ts import.meta.vitest
@@ -18175,6 +18267,12 @@ export const ensuring: {
18175
18267
  /**
18176
18268
  * Executes the provided finalizer after this stream's finalizers run.
18177
18269
  *
18270
+ * **Details**
18271
+ *
18272
+ * The finalizer runs when the stream ends on its own (completion, failure, or
18273
+ * defect), before downstream observes that end. If a downstream operator stops
18274
+ * pulling first, it runs no later than when the stream's scope closes.
18275
+ *
18178
18276
  * **Example** (Ensuring finalization)
18179
18277
  *
18180
18278
  * ```ts import.meta.vitest
@@ -20062,8 +20160,9 @@ export const runDrain = <A, E, R>(self: Stream<A, E, R>): Effect.Effect<void, E,
20062
20160
  *
20063
20161
  * **Details**
20064
20162
  *
20065
- * The pull fails with `Cause.Done` when the stream ends and with the stream
20066
- * error on failure.
20163
+ * The stream runs in the provided scope, which the pull leaves open; close it
20164
+ * to release any resources the stream still holds. The pull fails with
20165
+ * `Cause.Done` when the stream ends and with the stream error on failure.
20067
20166
  *
20068
20167
  * **Example** (Creating a scoped pull)
20069
20168
  *
@@ -20621,11 +20720,13 @@ export const toAsyncIterableWith: {
20621
20720
  ): AsyncIterable<A> => ({
20622
20721
  [Symbol.asyncIterator]() {
20623
20722
  const runPromise = Effect.runPromiseWith(context)
20624
- const runFork = Effect.runForkWith(context)
20723
+ const runPromiseExit = Effect.runPromiseExitWith(context)
20625
20724
  const scope = Scope.makeUnsafe()
20626
20725
  let pull: Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E, void, R> | undefined
20627
20726
  let currentIter: Iterator<A> | undefined
20628
- let currentFiber: Fiber.Fiber<Arr.NonEmptyReadonlyArray<A>, E | Cause.Done<void>> | undefined
20727
+ let currentFiber: Fiber.Fiber<unknown, unknown> | undefined
20728
+ let reading = false
20729
+ const queuedReads: Array<() => void> = []
20629
20730
  let closePromise: Promise<IteratorResult<A>> | undefined
20630
20731
  const close = (exit: Exit.Exit<unknown, unknown>): Promise<IteratorResult<A>> => {
20631
20732
  if (closePromise) return closePromise
@@ -20646,37 +20747,46 @@ export const toAsyncIterableWith: {
20646
20747
  await runPromise(Effect.logError("Suppressed error while closing Stream async iterator", error))
20647
20748
  }
20648
20749
  }
20750
+ // Register the fiber before pulling so a reentrant close can interrupt it.
20751
+ const pullChunk = Effect.withFiber((fiber) => {
20752
+ currentFiber = fiber
20753
+ return pull ??
20754
+ Effect.flatMap(Channel.toPullScoped(self.channel, scope), (nextPull) => {
20755
+ pull = nextPull
20756
+ return nextPull
20757
+ })
20758
+ })
20649
20759
  return {
20650
20760
  async next(): Promise<IteratorResult<A>> {
20651
- if (closePromise) return closePromise
20652
- if (currentIter) {
20653
- const next = currentIter.next()
20654
- if (!next.done) return next
20655
- currentIter = undefined
20761
+ if (reading) {
20762
+ await new Promise<void>((resolve) => queuedReads.push(resolve))
20656
20763
  }
20657
- const fiber = runFork(
20658
- pull ??
20659
- Effect.flatMap(Channel.toPullScoped(self.channel, scope), (nextPull) => {
20660
- pull = nextPull
20661
- return nextPull
20662
- })
20663
- )
20664
- currentFiber = fiber
20665
- const exit = await runPromise(Fiber.await(fiber))
20666
- if (currentFiber === fiber) {
20764
+ reading = true
20765
+ try {
20766
+ if (closePromise) return closePromise
20767
+ if (currentIter) {
20768
+ const next = currentIter.next()
20769
+ if (!next.done) return next
20770
+ currentIter = undefined
20771
+ }
20772
+ const exit = await runPromiseExit(pullChunk)
20667
20773
  currentFiber = undefined
20774
+ if (Exit.isSuccess(exit)) {
20775
+ currentIter = exit.value[Symbol.iterator]()
20776
+ return currentIter.next()
20777
+ } else if (Pull.isDoneCause(exit.cause)) {
20778
+ return close(Exit.void)
20779
+ }
20780
+ if (closePromise && Cause.hasInterruptsOnly(exit.cause)) {
20781
+ return closePromise
20782
+ }
20783
+ await closeAndReportError(exit)
20784
+ throw Cause.squash(exit.cause)
20785
+ } finally {
20786
+ const resume = queuedReads.shift()
20787
+ if (resume) resume()
20788
+ else reading = false
20668
20789
  }
20669
- if (Exit.isSuccess(exit)) {
20670
- currentIter = exit.value[Symbol.iterator]()
20671
- return currentIter.next()
20672
- } else if (Pull.isDoneCause(exit.cause)) {
20673
- return close(Exit.void)
20674
- }
20675
- if (closePromise && Cause.hasInterruptsOnly(exit.cause)) {
20676
- return closePromise
20677
- }
20678
- await closeAndReportError(exit)
20679
- throw Cause.squash(exit.cause)
20680
20790
  },
20681
20791
  return() {
20682
20792
  return close(Exit.void)
@@ -20869,6 +20979,10 @@ export const runIntoPubSub: {
20869
20979
  *
20870
20980
  * **Details**
20871
20981
  *
20982
+ * The surrounding scope owns the PubSub and the fiber that feeds it. The stream
20983
+ * runs like a run function inside that fiber, so its finalizers run when it
20984
+ * ends, or when the fiber is interrupted by the scope closing.
20985
+ *
20872
20986
  * `shutdownOnEnd` indicates whether the PubSub should be shut down when the
20873
20987
  * stream ends. By default this is `true`.
20874
20988
  *
@@ -20899,6 +21013,10 @@ export const toPubSub: {
20899
21013
  *
20900
21014
  * **Details**
20901
21015
  *
21016
+ * The surrounding scope owns the PubSub and the fiber that feeds it. The stream
21017
+ * runs like a run function inside that fiber, so its finalizers run when it
21018
+ * ends, or when the fiber is interrupted by the scope closing.
21019
+ *
20902
21020
  * `shutdownOnEnd` indicates whether the PubSub should be shut down when the
20903
21021
  * stream ends. By default this is `true`.
20904
21022
  *
@@ -20940,6 +21058,10 @@ export const toPubSub: {
20940
21058
  *
20941
21059
  * **Details**
20942
21060
  *
21061
+ * The surrounding scope owns the PubSub and the fiber that feeds it. The stream
21062
+ * runs like a run function inside that fiber, so its finalizers run when it
21063
+ * ends, or when the fiber is interrupted by the scope closing.
21064
+ *
20943
21065
  * `shutdownOnEnd` indicates whether the PubSub should be shut down when the
20944
21066
  * stream ends. By default this is `true`.
20945
21067
  *
@@ -21134,6 +21256,10 @@ export const toPubSubTake: {
21134
21256
  *
21135
21257
  * **Details**
21136
21258
  *
21259
+ * The surrounding scope owns the queue and the fiber that feeds it. The stream
21260
+ * runs like a run function inside that fiber, so its finalizers run when it
21261
+ * ends, or when the fiber is interrupted by the scope closing.
21262
+ *
21137
21263
  * Elements are offered to the queue as the stream runs. Stream completion is
21138
21264
  * signaled with `Cause.Done`, stream failures fail the queue, and the queue is
21139
21265
  * shut down when the surrounding scope closes.
@@ -21162,6 +21288,10 @@ export const toQueue: {
21162
21288
  *
21163
21289
  * **Details**
21164
21290
  *
21291
+ * The surrounding scope owns the queue and the fiber that feeds it. The stream
21292
+ * runs like a run function inside that fiber, so its finalizers run when it
21293
+ * ends, or when the fiber is interrupted by the scope closing.
21294
+ *
21165
21295
  * Elements are offered to the queue as the stream runs. Stream completion is
21166
21296
  * signaled with `Cause.Done`, stream failures fail the queue, and the queue is
21167
21297
  * shut down when the surrounding scope closes.
@@ -21197,6 +21327,10 @@ export const toQueue: {
21197
21327
  *
21198
21328
  * **Details**
21199
21329
  *
21330
+ * The surrounding scope owns the queue and the fiber that feeds it. The stream
21331
+ * runs like a run function inside that fiber, so its finalizers run when it
21332
+ * ends, or when the fiber is interrupted by the scope closing.
21333
+ *
21200
21334
  * Elements are offered to the queue as the stream runs. Stream completion is
21201
21335
  * signaled with `Cause.Done`, stream failures fail the queue, and the queue is
21202
21336
  * shut down when the surrounding scope closes.
package/src/String.ts CHANGED
@@ -1678,7 +1678,7 @@ class LinesIterator implements IterableIterator<string> {
1678
1678
  }
1679
1679
 
1680
1680
  [Symbol.iterator](): IterableIterator<string> {
1681
- return new LinesIterator(this.s, this.stripped)
1681
+ return this
1682
1682
  }
1683
1683
 
1684
1684
  private get done(): boolean {
package/src/Tracer.ts CHANGED
@@ -175,13 +175,21 @@ export const ParentSpanKey = "effect/Tracer/ParentSpan"
175
175
  * @category services
176
176
  * @since 2.0.0
177
177
  */
178
- export class ParentSpan extends Context.Service<ParentSpan, AnySpan>()(ParentSpanKey, { fiberCached: true }) {}
178
+ export class ParentSpan extends Context.Service<ParentSpan, AnySpan>()(ParentSpanKey) {}
179
179
 
180
180
  /**
181
181
  * Represents a span created outside Effect's tracer, carrying trace and span
182
182
  * identifiers, sampling state, and annotations so it can be used as a parent or
183
183
  * link in Effect tracing.
184
184
  *
185
+ * **Details**
186
+ *
187
+ * An external span identifies a parent or link only. Effect never records on
188
+ * it: it has no attributes, events, or end. While the nearest parent span is
189
+ * external, `Effect.currentSpan` fails, `Effect.annotateCurrentSpan` does
190
+ * nothing, and `Logger.tracerLogger` records nothing. Open a span with
191
+ * `Effect.withSpan` to get one that records.
192
+ *
185
193
  * **Example** (Creating an external span value)
186
194
  *
187
195
  * ```ts import.meta.vitest
@@ -514,6 +522,8 @@ export const make = (options: Tracer): Tracer => options
514
522
  * spans.map((span) => Option.getOrUndefined(span.parent)?.spanId) // => ["span-abc-123"]
515
523
  * ```
516
524
  *
525
+ * @see {@link ExternalSpan}
526
+ *
517
527
  * @stability stable
518
528
  * @category constructors
519
529
  * @since 2.0.0
@@ -660,7 +670,6 @@ export const TracerKey = "effect/Tracer"
660
670
  * @since 2.0.0
661
671
  */
662
672
  export const Tracer: Context.Reference<Tracer> = Context.Reference<Tracer>(TracerKey, {
663
- fiberCached: true,
664
673
  defaultValue: () => nativeTracer
665
674
  })
666
675