effect 4.1.2 → 4.1.3

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 (465) hide show
  1. package/ai-docs/package.json +1 -1
  2. package/ai-docs/tsconfig.json +2 -1
  3. package/dist/DateTime.d.ts +33 -2
  4. package/dist/DateTime.d.ts.map +1 -1
  5. package/dist/DateTime.js +16 -0
  6. package/dist/DateTime.js.map +1 -1
  7. package/dist/Match.d.ts +6 -6
  8. package/dist/Match.d.ts.map +1 -1
  9. package/dist/Match.js.map +1 -1
  10. package/dist/Queue.d.ts +2 -1
  11. package/dist/Queue.d.ts.map +1 -1
  12. package/dist/Queue.js +16 -9
  13. package/dist/Queue.js.map +1 -1
  14. package/dist/Rational.d.ts +1214 -0
  15. package/dist/Rational.d.ts.map +1 -0
  16. package/dist/Rational.js +880 -0
  17. package/dist/Rational.js.map +1 -0
  18. package/dist/RcMap.d.ts +3 -0
  19. package/dist/RcMap.d.ts.map +1 -1
  20. package/dist/RcMap.js +13 -14
  21. package/dist/RcMap.js.map +1 -1
  22. package/dist/Runtime.d.ts +75 -3
  23. package/dist/Runtime.d.ts.map +1 -1
  24. package/dist/Runtime.js +81 -4
  25. package/dist/Runtime.js.map +1 -1
  26. package/dist/Schema.d.ts +131 -29
  27. package/dist/Schema.d.ts.map +1 -1
  28. package/dist/Schema.js +128 -22
  29. package/dist/Schema.js.map +1 -1
  30. package/dist/SchemaAST.d.ts.map +1 -1
  31. package/dist/SchemaAST.js +24 -12
  32. package/dist/SchemaAST.js.map +1 -1
  33. package/dist/SchemaParser.js +2 -2
  34. package/dist/SchemaParser.js.map +1 -1
  35. package/dist/SchemaRepresentation.d.ts +9 -0
  36. package/dist/SchemaRepresentation.d.ts.map +1 -1
  37. package/dist/SchemaRepresentation.js +9 -0
  38. package/dist/SchemaRepresentation.js.map +1 -1
  39. package/dist/ScopedCache.d.ts +7 -0
  40. package/dist/ScopedCache.d.ts.map +1 -1
  41. package/dist/ScopedCache.js +18 -1
  42. package/dist/ScopedCache.js.map +1 -1
  43. package/dist/ai/AgUi.d.ts +109 -0
  44. package/dist/ai/AgUi.d.ts.map +1 -0
  45. package/dist/ai/AgUi.js +543 -0
  46. package/dist/ai/AgUi.js.map +1 -0
  47. package/dist/ai/AgUiSchema.d.ts +6965 -0
  48. package/dist/ai/AgUiSchema.d.ts.map +1 -0
  49. package/dist/ai/AgUiSchema.js +974 -0
  50. package/dist/ai/AgUiSchema.js.map +1 -0
  51. package/dist/ai/AgUiServer.d.ts +6400 -0
  52. package/dist/ai/AgUiServer.d.ts.map +1 -0
  53. package/dist/ai/AgUiServer.js +309 -0
  54. package/dist/ai/AgUiServer.js.map +1 -0
  55. package/dist/ai/Chat.d.ts +30 -4
  56. package/dist/ai/Chat.d.ts.map +1 -1
  57. package/dist/ai/Chat.js +34 -4
  58. package/dist/ai/Chat.js.map +1 -1
  59. package/dist/ai/LanguageModel.d.ts +1 -1
  60. package/dist/ai/LanguageModel.d.ts.map +1 -1
  61. package/dist/ai/LanguageModel.js +18 -8
  62. package/dist/ai/LanguageModel.js.map +1 -1
  63. package/dist/ai/McpClient.d.ts +5 -0
  64. package/dist/ai/McpClient.d.ts.map +1 -1
  65. package/dist/ai/McpClient.js +11 -1
  66. package/dist/ai/McpClient.js.map +1 -1
  67. package/dist/ai/McpServer.d.ts +18 -1
  68. package/dist/ai/McpServer.d.ts.map +1 -1
  69. package/dist/ai/McpServer.js +214 -34
  70. package/dist/ai/McpServer.js.map +1 -1
  71. package/dist/ai/Prompt.d.ts +6 -2
  72. package/dist/ai/Prompt.d.ts.map +1 -1
  73. package/dist/ai/Prompt.js.map +1 -1
  74. package/dist/ai/Response.d.ts +5 -2
  75. package/dist/ai/Response.d.ts.map +1 -1
  76. package/dist/ai/Response.js +5 -1
  77. package/dist/ai/Response.js.map +1 -1
  78. package/dist/ai/Tool.d.ts +265 -69
  79. package/dist/ai/Tool.d.ts.map +1 -1
  80. package/dist/ai/Tool.js +19 -2
  81. package/dist/ai/Tool.js.map +1 -1
  82. package/dist/ai/Toolkit.d.ts +32 -2
  83. package/dist/ai/Toolkit.d.ts.map +1 -1
  84. package/dist/ai/Toolkit.js +61 -8
  85. package/dist/ai/Toolkit.js.map +1 -1
  86. package/dist/ai/index.d.ts +15 -0
  87. package/dist/ai/index.d.ts.map +1 -1
  88. package/dist/ai/index.js +15 -0
  89. package/dist/ai/index.js.map +1 -1
  90. package/dist/ai/internal/mcpCore.d.ts +0 -2
  91. package/dist/ai/internal/mcpCore.d.ts.map +1 -1
  92. package/dist/ai/internal/mcpCore.js +2 -8
  93. package/dist/ai/internal/mcpCore.js.map +1 -1
  94. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +6 -11
  95. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  96. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +6 -11
  97. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  98. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +6 -8
  99. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  100. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +6 -8
  101. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  102. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +60 -51
  103. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  104. package/dist/ai/internal/mcpProtocol.js +11 -1
  105. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  106. package/dist/ai/internal/mcpProtocolRegistry.js +4 -0
  107. package/dist/ai/internal/mcpProtocolRegistry.js.map +1 -1
  108. package/dist/ai/internal/mcpRuntime.js +6 -2
  109. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  110. package/dist/ai/internal/mcpSchema/v2024_11_05.js +0 -2
  111. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  112. package/dist/ai/internal/mcpSchema/v2025_03_26.d.ts.map +1 -1
  113. package/dist/ai/internal/mcpSchema/v2025_03_26.js +0 -2
  114. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  115. package/dist/ai/internal/mcpSchema/v2025_06_18.d.ts.map +1 -1
  116. package/dist/ai/internal/mcpSchema/v2025_06_18.js +0 -2
  117. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  118. package/dist/ai/internal/mcpSchema/v2025_11_25.d.ts.map +1 -1
  119. package/dist/ai/internal/mcpSchema/v2025_11_25.js +0 -2
  120. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  121. package/dist/ai/internal/mcpSchema/v2026_07_28.d.ts.map +1 -1
  122. package/dist/ai/internal/mcpSchema/v2026_07_28.js +0 -2
  123. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  124. package/dist/ai/internal/mcpSkills.js +3 -93
  125. package/dist/ai/internal/mcpSkills.js.map +1 -1
  126. package/dist/ai/internal/mcpStatefulRuntime.js +0 -2
  127. package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
  128. package/dist/ai/internal/structured-output.js +1 -1
  129. package/dist/ai/internal/structured-output.js.map +1 -1
  130. package/dist/cli/Argument.d.ts +81 -0
  131. package/dist/cli/Argument.d.ts.map +1 -1
  132. package/dist/cli/Argument.js +26 -0
  133. package/dist/cli/Argument.js.map +1 -1
  134. package/dist/cli/CliError.d.ts +7 -4
  135. package/dist/cli/CliError.d.ts.map +1 -1
  136. package/dist/cli/CliError.js +7 -4
  137. package/dist/cli/CliError.js.map +1 -1
  138. package/dist/cli/Command.d.ts +241 -22
  139. package/dist/cli/Command.d.ts.map +1 -1
  140. package/dist/cli/Command.js +85 -9
  141. package/dist/cli/Command.js.map +1 -1
  142. package/dist/cli/CommandSpec.d.ts +287 -0
  143. package/dist/cli/CommandSpec.d.ts.map +1 -0
  144. package/dist/cli/CommandSpec.js +277 -0
  145. package/dist/cli/CommandSpec.js.map +1 -0
  146. package/dist/cli/Completions.d.ts +5 -0
  147. package/dist/cli/Completions.d.ts.map +1 -1
  148. package/dist/cli/Completions.js.map +1 -1
  149. package/dist/cli/Flag.d.ts +102 -0
  150. package/dist/cli/Flag.d.ts.map +1 -1
  151. package/dist/cli/Flag.js +47 -0
  152. package/dist/cli/Flag.js.map +1 -1
  153. package/dist/cli/Param.d.ts +154 -1
  154. package/dist/cli/Param.d.ts.map +1 -1
  155. package/dist/cli/Param.js +87 -29
  156. package/dist/cli/Param.js.map +1 -1
  157. package/dist/cli/index.d.ts +5 -0
  158. package/dist/cli/index.d.ts.map +1 -1
  159. package/dist/cli/index.js +5 -0
  160. package/dist/cli/index.js.map +1 -1
  161. package/dist/cli/internal/command.d.ts +2 -2
  162. package/dist/cli/internal/command.d.ts.map +1 -1
  163. package/dist/cli/internal/command.js +1 -1
  164. package/dist/cli/internal/command.js.map +1 -1
  165. package/dist/cli/internal/completions/bash.js +6 -7
  166. package/dist/cli/internal/completions/bash.js.map +1 -1
  167. package/dist/cli/internal/completions/descriptor.js +21 -7
  168. package/dist/cli/internal/completions/descriptor.js.map +1 -1
  169. package/dist/cli/internal/completions/fish.js +3 -3
  170. package/dist/cli/internal/completions/fish.js.map +1 -1
  171. package/dist/cli/internal/completions/powershell.js +2 -2
  172. package/dist/cli/internal/completions/powershell.js.map +1 -1
  173. package/dist/cli/internal/completions/zsh.js +2 -2
  174. package/dist/cli/internal/completions/zsh.js.map +1 -1
  175. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  176. package/dist/cluster/ClusterWorkflowEngine.js +15 -13
  177. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  178. package/dist/cluster/Entity.d.ts +17 -0
  179. package/dist/cluster/Entity.d.ts.map +1 -1
  180. package/dist/cluster/Entity.js +20 -0
  181. package/dist/cluster/Entity.js.map +1 -1
  182. package/dist/cluster/MessageRetention.d.ts +71 -0
  183. package/dist/cluster/MessageRetention.d.ts.map +1 -0
  184. package/dist/cluster/MessageRetention.js +100 -0
  185. package/dist/cluster/MessageRetention.js.map +1 -0
  186. package/dist/cluster/MessageStorage.d.ts +81 -0
  187. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  188. package/dist/cluster/MessageStorage.js +34 -2
  189. package/dist/cluster/MessageStorage.js.map +1 -1
  190. package/dist/cluster/ShardingConfig.d.ts +24 -2
  191. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  192. package/dist/cluster/ShardingConfig.js.map +1 -1
  193. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  194. package/dist/cluster/SqlMessageStorage.js +187 -29
  195. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  196. package/dist/cluster/index.d.ts +5 -0
  197. package/dist/cluster/index.d.ts.map +1 -1
  198. package/dist/cluster/index.js +5 -0
  199. package/dist/cluster/index.js.map +1 -1
  200. package/dist/encoding/Base64.d.ts +0 -6
  201. package/dist/encoding/Base64.d.ts.map +1 -1
  202. package/dist/encoding/Base64.js +25 -5
  203. package/dist/encoding/Base64.js.map +1 -1
  204. package/dist/encoding/Base64Url.d.ts +0 -6
  205. package/dist/encoding/Base64Url.d.ts.map +1 -1
  206. package/dist/encoding/Base64Url.js +91 -8
  207. package/dist/encoding/Base64Url.js.map +1 -1
  208. package/dist/encoding/Csv.d.ts.map +1 -1
  209. package/dist/encoding/Csv.js +11 -5
  210. package/dist/encoding/Csv.js.map +1 -1
  211. package/dist/encoding/Hex.d.ts.map +1 -1
  212. package/dist/encoding/Hex.js +51 -34
  213. package/dist/encoding/Hex.js.map +1 -1
  214. package/dist/encoding/SchemaBinary.d.ts +14 -2
  215. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  216. package/dist/encoding/SchemaBinary.js +78 -5
  217. package/dist/encoding/SchemaBinary.js.map +1 -1
  218. package/dist/encoding/Xml.d.ts +25 -0
  219. package/dist/encoding/Xml.d.ts.map +1 -1
  220. package/dist/encoding/Xml.js +44 -19
  221. package/dist/encoding/Xml.js.map +1 -1
  222. package/dist/graphql/GraphQL.d.ts.map +1 -1
  223. package/dist/graphql/GraphQL.js +4 -1
  224. package/dist/graphql/GraphQL.js.map +1 -1
  225. package/dist/http/Headers.d.ts +5 -1
  226. package/dist/http/Headers.d.ts.map +1 -1
  227. package/dist/http/Headers.js +7 -2
  228. package/dist/http/Headers.js.map +1 -1
  229. package/dist/http/HttpClient.d.ts +57 -12
  230. package/dist/http/HttpClient.d.ts.map +1 -1
  231. package/dist/http/HttpClient.js +92 -54
  232. package/dist/http/HttpClient.js.map +1 -1
  233. package/dist/http/HttpClientError.d.ts +22 -8
  234. package/dist/http/HttpClientError.d.ts.map +1 -1
  235. package/dist/http/HttpClientError.js +68 -14
  236. package/dist/http/HttpClientError.js.map +1 -1
  237. package/dist/http/HttpEffect.d.ts +63 -4
  238. package/dist/http/HttpEffect.d.ts.map +1 -1
  239. package/dist/http/HttpEffect.js +89 -9
  240. package/dist/http/HttpEffect.js.map +1 -1
  241. package/dist/http/HttpMiddleware.js +1 -1
  242. package/dist/http/HttpMiddleware.js.map +1 -1
  243. package/dist/http/HttpServer.d.ts +80 -0
  244. package/dist/http/HttpServer.d.ts.map +1 -1
  245. package/dist/http/HttpServer.js +16 -0
  246. package/dist/http/HttpServer.js.map +1 -1
  247. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  248. package/dist/http/HttpServerRequest.js +1 -14
  249. package/dist/http/HttpServerRequest.js.map +1 -1
  250. package/dist/http/HttpStaticServer.js +10 -16
  251. package/dist/http/HttpStaticServer.js.map +1 -1
  252. package/dist/http-api/HttpApiBuilder.js +9 -1
  253. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  254. package/dist/http-api/HttpApiSchema.d.ts +19 -0
  255. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  256. package/dist/http-api/HttpApiSchema.js +8 -1
  257. package/dist/http-api/HttpApiSchema.js.map +1 -1
  258. package/dist/index.d.ts +5 -0
  259. package/dist/index.d.ts.map +1 -1
  260. package/dist/index.js +5 -0
  261. package/dist/index.js.map +1 -1
  262. package/dist/internal/base64.d.ts +2 -0
  263. package/dist/internal/base64.d.ts.map +1 -0
  264. package/dist/internal/base64.js +30 -0
  265. package/dist/internal/base64.js.map +1 -0
  266. package/dist/internal/core.js +3 -4
  267. package/dist/internal/core.js.map +1 -1
  268. package/dist/internal/dateTime.js +18 -10
  269. package/dist/internal/dateTime.js.map +1 -1
  270. package/dist/internal/effect.js +41 -17
  271. package/dist/internal/effect.js.map +1 -1
  272. package/dist/internal/equal.js +7 -0
  273. package/dist/internal/equal.js.map +1 -1
  274. package/dist/internal/matcher.js +1 -1
  275. package/dist/internal/matcher.js.map +1 -1
  276. package/dist/internal/schema/codegen.js +7 -7
  277. package/dist/internal/schema/codegen.js.map +1 -1
  278. package/dist/internal/schema/fromJsonSchemaDocument.js +20 -1
  279. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  280. package/dist/internal/schema/interpreter.js +10 -10
  281. package/dist/internal/schema/interpreter.js.map +1 -1
  282. package/dist/internal/schema/parser.js +9 -4
  283. package/dist/internal/schema/parser.js.map +1 -1
  284. package/dist/internal/schema/toEquivalence.js +6 -5
  285. package/dist/internal/schema/toEquivalence.js.map +1 -1
  286. package/dist/internal/schema/toFormatter.js +3 -2
  287. package/dist/internal/schema/toFormatter.js.map +1 -1
  288. package/dist/internal/version.js +1 -1
  289. package/dist/observability/OtlpMetrics.js +1 -1
  290. package/dist/observability/OtlpMetrics.js.map +1 -1
  291. package/dist/observability/OtlpTracer.js +2 -2
  292. package/dist/observability/OtlpTracer.js.map +1 -1
  293. package/dist/persistence/PersistedQueue.d.ts +72 -3
  294. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  295. package/dist/persistence/PersistedQueue.js +142 -29
  296. package/dist/persistence/PersistedQueue.js.map +1 -1
  297. package/dist/persistence/RateLimiter.d.ts +12 -2
  298. package/dist/persistence/RateLimiter.d.ts.map +1 -1
  299. package/dist/persistence/RateLimiter.js +11 -4
  300. package/dist/persistence/RateLimiter.js.map +1 -1
  301. package/dist/process/CommandLine.d.ts +9 -9
  302. package/dist/process/CommandLine.js +6 -6
  303. package/dist/process/index.d.ts +1 -1
  304. package/dist/process/index.js +1 -1
  305. package/dist/reactivity/Atom.d.ts.map +1 -1
  306. package/dist/reactivity/Atom.js +24 -3
  307. package/dist/reactivity/Atom.js.map +1 -1
  308. package/dist/reactivity/AtomRpc.d.ts +24 -6
  309. package/dist/reactivity/AtomRpc.d.ts.map +1 -1
  310. package/dist/reactivity/AtomRpc.js.map +1 -1
  311. package/dist/rpc/OpenRpc.d.ts +384 -0
  312. package/dist/rpc/OpenRpc.d.ts.map +1 -0
  313. package/dist/rpc/OpenRpc.js +490 -0
  314. package/dist/rpc/OpenRpc.js.map +1 -0
  315. package/dist/rpc/Rpc.d.ts +22 -3
  316. package/dist/rpc/Rpc.d.ts.map +1 -1
  317. package/dist/rpc/Rpc.js.map +1 -1
  318. package/dist/rpc/RpcClient.d.ts +20 -21
  319. package/dist/rpc/RpcClient.d.ts.map +1 -1
  320. package/dist/rpc/RpcClient.js.map +1 -1
  321. package/dist/rpc/RpcServer.d.ts +23 -2
  322. package/dist/rpc/RpcServer.d.ts.map +1 -1
  323. package/dist/rpc/RpcServer.js +67 -25
  324. package/dist/rpc/RpcServer.js.map +1 -1
  325. package/dist/rpc/index.d.ts +5 -0
  326. package/dist/rpc/index.d.ts.map +1 -1
  327. package/dist/rpc/index.js +5 -0
  328. package/dist/rpc/index.js.map +1 -1
  329. package/dist/schema/SchemaCompiler/runtime.js +3 -2
  330. package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
  331. package/dist/sql/SqlClient.d.ts +59 -6
  332. package/dist/sql/SqlClient.d.ts.map +1 -1
  333. package/dist/sql/SqlClient.js +64 -17
  334. package/dist/sql/SqlClient.js.map +1 -1
  335. package/dist/sql/Statement.d.ts +1 -1
  336. package/dist/sql/Statement.d.ts.map +1 -1
  337. package/dist/sql/Statement.js +9 -16
  338. package/dist/sql/Statement.js.map +1 -1
  339. package/dist/testing/TestClock.d.ts +2 -12
  340. package/dist/testing/TestClock.d.ts.map +1 -1
  341. package/dist/testing/TestClock.js +177 -169
  342. package/dist/testing/TestClock.js.map +1 -1
  343. package/dist/workflow/DurableClock.d.ts +27 -0
  344. package/dist/workflow/DurableClock.d.ts.map +1 -1
  345. package/dist/workflow/DurableClock.js +18 -2
  346. package/dist/workflow/DurableClock.js.map +1 -1
  347. package/dist/workflow/Workflow.d.ts.map +1 -1
  348. package/dist/workflow/Workflow.js +5 -4
  349. package/dist/workflow/Workflow.js.map +1 -1
  350. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  351. package/dist/workflow/WorkflowEngine.js +14 -3
  352. package/dist/workflow/WorkflowEngine.js.map +1 -1
  353. package/package.json +3 -3
  354. package/src/DateTime.ts +35 -2
  355. package/src/Match.ts +10 -8
  356. package/src/Queue.ts +16 -11
  357. package/src/Rational.ts +1549 -0
  358. package/src/RcMap.ts +16 -14
  359. package/src/Runtime.ts +84 -4
  360. package/src/Schema.ts +188 -29
  361. package/src/SchemaAST.ts +29 -13
  362. package/src/SchemaParser.ts +2 -2
  363. package/src/SchemaRepresentation.ts +13 -0
  364. package/src/ScopedCache.ts +18 -1
  365. package/src/ai/AgUi.ts +485 -0
  366. package/src/ai/AgUiSchema.ts +1666 -0
  367. package/src/ai/AgUiServer.ts +451 -0
  368. package/src/ai/Chat.ts +78 -16
  369. package/src/ai/LanguageModel.ts +27 -9
  370. package/src/ai/McpClient.ts +11 -1
  371. package/src/ai/McpServer.ts +247 -50
  372. package/src/ai/Prompt.ts +6 -2
  373. package/src/ai/Response.ts +19 -3
  374. package/src/ai/Tool.ts +426 -110
  375. package/src/ai/Toolkit.ts +71 -10
  376. package/src/ai/index.ts +18 -0
  377. package/src/ai/internal/mcpCore.ts +11 -15
  378. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +9 -14
  379. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +9 -14
  380. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +9 -11
  381. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +9 -11
  382. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +76 -55
  383. package/src/ai/internal/mcpProtocol.ts +22 -3
  384. package/src/ai/internal/mcpProtocolRegistry.ts +5 -0
  385. package/src/ai/internal/mcpRuntime.ts +10 -4
  386. package/src/ai/internal/mcpSchema/v2024_11_05.ts +0 -2
  387. package/src/ai/internal/mcpSchema/v2025_03_26.ts +0 -2
  388. package/src/ai/internal/mcpSchema/v2025_06_18.ts +0 -2
  389. package/src/ai/internal/mcpSchema/v2025_11_25.ts +0 -2
  390. package/src/ai/internal/mcpSchema/v2026_07_28.ts +0 -2
  391. package/src/ai/internal/mcpSkills.ts +3 -86
  392. package/src/ai/internal/mcpStatefulRuntime.ts +0 -2
  393. package/src/ai/internal/structured-output.ts +1 -1
  394. package/src/cli/Argument.ts +86 -0
  395. package/src/cli/CliError.ts +7 -4
  396. package/src/cli/Command.ts +261 -35
  397. package/src/cli/CommandSpec.ts +508 -0
  398. package/src/cli/Completions.ts +5 -0
  399. package/src/cli/Flag.ts +106 -0
  400. package/src/cli/Param.ts +225 -23
  401. package/src/cli/index.ts +6 -0
  402. package/src/cli/internal/command.ts +3 -4
  403. package/src/cli/internal/completions/bash.ts +9 -7
  404. package/src/cli/internal/completions/descriptor.ts +37 -5
  405. package/src/cli/internal/completions/fish.ts +9 -3
  406. package/src/cli/internal/completions/powershell.ts +2 -1
  407. package/src/cli/internal/completions/zsh.ts +2 -2
  408. package/src/cluster/ClusterWorkflowEngine.ts +14 -15
  409. package/src/cluster/Entity.ts +24 -0
  410. package/src/cluster/MessageRetention.ts +111 -0
  411. package/src/cluster/MessageStorage.ts +73 -2
  412. package/src/cluster/ShardingConfig.ts +12 -1
  413. package/src/cluster/SqlMessageStorage.ts +271 -41
  414. package/src/cluster/index.ts +6 -0
  415. package/src/encoding/Base64.ts +26 -5
  416. package/src/encoding/Base64Url.ts +93 -10
  417. package/src/encoding/Csv.ts +11 -5
  418. package/src/encoding/Hex.ts +56 -42
  419. package/src/encoding/SchemaBinary.ts +76 -5
  420. package/src/encoding/Xml.ts +65 -16
  421. package/src/graphql/GraphQL.ts +7 -4
  422. package/src/http/Headers.ts +7 -2
  423. package/src/http/HttpClient.ts +118 -68
  424. package/src/http/HttpClientError.ts +82 -15
  425. package/src/http/HttpEffect.ts +101 -10
  426. package/src/http/HttpMiddleware.ts +2 -2
  427. package/src/http/HttpServer.ts +80 -0
  428. package/src/http/HttpServerRequest.ts +1 -19
  429. package/src/http/HttpStaticServer.ts +10 -16
  430. package/src/http-api/HttpApiBuilder.ts +11 -1
  431. package/src/http-api/HttpApiSchema.ts +22 -1
  432. package/src/index.ts +6 -0
  433. package/src/internal/base64.ts +42 -0
  434. package/src/internal/core.ts +3 -4
  435. package/src/internal/dateTime.ts +27 -13
  436. package/src/internal/effect.ts +45 -18
  437. package/src/internal/equal.ts +8 -0
  438. package/src/internal/matcher.ts +7 -3
  439. package/src/internal/schema/codegen.ts +8 -7
  440. package/src/internal/schema/fromJsonSchemaDocument.ts +21 -1
  441. package/src/internal/schema/interpreter.ts +10 -10
  442. package/src/internal/schema/parser.ts +8 -4
  443. package/src/internal/schema/toEquivalence.ts +7 -5
  444. package/src/internal/schema/toFormatter.ts +3 -2
  445. package/src/internal/version.ts +1 -1
  446. package/src/observability/OtlpMetrics.ts +1 -1
  447. package/src/observability/OtlpTracer.ts +2 -2
  448. package/src/persistence/PersistedQueue.ts +199 -41
  449. package/src/persistence/RateLimiter.ts +17 -5
  450. package/src/process/CommandLine.ts +10 -10
  451. package/src/process/index.ts +1 -1
  452. package/src/reactivity/Atom.ts +25 -3
  453. package/src/reactivity/AtomRpc.ts +61 -45
  454. package/src/rpc/OpenRpc.ts +747 -0
  455. package/src/rpc/Rpc.ts +38 -6
  456. package/src/rpc/RpcClient.ts +45 -82
  457. package/src/rpc/RpcServer.ts +77 -28
  458. package/src/rpc/index.ts +6 -0
  459. package/src/schema/SchemaCompiler/runtime.ts +8 -3
  460. package/src/sql/SqlClient.ts +112 -26
  461. package/src/sql/Statement.ts +19 -23
  462. package/src/testing/TestClock.ts +204 -189
  463. package/src/workflow/DurableClock.ts +20 -3
  464. package/src/workflow/Workflow.ts +5 -3
  465. package/src/workflow/WorkflowEngine.ts +20 -5
@@ -0,0 +1,880 @@
1
+ /**
2
+ * Exact rational numbers for ratios that decimal arithmetic cannot represent.
3
+ * A `Rational` stores a `bigint` numerator and denominator in lowest terms, so
4
+ * values such as one third survive multiplication, comparison and compounding
5
+ * without rounding. Use `BigDecimal` for decimal quantities such as money, and
6
+ * `Rational` when a ratio must stay exact until an explicit conversion.
7
+ *
8
+ * @stability unstable
9
+ * @since 4.1.3
10
+ */
11
+ import * as BigDecimal from "./BigDecimal.js";
12
+ import * as BI from "./BigInt.js";
13
+ import * as Equal from "./Equal.js";
14
+ import * as Equ from "./Equivalence.js";
15
+ import { dual } from "./Function.js";
16
+ import * as Hash from "./Hash.js";
17
+ import { NodeInspectSymbol } from "./Inspectable.js";
18
+ import * as Option from "./Option.js";
19
+ import * as order from "./Order.js";
20
+ import { pipeArguments } from "./Pipeable.js";
21
+ import { hasProperty } from "./Predicate.js";
22
+ const TypeId = "~effect/Rational";
23
+ const bigint0 = /*#__PURE__*/BigInt(0);
24
+ const bigint1 = /*#__PURE__*/BigInt(1);
25
+ const bigint2 = /*#__PURE__*/BigInt(2);
26
+ const bigint10 = /*#__PURE__*/BigInt(10);
27
+ const FRACTION_REGEXP = /^([+-]?\d+)(?:\/([+-]?\d+))?$/;
28
+ const QUOTIENT_BITS = 64;
29
+ const MANTISSA_BITS = 53;
30
+ const MIN_SUBNORMAL_EXPONENT = -1074;
31
+ const RationalProto = {
32
+ [TypeId]: TypeId,
33
+ [Hash.symbol]() {
34
+ return Hash.combine(Hash.hash(this.numerator), Hash.hash(this.denominator));
35
+ },
36
+ [Equal.symbol](that) {
37
+ return isRational(that) && Equivalence(this, that);
38
+ },
39
+ toString() {
40
+ return `Rational(${format(this)})`;
41
+ },
42
+ toJSON() {
43
+ return {
44
+ _id: "Rational",
45
+ numerator: String(this.numerator),
46
+ denominator: String(this.denominator)
47
+ };
48
+ },
49
+ [NodeInspectSymbol]() {
50
+ return this.toJSON();
51
+ },
52
+ pipe() {
53
+ return pipeArguments(this, arguments);
54
+ }
55
+ };
56
+ // Both arguments must already be coprime with a positive denominator.
57
+ const canonical = (numerator, denominator) => {
58
+ const rational = Object.create(RationalProto);
59
+ rational.numerator = numerator;
60
+ rational.denominator = denominator;
61
+ return rational;
62
+ };
63
+ // `denominator` must be non-zero.
64
+ const reduce = (numerator, denominator) => {
65
+ if (denominator < bigint0) {
66
+ numerator = -numerator;
67
+ denominator = -denominator;
68
+ }
69
+ const divisor = BI.gcd(numerator, denominator);
70
+ return canonical(numerator / divisor, denominator / divisor);
71
+ };
72
+ // Both pairs must already be coprime with positive denominators. The sum can only
73
+ // share factors with the denominators' gcd (Knuth, TAOCP vol. 2, §4.5.1).
74
+ const sumCoprime = (n1, d1, n2, d2) => {
75
+ const g = BI.gcd(d1, d2);
76
+ if (g === bigint1) {
77
+ return canonical(n1 * d2 + n2 * d1, d1 * d2);
78
+ }
79
+ const t = n1 * (d2 / g) + n2 * (d1 / g);
80
+ const e = BI.gcd(t, g);
81
+ return canonical(t / e, d1 / g * (d2 / e));
82
+ };
83
+ // Both pairs must already be coprime with positive denominators. Canonical fractions share factors
84
+ // only crosswise, so cancelling those first leaves the products coprime (Knuth, TAOCP vol. 2, §4.5.1).
85
+ const multiplyCoprime = (n1, d1, n2, d2) => {
86
+ const g1 = BI.gcd(n1, d2);
87
+ const g2 = BI.gcd(n2, d1);
88
+ return canonical(n1 / g1 * (n2 / g2), d1 / g2 * (d2 / g1));
89
+ };
90
+ const zero = /*#__PURE__*/canonical(bigint0, bigint1);
91
+ const one = /*#__PURE__*/canonical(bigint1, bigint1);
92
+ /**
93
+ * Checks whether a given value is a `Rational`.
94
+ *
95
+ * **Example** (Checking Rational values)
96
+ *
97
+ * ```ts import.meta.vitest
98
+ * import { Rational } from "effect"
99
+ *
100
+ * Rational.isRational(Rational.fromBigInt(1n)) // => true
101
+ * Rational.isRational("1/3") // => false
102
+ * ```
103
+ *
104
+ * @stability unstable
105
+ * @category guards
106
+ * @since 4.1.3
107
+ */
108
+ export const isRational = u => hasProperty(u, TypeId);
109
+ /**
110
+ * Creates a `Rational` from a numerator and denominator, returning
111
+ * `Option.none()` when the denominator is zero.
112
+ *
113
+ * **Details**
114
+ *
115
+ * The result is reduced to lowest terms with a positive denominator, so
116
+ * `make(6n, -4n)` and `make(-3n, 2n)` produce the same value.
117
+ *
118
+ * **Example** (Creating rationals safely)
119
+ *
120
+ * ```ts import.meta.vitest
121
+ * import { Option, Rational } from "effect"
122
+ *
123
+ * Rational.make(6n, -4n) // => Option.some(Rational.makeUnsafe(-3n, 2n))
124
+ * Rational.make(1n, 0n) // => Option.none()
125
+ * ```
126
+ *
127
+ * @see {@link makeUnsafe} for throwing on a zero denominator
128
+ *
129
+ * @stability unstable
130
+ * @category constructors
131
+ * @since 4.1.3
132
+ */
133
+ export const make = (numerator, denominator) => denominator === bigint0 ? Option.none() : Option.some(reduce(numerator, denominator));
134
+ /**
135
+ * Creates a `Rational` from a numerator and denominator.
136
+ *
137
+ * **Gotchas**
138
+ *
139
+ * Throws a `RangeError` if the denominator is zero.
140
+ *
141
+ * **Example** (Creating rationals from bigint pairs)
142
+ *
143
+ * ```ts import.meta.vitest
144
+ * import { Rational } from "effect"
145
+ *
146
+ * Rational.format(Rational.makeUnsafe(2n, 6n)) // => "1/3"
147
+ * ```
148
+ *
149
+ * @see {@link make} for returning `Option.none` on a zero denominator
150
+ *
151
+ * @stability unstable
152
+ * @category constructors
153
+ * @since 4.1.3
154
+ */
155
+ export const makeUnsafe = (numerator, denominator) => {
156
+ if (denominator === bigint0) {
157
+ throw new RangeError("Denominator must be non-zero");
158
+ }
159
+ return reduce(numerator, denominator);
160
+ };
161
+ /**
162
+ * Creates an integer `Rational` from a `bigint`.
163
+ *
164
+ * **Example** (Creating rationals from bigint)
165
+ *
166
+ * ```ts import.meta.vitest
167
+ * import { Rational } from "effect"
168
+ *
169
+ * Rational.format(Rational.fromBigInt(-3n)) // => "-3/1"
170
+ * ```
171
+ *
172
+ * @stability unstable
173
+ * @category constructors
174
+ * @since 4.1.3
175
+ */
176
+ export const fromBigInt = n => canonical(n, bigint1);
177
+ /**
178
+ * Converts a `BigDecimal` to the exact `Rational` it denotes.
179
+ *
180
+ * **When to use**
181
+ *
182
+ * Use as the exact route from decimal text: `0.1` becomes `1/10`, which
183
+ * {@link fromNumber} cannot produce.
184
+ *
185
+ * **Example** (Converting decimals exactly)
186
+ *
187
+ * ```ts import.meta.vitest
188
+ * import { BigDecimal, Rational } from "effect"
189
+ *
190
+ * Rational.fromBigDecimal(BigDecimal.fromStringUnsafe("-12.50")) // => Rational.makeUnsafe(-25n, 2n)
191
+ * ```
192
+ *
193
+ * @see {@link toBigDecimal} for the rounded conversion back
194
+ *
195
+ * @stability unstable
196
+ * @category constructors
197
+ * @since 4.1.3
198
+ */
199
+ export const fromBigDecimal = n => {
200
+ const normalized = BigDecimal.normalize(n);
201
+ return normalized.scale >= 0 ? reduce(normalized.value, bigint10 ** BigInt(normalized.scale)) : canonical(normalized.value * bigint10 ** BigInt(-normalized.scale), bigint1);
202
+ };
203
+ /**
204
+ * Creates a `Rational` from a finite `number`, returning `Option.none()` for
205
+ * `NaN`, `+Infinity` and `-Infinity`.
206
+ *
207
+ * **Details**
208
+ *
209
+ * The result is the exact binary value of the number, not its decimal display.
210
+ * Negative zero becomes `0/1`.
211
+ *
212
+ * **Gotchas**
213
+ *
214
+ * `0.1` is not one tenth: the nearest double is `3602879701896397 / 2^55`, and
215
+ * that is the value this function returns. Use {@link fromBigDecimal} with a
216
+ * decimal string when the decimal reading is intended.
217
+ *
218
+ * **Example** (Creating rationals from numbers)
219
+ *
220
+ * ```ts import.meta.vitest
221
+ * import { Option, Rational } from "effect"
222
+ *
223
+ * Rational.fromNumber(0.75) // => Option.some(Rational.makeUnsafe(3n, 4n))
224
+ * Rational.fromNumber(NaN) // => Option.none()
225
+ * ```
226
+ *
227
+ * @see {@link fromNumberUnsafe} for throwing when the number is not finite
228
+ *
229
+ * @stability unstable
230
+ * @category constructors
231
+ * @since 4.1.3
232
+ */
233
+ export const fromNumber = n => {
234
+ if (!Number.isFinite(n)) {
235
+ return Option.none();
236
+ }
237
+ if (n === 0) {
238
+ return Option.some(zero);
239
+ }
240
+ // Doubling is exact, and a finite double becomes integral within 1074 steps.
241
+ let scaled = n;
242
+ let exponent = 0;
243
+ while (!Number.isInteger(scaled)) {
244
+ scaled *= 2;
245
+ exponent++;
246
+ }
247
+ return Option.some(reduce(BigInt(scaled), bigint1 << BigInt(exponent)));
248
+ };
249
+ /**
250
+ * Creates a `Rational` from a finite `number`.
251
+ *
252
+ * **Gotchas**
253
+ *
254
+ * Throws a `RangeError` if the number is not finite. See {@link fromNumber}
255
+ * for why `0.1` does not become one tenth.
256
+ *
257
+ * **Example** (Creating rationals from trusted numbers)
258
+ *
259
+ * ```ts import.meta.vitest
260
+ * import { Rational } from "effect"
261
+ *
262
+ * Rational.fromNumberUnsafe(0.5) // => Rational.makeUnsafe(1n, 2n)
263
+ * ```
264
+ *
265
+ * @see {@link fromNumber} for returning `Option.none` when the number is not finite
266
+ *
267
+ * @stability unstable
268
+ * @category constructors
269
+ * @since 4.1.3
270
+ */
271
+ export const fromNumberUnsafe = n => Option.getOrThrowWith(fromNumber(n), () => new RangeError(`Number must be finite, got ${n}`));
272
+ /**
273
+ * Parses an integer or fraction string into a `Rational` safely.
274
+ *
275
+ * **Details**
276
+ *
277
+ * Accepts `[+-]digits` or `[+-]digits/[+-]digits`. Reducible fractions and
278
+ * negative denominators are normalized. Whitespace, decimal points, exponents,
279
+ * the empty string and a zero denominator produce `Option.none()`.
280
+ *
281
+ * **Example** (Parsing fraction strings)
282
+ *
283
+ * ```ts import.meta.vitest
284
+ * import { Option, Rational } from "effect"
285
+ *
286
+ * Rational.fromString("-4/-6") // => Option.some(Rational.makeUnsafe(2n, 3n))
287
+ * Rational.fromString("3") // => Option.some(Rational.fromBigInt(3n))
288
+ * Rational.fromString("1.5") // => Option.none()
289
+ * ```
290
+ *
291
+ * @see {@link fromStringUnsafe} for parsing that throws on invalid input
292
+ * @see {@link format} for the inverse operation
293
+ *
294
+ * @stability unstable
295
+ * @category constructors
296
+ * @since 4.1.3
297
+ */
298
+ export const fromString = s => {
299
+ const match = FRACTION_REGEXP.exec(s);
300
+ if (match === null) {
301
+ return Option.none();
302
+ }
303
+ return make(BigInt(match[1]), match[2] === undefined ? bigint1 : BigInt(match[2]));
304
+ };
305
+ /**
306
+ * Parses an integer or fraction string into a `Rational`.
307
+ *
308
+ * **Gotchas**
309
+ *
310
+ * Throws an `Error` if the string is not a valid fraction. See
311
+ * {@link fromString} for the accepted grammar.
312
+ *
313
+ * **Example** (Parsing trusted fraction strings)
314
+ *
315
+ * ```ts import.meta.vitest
316
+ * import { Rational } from "effect"
317
+ *
318
+ * Rational.fromStringUnsafe("6/5") // => Rational.makeUnsafe(6n, 5n)
319
+ * ```
320
+ *
321
+ * @see {@link fromString} for returning `Option.none` on invalid input
322
+ *
323
+ * @stability unstable
324
+ * @category constructors
325
+ * @since 4.1.3
326
+ */
327
+ export const fromStringUnsafe = s => Option.getOrThrowWith(fromString(s), () => new Error(`Invalid rational string: ${s}`));
328
+ /**
329
+ * Adds two rationals exactly.
330
+ *
331
+ * **Example** (Adding rationals)
332
+ *
333
+ * ```ts import.meta.vitest
334
+ * import { Rational } from "effect"
335
+ *
336
+ * Rational.sum(Rational.makeUnsafe(1n, 3n), Rational.makeUnsafe(1n, 6n)) // => Rational.makeUnsafe(1n, 2n)
337
+ * ```
338
+ *
339
+ * @stability unstable
340
+ * @category math
341
+ * @since 4.1.3
342
+ */
343
+ export const sum = /*#__PURE__*/dual(2, (self, that) => sumCoprime(self.numerator, self.denominator, that.numerator, that.denominator));
344
+ /**
345
+ * Sums all rationals in an iterable, returning zero for an empty collection.
346
+ *
347
+ * **Example** (Summing rationals)
348
+ *
349
+ * ```ts import.meta.vitest
350
+ * import { Rational } from "effect"
351
+ *
352
+ * const third = Rational.makeUnsafe(1n, 3n)
353
+ *
354
+ * Rational.sumAll([third, third, third]) // => Rational.fromBigInt(1n)
355
+ * ```
356
+ *
357
+ * @stability unstable
358
+ * @category math
359
+ * @since 4.1.3
360
+ */
361
+ export const sumAll = collection => {
362
+ let out = zero;
363
+ for (const n of collection) {
364
+ out = sum(out, n);
365
+ }
366
+ return out;
367
+ };
368
+ /**
369
+ * Subtracts `that` from `self` exactly.
370
+ *
371
+ * **Example** (Subtracting rationals)
372
+ *
373
+ * ```ts import.meta.vitest
374
+ * import { Rational } from "effect"
375
+ *
376
+ * Rational.subtract(Rational.fromBigInt(1n), Rational.makeUnsafe(1n, 3n)) // => Rational.makeUnsafe(2n, 3n)
377
+ * ```
378
+ *
379
+ * @stability unstable
380
+ * @category math
381
+ * @since 4.1.3
382
+ */
383
+ export const subtract = /*#__PURE__*/dual(2, (self, that) => sumCoprime(self.numerator, self.denominator, -that.numerator, that.denominator));
384
+ /**
385
+ * Multiplies two rationals exactly.
386
+ *
387
+ * **Example** (Multiplying rationals)
388
+ *
389
+ * ```ts import.meta.vitest
390
+ * import { Rational } from "effect"
391
+ *
392
+ * Rational.multiply(Rational.makeUnsafe(1n, 3n), Rational.fromBigInt(3n)) // => Rational.fromBigInt(1n)
393
+ * ```
394
+ *
395
+ * @stability unstable
396
+ * @category math
397
+ * @since 4.1.3
398
+ */
399
+ export const multiply = /*#__PURE__*/dual(2, (self, that) => multiplyCoprime(self.numerator, self.denominator, that.numerator, that.denominator));
400
+ /**
401
+ * Multiplies all rationals in an iterable, returning one for an empty
402
+ * collection.
403
+ *
404
+ * **Example** (Compounding ratios)
405
+ *
406
+ * ```ts import.meta.vitest
407
+ * import { Rational } from "effect"
408
+ *
409
+ * Rational.multiplyAll([Rational.makeUnsafe(3n, 2n), Rational.makeUnsafe(4n, 3n)]) // => Rational.fromBigInt(2n)
410
+ * ```
411
+ *
412
+ * @stability unstable
413
+ * @category math
414
+ * @since 4.1.3
415
+ */
416
+ export const multiplyAll = collection => {
417
+ let out = one;
418
+ for (const n of collection) {
419
+ if (n.numerator === bigint0) {
420
+ return zero;
421
+ }
422
+ out = multiply(out, n);
423
+ }
424
+ return out;
425
+ };
426
+ /**
427
+ * Divides `self` by `that`, returning `Option.none()` when `that` is zero.
428
+ *
429
+ * **Example** (Dividing rationals safely)
430
+ *
431
+ * ```ts import.meta.vitest
432
+ * import { Option, Rational } from "effect"
433
+ *
434
+ * const third = Rational.makeUnsafe(1n, 3n)
435
+ *
436
+ * Rational.divide(third, Rational.fromBigInt(3n)) // => Option.some(Rational.makeUnsafe(1n, 9n))
437
+ * Rational.divide(third, Rational.fromBigInt(0n)) // => Option.none()
438
+ * ```
439
+ *
440
+ * @see {@link divideUnsafe} for division that throws when the divisor is zero
441
+ *
442
+ * @stability unstable
443
+ * @category math
444
+ * @since 4.1.3
445
+ */
446
+ export const divide = /*#__PURE__*/dual(2, (self, that) => that.numerator === bigint0 ? Option.none() : Option.some(that.numerator < bigint0 ? multiplyCoprime(self.numerator, self.denominator, -that.denominator, -that.numerator) : multiplyCoprime(self.numerator, self.denominator, that.denominator, that.numerator)));
447
+ /**
448
+ * Divides `self` by `that`.
449
+ *
450
+ * **Gotchas**
451
+ *
452
+ * Throws a `RangeError` if the divisor is zero.
453
+ *
454
+ * **Example** (Dividing rationals)
455
+ *
456
+ * ```ts import.meta.vitest
457
+ * import { Rational } from "effect"
458
+ *
459
+ * Rational.divideUnsafe(Rational.makeUnsafe(-2n, 3n), Rational.makeUnsafe(4n, 9n)) // => Rational.makeUnsafe(-3n, 2n)
460
+ * ```
461
+ *
462
+ * @see {@link divide} for division that returns `Option.none` when the divisor is zero
463
+ *
464
+ * @stability unstable
465
+ * @category math
466
+ * @since 4.1.3
467
+ */
468
+ export const divideUnsafe = /*#__PURE__*/dual(2, (self, that) => Option.getOrThrowWith(divide(self, that), divisionByZero));
469
+ const divisionByZero = () => new RangeError("Division by zero");
470
+ /**
471
+ * Raises a rational to an integer power, returning `Option.none()` for zero
472
+ * raised to a negative exponent.
473
+ *
474
+ * **Details**
475
+ *
476
+ * A negative exponent inverts the fraction before raising it, and any value
477
+ * to the power zero is one, including zero itself.
478
+ *
479
+ * **Gotchas**
480
+ *
481
+ * The exponent must be a safe integer. Anything else, including `0.5`, `NaN`
482
+ * and `Infinity`, throws a `RangeError` instead of being rounded.
483
+ *
484
+ * **Example** (Raising to integer powers)
485
+ *
486
+ * ```ts import.meta.vitest
487
+ * import { Option, Rational } from "effect"
488
+ *
489
+ * Rational.pow(Rational.makeUnsafe(1n, 3n), -1) // => Option.some(Rational.fromBigInt(3n))
490
+ * Rational.pow(Rational.fromBigInt(0n), -1) // => Option.none()
491
+ * ```
492
+ *
493
+ * @see {@link powUnsafe} for throwing when zero is raised to a negative exponent
494
+ *
495
+ * @stability unstable
496
+ * @category math
497
+ * @since 4.1.3
498
+ */
499
+ export const pow = /*#__PURE__*/dual(2, (self, exponent) => {
500
+ if (!Number.isSafeInteger(exponent)) {
501
+ throw new RangeError(`Exponent must be a safe integer, got ${exponent}`);
502
+ }
503
+ if (exponent === 0) {
504
+ return Option.some(one);
505
+ }
506
+ if (exponent > 0) {
507
+ const e = BigInt(exponent);
508
+ return Option.some(canonical(self.numerator ** e, self.denominator ** e));
509
+ }
510
+ if (self.numerator === bigint0) {
511
+ return Option.none();
512
+ }
513
+ // Powers of coprime integers stay coprime, so only the sign needs fixing.
514
+ const e = BigInt(-exponent);
515
+ const numerator = self.numerator ** e;
516
+ const denominator = self.denominator ** e;
517
+ return Option.some(numerator < bigint0 ? canonical(-denominator, -numerator) : canonical(denominator, numerator));
518
+ });
519
+ /**
520
+ * Raises a rational to an integer power.
521
+ *
522
+ * **Gotchas**
523
+ *
524
+ * Throws a `RangeError` for zero raised to a negative exponent, and for an
525
+ * exponent that is not a safe integer.
526
+ *
527
+ * **Example** (Compounding a ratio)
528
+ *
529
+ * ```ts import.meta.vitest
530
+ * import { Rational } from "effect"
531
+ *
532
+ * // Twelve pure fifths overshoot seven octaves by the Pythagorean comma.
533
+ * Rational.powUnsafe(Rational.makeUnsafe(3n, 2n), 12) // => Rational.makeUnsafe(531441n, 4096n)
534
+ * ```
535
+ *
536
+ * @see {@link pow} for returning `Option.none` when zero is raised to a negative exponent
537
+ *
538
+ * @stability unstable
539
+ * @category math
540
+ * @since 4.1.3
541
+ */
542
+ export const powUnsafe = /*#__PURE__*/dual(2, (self, exponent) => Option.getOrThrowWith(pow(self, exponent), divisionByZero));
543
+ /**
544
+ * Negates a rational.
545
+ *
546
+ * @stability unstable
547
+ * @category math
548
+ * @since 4.1.3
549
+ */
550
+ export const negate = n => canonical(-n.numerator, n.denominator);
551
+ /**
552
+ * Returns the absolute value of a rational.
553
+ *
554
+ * @stability unstable
555
+ * @category math
556
+ * @since 4.1.3
557
+ */
558
+ export const abs = n => n.numerator < bigint0 ? negate(n) : n;
559
+ /**
560
+ * Returns the sign of a rational as an `Ordering`.
561
+ *
562
+ * @stability unstable
563
+ * @category math
564
+ * @since 4.1.3
565
+ */
566
+ export const sign = n => n.numerator === bigint0 ? 0 : n.numerator < bigint0 ? -1 : 1;
567
+ const compare = (self, that) => {
568
+ // Denominators are positive, so cross-multiplying preserves the ordering.
569
+ const left = self.numerator * that.denominator;
570
+ const right = that.numerator * self.denominator;
571
+ return left < right ? -1 : left > right ? 1 : 0;
572
+ };
573
+ /**
574
+ * An `Order` instance comparing rationals by exact value.
575
+ *
576
+ * **Example** (Comparing rationals)
577
+ *
578
+ * ```ts import.meta.vitest
579
+ * import { BigDecimal, Rational } from "effect"
580
+ *
581
+ * const third = Rational.makeUnsafe(1n, 3n)
582
+ * const nearlyThird = Rational.fromBigDecimal(BigDecimal.fromStringUnsafe("0.3333333333"))
583
+ *
584
+ * Rational.Order(third, nearlyThird) // => 1
585
+ * ```
586
+ *
587
+ * @stability unstable
588
+ * @category instances
589
+ * @since 4.1.3
590
+ */
591
+ export const Order = /*#__PURE__*/order.make(compare);
592
+ /**
593
+ * An `Equivalence` instance for rationals. Canonical form makes this a field
594
+ * comparison.
595
+ *
596
+ * @stability unstable
597
+ * @category instances
598
+ * @since 4.1.3
599
+ */
600
+ export const Equivalence = /*#__PURE__*/Equ.make((self, that) => self.numerator === that.numerator && self.denominator === that.denominator);
601
+ /**
602
+ * Checks whether two rationals are equal.
603
+ *
604
+ * @see {@link Equivalence} for passing rational equality to APIs that require an `Equivalence`
605
+ *
606
+ * @stability unstable
607
+ * @category predicates
608
+ * @since 4.1.3
609
+ */
610
+ export const equals = /*#__PURE__*/dual(2, (self, that) => Equivalence(self, that));
611
+ /**
612
+ * Returns `true` if the first argument is less than the second.
613
+ *
614
+ * @stability unstable
615
+ * @category predicates
616
+ * @since 4.1.3
617
+ */
618
+ export const isLessThan = /*#__PURE__*/order.isLessThan(Order);
619
+ /**
620
+ * Returns `true` if the first argument is less than or equal to the second.
621
+ *
622
+ * @stability unstable
623
+ * @category predicates
624
+ * @since 4.1.3
625
+ */
626
+ export const isLessThanOrEqualTo = /*#__PURE__*/order.isLessThanOrEqualTo(Order);
627
+ /**
628
+ * Returns `true` if the first argument is greater than the second.
629
+ *
630
+ * @stability unstable
631
+ * @category predicates
632
+ * @since 4.1.3
633
+ */
634
+ export const isGreaterThan = /*#__PURE__*/order.isGreaterThan(Order);
635
+ /**
636
+ * Returns `true` if the first argument is greater than or equal to the second.
637
+ *
638
+ * @stability unstable
639
+ * @category predicates
640
+ * @since 4.1.3
641
+ */
642
+ export const isGreaterThanOrEqualTo = /*#__PURE__*/order.isGreaterThanOrEqualTo(Order);
643
+ /**
644
+ * Checks whether a rational lies within an inclusive range.
645
+ *
646
+ * @stability unstable
647
+ * @category predicates
648
+ * @since 4.1.3
649
+ */
650
+ export const between = /*#__PURE__*/order.isBetween(Order);
651
+ /**
652
+ * Restricts a rational to an inclusive range.
653
+ *
654
+ * @stability unstable
655
+ * @category math
656
+ * @since 4.1.3
657
+ */
658
+ export const clamp = /*#__PURE__*/order.clamp(Order);
659
+ /**
660
+ * Returns the smaller of two rationals.
661
+ *
662
+ * @stability unstable
663
+ * @category math
664
+ * @since 4.1.3
665
+ */
666
+ export const min = /*#__PURE__*/order.min(Order);
667
+ /**
668
+ * Returns the larger of two rationals.
669
+ *
670
+ * @stability unstable
671
+ * @category math
672
+ * @since 4.1.3
673
+ */
674
+ export const max = /*#__PURE__*/order.max(Order);
675
+ /**
676
+ * Checks whether a rational is zero.
677
+ *
678
+ * @stability unstable
679
+ * @category predicates
680
+ * @since 4.1.3
681
+ */
682
+ export const isZero = n => n.numerator === bigint0;
683
+ /**
684
+ * Checks whether a rational is strictly negative.
685
+ *
686
+ * @stability unstable
687
+ * @category predicates
688
+ * @since 4.1.3
689
+ */
690
+ export const isNegative = n => n.numerator < bigint0;
691
+ /**
692
+ * Checks whether a rational is strictly positive.
693
+ *
694
+ * @stability unstable
695
+ * @category predicates
696
+ * @since 4.1.3
697
+ */
698
+ export const isPositive = n => n.numerator > bigint0;
699
+ /**
700
+ * Checks whether a rational is an integer, that is, whether its denominator is
701
+ * one.
702
+ *
703
+ * @stability unstable
704
+ * @category predicates
705
+ * @since 4.1.3
706
+ */
707
+ export const isInteger = n => n.denominator === bigint1;
708
+ /**
709
+ * Formats a rational as `numerator/denominator`.
710
+ *
711
+ * **Details**
712
+ *
713
+ * The output is always a fraction in lowest terms, so integers render as
714
+ * `3/1` and zero as `0/1`. It is the inverse of {@link fromString}.
715
+ *
716
+ * **Example** (Formatting rationals)
717
+ *
718
+ * ```ts import.meta.vitest
719
+ * import { Rational } from "effect"
720
+ *
721
+ * Rational.format(Rational.makeUnsafe(12n, 10n)) // => "6/5"
722
+ * Rational.format(Rational.fromBigInt(0n)) // => "0/1"
723
+ * ```
724
+ *
725
+ * @stability unstable
726
+ * @category converting
727
+ * @since 4.1.3
728
+ */
729
+ export const format = n => `${n.numerator}/${n.denominator}`;
730
+ const bitLength = n => n.toString(2).length;
731
+ /**
732
+ * Converts a rational to the nearest JavaScript `number`.
733
+ *
734
+ * **Details**
735
+ *
736
+ * The ratio is rounded as a whole, so a numerator and denominator that each
737
+ * exceed `Number.MAX_VALUE` still produce a finite result when their quotient
738
+ * is finite. Every finite double round-trips through {@link fromNumber}.
739
+ *
740
+ * **Gotchas**
741
+ *
742
+ * This conversion is unsafe because most rationals are not representable as
743
+ * doubles: the result is rounded, and very large magnitudes become
744
+ * `Infinity`.
745
+ *
746
+ * **Example** (Converting rationals to numbers)
747
+ *
748
+ * ```ts import.meta.vitest
749
+ * import { Rational } from "effect"
750
+ *
751
+ * Rational.toNumberUnsafe(Rational.makeUnsafe(1n, 3n)) // => 1 / 3
752
+ * ```
753
+ *
754
+ * @see {@link toBigDecimal} for a conversion with an explicit scale
755
+ *
756
+ * @stability unstable
757
+ * @category converting
758
+ * @since 4.1.3
759
+ */
760
+ export const toNumberUnsafe = n => {
761
+ if (n.numerator === bigint0) {
762
+ return 0;
763
+ }
764
+ const negative = n.numerator < bigint0;
765
+ let numerator = negative ? -n.numerator : n.numerator;
766
+ let denominator = n.denominator;
767
+ // Shift so the integer quotient carries more bits than a double mantissa.
768
+ const shift = QUOTIENT_BITS + bitLength(denominator) - bitLength(numerator);
769
+ if (shift > 0) {
770
+ numerator <<= BigInt(shift);
771
+ } else if (shift < 0) {
772
+ denominator <<= BigInt(-shift);
773
+ }
774
+ let quotient = numerator / denominator;
775
+ if (quotient * denominator !== numerator) {
776
+ // A sticky bit keeps a truncated remainder from being mistaken for a tie.
777
+ quotient |= bigint1;
778
+ }
779
+ // Round once, at the destination precision: 53 bits for normal results, or
780
+ // units of Number.MIN_VALUE for subnormal ones. The quotient has at least 64
781
+ // bits, so at least 11 are dropped.
782
+ const exponent = Math.max(bitLength(quotient) - shift - MANTISSA_BITS, MIN_SUBNORMAL_EXPONENT);
783
+ const drop = BigInt(exponent + shift);
784
+ let rounded = quotient >> drop;
785
+ const remainder = quotient & (bigint1 << drop) - bigint1;
786
+ const half = bigint1 << drop - bigint1;
787
+ if (remainder > half || remainder === half && (rounded & bigint1) === bigint1) {
788
+ rounded += bigint1;
789
+ }
790
+ // `rounded` is at most 2^53 and `exponent` is at least -1074, so both the
791
+ // conversion and the power-of-two scaling are exact; overflow gives Infinity.
792
+ const magnitude = Number(rounded) * 2 ** exponent;
793
+ return negative ? -magnitude : magnitude;
794
+ };
795
+ /**
796
+ * Converts a rational to a `BigDecimal` rounded at the given scale.
797
+ *
798
+ * **Details**
799
+ *
800
+ * `scale` is the number of decimal places to keep; a negative scale rounds to
801
+ * tens, hundreds and so on. `mode` defaults to `"half-from-zero"`, matching
802
+ * `BigDecimal.round`.
803
+ *
804
+ * **Gotchas**
805
+ *
806
+ * Throws a `RangeError` if `scale` is not a safe integer.
807
+ *
808
+ * **Example** (Rounding rationals to decimals)
809
+ *
810
+ * ```ts import.meta.vitest
811
+ * import { BigDecimal, Rational } from "effect"
812
+ *
813
+ * const twoThirds = Rational.makeUnsafe(2n, 3n)
814
+ *
815
+ * Rational.toBigDecimal(twoThirds, { scale: 3 }) // => BigDecimal.fromStringUnsafe("0.667")
816
+ * Rational.toBigDecimal(twoThirds, { scale: 3, mode: "floor" }) // => BigDecimal.fromStringUnsafe("0.666")
817
+ * ```
818
+ *
819
+ * @see {@link fromBigDecimal} for the exact conversion back
820
+ *
821
+ * @stability unstable
822
+ * @category converting
823
+ * @since 4.1.3
824
+ */
825
+ export const toBigDecimal = /*#__PURE__*/dual(2, (self, options) => {
826
+ const scale = options.scale;
827
+ if (!Number.isSafeInteger(scale)) {
828
+ throw new RangeError(`Scale must be a safe integer, got ${scale}`);
829
+ }
830
+ let numerator = self.numerator;
831
+ let denominator = self.denominator;
832
+ if (scale >= 0) {
833
+ numerator *= bigint10 ** BigInt(scale);
834
+ } else {
835
+ denominator *= bigint10 ** BigInt(-scale);
836
+ }
837
+ const quotient = numerator / denominator;
838
+ const remainder = numerator - quotient * denominator;
839
+ return BigDecimal.make(quotient + roundingAdjustment(quotient, remainder, denominator, options.mode), scale);
840
+ });
841
+ // `remainder` carries the sign of the value; returns the unit to add to the truncated quotient.
842
+ const roundingAdjustment = (quotient, remainder, denominator, mode = "half-from-zero") => {
843
+ if (remainder === bigint0) {
844
+ return bigint0;
845
+ }
846
+ const negative = remainder < bigint0;
847
+ const awayFromZero = negative ? -bigint1 : bigint1;
848
+ switch (mode) {
849
+ case "to-zero":
850
+ return bigint0;
851
+ case "from-zero":
852
+ return awayFromZero;
853
+ case "ceil":
854
+ return negative ? bigint0 : bigint1;
855
+ case "floor":
856
+ return negative ? -bigint1 : bigint0;
857
+ }
858
+ const twiceRemainder = (negative ? -remainder : remainder) * bigint2;
859
+ if (twiceRemainder < denominator) {
860
+ return bigint0;
861
+ }
862
+ if (twiceRemainder > denominator) {
863
+ return awayFromZero;
864
+ }
865
+ switch (mode) {
866
+ case "half-ceil":
867
+ return negative ? bigint0 : bigint1;
868
+ case "half-floor":
869
+ return negative ? -bigint1 : bigint0;
870
+ case "half-to-zero":
871
+ return bigint0;
872
+ case "half-from-zero":
873
+ return awayFromZero;
874
+ case "half-even":
875
+ return quotient % bigint2 === bigint0 ? bigint0 : awayFromZero;
876
+ case "half-odd":
877
+ return quotient % bigint2 === bigint0 ? awayFromZero : bigint0;
878
+ }
879
+ };
880
+ //# sourceMappingURL=Rational.js.map