effect 4.0.6 → 4.0.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 (480) hide show
  1. package/dist/Arbitrary.d.ts +10 -2
  2. package/dist/Arbitrary.d.ts.map +1 -1
  3. package/dist/Arbitrary.js +2 -1
  4. package/dist/Arbitrary.js.map +1 -1
  5. package/dist/Channel.d.ts.map +1 -1
  6. package/dist/Channel.js +21 -6
  7. package/dist/Channel.js.map +1 -1
  8. package/dist/Data.d.ts +54 -235
  9. package/dist/Data.d.ts.map +1 -1
  10. package/dist/Data.js.map +1 -1
  11. package/dist/Effect.d.ts +1 -1
  12. package/dist/Effect.js +1 -1
  13. package/dist/Equal.d.ts.map +1 -1
  14. package/dist/Equal.js +8 -1
  15. package/dist/Equal.js.map +1 -1
  16. package/dist/Exit.d.ts +3 -3
  17. package/dist/Exit.d.ts.map +1 -1
  18. package/dist/Exit.js.map +1 -1
  19. package/dist/Formatter.d.ts.map +1 -1
  20. package/dist/Formatter.js +27 -13
  21. package/dist/Formatter.js.map +1 -1
  22. package/dist/Hash.d.ts.map +1 -1
  23. package/dist/Hash.js +4 -1
  24. package/dist/Hash.js.map +1 -1
  25. package/dist/JsonPatch.js +4 -0
  26. package/dist/JsonPatch.js.map +1 -1
  27. package/dist/JsonSchema.d.ts.map +1 -1
  28. package/dist/JsonSchema.js +13 -40
  29. package/dist/JsonSchema.js.map +1 -1
  30. package/dist/Metric.d.ts +3 -3
  31. package/dist/MutableList.d.ts +5 -2
  32. package/dist/MutableList.d.ts.map +1 -1
  33. package/dist/MutableList.js +7 -5
  34. package/dist/MutableList.js.map +1 -1
  35. package/dist/MutableRef.d.ts.map +1 -1
  36. package/dist/MutableRef.js +7 -0
  37. package/dist/MutableRef.js.map +1 -1
  38. package/dist/PartitionedSemaphore.d.ts +2 -1
  39. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  40. package/dist/PartitionedSemaphore.js +22 -12
  41. package/dist/PartitionedSemaphore.js.map +1 -1
  42. package/dist/Pool.d.ts.map +1 -1
  43. package/dist/Pool.js +77 -27
  44. package/dist/Pool.js.map +1 -1
  45. package/dist/PubSub.d.ts.map +1 -1
  46. package/dist/PubSub.js +5 -6
  47. package/dist/PubSub.js.map +1 -1
  48. package/dist/Ref.d.ts.map +1 -1
  49. package/dist/Ref.js +8 -0
  50. package/dist/Ref.js.map +1 -1
  51. package/dist/Schedule.js +1 -1
  52. package/dist/Schedule.js.map +1 -1
  53. package/dist/Schema.d.ts +24 -8
  54. package/dist/Schema.d.ts.map +1 -1
  55. package/dist/Schema.js +37 -28
  56. package/dist/Schema.js.map +1 -1
  57. package/dist/SchemaAST.d.ts +4 -2
  58. package/dist/SchemaAST.d.ts.map +1 -1
  59. package/dist/SchemaAST.js +14 -17
  60. package/dist/SchemaAST.js.map +1 -1
  61. package/dist/SchemaParser.d.ts.map +1 -1
  62. package/dist/SchemaParser.js +48 -22
  63. package/dist/SchemaParser.js.map +1 -1
  64. package/dist/SchemaRepresentation.d.ts +19 -10
  65. package/dist/SchemaRepresentation.d.ts.map +1 -1
  66. package/dist/SchemaRepresentation.js +23 -13
  67. package/dist/SchemaRepresentation.js.map +1 -1
  68. package/dist/SchemaTransformation.d.ts +4 -1
  69. package/dist/SchemaTransformation.d.ts.map +1 -1
  70. package/dist/SchemaTransformation.js +9 -2
  71. package/dist/SchemaTransformation.js.map +1 -1
  72. package/dist/Semaphore.d.ts.map +1 -1
  73. package/dist/Semaphore.js +54 -35
  74. package/dist/Semaphore.js.map +1 -1
  75. package/dist/Sink.d.ts.map +1 -1
  76. package/dist/Sink.js +7 -2
  77. package/dist/Sink.js.map +1 -1
  78. package/dist/Stream.d.ts.map +1 -1
  79. package/dist/Stream.js +22 -10
  80. package/dist/Stream.js.map +1 -1
  81. package/dist/String.d.ts +3 -0
  82. package/dist/String.d.ts.map +1 -1
  83. package/dist/String.js +3 -0
  84. package/dist/String.js.map +1 -1
  85. package/dist/Tracer.d.ts +11 -1
  86. package/dist/Tracer.d.ts.map +1 -1
  87. package/dist/Tracer.js +6 -1
  88. package/dist/Tracer.js.map +1 -1
  89. package/dist/ai/LanguageModel.d.ts.map +1 -1
  90. package/dist/ai/LanguageModel.js +9 -0
  91. package/dist/ai/LanguageModel.js.map +1 -1
  92. package/dist/ai/McpSchema.d.ts +110 -110
  93. package/dist/ai/McpSchema.d.ts.map +1 -1
  94. package/dist/ai/McpServer.d.ts.map +1 -1
  95. package/dist/ai/McpServer.js +21 -15
  96. package/dist/ai/McpServer.js.map +1 -1
  97. package/dist/ai/Prompt.d.ts +52 -0
  98. package/dist/ai/Prompt.d.ts.map +1 -1
  99. package/dist/ai/Prompt.js +38 -0
  100. package/dist/ai/Prompt.js.map +1 -1
  101. package/dist/ai/Response.d.ts +16 -3
  102. package/dist/ai/Response.d.ts.map +1 -1
  103. package/dist/ai/Response.js +4 -0
  104. package/dist/ai/Response.js.map +1 -1
  105. package/dist/ai/Tool.d.ts +24 -0
  106. package/dist/ai/Tool.d.ts.map +1 -1
  107. package/dist/ai/Tool.js +5 -2
  108. package/dist/ai/Tool.js.map +1 -1
  109. package/dist/ai/Toolkit.d.ts.map +1 -1
  110. package/dist/ai/Toolkit.js +8 -1
  111. package/dist/ai/Toolkit.js.map +1 -1
  112. package/dist/cli/Argument.d.ts +15 -0
  113. package/dist/cli/Argument.d.ts.map +1 -1
  114. package/dist/cli/Argument.js +5 -0
  115. package/dist/cli/Argument.js.map +1 -1
  116. package/dist/cli/CliError.d.ts +78 -0
  117. package/dist/cli/CliError.d.ts.map +1 -1
  118. package/dist/cli/CliError.js +65 -3
  119. package/dist/cli/CliError.js.map +1 -1
  120. package/dist/cli/CliOutput.d.ts +155 -6
  121. package/dist/cli/CliOutput.d.ts.map +1 -1
  122. package/dist/cli/CliOutput.js +62 -6
  123. package/dist/cli/CliOutput.js.map +1 -1
  124. package/dist/cli/Command.d.ts +24 -16
  125. package/dist/cli/Command.d.ts.map +1 -1
  126. package/dist/cli/Command.js +59 -29
  127. package/dist/cli/Command.js.map +1 -1
  128. package/dist/cli/Completions.d.ts +58 -0
  129. package/dist/cli/Completions.d.ts.map +1 -1
  130. package/dist/cli/Completions.js +49 -9
  131. package/dist/cli/Completions.js.map +1 -1
  132. package/dist/cli/Flag.d.ts +15 -0
  133. package/dist/cli/Flag.d.ts.map +1 -1
  134. package/dist/cli/Flag.js +5 -0
  135. package/dist/cli/Flag.js.map +1 -1
  136. package/dist/cli/GlobalFlag.d.ts.map +1 -1
  137. package/dist/cli/GlobalFlag.js +15 -7
  138. package/dist/cli/GlobalFlag.js.map +1 -1
  139. package/dist/cli/Param.d.ts +9 -0
  140. package/dist/cli/Param.d.ts.map +1 -1
  141. package/dist/cli/Param.js +21 -2
  142. package/dist/cli/Param.js.map +1 -1
  143. package/dist/cli/TerminalCapabilities.d.ts +3 -2
  144. package/dist/cli/TerminalCapabilities.d.ts.map +1 -1
  145. package/dist/cli/TerminalCapabilities.js +3 -1
  146. package/dist/cli/TerminalCapabilities.js.map +1 -1
  147. package/dist/cli/internal/completions/bash.js +73 -27
  148. package/dist/cli/internal/completions/bash.js.map +1 -1
  149. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  150. package/dist/cluster/ClusterWorkflowEngine.js +45 -10
  151. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  152. package/dist/cluster/MessageStorage.d.ts +23 -45
  153. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  154. package/dist/cluster/MessageStorage.js +6 -7
  155. package/dist/cluster/MessageStorage.js.map +1 -1
  156. package/dist/cluster/Sharding.d.ts.map +1 -1
  157. package/dist/cluster/Sharding.js +61 -21
  158. package/dist/cluster/Sharding.js.map +1 -1
  159. package/dist/cluster/ShardingConfig.d.ts +10 -0
  160. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  161. package/dist/cluster/ShardingConfig.js.map +1 -1
  162. package/dist/cluster/Snowflake.d.ts.map +1 -1
  163. package/dist/cluster/Snowflake.js +3 -7
  164. package/dist/cluster/Snowflake.js.map +1 -1
  165. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  166. package/dist/cluster/SqlRunnerStorage.js +87 -39
  167. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  168. package/dist/cluster/internal/entityManager.js +54 -20
  169. package/dist/cluster/internal/entityManager.js.map +1 -1
  170. package/dist/devtools/DevToolsClient.d.ts.map +1 -1
  171. package/dist/devtools/DevToolsClient.js +2 -0
  172. package/dist/devtools/DevToolsClient.js.map +1 -1
  173. package/dist/encoding/Base64.js +36 -0
  174. package/dist/encoding/Base64.js.map +1 -1
  175. package/dist/encoding/Sse.d.ts.map +1 -1
  176. package/dist/encoding/Sse.js +3 -3
  177. package/dist/encoding/Sse.js.map +1 -1
  178. package/dist/encoding/Toml.d.ts.map +1 -1
  179. package/dist/encoding/Toml.js +21 -16
  180. package/dist/encoding/Toml.js.map +1 -1
  181. package/dist/eventlog/SqlEventJournal.d.ts.map +1 -1
  182. package/dist/eventlog/SqlEventJournal.js +47 -27
  183. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  184. package/dist/eventlog/internal/conflicts.d.ts +0 -1
  185. package/dist/eventlog/internal/conflicts.d.ts.map +1 -1
  186. package/dist/eventlog/internal/conflicts.js +0 -3
  187. package/dist/eventlog/internal/conflicts.js.map +1 -1
  188. package/dist/http/Cookies.d.ts.map +1 -1
  189. package/dist/http/Cookies.js +10 -9
  190. package/dist/http/Cookies.js.map +1 -1
  191. package/dist/http/HttpClient.d.ts +423 -0
  192. package/dist/http/HttpClient.d.ts.map +1 -1
  193. package/dist/http/HttpClient.js +231 -7
  194. package/dist/http/HttpClient.js.map +1 -1
  195. package/dist/http/HttpClientError.d.ts +8 -1
  196. package/dist/http/HttpClientError.d.ts.map +1 -1
  197. package/dist/http/HttpClientError.js +37 -1
  198. package/dist/http/HttpClientError.js.map +1 -1
  199. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  200. package/dist/http/HttpClientRequest.js +1 -1
  201. package/dist/http/HttpClientRequest.js.map +1 -1
  202. package/dist/http/HttpMiddleware.d.ts +1 -1
  203. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  204. package/dist/http/HttpMiddleware.js +14 -16
  205. package/dist/http/HttpMiddleware.js.map +1 -1
  206. package/dist/http/HttpRouter.d.ts.map +1 -1
  207. package/dist/http/HttpRouter.js +2 -1
  208. package/dist/http/HttpRouter.js.map +1 -1
  209. package/dist/http/HttpServerError.js +2 -2
  210. package/dist/http/HttpServerError.js.map +1 -1
  211. package/dist/http/HttpServerRequest.d.ts +6 -1
  212. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  213. package/dist/http/HttpServerRequest.js +73 -10
  214. package/dist/http/HttpServerRequest.js.map +1 -1
  215. package/dist/http/HttpStaticServer.d.ts.map +1 -1
  216. package/dist/http/HttpStaticServer.js +48 -21
  217. package/dist/http/HttpStaticServer.js.map +1 -1
  218. package/dist/http/MultipartParser/internal/contentType.js +3 -3
  219. package/dist/http/UrlParams.d.ts +3 -1
  220. package/dist/http/UrlParams.d.ts.map +1 -1
  221. package/dist/http/UrlParams.js +4 -2
  222. package/dist/http/UrlParams.js.map +1 -1
  223. package/dist/http/internal/compression.js +4 -5
  224. package/dist/http/internal/compression.js.map +1 -1
  225. package/dist/http/internal/decompression.js +3 -0
  226. package/dist/http/internal/decompression.js.map +1 -1
  227. package/dist/http/internal/httpBody.js +8 -1
  228. package/dist/http/internal/httpBody.js.map +1 -1
  229. package/dist/http/internal/urlParams.js +25 -0
  230. package/dist/http/internal/urlParams.js.map +1 -1
  231. package/dist/http-api/HttpApi.d.ts +3 -6
  232. package/dist/http-api/HttpApi.d.ts.map +1 -1
  233. package/dist/http-api/HttpApi.js +3 -6
  234. package/dist/http-api/HttpApi.js.map +1 -1
  235. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  236. package/dist/http-api/HttpApiBuilder.js +27 -11
  237. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  238. package/dist/http-api/HttpApiClient.d.ts +77 -7
  239. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  240. package/dist/http-api/HttpApiClient.js +142 -44
  241. package/dist/http-api/HttpApiClient.js.map +1 -1
  242. package/dist/http-api/HttpApiEndpoint.d.ts +24 -7
  243. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  244. package/dist/http-api/HttpApiEndpoint.js +109 -27
  245. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  246. package/dist/http-api/HttpApiSchema.d.ts +76 -29
  247. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  248. package/dist/http-api/HttpApiSchema.js +70 -59
  249. package/dist/http-api/HttpApiSchema.js.map +1 -1
  250. package/dist/http-api/HttpApiTest.d.ts.map +1 -1
  251. package/dist/http-api/HttpApiTest.js +3 -2
  252. package/dist/http-api/HttpApiTest.js.map +1 -1
  253. package/dist/http-api/OpenApi.d.ts.map +1 -1
  254. package/dist/http-api/OpenApi.js +25 -16
  255. package/dist/http-api/OpenApi.js.map +1 -1
  256. package/dist/http-api/internal/toCodecHttpProperties.d.ts +2 -0
  257. package/dist/http-api/internal/toCodecHttpProperties.d.ts.map +1 -0
  258. package/dist/http-api/internal/toCodecHttpProperties.js +38 -0
  259. package/dist/http-api/internal/toCodecHttpProperties.js.map +1 -0
  260. package/dist/internal/arbitrary/runner.d.ts.map +1 -1
  261. package/dist/internal/arbitrary/runner.js +120 -44
  262. package/dist/internal/arbitrary/runner.js.map +1 -1
  263. package/dist/internal/core.js +2 -0
  264. package/dist/internal/core.js.map +1 -1
  265. package/dist/internal/effect.js +21 -13
  266. package/dist/internal/effect.js.map +1 -1
  267. package/dist/internal/equal.js +14 -0
  268. package/dist/internal/equal.js.map +1 -1
  269. package/dist/internal/jsonSchema.d.ts +2 -0
  270. package/dist/internal/jsonSchema.d.ts.map +1 -0
  271. package/dist/internal/jsonSchema.js +28 -0
  272. package/dist/internal/jsonSchema.js.map +1 -0
  273. package/dist/internal/matcher.js +1 -1
  274. package/dist/internal/matcher.js.map +1 -1
  275. package/dist/internal/schema/compilerRegistry.js +4 -1
  276. package/dist/internal/schema/compilerRegistry.js.map +1 -1
  277. package/dist/internal/schema/content.d.ts +2 -0
  278. package/dist/internal/schema/content.d.ts.map +1 -0
  279. package/dist/internal/schema/content.js +13 -0
  280. package/dist/internal/schema/content.js.map +1 -0
  281. package/dist/internal/schema/fromJsonSchemaDocument.js +173 -185
  282. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  283. package/dist/internal/schema/fromRepresentation.js +2 -1
  284. package/dist/internal/schema/fromRepresentation.js.map +1 -1
  285. package/dist/internal/schema/standardSchema.js +8 -2
  286. package/dist/internal/schema/standardSchema.js.map +1 -1
  287. package/dist/internal/schema/toCodeDocument.js +3 -3
  288. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  289. package/dist/internal/schema/toCodec.js +21 -24
  290. package/dist/internal/schema/toCodec.js.map +1 -1
  291. package/dist/internal/schema/toJsonSchemaDocument.js +205 -140
  292. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  293. package/dist/internal/schema/toRepresentation.js +107 -129
  294. package/dist/internal/schema/toRepresentation.js.map +1 -1
  295. package/dist/internal/sql.d.ts +2 -0
  296. package/dist/internal/sql.d.ts.map +1 -0
  297. package/dist/internal/sql.js +13 -0
  298. package/dist/internal/sql.js.map +1 -0
  299. package/dist/internal/version.js +1 -1
  300. package/dist/observability/OtlpProxy.d.ts +154 -0
  301. package/dist/observability/OtlpProxy.d.ts.map +1 -0
  302. package/dist/observability/OtlpProxy.js +235 -0
  303. package/dist/observability/OtlpProxy.js.map +1 -0
  304. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  305. package/dist/observability/OtlpTracer.js +4 -0
  306. package/dist/observability/OtlpTracer.js.map +1 -1
  307. package/dist/observability/index.d.ts +5 -0
  308. package/dist/observability/index.d.ts.map +1 -1
  309. package/dist/observability/index.js +5 -0
  310. package/dist/observability/index.js.map +1 -1
  311. package/dist/persistence/CircuitBreaker.d.ts +897 -0
  312. package/dist/persistence/CircuitBreaker.d.ts.map +1 -0
  313. package/dist/persistence/CircuitBreaker.js +1165 -0
  314. package/dist/persistence/CircuitBreaker.js.map +1 -0
  315. package/dist/persistence/Redis.d.ts +78 -2
  316. package/dist/persistence/Redis.d.ts.map +1 -1
  317. package/dist/persistence/Redis.js +62 -7
  318. package/dist/persistence/Redis.js.map +1 -1
  319. package/dist/persistence/index.d.ts +5 -0
  320. package/dist/persistence/index.d.ts.map +1 -1
  321. package/dist/persistence/index.js +5 -0
  322. package/dist/persistence/index.js.map +1 -1
  323. package/dist/process/ChildProcess.d.ts +30 -4
  324. package/dist/process/ChildProcess.d.ts.map +1 -1
  325. package/dist/process/ChildProcess.js.map +1 -1
  326. package/dist/process/ChildProcessSpawner.d.ts +30 -0
  327. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  328. package/dist/process/ChildProcessSpawner.js +5 -2
  329. package/dist/process/ChildProcessSpawner.js.map +1 -1
  330. package/dist/reactivity/AsyncResult.d.ts +1 -1
  331. package/dist/reactivity/AsyncResult.d.ts.map +1 -1
  332. package/dist/rpc/RpcClient.d.ts.map +1 -1
  333. package/dist/rpc/RpcClient.js +9 -8
  334. package/dist/rpc/RpcClient.js.map +1 -1
  335. package/dist/rpc/RpcSerialization.d.ts +14 -0
  336. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  337. package/dist/rpc/RpcSerialization.js +20 -8
  338. package/dist/rpc/RpcSerialization.js.map +1 -1
  339. package/dist/rpc/RpcServer.d.ts.map +1 -1
  340. package/dist/rpc/RpcServer.js +11 -1
  341. package/dist/rpc/RpcServer.js.map +1 -1
  342. package/dist/rpc/RpcTest.d.ts +1 -0
  343. package/dist/rpc/RpcTest.d.ts.map +1 -1
  344. package/dist/rpc/RpcTest.js +1 -0
  345. package/dist/rpc/RpcTest.js.map +1 -1
  346. package/dist/sql/Migrator.d.ts +2 -1
  347. package/dist/sql/Migrator.d.ts.map +1 -1
  348. package/dist/sql/Migrator.js +11 -8
  349. package/dist/sql/Migrator.js.map +1 -1
  350. package/dist/sql/SqlClient.d.ts +9 -4
  351. package/dist/sql/SqlClient.d.ts.map +1 -1
  352. package/dist/sql/SqlClient.js +8 -1
  353. package/dist/sql/SqlClient.js.map +1 -1
  354. package/dist/sql/SqlResolver.d.ts +4 -0
  355. package/dist/sql/SqlResolver.d.ts.map +1 -1
  356. package/dist/sql/SqlResolver.js +18 -4
  357. package/dist/sql/SqlResolver.js.map +1 -1
  358. package/dist/sql/Statement.d.ts +7 -0
  359. package/dist/sql/Statement.d.ts.map +1 -1
  360. package/dist/sql/Statement.js +21 -2
  361. package/dist/sql/Statement.js.map +1 -1
  362. package/dist/workflow/DurableDeferred.d.ts.map +1 -1
  363. package/dist/workflow/DurableDeferred.js +21 -2
  364. package/dist/workflow/DurableDeferred.js.map +1 -1
  365. package/package.json +1 -1
  366. package/src/Arbitrary.ts +10 -2
  367. package/src/Channel.ts +47 -18
  368. package/src/Data.ts +60 -265
  369. package/src/Effect.ts +1 -1
  370. package/src/Equal.ts +8 -1
  371. package/src/Exit.ts +3 -3
  372. package/src/Formatter.ts +28 -13
  373. package/src/Hash.ts +4 -1
  374. package/src/JsonPatch.ts +4 -0
  375. package/src/JsonSchema.ts +12 -40
  376. package/src/Metric.ts +3 -3
  377. package/src/MutableList.ts +7 -5
  378. package/src/MutableRef.ts +8 -1
  379. package/src/PartitionedSemaphore.ts +24 -13
  380. package/src/Pool.ts +109 -37
  381. package/src/PubSub.ts +5 -6
  382. package/src/Ref.ts +8 -0
  383. package/src/Schedule.ts +1 -1
  384. package/src/Schema.ts +48 -25
  385. package/src/SchemaAST.ts +20 -20
  386. package/src/SchemaParser.ts +51 -18
  387. package/src/SchemaRepresentation.ts +31 -34
  388. package/src/SchemaTransformation.ts +9 -2
  389. package/src/Semaphore.ts +67 -40
  390. package/src/Sink.ts +15 -2
  391. package/src/Stream.ts +33 -16
  392. package/src/String.ts +3 -0
  393. package/src/Tracer.ts +15 -1
  394. package/src/ai/LanguageModel.ts +9 -0
  395. package/src/ai/McpServer.ts +14 -13
  396. package/src/ai/Prompt.ts +65 -0
  397. package/src/ai/Response.ts +34 -9
  398. package/src/ai/Tool.ts +38 -2
  399. package/src/ai/Toolkit.ts +4 -1
  400. package/src/cli/Argument.ts +15 -0
  401. package/src/cli/CliError.ts +90 -3
  402. package/src/cli/CliOutput.ts +183 -6
  403. package/src/cli/Command.ts +53 -41
  404. package/src/cli/Completions.ts +51 -0
  405. package/src/cli/Flag.ts +15 -0
  406. package/src/cli/GlobalFlag.ts +6 -7
  407. package/src/cli/Param.ts +29 -6
  408. package/src/cli/TerminalCapabilities.ts +6 -3
  409. package/src/cli/internal/completions/bash.ts +79 -29
  410. package/src/cluster/ClusterWorkflowEngine.ts +46 -16
  411. package/src/cluster/MessageStorage.ts +19 -14
  412. package/src/cluster/Sharding.ts +83 -21
  413. package/src/cluster/ShardingConfig.ts +5 -0
  414. package/src/cluster/Snowflake.ts +3 -7
  415. package/src/cluster/SqlRunnerStorage.ts +110 -47
  416. package/src/cluster/internal/entityManager.ts +75 -22
  417. package/src/devtools/DevToolsClient.ts +2 -0
  418. package/src/encoding/Base64.ts +38 -0
  419. package/src/encoding/Sse.ts +4 -3
  420. package/src/encoding/Toml.ts +33 -16
  421. package/src/eventlog/SqlEventJournal.ts +68 -45
  422. package/src/eventlog/internal/conflicts.ts +0 -4
  423. package/src/http/Cookies.ts +10 -11
  424. package/src/http/HttpClient.ts +547 -7
  425. package/src/http/HttpClientError.ts +35 -1
  426. package/src/http/HttpClientRequest.ts +9 -1
  427. package/src/http/HttpMiddleware.ts +15 -18
  428. package/src/http/HttpRouter.ts +2 -1
  429. package/src/http/HttpServerError.ts +2 -2
  430. package/src/http/HttpServerRequest.ts +102 -16
  431. package/src/http/HttpStaticServer.ts +51 -22
  432. package/src/http/MultipartParser/internal/contentType.ts +3 -3
  433. package/src/http/UrlParams.ts +6 -1
  434. package/src/http/internal/compression.ts +4 -5
  435. package/src/http/internal/decompression.ts +6 -0
  436. package/src/http/internal/httpBody.ts +10 -2
  437. package/src/http/internal/urlParams.ts +29 -0
  438. package/src/http-api/HttpApi.ts +3 -6
  439. package/src/http-api/HttpApiBuilder.ts +45 -15
  440. package/src/http-api/HttpApiClient.ts +218 -72
  441. package/src/http-api/HttpApiEndpoint.ts +121 -30
  442. package/src/http-api/HttpApiSchema.ts +141 -48
  443. package/src/http-api/HttpApiTest.ts +3 -2
  444. package/src/http-api/OpenApi.ts +20 -17
  445. package/src/http-api/internal/toCodecHttpProperties.ts +56 -0
  446. package/src/internal/arbitrary/runner.ts +133 -36
  447. package/src/internal/core.ts +2 -0
  448. package/src/internal/effect.ts +24 -16
  449. package/src/internal/equal.ts +17 -0
  450. package/src/internal/jsonSchema.ts +27 -0
  451. package/src/internal/matcher.ts +1 -1
  452. package/src/internal/schema/compilerRegistry.ts +6 -1
  453. package/src/internal/schema/content.ts +18 -0
  454. package/src/internal/schema/fromJsonSchemaDocument.ts +228 -190
  455. package/src/internal/schema/fromRepresentation.ts +2 -1
  456. package/src/internal/schema/standardSchema.ts +2 -2
  457. package/src/internal/schema/toCodeDocument.ts +4 -4
  458. package/src/internal/schema/toCodec.ts +26 -22
  459. package/src/internal/schema/toJsonSchemaDocument.ts +189 -167
  460. package/src/internal/schema/toRepresentation.ts +122 -140
  461. package/src/internal/sql.ts +14 -0
  462. package/src/internal/version.ts +1 -1
  463. package/src/observability/OtlpProxy.ts +314 -0
  464. package/src/observability/OtlpTracer.ts +4 -0
  465. package/src/observability/index.ts +6 -0
  466. package/src/persistence/CircuitBreaker.ts +1678 -0
  467. package/src/persistence/Redis.ts +129 -8
  468. package/src/persistence/index.ts +6 -0
  469. package/src/process/ChildProcess.ts +30 -4
  470. package/src/process/ChildProcessSpawner.ts +41 -2
  471. package/src/reactivity/AsyncResult.ts +1 -1
  472. package/src/rpc/RpcClient.ts +13 -10
  473. package/src/rpc/RpcSerialization.ts +32 -9
  474. package/src/rpc/RpcServer.ts +16 -1
  475. package/src/rpc/RpcTest.ts +3 -0
  476. package/src/sql/Migrator.ts +12 -7
  477. package/src/sql/SqlClient.ts +11 -4
  478. package/src/sql/SqlResolver.ts +23 -9
  479. package/src/sql/Statement.ts +30 -2
  480. package/src/workflow/DurableDeferred.ts +23 -6
@@ -0,0 +1,897 @@
1
+ /**
2
+ * Keyed circuit breakers for calls to unreliable dependencies.
3
+ *
4
+ * A `CircuitBreaker` holds one circuit per key, so one policy can guard many
5
+ * hosts or tenants. State lives in a `CircuitBreakerStore`: `layerStoreMemory`
6
+ * keeps it in the process, `layerStoreRedis` shares it between processes.
7
+ *
8
+ * **Details**
9
+ *
10
+ * - Closed: calls run, and the trip policy decides when the circuit opens.
11
+ * - Open: calls fail with `CircuitOpen` until the open time ends.
12
+ * - HalfOpen: the next call is the probe, and other calls fail with
13
+ * `CircuitHalfOpen` while it runs. A successful probe closes the circuit and
14
+ * a failed one reopens it. An interrupted or `Ignored` probe frees the slot.
15
+ * - The backoff count survives a close. It resets once the circuit has stayed
16
+ * closed as long as it was last open.
17
+ *
18
+ * The breaker never waits. Retry rejections outside it, as in "Retrying
19
+ * rejections" below. Put `Effect.retry` and `Effect.timeout` inside it, so it
20
+ * sees one outcome per call. With `ExecutionPlan`, put a breaker inside each
21
+ * step under its own key.
22
+ *
23
+ * The breaker emits no metrics or spans. Observe it through `state(key)`,
24
+ * `transitions` and the typed error.
25
+ *
26
+ * **Gotchas**
27
+ *
28
+ * - Use one policy per key. Breakers that share a key and a store share one
29
+ * circuit, and nothing checks that their policies match. Separate them with
30
+ * distinct keys or a Redis `prefix`.
31
+ * - Calls admitted before a trip still run to completion, but their outcomes
32
+ * change nothing.
33
+ * - "Consecutive" counts in order of completion, not of start.
34
+ * - `state(key)` reads the shared store. `transitions` only shows what this
35
+ * breaker instance did.
36
+ * - Store errors the breaker swallows (a fail-open admit, a failed record, a
37
+ * failed Redis lease renewal) are reported with their cause at
38
+ * `References.UnhandledLogLevel`. Set it to `undefined` to silence them.
39
+ * - Cap an exponential `openDuration`, with `Schedule.upTo` or with
40
+ * `Schedule.min` and a `Schedule.spaced`, or it keeps growing for a
41
+ * dependency that flaps.
42
+ *
43
+ * **Example** (Rejecting calls once a circuit opens)
44
+ *
45
+ * ```ts import.meta.vitest
46
+ * import { Data, Effect } from "effect"
47
+ * import { CircuitBreaker } from "effect/persistence"
48
+ *
49
+ * class PaymentsError extends Data.TaggedError("PaymentsError") {}
50
+ *
51
+ * const program = Effect.gen(function*() {
52
+ * const breaker = yield* CircuitBreaker.make({
53
+ * tripPolicy: CircuitBreaker.consecutive(2),
54
+ * openDuration: "30 seconds"
55
+ * })
56
+ * const charge = Effect.fail(new PaymentsError()).pipe(
57
+ * breaker.execute({ key: "payments" })
58
+ * )
59
+ *
60
+ * // Two failures in a row open the circuit.
61
+ * yield* Effect.flip(charge)
62
+ * yield* Effect.flip(charge)
63
+ *
64
+ * // The third call is rejected without running.
65
+ * return yield* charge.pipe(
66
+ * Effect.catchReason("CircuitBreakerError", "CircuitOpen", (reason) => Effect.succeed(`${reason.key} is open`))
67
+ * )
68
+ * }).pipe(Effect.scoped, Effect.provide(CircuitBreaker.layerStoreMemory()))
69
+ *
70
+ * await Effect.runPromise(program) // => "payments is open"
71
+ * ```
72
+ *
73
+ * **Example** (Retrying rejections)
74
+ *
75
+ * For `CircuitOpen`, wait at least the rejection's `retryAfter`. For
76
+ * `CircuitHalfOpen`, the jittered backoff keeps waiting callers from retrying
77
+ * at the same moment. Store errors and the call's own errors are not retried.
78
+ *
79
+ * ```ts import.meta.vitest
80
+ * import { Data, Duration, Effect, Ref, Schedule } from "effect"
81
+ * import { CircuitBreaker } from "effect/persistence"
82
+ *
83
+ * const isRejection = (error: unknown): error is CircuitBreaker.CircuitBreakerError =>
84
+ * error instanceof CircuitBreaker.CircuitBreakerError && error.reason._tag !== "CircuitBreakerStoreError"
85
+ *
86
+ * const retryRejections = Schedule.exponential("20 millis").pipe(
87
+ * Schedule.jittered,
88
+ * Schedule.modifyDelay(({ duration, input }) =>
89
+ * Effect.succeed(
90
+ * isRejection(input) && input.reason._tag === "CircuitOpen"
91
+ * ? Duration.max(duration, input.reason.retryAfter)
92
+ * : duration
93
+ * )
94
+ * )
95
+ * )
96
+ *
97
+ * class QuoteError extends Data.TaggedError("QuoteError") {}
98
+ *
99
+ * const program = Effect.gen(function*() {
100
+ * const breaker = yield* CircuitBreaker.make({
101
+ * tripPolicy: CircuitBreaker.consecutive(1),
102
+ * openDuration: "50 millis"
103
+ * })
104
+ * const healthy = yield* Ref.make(false)
105
+ * const quote = Effect.flatMap(Ref.get(healthy), (ok) => ok ? Effect.succeed(42) : Effect.fail(new QuoteError()))
106
+ *
107
+ * // One failure opens the circuit, then the dependency recovers.
108
+ * yield* Effect.flip(quote.pipe(breaker.execute({ key: "quotes" })))
109
+ * yield* Ref.set(healthy, true)
110
+ *
111
+ * // Rejected while open, then retried once the circuit lets a probe through.
112
+ * return yield* quote.pipe(
113
+ * breaker.execute({ key: "quotes" }),
114
+ * Effect.retry({ schedule: retryRejections, while: isRejection, times: 5 })
115
+ * )
116
+ * }).pipe(Effect.scoped, Effect.provide(CircuitBreaker.layerStoreMemory()))
117
+ *
118
+ * await Effect.runPromise(program) // => 42
119
+ * ```
120
+ *
121
+ * @stability experimental
122
+ * @since 4.0.6
123
+ */
124
+ import * as Cause from "../Cause.ts";
125
+ import * as Config from "../Config.ts";
126
+ import * as Context from "../Context.ts";
127
+ import * as Duration from "../Duration.ts";
128
+ import * as Effect from "../Effect.ts";
129
+ import * as Exit from "../Exit.ts";
130
+ import * as Layer from "../Layer.ts";
131
+ import * as Schedule from "../Schedule.ts";
132
+ import * as Schema from "../Schema.ts";
133
+ import * as Scope from "../Scope.ts";
134
+ import * as Stream from "../Stream.ts";
135
+ import * as Redis from "./Redis.ts";
136
+ /**
137
+ * Runtime type identifier for `CircuitBreaker` values.
138
+ *
139
+ * @stability experimental
140
+ * @category type IDs
141
+ * @since 4.0.6
142
+ */
143
+ export declare const TypeId: TypeId;
144
+ /**
145
+ * Type-level identifier used to brand `CircuitBreaker` values.
146
+ *
147
+ * @stability experimental
148
+ * @category type IDs
149
+ * @since 4.0.6
150
+ */
151
+ export type TypeId = "~effect/persistence/CircuitBreaker";
152
+ /**
153
+ * Service that runs effects through keyed circuits and reports their state.
154
+ *
155
+ * **Details**
156
+ *
157
+ * - `execute` runs the call through the circuit for `key` and records its
158
+ * outcome. `classify` maps the call's `Exit` to an `Outcome`, directly or as
159
+ * an effect. By default a success is a `Success` and any failure, defects
160
+ * included, is a `Failure`, since a rejected `Effect.promise` only surfaces
161
+ * as a defect. An exit that is only interruption is always `Ignored`.
162
+ * - `state` reads the shared state of a circuit.
163
+ * - `transitions` emits this breaker's transitions and ends when its scope
164
+ * closes.
165
+ *
166
+ * **Gotchas**
167
+ *
168
+ * - If `classify` throws or dies, the outcome is `Ignored` and the call dies.
169
+ * - Bound an effectful `classify` with `Effect.timeoutOrElse` or
170
+ * `Effect.timeoutOption`, since `Effect.timeout` adds a typed error. A call
171
+ * to the same key from inside `classify` is rejected while its call is the
172
+ * probe.
173
+ *
174
+ * **Example** (Timing out calls inside the breaker)
175
+ *
176
+ * A timeout inside the breaker counts as a `Failure`. Outside, it interrupts
177
+ * the call, which is `Ignored`.
178
+ *
179
+ * ```ts import.meta.vitest
180
+ * import { Effect } from "effect"
181
+ * import { CircuitBreaker } from "effect/persistence"
182
+ *
183
+ * const program = Effect.gen(function*() {
184
+ * const breaker = yield* CircuitBreaker.make({
185
+ * tripPolicy: CircuitBreaker.consecutive(1),
186
+ * openDuration: "1 minute"
187
+ * })
188
+ *
189
+ * yield* Effect.never.pipe(
190
+ * Effect.timeout("10 millis"),
191
+ * breaker.execute({ key: "inside" }),
192
+ * Effect.ignore
193
+ * )
194
+ * yield* Effect.never.pipe(
195
+ * breaker.execute({ key: "outside" }),
196
+ * Effect.timeout("10 millis"),
197
+ * Effect.ignore
198
+ * )
199
+ *
200
+ * const inside = yield* breaker.state("inside")
201
+ * const outside = yield* breaker.state("outside")
202
+ * return [inside._tag, outside._tag]
203
+ * }).pipe(Effect.scoped, Effect.provide(CircuitBreaker.layerStoreMemory()))
204
+ *
205
+ * await Effect.runPromise(program) // => ["Open", "Closed"]
206
+ * ```
207
+ *
208
+ * **Example** (Retrying inside the breaker)
209
+ *
210
+ * The breaker sees one outcome per call, so a call a retry rescued counts as
211
+ * one `Success`.
212
+ *
213
+ * ```ts import.meta.vitest
214
+ * import { Data, Effect, Ref, Schedule } from "effect"
215
+ * import { CircuitBreaker } from "effect/persistence"
216
+ *
217
+ * class InventoryError extends Data.TaggedError("InventoryError") {}
218
+ *
219
+ * const program = Effect.gen(function*() {
220
+ * const breaker = yield* CircuitBreaker.make({
221
+ * tripPolicy: CircuitBreaker.consecutive(1),
222
+ * openDuration: "1 minute"
223
+ * })
224
+ * const attempts = yield* Ref.make(0)
225
+ * // Fails twice, then succeeds.
226
+ * const stock = Effect.flatMap(
227
+ * Ref.updateAndGet(attempts, (n) => n + 1),
228
+ * (n) => n <= 2 ? Effect.fail(new InventoryError()) : Effect.succeed(7)
229
+ * )
230
+ *
231
+ * const result = yield* stock.pipe(
232
+ * Effect.retry({ schedule: Schedule.exponential("1 millis"), times: 3 }),
233
+ * breaker.execute({ key: "inventory" })
234
+ * )
235
+ * const state = yield* breaker.state("inventory")
236
+ * return [result, state._tag]
237
+ * }).pipe(Effect.scoped, Effect.provide(CircuitBreaker.layerStoreMemory()))
238
+ *
239
+ * await Effect.runPromise(program) // => [7, "Closed"]
240
+ * ```
241
+ *
242
+ * **Example** (Falling back to another provider with ExecutionPlan)
243
+ *
244
+ * Each provider guards its calls under its own key, so once the primary's
245
+ * circuit opens its step fails fast and the plan moves to the fallback.
246
+ *
247
+ * ```ts import.meta.vitest
248
+ * import { Context, Data, Effect, ExecutionPlan, Layer } from "effect"
249
+ * import { CircuitBreaker } from "effect/persistence"
250
+ *
251
+ * class GeocoderError extends Data.TaggedError("GeocoderError") {}
252
+ *
253
+ * class Geocoder extends Context.Service<Geocoder, {
254
+ * readonly lookup: (address: string) => Effect.Effect<string, GeocoderError | CircuitBreaker.CircuitBreakerError>
255
+ * }>()("app/Geocoder") {}
256
+ *
257
+ * const provider = (name: string, lookup: (address: string) => Effect.Effect<string, GeocoderError>) =>
258
+ * Layer.effect(
259
+ * Geocoder,
260
+ * Effect.gen(function*() {
261
+ * const breaker = yield* CircuitBreaker.CircuitBreaker
262
+ * return Geocoder.of({
263
+ * lookup: (address) => lookup(address).pipe(breaker.execute({ key: `geocoder:${name}` }))
264
+ * })
265
+ * })
266
+ * )
267
+ *
268
+ * const Primary = provider("primary", () => Effect.fail(new GeocoderError()))
269
+ * const Fallback = provider("fallback", (address) => Effect.succeed(`${address} (fallback)`))
270
+ *
271
+ * const plan = ExecutionPlan.make({ provide: Primary }, { provide: Fallback })
272
+ *
273
+ * const program = Effect.gen(function*() {
274
+ * const geocoder = yield* Geocoder
275
+ * return yield* geocoder.lookup("1 Main St")
276
+ * }).pipe(
277
+ * Effect.withExecutionPlan(plan),
278
+ * Effect.provide(
279
+ * CircuitBreaker.layer({ tripPolicy: CircuitBreaker.consecutive(3), openDuration: "30 seconds" }).pipe(
280
+ * Layer.provide(CircuitBreaker.layerStoreMemory())
281
+ * )
282
+ * )
283
+ * )
284
+ *
285
+ * await Effect.runPromise(program) // => "1 Main St (fallback)"
286
+ * ```
287
+ *
288
+ * **Example** (Counting transitions)
289
+ *
290
+ * Label by `from` and `to`, not `key`, to keep the number of series fixed.
291
+ *
292
+ * ```ts import.meta.vitest
293
+ * import { Effect, Metric, Stream } from "effect"
294
+ * import { CircuitBreaker } from "effect/persistence"
295
+ *
296
+ * const transitionsTotal = Metric.counter("circuit_breaker_transitions_total", { incremental: true })
297
+ *
298
+ * const countTransitions = (breaker: CircuitBreaker.CircuitBreaker) =>
299
+ * breaker.transitions.pipe(
300
+ * Stream.runForEach((transition) =>
301
+ * Metric.update(Metric.withAttributes(transitionsTotal, { from: transition.from, to: transition.to }), 1)
302
+ * ),
303
+ * Effect.forkScoped({ startImmediately: true })
304
+ * )
305
+ *
306
+ * const program = Effect.gen(function*() {
307
+ * const breaker = yield* CircuitBreaker.make({
308
+ * tripPolicy: CircuitBreaker.consecutive(1),
309
+ * openDuration: "1 minute"
310
+ * })
311
+ * yield* countTransitions(breaker)
312
+ *
313
+ * yield* Effect.fail("unavailable").pipe(breaker.execute({ key: "a" }), Effect.ignore)
314
+ * yield* Effect.fail("unavailable").pipe(breaker.execute({ key: "b" }), Effect.ignore)
315
+ * yield* Effect.yieldNow
316
+ *
317
+ * const opened = yield* Metric.value(Metric.withAttributes(transitionsTotal, { from: "Closed", to: "Open" }))
318
+ * return opened.count
319
+ * }).pipe(
320
+ * Effect.scoped,
321
+ * Effect.provide(CircuitBreaker.layerStoreMemory()),
322
+ * Effect.provideService(Metric.MetricRegistry, new Map())
323
+ * )
324
+ *
325
+ * await Effect.runPromise(program) // => 2
326
+ * ```
327
+ *
328
+ * @stability experimental
329
+ * @category models
330
+ * @since 4.0.6
331
+ */
332
+ export interface CircuitBreaker {
333
+ readonly [TypeId]: TypeId;
334
+ readonly execute: {
335
+ <A, E, R2 = never>(options: {
336
+ readonly key: string;
337
+ readonly classify?: ((exit: Exit.Exit<A, E>) => Outcome | Effect.Effect<Outcome, never, R2>) | undefined;
338
+ }): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | CircuitBreakerError, R | R2>;
339
+ <A, E, R, R2 = never>(self: Effect.Effect<A, E, R>, options: {
340
+ readonly key: string;
341
+ readonly classify?: ((exit: Exit.Exit<A, E>) => Outcome | Effect.Effect<Outcome, never, R2>) | undefined;
342
+ }): Effect.Effect<A, E | CircuitBreakerError, R | R2>;
343
+ };
344
+ readonly state: (key: string) => Effect.Effect<State, CircuitBreakerError>;
345
+ readonly transitions: Stream.Stream<Transition>;
346
+ }
347
+ /**
348
+ * Service tag for the default `CircuitBreaker`.
349
+ *
350
+ * **When to use**
351
+ *
352
+ * Use when one breaker policy serves the whole context. For several policies,
353
+ * use a `LayerMap` keyed by policy, with every entry sharing one store, or
354
+ * define your own tags.
355
+ *
356
+ * **Example** (Several breaker policies with LayerMap)
357
+ *
358
+ * ```ts import.meta.vitest
359
+ * import { Effect, LayerMap, Schedule } from "effect"
360
+ * import { CircuitBreaker } from "effect/persistence"
361
+ *
362
+ * class Breakers extends LayerMap.Service<Breakers>()("app/Breakers", {
363
+ * lookup: (dependency: "payments" | "search") =>
364
+ * dependency === "payments"
365
+ * ? CircuitBreaker.layer({ tripPolicy: CircuitBreaker.consecutive(5), openDuration: "30 seconds" })
366
+ * : CircuitBreaker.layer({
367
+ * tripPolicy: CircuitBreaker.rate({ threshold: 0.5, size: 20 }),
368
+ * openDuration: Schedule.exponential("1 second")
369
+ * }),
370
+ * // One store shared by every entry.
371
+ * dependencies: [CircuitBreaker.layerStoreMemory()],
372
+ * idleTimeToLive: "10 minutes"
373
+ * }) {}
374
+ *
375
+ * const search = Effect.gen(function*() {
376
+ * const breaker = yield* CircuitBreaker.CircuitBreaker
377
+ * return yield* Effect.succeed(["result"]).pipe(breaker.execute({ key: "search:eu" }))
378
+ * }).pipe(Effect.provide(Breakers.get("search")))
379
+ *
380
+ * await Effect.runPromise(search.pipe(Effect.provide(Breakers.layer))) // => ["result"]
381
+ * ```
382
+ *
383
+ * @stability experimental
384
+ * @category services
385
+ * @since 4.0.6
386
+ */
387
+ export declare const CircuitBreaker: Context.Service<CircuitBreaker, CircuitBreaker>;
388
+ /**
389
+ * Creates a `CircuitBreaker` from the current `CircuitBreakerStore`.
390
+ *
391
+ * **Details**
392
+ *
393
+ * - `tripPolicy` decides when a Closed circuit opens.
394
+ * - `openDuration` is a duration or a `Schedule`. The n-th consecutive opening
395
+ * lasts the schedule's n-th delay, and the last delay repeats once the
396
+ * schedule ends. Elapsed-time combinators such as `upTo` and `during`
397
+ * measure the time spent open, not wall time. Schedules that read the
398
+ * current date, such as `cron`, are not supported.
399
+ * - `maxOpenDuration` (default one hour) caps a `Retry-After` hint. It never
400
+ * caps `openDuration`.
401
+ * - `onStoreError` decides what a call does when the store cannot admit it:
402
+ * `"allow"` (the default) runs it unrecorded, `"fail"` fails it with
403
+ * `CircuitBreakerStoreError`.
404
+ *
405
+ * The backoff count resets once the circuit has stayed closed as long as its
406
+ * last opening, `Retry-After` hint included.
407
+ *
408
+ * **Example** (Capping backoff growth by time spent open)
409
+ *
410
+ * ```ts import.meta.vitest
411
+ * import { Effect, Schedule } from "effect"
412
+ * import { CircuitBreaker } from "effect/persistence"
413
+ *
414
+ * // Openings last 1, 2, 4, 8, 16 and 32 seconds. By then 63 seconds have been
415
+ * // spent open, past the one-minute cap, so later openings stay at 32 seconds.
416
+ * const program = Effect.gen(function*() {
417
+ * const breaker = yield* CircuitBreaker.make({
418
+ * tripPolicy: CircuitBreaker.consecutive(5),
419
+ * openDuration: Schedule.exponential("1 second").pipe(
420
+ * Schedule.upTo({ duration: "1 minute" })
421
+ * )
422
+ * })
423
+ * return yield* Effect.succeed("ok").pipe(breaker.execute({ key: "payments" }))
424
+ * }).pipe(Effect.scoped, Effect.provide(CircuitBreaker.layerStoreMemory()))
425
+ *
426
+ * await Effect.runPromise(program) // => "ok"
427
+ * ```
428
+ *
429
+ * @stability experimental
430
+ * @category constructors
431
+ * @since 4.0.6
432
+ */
433
+ export declare const make: (options: {
434
+ readonly tripPolicy: TripPolicy;
435
+ readonly openDuration: Duration.Input | Schedule.Schedule<unknown, number, never, never>;
436
+ readonly maxOpenDuration?: Duration.Input | undefined;
437
+ readonly onStoreError?: "allow" | "fail" | undefined;
438
+ }) => Effect.Effect<CircuitBreaker, never, CircuitBreakerStore | Scope.Scope>;
439
+ /**
440
+ * Provides `CircuitBreaker` using the current `CircuitBreakerStore`.
441
+ *
442
+ * **Details**
443
+ *
444
+ * Takes the same options as `make`.
445
+ *
446
+ * @stability experimental
447
+ * @category layers
448
+ * @since 4.0.6
449
+ */
450
+ export declare const layer: (options: {
451
+ readonly tripPolicy: TripPolicy;
452
+ readonly openDuration: Duration.Input | Schedule.Schedule<unknown, number, never, never>;
453
+ readonly maxOpenDuration?: Duration.Input | undefined;
454
+ readonly onStoreError?: "allow" | "fail" | undefined;
455
+ }) => Layer.Layer<CircuitBreaker, never, CircuitBreakerStore>;
456
+ /**
457
+ * Policy that decides when a Closed circuit opens.
458
+ *
459
+ * **Details**
460
+ *
461
+ * - `Consecutive` opens after `failures` failures in a row, in order of
462
+ * completion. Only a `Success` resets the streak.
463
+ * - `Rate` keeps the last `size` recorded outcomes and opens when the
464
+ * fraction of failures reaches `threshold`, once at least `minimumCalls`
465
+ * outcomes are recorded.
466
+ *
467
+ * `Ignored` outcomes never count towards either policy.
468
+ *
469
+ * @stability experimental
470
+ * @category models
471
+ * @since 4.0.6
472
+ */
473
+ export type TripPolicy = {
474
+ readonly _tag: "Consecutive";
475
+ readonly failures: number;
476
+ } | {
477
+ readonly _tag: "Rate";
478
+ readonly threshold: number;
479
+ readonly minimumCalls: number;
480
+ readonly size: number;
481
+ };
482
+ /**
483
+ * Creates a trip policy that opens after `failures` consecutive failures.
484
+ *
485
+ * **Gotchas**
486
+ *
487
+ * Throws a `RangeError` when `failures` is not an integer of at least 1.
488
+ *
489
+ * @stability experimental
490
+ * @category constructors
491
+ * @since 4.0.6
492
+ */
493
+ export declare const consecutive: (failures: number) => TripPolicy;
494
+ /**
495
+ * Creates a trip policy that opens when the failure rate over the last
496
+ * recorded calls reaches a threshold.
497
+ *
498
+ * **Details**
499
+ *
500
+ * `threshold` is a fraction in `[0, 1]` and defaults to `0.5`. `size` is the
501
+ * number of recorded calls kept and defaults to `100`. `minimumCalls`
502
+ * defaults to `size`. A ring with no failures never opens the circuit.
503
+ *
504
+ * **Gotchas**
505
+ *
506
+ * Throws a `RangeError` when `threshold` is outside `[0, 1]`, when `size` is
507
+ * not an integer of at least 1, or when `minimumCalls` is not an integer
508
+ * between 1 and `size`.
509
+ *
510
+ * @stability experimental
511
+ * @category constructors
512
+ * @since 4.0.6
513
+ */
514
+ export declare const rate: (options: {
515
+ readonly threshold?: number | undefined;
516
+ readonly size?: number | undefined;
517
+ readonly minimumCalls?: number | undefined;
518
+ }) => TripPolicy;
519
+ /**
520
+ * Classification of a call's exit, as returned by a `classify` function.
521
+ *
522
+ * @stability experimental
523
+ * @category models
524
+ * @since 4.0.6
525
+ */
526
+ export type Outcome = Outcome.Success | Outcome.Ignored | Outcome.Failure;
527
+ /**
528
+ * Members of the `Outcome` union.
529
+ *
530
+ * @stability experimental
531
+ * @category models
532
+ * @since 4.0.6
533
+ */
534
+ export declare namespace Outcome {
535
+ /**
536
+ * Outcome for a call that shows the dependency is healthy.
537
+ *
538
+ * @stability experimental
539
+ * @category models
540
+ * @since 4.0.6
541
+ */
542
+ interface Success {
543
+ readonly _tag: "Success";
544
+ }
545
+ /**
546
+ * Outcome for a call that says nothing about the dependency's health.
547
+ *
548
+ * @stability experimental
549
+ * @category models
550
+ * @since 4.0.6
551
+ */
552
+ interface Ignored {
553
+ readonly _tag: "Ignored";
554
+ }
555
+ /**
556
+ * Outcome for a call that counts against the dependency, with an optional
557
+ * hint for how long to stay open.
558
+ *
559
+ * @stability experimental
560
+ * @category models
561
+ * @since 4.0.6
562
+ */
563
+ interface Failure {
564
+ readonly _tag: "Failure";
565
+ readonly retryAfter?: Duration.Duration | undefined;
566
+ }
567
+ }
568
+ /**
569
+ * Outcome that records a success and resets a consecutive failure streak.
570
+ *
571
+ * @stability experimental
572
+ * @category constructors
573
+ * @since 4.0.6
574
+ */
575
+ export declare const success: Outcome;
576
+ /**
577
+ * Outcome that records nothing.
578
+ *
579
+ * @stability experimental
580
+ * @category constructors
581
+ * @since 4.0.6
582
+ */
583
+ export declare const ignored: Outcome;
584
+ /**
585
+ * Creates an outcome that records a failure.
586
+ *
587
+ * **Details**
588
+ *
589
+ * `retryAfter` is a hint, such as an HTTP `Retry-After` header. It is used
590
+ * only when this failure opens the circuit, can only lengthen the opening,
591
+ * and is capped at `maxOpenDuration`.
592
+ *
593
+ * @stability experimental
594
+ * @category constructors
595
+ * @since 4.0.6
596
+ */
597
+ export declare const failure: (options?: {
598
+ readonly retryAfter?: Duration.Input | undefined;
599
+ }) => Outcome;
600
+ /**
601
+ * State of one circuit, as read from the store.
602
+ *
603
+ * **Details**
604
+ *
605
+ * - `Open.retryAfter` is the remaining open time, clamped to zero. A circuit
606
+ * past its open time reads as Open until the next call moves it to
607
+ * HalfOpen.
608
+ * - `HalfOpen.probing` is `false` when no probe currently holds the slot.
609
+ * - `consecutiveOpenings` on Open and HalfOpen counts the openings since the
610
+ * backoff last reset, not since the circuit last closed.
611
+ *
612
+ * @stability experimental
613
+ * @category models
614
+ * @since 4.0.6
615
+ */
616
+ export type State = {
617
+ readonly _tag: "Closed";
618
+ readonly key: string;
619
+ } | {
620
+ readonly _tag: "Open";
621
+ readonly key: string;
622
+ readonly retryAfter: Duration.Duration;
623
+ readonly consecutiveOpenings: number;
624
+ } | {
625
+ readonly _tag: "HalfOpen";
626
+ readonly key: string;
627
+ readonly probing: boolean;
628
+ readonly consecutiveOpenings: number;
629
+ };
630
+ /**
631
+ * Transition between circuit states made by a breaker.
632
+ *
633
+ * **Details**
634
+ *
635
+ * Only the legal edges appear. `from` tells a failed probe (`"HalfOpen"`)
636
+ * apart from a fresh trip (`"Closed"`). On an opening, `consecutiveOpenings`
637
+ * counts the openings since the backoff last reset, including this one.
638
+ *
639
+ * @stability experimental
640
+ * @category models
641
+ * @since 4.0.6
642
+ */
643
+ export type Transition = {
644
+ readonly key: string;
645
+ readonly from: "Closed" | "HalfOpen";
646
+ readonly to: "Open";
647
+ readonly retryAfter: Duration.Duration;
648
+ readonly consecutiveOpenings: number;
649
+ } | {
650
+ readonly key: string;
651
+ readonly from: "Open";
652
+ readonly to: "HalfOpen";
653
+ } | {
654
+ readonly key: string;
655
+ readonly from: "HalfOpen";
656
+ readonly to: "Closed";
657
+ };
658
+ declare const CircuitOpen_base: Schema.Class<CircuitOpen, Schema.Struct<{
659
+ readonly _tag: Schema.tag<"CircuitOpen">;
660
+ readonly key: Schema.String;
661
+ readonly retryAfter: Schema.DurationFromMillis;
662
+ }>, Cause.YieldableError>;
663
+ /**
664
+ * Error reason for a call rejected by an Open circuit.
665
+ *
666
+ * @stability experimental
667
+ * @category errors
668
+ * @since 4.0.6
669
+ */
670
+ export declare class CircuitOpen extends CircuitOpen_base {
671
+ /**
672
+ * Public message used when an Open circuit rejects a call.
673
+ *
674
+ * @stability experimental
675
+ * @since 4.0.6
676
+ */
677
+ get message(): string;
678
+ }
679
+ declare const CircuitHalfOpen_base: Schema.Class<CircuitHalfOpen, Schema.Struct<{
680
+ readonly _tag: Schema.tag<"CircuitHalfOpen">;
681
+ readonly key: Schema.String;
682
+ }>, Cause.YieldableError>;
683
+ /**
684
+ * Error reason for a call rejected while a HalfOpen circuit's probe runs.
685
+ *
686
+ * @stability experimental
687
+ * @category errors
688
+ * @since 4.0.6
689
+ */
690
+ export declare class CircuitHalfOpen extends CircuitHalfOpen_base {
691
+ /**
692
+ * Public message used when a HalfOpen circuit rejects a call.
693
+ *
694
+ * @stability experimental
695
+ * @since 4.0.6
696
+ */
697
+ get message(): string;
698
+ }
699
+ declare const CircuitBreakerStoreError_base: Schema.Class<CircuitBreakerStoreError, Schema.Struct<{
700
+ readonly _tag: Schema.tag<"CircuitBreakerStoreError">;
701
+ readonly message: Schema.String;
702
+ readonly cause: Schema.optional<Schema.Defect>;
703
+ }>, Cause.YieldableError>;
704
+ /**
705
+ * Error reason for failures in the backing `CircuitBreakerStore`.
706
+ *
707
+ * @stability experimental
708
+ * @category errors
709
+ * @since 4.0.6
710
+ */
711
+ export declare class CircuitBreakerStoreError extends CircuitBreakerStoreError_base {
712
+ }
713
+ /**
714
+ * Union of reasons carried by `CircuitBreakerError`.
715
+ *
716
+ * @stability experimental
717
+ * @category errors
718
+ * @since 4.0.6
719
+ */
720
+ export type CircuitBreakerErrorReason = CircuitOpen | CircuitHalfOpen | CircuitBreakerStoreError;
721
+ /**
722
+ * Schema for all reasons that can be carried by `CircuitBreakerError`.
723
+ *
724
+ * @stability experimental
725
+ * @category errors
726
+ * @since 4.0.6
727
+ */
728
+ export declare const CircuitBreakerErrorReason: Schema.Union<[
729
+ typeof CircuitOpen,
730
+ typeof CircuitHalfOpen,
731
+ typeof CircuitBreakerStoreError
732
+ ]>;
733
+ /**
734
+ * Runtime type identifier for `CircuitBreakerError`.
735
+ *
736
+ * @stability experimental
737
+ * @category type IDs
738
+ * @since 4.0.6
739
+ */
740
+ export declare const ErrorTypeId: ErrorTypeId;
741
+ /**
742
+ * Type-level identifier used to brand `CircuitBreakerError` values.
743
+ *
744
+ * @stability experimental
745
+ * @category type IDs
746
+ * @since 4.0.6
747
+ */
748
+ export type ErrorTypeId = "~effect/persistence/CircuitBreaker/CircuitBreakerError";
749
+ declare const CircuitBreakerError_base: Schema.Class<CircuitBreakerError, Schema.Struct<{
750
+ readonly _tag: Schema.tag<"CircuitBreakerError">;
751
+ readonly reason: Schema.Union<[typeof CircuitOpen, typeof CircuitHalfOpen, typeof CircuitBreakerStoreError]>;
752
+ }>, Cause.YieldableError>;
753
+ /**
754
+ * Error raised by circuit breaker operations, wrapping a concrete failure
755
+ * `reason`.
756
+ *
757
+ * @stability experimental
758
+ * @category errors
759
+ * @since 4.0.6
760
+ */
761
+ export declare class CircuitBreakerError extends CircuitBreakerError_base {
762
+ constructor(props: {
763
+ readonly reason: CircuitBreakerErrorReason;
764
+ });
765
+ /**
766
+ * Marks this value as a circuit breaker error for runtime guards.
767
+ *
768
+ * @stability experimental
769
+ * @since 4.0.6
770
+ */
771
+ readonly [ErrorTypeId]: ErrorTypeId;
772
+ get message(): string;
773
+ }
774
+ declare const CircuitBreakerStore_base: Context.ServiceClass<CircuitBreakerStore, "effect/persistence/CircuitBreaker/CircuitBreakerStore", {
775
+ readonly admit: (key: string) => Effect.Effect<Admission, CircuitBreakerError, Scope.Scope>;
776
+ readonly record: (options: {
777
+ readonly key: string;
778
+ readonly generation: number;
779
+ readonly outcome: "Success" | "Failure" | "Ignored";
780
+ readonly tripPolicy: TripPolicy;
781
+ readonly openFor: Duration.Duration;
782
+ }) => Effect.Effect<Transition | undefined, CircuitBreakerError>;
783
+ readonly state: (key: string) => Effect.Effect<State, CircuitBreakerError>;
784
+ }>;
785
+ /**
786
+ * Store that holds circuit state for a `CircuitBreaker`.
787
+ *
788
+ * **Details**
789
+ *
790
+ * - `admit` returns an `Admission`, or fails with `CircuitOpen` or
791
+ * `CircuitHalfOpen`. Its scope stays open while the call runs.
792
+ * - `record` applies an outcome atomically and opens the circuit for
793
+ * `openFor` if it trips. An outcome stamped with an older generation
794
+ * changes nothing.
795
+ * - `state` reads a key without changing it.
796
+ *
797
+ * Each operation reads the current time inside the store. A close keeps
798
+ * `consecutiveOpenings` and sets a reset deadline of the close time plus the
799
+ * last `openFor`. The first `admit` at or after the deadline resets the count
800
+ * to 0. `record` never reads the deadline, so a call admitted before a reset
801
+ * still opens with the `openFor` it computed.
802
+ *
803
+ * @stability experimental
804
+ * @category services
805
+ * @since 4.0.6
806
+ */
807
+ export declare class CircuitBreakerStore extends CircuitBreakerStore_base {
808
+ }
809
+ /**
810
+ * Permit returned by `CircuitBreakerStore.admit`.
811
+ *
812
+ * **Details**
813
+ *
814
+ * - `generation` is an opaque fencing token to pass back to `record`.
815
+ * - `probe` is `true` when this call is the HalfOpen probe.
816
+ * - `consecutiveOpenings` counts the openings since the backoff last reset.
817
+ * - `transition` is the Open to HalfOpen transition this admission made, if
818
+ * any.
819
+ *
820
+ * @stability experimental
821
+ * @category models
822
+ * @since 4.0.6
823
+ */
824
+ export interface Admission {
825
+ readonly generation: number;
826
+ readonly probe: boolean;
827
+ readonly consecutiveOpenings: number;
828
+ readonly transition: Transition | undefined;
829
+ }
830
+ /**
831
+ * Creates an in-memory `CircuitBreakerStore` layer.
832
+ *
833
+ * **Details**
834
+ *
835
+ * State is local to the layer and uses `Clock`. `idleTimeToLive` (default
836
+ * one hour) drops a key once it has been idle that long. An Open key is kept
837
+ * that long past its open time, and a key whose probe is running is never
838
+ * dropped. A dropped key starts again as Closed with a backoff count of 0.
839
+ *
840
+ * @stability experimental
841
+ * @category layers
842
+ * @since 4.0.6
843
+ */
844
+ export declare const layerStoreMemory: (options?: {
845
+ readonly idleTimeToLive?: Duration.Input | undefined;
846
+ }) => Layer.Layer<CircuitBreakerStore>;
847
+ /**
848
+ * Creates a Redis-backed `CircuitBreakerStore` layer.
849
+ *
850
+ * **Details**
851
+ *
852
+ * - Each circuit is one hash at `${prefix}${key}`, and `prefix` defaults to
853
+ * `"circuitbreaker:"`. Times come from Redis `TIME`, so client clock skew
854
+ * never matters. Requires Redis 5 or later.
855
+ * - The probe holds a lease of `probeLease` (default 10 seconds), renewed
856
+ * while it runs. If the lease lapses, another caller takes over and the old
857
+ * probe's outcome is discarded.
858
+ * - `idleTimeToLive` (default one hour) expires idle keys. An Open key, or one
859
+ * whose probe holds the lease, is kept that long past its open time or
860
+ * lease, so expiry never cuts a probe short or resets the backoff early. An
861
+ * expired key starts again as Closed with a backoff count of 0.
862
+ *
863
+ * **Gotchas**
864
+ *
865
+ * - If renewals cannot reach Redis, the lease lapses and a second probe can
866
+ * start.
867
+ * - Durations above 2^50 milliseconds cannot be stored. An operation that
868
+ * needs one fails with `CircuitBreakerStoreError`.
869
+ *
870
+ * @stability experimental
871
+ * @category layers
872
+ * @since 4.0.6
873
+ */
874
+ export declare const layerStoreRedis: (options?: {
875
+ readonly prefix?: string | undefined;
876
+ readonly probeLease?: Duration.Input | undefined;
877
+ readonly idleTimeToLive?: Duration.Input | undefined;
878
+ }) => Layer.Layer<CircuitBreakerStore, never, Redis.Redis>;
879
+ /**
880
+ * Creates a Redis-backed `CircuitBreakerStore` layer from wrapped
881
+ * configuration options.
882
+ *
883
+ * **Details**
884
+ *
885
+ * Takes the same options as `layerStoreRedis`.
886
+ *
887
+ * @stability experimental
888
+ * @category layers
889
+ * @since 4.0.6
890
+ */
891
+ export declare const layerStoreRedisConfig: (options: Config.Wrap<{
892
+ readonly prefix?: string | undefined;
893
+ readonly probeLease?: Duration.Input | undefined;
894
+ readonly idleTimeToLive?: Duration.Input | undefined;
895
+ }>) => Layer.Layer<CircuitBreakerStore, Config.ConfigError, Redis.Redis>;
896
+ export {};
897
+ //# sourceMappingURL=CircuitBreaker.d.ts.map