effect 4.1.5 → 4.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (441) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/dist/Channel.d.ts +104 -7
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +73 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Codegen.d.ts +7 -2
  7. package/dist/Codegen.d.ts.map +1 -1
  8. package/dist/Codegen.js +7 -2
  9. package/dist/Codegen.js.map +1 -1
  10. package/dist/Config.d.ts +1 -1
  11. package/dist/Config.d.ts.map +1 -1
  12. package/dist/Config.js +5 -3
  13. package/dist/Config.js.map +1 -1
  14. package/dist/Context.d.ts.map +1 -1
  15. package/dist/Context.js +79 -31
  16. package/dist/Context.js.map +1 -1
  17. package/dist/Cron.d.ts.map +1 -1
  18. package/dist/Cron.js +10 -9
  19. package/dist/Cron.js.map +1 -1
  20. package/dist/Effect.d.ts +139 -18
  21. package/dist/Effect.d.ts.map +1 -1
  22. package/dist/Effect.js +10 -2
  23. package/dist/Effect.js.map +1 -1
  24. package/dist/Equal.d.ts +4 -4
  25. package/dist/Equal.d.ts.map +1 -1
  26. package/dist/Equal.js +78 -66
  27. package/dist/Equal.js.map +1 -1
  28. package/dist/Formatter.js +4 -4
  29. package/dist/Formatter.js.map +1 -1
  30. package/dist/Hash.d.ts.map +1 -1
  31. package/dist/Hash.js +34 -41
  32. package/dist/Hash.js.map +1 -1
  33. package/dist/LayerRef.d.ts +1 -1
  34. package/dist/LayerRef.d.ts.map +1 -1
  35. package/dist/LayerRef.js +3 -3
  36. package/dist/LayerRef.js.map +1 -1
  37. package/dist/Logger.d.ts +37 -13
  38. package/dist/Logger.d.ts.map +1 -1
  39. package/dist/Logger.js +39 -10
  40. package/dist/Logger.js.map +1 -1
  41. package/dist/Match.d.ts +23 -23
  42. package/dist/Match.d.ts.map +1 -1
  43. package/dist/Match.js.map +1 -1
  44. package/dist/Metric.d.ts.map +1 -1
  45. package/dist/Metric.js +3 -4
  46. package/dist/Metric.js.map +1 -1
  47. package/dist/Order.js +1 -1
  48. package/dist/Order.js.map +1 -1
  49. package/dist/Pool.d.ts.map +1 -1
  50. package/dist/Pool.js +49 -21
  51. package/dist/Pool.js.map +1 -1
  52. package/dist/Predicate.d.ts.map +1 -1
  53. package/dist/Predicate.js +2 -1
  54. package/dist/Predicate.js.map +1 -1
  55. package/dist/Scheduler.d.ts.map +1 -1
  56. package/dist/Scheduler.js +15 -9
  57. package/dist/Scheduler.js.map +1 -1
  58. package/dist/Schema.d.ts +41 -0
  59. package/dist/Schema.d.ts.map +1 -1
  60. package/dist/Schema.js +51 -390
  61. package/dist/Schema.js.map +1 -1
  62. package/dist/SchemaAST.d.ts +2 -2
  63. package/dist/SchemaAST.d.ts.map +1 -1
  64. package/dist/SchemaAST.js +199 -98
  65. package/dist/SchemaAST.js.map +1 -1
  66. package/dist/SchemaParser.d.ts.map +1 -1
  67. package/dist/SchemaParser.js +29 -50
  68. package/dist/SchemaParser.js.map +1 -1
  69. package/dist/ScopedCache.d.ts.map +1 -1
  70. package/dist/ScopedCache.js +6 -4
  71. package/dist/ScopedCache.js.map +1 -1
  72. package/dist/Stream.d.ts +128 -5
  73. package/dist/Stream.d.ts.map +1 -1
  74. package/dist/Stream.js +124 -29
  75. package/dist/Stream.js.map +1 -1
  76. package/dist/String.js +1 -1
  77. package/dist/String.js.map +1 -1
  78. package/dist/Tracer.d.ts +10 -0
  79. package/dist/Tracer.d.ts.map +1 -1
  80. package/dist/Tracer.js +3 -4
  81. package/dist/Tracer.js.map +1 -1
  82. package/dist/ai/McpClient.d.ts +68 -4
  83. package/dist/ai/McpClient.d.ts.map +1 -1
  84. package/dist/ai/McpClient.js +100 -17
  85. package/dist/ai/McpClient.js.map +1 -1
  86. package/dist/ai/McpClientError.d.ts +46 -4
  87. package/dist/ai/McpClientError.d.ts.map +1 -1
  88. package/dist/ai/McpClientError.js +38 -3
  89. package/dist/ai/McpClientError.js.map +1 -1
  90. package/dist/ai/McpServer.d.ts +158 -7
  91. package/dist/ai/McpServer.d.ts.map +1 -1
  92. package/dist/ai/McpServer.js +103 -49
  93. package/dist/ai/McpServer.js.map +1 -1
  94. package/dist/ai/Prompt.d.ts +3 -1
  95. package/dist/ai/Prompt.d.ts.map +1 -1
  96. package/dist/ai/Prompt.js +17 -3
  97. package/dist/ai/Prompt.js.map +1 -1
  98. package/dist/ai/Skill.d.ts +172 -0
  99. package/dist/ai/Skill.d.ts.map +1 -0
  100. package/dist/ai/Skill.js +209 -0
  101. package/dist/ai/Skill.js.map +1 -0
  102. package/dist/ai/index.d.ts +5 -0
  103. package/dist/ai/index.d.ts.map +1 -1
  104. package/dist/ai/index.js +5 -0
  105. package/dist/ai/index.js.map +1 -1
  106. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +9 -7
  107. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  108. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +12 -11
  109. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  110. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +18 -17
  111. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  112. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +19 -18
  113. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  114. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +1 -1
  115. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  116. package/dist/ai/internal/mcpProtocol.js +11 -0
  117. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  118. package/dist/ai/internal/mcpRuntime.js +29 -17
  119. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  120. package/dist/ai/internal/mcpSchema/v2024_11_05.js +2 -1
  121. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  122. package/dist/ai/internal/mcpSchema/v2025_03_26.js +1 -8
  123. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  124. package/dist/ai/internal/mcpSchema/v2025_06_18.js +5 -9
  125. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  126. package/dist/ai/internal/mcpSchema/v2025_11_25.js +1 -8
  127. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  128. package/dist/ai/internal/mcpSchema/v2026_07_28.js +4 -3
  129. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  130. package/dist/cluster/ClusterCron.d.ts +5 -20
  131. package/dist/cluster/ClusterCron.d.ts.map +1 -1
  132. package/dist/cluster/ClusterCron.js +16 -4
  133. package/dist/cluster/ClusterCron.js.map +1 -1
  134. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  135. package/dist/cluster/ClusterWorkflowEngine.js +155 -83
  136. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  137. package/dist/cluster/MessageStorage.d.ts +56 -0
  138. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  139. package/dist/cluster/MessageStorage.js +18 -2
  140. package/dist/cluster/MessageStorage.js.map +1 -1
  141. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  142. package/dist/cluster/SqlMessageStorage.js +48 -23
  143. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  144. package/dist/cluster/internal/entityActivation.js +2 -0
  145. package/dist/cluster/internal/entityActivation.js.map +1 -1
  146. package/dist/cluster/internal/entityManager.js +8 -5
  147. package/dist/cluster/internal/entityManager.js.map +1 -1
  148. package/dist/encoding/Base64.js +5 -1
  149. package/dist/encoding/Base64.js.map +1 -1
  150. package/dist/encoding/Base64Url.d.ts.map +1 -1
  151. package/dist/encoding/Base64Url.js +6 -1
  152. package/dist/encoding/Base64Url.js.map +1 -1
  153. package/dist/encoding/Hex.js +7 -5
  154. package/dist/encoding/Hex.js.map +1 -1
  155. package/dist/encoding/Xml.d.ts +38 -9
  156. package/dist/encoding/Xml.d.ts.map +1 -1
  157. package/dist/encoding/Xml.js +63 -31
  158. package/dist/encoding/Xml.js.map +1 -1
  159. package/dist/http/FetchHttpClient.d.ts +2 -1
  160. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  161. package/dist/http/FetchHttpClient.js +14 -10
  162. package/dist/http/FetchHttpClient.js.map +1 -1
  163. package/dist/http/Headers.d.ts +201 -3
  164. package/dist/http/Headers.d.ts.map +1 -1
  165. package/dist/http/Headers.js +205 -3
  166. package/dist/http/Headers.js.map +1 -1
  167. package/dist/http/HttpClient.d.ts.map +1 -1
  168. package/dist/http/HttpClient.js +11 -7
  169. package/dist/http/HttpClient.js.map +1 -1
  170. package/dist/http/HttpClientError.d.ts +1 -0
  171. package/dist/http/HttpClientError.d.ts.map +1 -1
  172. package/dist/http/HttpClientError.js +32 -9
  173. package/dist/http/HttpClientError.js.map +1 -1
  174. package/dist/http/HttpClientRequest.d.ts +46 -0
  175. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  176. package/dist/http/HttpClientRequest.js +15 -0
  177. package/dist/http/HttpClientRequest.js.map +1 -1
  178. package/dist/http/HttpClientResponse.d.ts +132 -0
  179. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  180. package/dist/http/HttpClientResponse.js +83 -0
  181. package/dist/http/HttpClientResponse.js.map +1 -1
  182. package/dist/http/HttpEffect.d.ts.map +1 -1
  183. package/dist/http/HttpEffect.js +31 -2
  184. package/dist/http/HttpEffect.js.map +1 -1
  185. package/dist/http/HttpMiddleware.js +1 -1
  186. package/dist/http/HttpMiddleware.js.map +1 -1
  187. package/dist/http/HttpServerError.d.ts +1 -1
  188. package/dist/http/HttpServerError.js +1 -1
  189. package/dist/http/HttpServerResponse.d.ts +118 -0
  190. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  191. package/dist/http/HttpServerResponse.js +43 -0
  192. package/dist/http/HttpServerResponse.js.map +1 -1
  193. package/dist/http/Multipart.d.ts.map +1 -1
  194. package/dist/http/Multipart.js +0 -5
  195. package/dist/http/Multipart.js.map +1 -1
  196. package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
  197. package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
  198. package/dist/http/MultipartParser/internal/contentType.js +1 -1
  199. package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
  200. package/dist/http/internal/clientPath.d.ts +2 -0
  201. package/dist/http/internal/clientPath.d.ts.map +1 -0
  202. package/dist/http/internal/clientPath.js +24 -0
  203. package/dist/http/internal/clientPath.js.map +1 -0
  204. package/dist/http/internal/redactedPath.js +2 -0
  205. package/dist/http/internal/redactedPath.js.map +1 -1
  206. package/dist/http/internal/tracing.js +5 -3
  207. package/dist/http/internal/tracing.js.map +1 -1
  208. package/dist/http-api/HttpApi.d.ts +2 -2
  209. package/dist/http-api/HttpApi.d.ts.map +1 -1
  210. package/dist/http-api/HttpApi.js +30 -7
  211. package/dist/http-api/HttpApi.js.map +1 -1
  212. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  213. package/dist/http-api/HttpApiBuilder.js +5 -2
  214. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  215. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  216. package/dist/http-api/HttpApiClient.js +23 -6
  217. package/dist/http-api/HttpApiClient.js.map +1 -1
  218. package/dist/http-api/internal/redactedKeys.d.ts +2 -0
  219. package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
  220. package/dist/http-api/internal/redactedKeys.js +37 -0
  221. package/dist/http-api/internal/redactedKeys.js.map +1 -0
  222. package/dist/internal/base64.js +34 -2
  223. package/dist/internal/base64.js.map +1 -1
  224. package/dist/internal/core.js +60 -43
  225. package/dist/internal/core.js.map +1 -1
  226. package/dist/internal/dateTime.js +35 -17
  227. package/dist/internal/dateTime.js.map +1 -1
  228. package/dist/internal/effect.js +60 -52
  229. package/dist/internal/effect.js.map +1 -1
  230. package/dist/internal/equal.js +44 -13
  231. package/dist/internal/equal.js.map +1 -1
  232. package/dist/internal/fiberCachedKeys.d.ts +2 -0
  233. package/dist/internal/fiberCachedKeys.d.ts.map +1 -0
  234. package/dist/internal/fiberCachedKeys.js +48 -0
  235. package/dist/internal/fiberCachedKeys.js.map +1 -0
  236. package/dist/internal/hashMap.js +1 -1
  237. package/dist/internal/hashMap.js.map +1 -1
  238. package/dist/internal/matcher.js +17 -17
  239. package/dist/internal/matcher.js.map +1 -1
  240. package/dist/internal/predicate.d.ts +2 -0
  241. package/dist/internal/predicate.d.ts.map +1 -0
  242. package/dist/internal/predicate.js +10 -0
  243. package/dist/internal/predicate.js.map +1 -0
  244. package/dist/internal/references.js +8 -11
  245. package/dist/internal/references.js.map +1 -1
  246. package/dist/internal/schema/schemaCodegen.js +3 -2
  247. package/dist/internal/schema/schemaCodegen.js.map +1 -1
  248. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
  249. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
  250. package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
  251. package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
  252. package/dist/internal/schema/toEquivalence.js +3 -4
  253. package/dist/internal/schema/toEquivalence.js.map +1 -1
  254. package/dist/internal/version.js +1 -1
  255. package/dist/jose/JoseError.d.ts +51 -1
  256. package/dist/jose/JoseError.d.ts.map +1 -1
  257. package/dist/jose/JoseError.js +25 -18
  258. package/dist/jose/JoseError.js.map +1 -1
  259. package/dist/jose/internal/compact.js +10 -5
  260. package/dist/jose/internal/compact.js.map +1 -1
  261. package/dist/observability/Otlp.d.ts +19 -0
  262. package/dist/observability/Otlp.d.ts.map +1 -1
  263. package/dist/observability/Otlp.js +10 -0
  264. package/dist/observability/Otlp.js.map +1 -1
  265. package/dist/observability/OtlpExporter.d.ts +49 -13
  266. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  267. package/dist/observability/OtlpExporter.js +135 -54
  268. package/dist/observability/OtlpExporter.js.map +1 -1
  269. package/dist/observability/OtlpLogger.d.ts +14 -0
  270. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  271. package/dist/observability/OtlpLogger.js +10 -2
  272. package/dist/observability/OtlpLogger.js.map +1 -1
  273. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  274. package/dist/observability/OtlpMetrics.js +2 -0
  275. package/dist/observability/OtlpMetrics.js.map +1 -1
  276. package/dist/observability/OtlpTracer.d.ts +14 -0
  277. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  278. package/dist/observability/OtlpTracer.js +10 -2
  279. package/dist/observability/OtlpTracer.js.map +1 -1
  280. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  281. package/dist/persistence/KeyValueStore.js +6 -4
  282. package/dist/persistence/KeyValueStore.js.map +1 -1
  283. package/dist/reactivity/Atom.d.ts.map +1 -1
  284. package/dist/reactivity/Atom.js +10 -9
  285. package/dist/reactivity/Atom.js.map +1 -1
  286. package/dist/rpc/RpcClient.d.ts.map +1 -1
  287. package/dist/rpc/RpcClient.js +32 -1
  288. package/dist/rpc/RpcClient.js.map +1 -1
  289. package/dist/rpc/RpcGroup.d.ts +1 -1
  290. package/dist/rpc/RpcGroup.d.ts.map +1 -1
  291. package/dist/rpc/RpcGroup.js +4 -0
  292. package/dist/rpc/RpcGroup.js.map +1 -1
  293. package/dist/sql/Migrator.d.ts.map +1 -1
  294. package/dist/sql/Migrator.js +2 -5
  295. package/dist/sql/Migrator.js.map +1 -1
  296. package/dist/sql/SqlClient.d.ts.map +1 -1
  297. package/dist/sql/SqlClient.js +5 -1
  298. package/dist/sql/SqlClient.js.map +1 -1
  299. package/dist/sql/Statement.d.ts +23 -0
  300. package/dist/sql/Statement.d.ts.map +1 -1
  301. package/dist/sql/Statement.js +30 -5
  302. package/dist/sql/Statement.js.map +1 -1
  303. package/dist/workers/Worker.d.ts +21 -0
  304. package/dist/workers/Worker.d.ts.map +1 -1
  305. package/dist/workers/Worker.js +23 -0
  306. package/dist/workers/Worker.js.map +1 -1
  307. package/dist/workflow/Activity.d.ts +18 -0
  308. package/dist/workflow/Activity.d.ts.map +1 -1
  309. package/dist/workflow/Activity.js +13 -4
  310. package/dist/workflow/Activity.js.map +1 -1
  311. package/dist/workflow/Workflow.d.ts +10 -9
  312. package/dist/workflow/Workflow.d.ts.map +1 -1
  313. package/dist/workflow/Workflow.js +33 -22
  314. package/dist/workflow/Workflow.js.map +1 -1
  315. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  316. package/dist/workflow/WorkflowEngine.js +26 -12
  317. package/dist/workflow/WorkflowEngine.js.map +1 -1
  318. package/dist/workflow/internal/retry.d.ts +2 -0
  319. package/dist/workflow/internal/retry.d.ts.map +1 -0
  320. package/dist/workflow/internal/retry.js +11 -0
  321. package/dist/workflow/internal/retry.js.map +1 -0
  322. package/dist/workflow/internal/scope.d.ts +2 -0
  323. package/dist/workflow/internal/scope.d.ts.map +1 -0
  324. package/dist/workflow/internal/scope.js +26 -0
  325. package/dist/workflow/internal/scope.js.map +1 -0
  326. package/package.json +3 -3
  327. package/src/Channel.ts +105 -8
  328. package/src/Codegen.ts +7 -2
  329. package/src/Config.ts +6 -3
  330. package/src/Context.ts +108 -50
  331. package/src/Cron.ts +11 -10
  332. package/src/Effect.ts +224 -48
  333. package/src/Equal.ts +93 -80
  334. package/src/Formatter.ts +4 -4
  335. package/src/Hash.ts +49 -48
  336. package/src/LayerRef.ts +6 -4
  337. package/src/Logger.ts +68 -25
  338. package/src/Match.ts +78 -50
  339. package/src/Metric.ts +4 -4
  340. package/src/Order.ts +1 -1
  341. package/src/Pool.ts +62 -33
  342. package/src/Predicate.ts +2 -5
  343. package/src/Scheduler.ts +27 -10
  344. package/src/Schema.ts +79 -296
  345. package/src/SchemaAST.ts +231 -157
  346. package/src/SchemaParser.ts +40 -57
  347. package/src/ScopedCache.ts +6 -4
  348. package/src/Stream.ts +167 -33
  349. package/src/String.ts +1 -1
  350. package/src/Tracer.ts +11 -2
  351. package/src/ai/McpClient.ts +157 -15
  352. package/src/ai/McpClientError.ts +55 -4
  353. package/src/ai/McpServer.ts +318 -91
  354. package/src/ai/Prompt.ts +20 -3
  355. package/src/ai/Skill.ts +236 -0
  356. package/src/ai/index.ts +6 -0
  357. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -13
  358. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +13 -15
  359. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +21 -23
  360. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +22 -24
  361. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +1 -1
  362. package/src/ai/internal/mcpProtocol.ts +15 -0
  363. package/src/ai/internal/mcpRuntime.ts +36 -13
  364. package/src/ai/internal/mcpSchema/v2024_11_05.ts +2 -1
  365. package/src/ai/internal/mcpSchema/v2025_03_26.ts +1 -9
  366. package/src/ai/internal/mcpSchema/v2025_06_18.ts +3 -10
  367. package/src/ai/internal/mcpSchema/v2025_11_25.ts +1 -9
  368. package/src/ai/internal/mcpSchema/v2026_07_28.ts +6 -8
  369. package/src/cluster/ClusterCron.ts +31 -20
  370. package/src/cluster/ClusterWorkflowEngine.ts +172 -96
  371. package/src/cluster/MessageStorage.ts +51 -2
  372. package/src/cluster/SqlMessageStorage.ts +88 -36
  373. package/src/cluster/internal/entityActivation.ts +6 -0
  374. package/src/cluster/internal/entityManager.ts +8 -4
  375. package/src/encoding/Base64.ts +5 -1
  376. package/src/encoding/Base64Url.ts +6 -1
  377. package/src/encoding/Hex.ts +5 -5
  378. package/src/encoding/Xml.ts +96 -26
  379. package/src/http/FetchHttpClient.ts +8 -5
  380. package/src/http/Headers.ts +309 -3
  381. package/src/http/HttpClient.ts +19 -7
  382. package/src/http/HttpClientError.ts +42 -9
  383. package/src/http/HttpClientRequest.ts +51 -0
  384. package/src/http/HttpClientResponse.ts +156 -0
  385. package/src/http/HttpEffect.ts +23 -3
  386. package/src/http/HttpMiddleware.ts +1 -1
  387. package/src/http/HttpServerError.ts +1 -1
  388. package/src/http/HttpServerResponse.ts +126 -0
  389. package/src/http/Multipart.ts +0 -5
  390. package/src/http/MultipartParser/internal/contentType.ts +1 -1
  391. package/src/http/internal/clientPath.ts +39 -0
  392. package/src/http/internal/redactedPath.ts +4 -0
  393. package/src/http/internal/tracing.ts +6 -3
  394. package/src/http-api/HttpApi.ts +29 -8
  395. package/src/http-api/HttpApiBuilder.ts +7 -2
  396. package/src/http-api/HttpApiClient.ts +30 -7
  397. package/src/http-api/internal/redactedKeys.ts +40 -0
  398. package/src/internal/base64.ts +57 -2
  399. package/src/internal/core.ts +80 -44
  400. package/src/internal/dateTime.ts +43 -24
  401. package/src/internal/effect.ts +115 -157
  402. package/src/internal/equal.ts +73 -17
  403. package/src/internal/fiberCachedKeys.ts +81 -0
  404. package/src/internal/hashMap.ts +1 -1
  405. package/src/internal/matcher.ts +34 -113
  406. package/src/internal/predicate.ts +10 -0
  407. package/src/internal/references.ts +21 -14
  408. package/src/internal/schema/schemaCodegen.ts +5 -4
  409. package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
  410. package/src/internal/schema/toEquivalence.ts +3 -5
  411. package/src/internal/version.ts +1 -1
  412. package/src/jose/JoseError.ts +34 -0
  413. package/src/jose/internal/compact.ts +14 -5
  414. package/src/observability/Otlp.ts +29 -0
  415. package/src/observability/OtlpExporter.ts +206 -75
  416. package/src/observability/OtlpLogger.ts +24 -2
  417. package/src/observability/OtlpMetrics.ts +2 -0
  418. package/src/observability/OtlpTracer.ts +24 -3
  419. package/src/persistence/KeyValueStore.ts +17 -14
  420. package/src/reactivity/Atom.ts +12 -18
  421. package/src/rpc/RpcClient.ts +26 -1
  422. package/src/rpc/RpcGroup.ts +4 -1
  423. package/src/sql/Migrator.ts +2 -11
  424. package/src/sql/SqlClient.ts +14 -8
  425. package/src/sql/Statement.ts +48 -12
  426. package/src/workers/Worker.ts +25 -0
  427. package/src/workflow/Activity.ts +28 -4
  428. package/src/workflow/Workflow.ts +68 -44
  429. package/src/workflow/WorkflowEngine.ts +38 -15
  430. package/src/workflow/internal/retry.ts +12 -0
  431. package/src/workflow/internal/scope.ts +36 -0
  432. package/dist/internal/hash.d.ts +0 -2
  433. package/dist/internal/hash.d.ts.map +0 -1
  434. package/dist/internal/hash.js +0 -11
  435. package/dist/internal/hash.js.map +0 -1
  436. package/dist/internal/metric.d.ts +0 -2
  437. package/dist/internal/metric.d.ts.map +0 -1
  438. package/dist/internal/metric.js +0 -3
  439. package/dist/internal/metric.js.map +0 -1
  440. package/src/internal/hash.ts +0 -11
  441. package/src/internal/metric.ts +0 -2
package/src/Effect.ts CHANGED
@@ -84,6 +84,7 @@ import type {
84
84
  ExcludeTag,
85
85
  ExtractReason,
86
86
  ExtractTag,
87
+ IsUnion,
87
88
  NarrowReason,
88
89
  NoInfer,
89
90
  OmitReason,
@@ -4905,12 +4906,13 @@ export const catchTag: {
4905
4906
  */
4906
4907
  <
4907
4908
  A,
4908
- E,
4909
- R,
4910
- const K extends Tags<E> | Arr.NonEmptyReadonlyArray<Tags<E>>,
4911
- R1,
4912
- E1,
4913
- A1,
4909
+ // Default `E` to `any` so `K` is not rejected while TS defers an inline `self` (e.g. `Effect.map(...)`)
4910
+ E = any,
4911
+ R = unknown,
4912
+ const K extends Tags<E> | Arr.NonEmptyReadonlyArray<Tags<E>> = never,
4913
+ R1 = unknown,
4914
+ E1 = unknown,
4915
+ A1 = unknown,
4914
4916
  A2 = unassigned,
4915
4917
  E2 = never,
4916
4918
  R2 = never
@@ -5382,6 +5384,22 @@ export const catchReason: {
5382
5384
  >
5383
5385
  } = internal.catchReason
5384
5386
 
5387
+ type RequiredCaseKeys<Cases> = {
5388
+ [RK in keyof Cases & string]: {} extends Record<RK, 1> ? never
5389
+ : [Cases] extends [Record<RK, (...args: Array<any>) => any>] ? RK
5390
+ : never
5391
+ }[keyof Cases & string]
5392
+
5393
+ type CaseReturn<Cases> = Cases extends unknown ? ReturnType<Extract<Cases[keyof Cases], (...args: Array<any>) => any>>
5394
+ : never
5395
+
5396
+ type UnhandledParent<E, K extends string, Handled extends string> = {} extends Record<K, 1> ? ExtractTag<E, K>
5397
+ : IsUnion<K> extends true ? ExtractTag<E, K>
5398
+ : ExtractTag<E, K> extends infer P
5399
+ ? P extends { readonly reason: { readonly _tag: string } } ? [ExcludeReason<P, Handled>] extends [never] ? never : P
5400
+ : P
5401
+ : never
5402
+
5385
5403
  /**
5386
5404
  * Catches multiple reasons within a tagged error using an object of handlers.
5387
5405
  *
@@ -5391,6 +5409,8 @@ export const catchReason: {
5391
5409
  * is converted to a defect, preserving reason order and interrupts. An
5392
5410
  * interruption alongside a typed error does not prevent recovery.
5393
5411
  *
5412
+ * Only own enumerable properties of `cases` are matched; inherited properties are ignored.
5413
+ *
5394
5414
  * **Example** (Handling multiple error reasons)
5395
5415
  *
5396
5416
  * ```ts import.meta.vitest
@@ -5438,6 +5458,8 @@ export const catchReasons: {
5438
5458
  * is converted to a defect, preserving reason order and interrupts. An
5439
5459
  * interruption alongside a typed error does not prevent recovery.
5440
5460
  *
5461
+ * Only own enumerable properties of `cases` are matched; inherited properties are ignored.
5462
+ *
5441
5463
  * **Example** (Handling multiple error reasons)
5442
5464
  *
5443
5465
  * ```ts import.meta.vitest
@@ -5484,37 +5506,105 @@ export const catchReasons: {
5484
5506
  error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
5485
5507
  ) => Effect<any, any, any>
5486
5508
  },
5487
- A2 = unassigned,
5509
+ // `A2`, `E2` and `R2` are only for calls that pass explicit type arguments.
5510
+ A2 = never,
5488
5511
  E2 = never,
5489
- R2 = never
5512
+ R2 = never,
5513
+ Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
5514
+ >(
5515
+ errorTag: K,
5516
+ cases: Cases,
5517
+ orElse: (
5518
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
5519
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
5520
+ ) => Ret
5521
+ ): <A, R>(
5522
+ self: Effect<A, E, R>
5523
+ ) => Effect<
5524
+ A | Success<Ret | CaseReturn<Cases>>,
5525
+ | ExcludeTag<E, K>
5526
+ | UnhandledParent<E, K, string>
5527
+ | Error<Ret | CaseReturn<Cases>>,
5528
+ R | Services<Ret | CaseReturn<Cases>>
5529
+ >
5530
+ /**
5531
+ * Catches multiple reasons within a tagged error using an object of handlers.
5532
+ *
5533
+ * **Gotchas**
5534
+ *
5535
+ * If the cause contains a defect, the handler is skipped and every typed error
5536
+ * is converted to a defect, preserving reason order and interrupts. An
5537
+ * interruption alongside a typed error does not prevent recovery.
5538
+ *
5539
+ * Only own enumerable properties of `cases` are matched; inherited properties are ignored.
5540
+ *
5541
+ * **Example** (Handling multiple error reasons)
5542
+ *
5543
+ * ```ts import.meta.vitest
5544
+ * import { Data, Effect } from "effect"
5545
+ *
5546
+ * class RateLimitError extends Data.TaggedError("RateLimitError")<{
5547
+ * retryAfter: number
5548
+ * }> {}
5549
+ *
5550
+ * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{
5551
+ * limit: number
5552
+ * }> {}
5553
+ *
5554
+ * class AiError extends Data.TaggedError("AiError")<{
5555
+ * reason: RateLimitError | QuotaExceededError
5556
+ * }> {}
5557
+ *
5558
+ * const program: Effect.Effect<string, AiError> = Effect.fail(
5559
+ * new AiError({ reason: new QuotaExceededError({ limit: 100 }) })
5560
+ * )
5561
+ *
5562
+ * const handled = program.pipe(
5563
+ * Effect.catchReasons("AiError", {
5564
+ * RateLimitError: (reason) =>
5565
+ * Effect.succeed(`Retry after ${reason.retryAfter}s`),
5566
+ * QuotaExceededError: (reason) =>
5567
+ * Effect.succeed(`Quota exceeded: ${reason.limit}`)
5568
+ * })
5569
+ * )
5570
+ *
5571
+ * Effect.runSync(handled) // => "Quota exceeded: 100"
5572
+ * ```
5573
+ *
5574
+ * @stability stable
5575
+ * @category error handling
5576
+ * @since 4.0.0
5577
+ */
5578
+ <
5579
+ K extends Tags<E>,
5580
+ E,
5581
+ Cases extends {
5582
+ [RK in ReasonTags<ExtractTag<NoInfer<E>, K>>]+?: (
5583
+ reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
5584
+ error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
5585
+ ) => Effect<any, any, any>
5586
+ },
5587
+ A2 = never,
5588
+ E2 = never,
5589
+ R2 = never,
5590
+ Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
5490
5591
  >(
5491
5592
  errorTag: K,
5492
5593
  cases: Cases,
5493
5594
  orElse?:
5494
5595
  | ((
5495
- reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
5496
- error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
5497
- ) => Effect<A2, E2, R2>)
5596
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
5597
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
5598
+ ) => Ret)
5498
5599
  | undefined
5499
5600
  ): <A, R>(
5500
5601
  self: Effect<A, E, R>
5501
5602
  ) => Effect<
5502
- | A
5503
- | Exclude<A2, unassigned>
5504
- | {
5505
- [RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<infer A, any, any> ? A : never
5506
- }[keyof Cases],
5603
+ A | Success<Ret | CaseReturn<Cases>>,
5507
5604
  | ExcludeTag<E, K>
5508
- | E2
5509
- | (A2 extends unassigned ? ExtractTag<E, K> : never)
5510
- | {
5511
- [RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, infer E, any> ? E : never
5512
- }[keyof Cases],
5513
- | R
5514
- | R2
5515
- | {
5516
- [RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, any, infer R> ? R : never
5517
- }[keyof Cases]
5605
+ | UnhandledParent<E, K, RequiredCaseKeys<Cases>>
5606
+ | Error<Ret | CaseReturn<Cases>>,
5607
+ R | Services<Ret | CaseReturn<Cases>>
5518
5608
  >
5519
5609
  /**
5520
5610
  * Catches multiple reasons within a tagged error using an object of handlers.
@@ -5525,6 +5615,8 @@ export const catchReasons: {
5525
5615
  * is converted to a defect, preserving reason order and interrupts. An
5526
5616
  * interruption alongside a typed error does not prevent recovery.
5527
5617
  *
5618
+ * Only own enumerable properties of `cases` are matched; inherited properties are ignored.
5619
+ *
5528
5620
  * **Example** (Handling multiple error reasons)
5529
5621
  *
5530
5622
  * ```ts import.meta.vitest
@@ -5573,36 +5665,104 @@ export const catchReasons: {
5573
5665
  error: NarrowReason<ExtractTag<E, K>, RK>
5574
5666
  ) => Effect<any, any, any>
5575
5667
  },
5576
- A2 = unassigned,
5668
+ A2 = never,
5577
5669
  E2 = never,
5578
- R2 = never
5670
+ R2 = never,
5671
+ Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
5672
+ >(
5673
+ self: Effect<A, E, R>,
5674
+ errorTag: K,
5675
+ cases: Cases,
5676
+ orElse: (
5677
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
5678
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
5679
+ ) => Ret
5680
+ ): Effect<
5681
+ A | Success<Ret | CaseReturn<Cases>>,
5682
+ | ExcludeTag<E, K>
5683
+ | UnhandledParent<E, K, string>
5684
+ | Error<Ret | CaseReturn<Cases>>,
5685
+ R | Services<Ret | CaseReturn<Cases>>
5686
+ >
5687
+ /**
5688
+ * Catches multiple reasons within a tagged error using an object of handlers.
5689
+ *
5690
+ * **Gotchas**
5691
+ *
5692
+ * If the cause contains a defect, the handler is skipped and every typed error
5693
+ * is converted to a defect, preserving reason order and interrupts. An
5694
+ * interruption alongside a typed error does not prevent recovery.
5695
+ *
5696
+ * Only own enumerable properties of `cases` are matched; inherited properties are ignored.
5697
+ *
5698
+ * **Example** (Handling multiple error reasons)
5699
+ *
5700
+ * ```ts import.meta.vitest
5701
+ * import { Data, Effect } from "effect"
5702
+ *
5703
+ * class RateLimitError extends Data.TaggedError("RateLimitError")<{
5704
+ * retryAfter: number
5705
+ * }> {}
5706
+ *
5707
+ * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{
5708
+ * limit: number
5709
+ * }> {}
5710
+ *
5711
+ * class AiError extends Data.TaggedError("AiError")<{
5712
+ * reason: RateLimitError | QuotaExceededError
5713
+ * }> {}
5714
+ *
5715
+ * const program: Effect.Effect<string, AiError> = Effect.fail(
5716
+ * new AiError({ reason: new QuotaExceededError({ limit: 100 }) })
5717
+ * )
5718
+ *
5719
+ * const handled = program.pipe(
5720
+ * Effect.catchReasons("AiError", {
5721
+ * RateLimitError: (reason) =>
5722
+ * Effect.succeed(`Retry after ${reason.retryAfter}s`),
5723
+ * QuotaExceededError: (reason) =>
5724
+ * Effect.succeed(`Quota exceeded: ${reason.limit}`)
5725
+ * })
5726
+ * )
5727
+ *
5728
+ * Effect.runSync(handled) // => "Quota exceeded: 100"
5729
+ * ```
5730
+ *
5731
+ * @stability stable
5732
+ * @category error handling
5733
+ * @since 4.0.0
5734
+ */
5735
+ <
5736
+ A,
5737
+ E,
5738
+ R,
5739
+ K extends Tags<E>,
5740
+ Cases extends {
5741
+ [RK in ReasonTags<ExtractTag<E, K>>]+?: (
5742
+ reason: ExtractReason<ExtractTag<E, K>, RK>,
5743
+ error: NarrowReason<ExtractTag<E, K>, RK>
5744
+ ) => Effect<any, any, any>
5745
+ },
5746
+ A2 = never,
5747
+ E2 = never,
5748
+ R2 = never,
5749
+ Ret extends Effect<any, any, any> = Effect<A2, E2, R2>
5579
5750
  >(
5580
5751
  self: Effect<A, E, R>,
5581
5752
  errorTag: K,
5582
5753
  cases: Cases,
5583
5754
  orElse?:
5584
5755
  | ((
5585
- reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
5586
- error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
5587
- ) => Effect<A2, E2, R2>)
5756
+ reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>,
5757
+ error: OmitReason<ExtractTag<NoInfer<E>, K>, RequiredCaseKeys<Cases>>
5758
+ ) => Ret)
5588
5759
  | undefined
5589
5760
  ): Effect<
5590
- | A
5591
- | Exclude<A2, unassigned>
5592
- | {
5593
- [RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<infer A, any, any> ? A : never
5594
- }[keyof Cases],
5761
+ A | Success<Ret | CaseReturn<Cases>>,
5595
5762
  | ExcludeTag<E, K>
5596
- | E2
5597
- | (A2 extends unassigned ? ExtractTag<E, K> : never)
5598
- | {
5599
- [RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, infer E, any> ? E : never
5600
- }[keyof Cases],
5601
- | R
5602
- | R2
5603
- | {
5604
- [RK in keyof Cases]: Cases[RK] extends (...args: Array<any>) => Effect<any, any, infer R> ? R : never
5605
- }[keyof Cases]
5763
+ | UnhandledParent<E, K, RequiredCaseKeys<Cases>>
5764
+ | Error<Ret | CaseReturn<Cases>>,
5765
+ R | Services<Ret | CaseReturn<Cases>>
5606
5766
  >
5607
5767
  } = internal.catchReasons
5608
5768
 
@@ -17916,6 +18076,11 @@ export const annotateSpans: {
17916
18076
  /**
17917
18077
  * Adds an annotation to the current span if available.
17918
18078
  *
18079
+ * **Details**
18080
+ *
18081
+ * Does nothing when there is no current span or when the nearest parent span is
18082
+ * an `ExternalSpan`.
18083
+ *
17919
18084
  * **Example** (Annotating the current span)
17920
18085
  *
17921
18086
  * ```ts import.meta.vitest
@@ -17941,6 +18106,11 @@ export const annotateCurrentSpan: {
17941
18106
  /**
17942
18107
  * Adds an annotation to the current span if available.
17943
18108
  *
18109
+ * **Details**
18110
+ *
18111
+ * Does nothing when there is no current span or when the nearest parent span is
18112
+ * an `ExternalSpan`.
18113
+ *
17944
18114
  * **Example** (Annotating the current span)
17945
18115
  *
17946
18116
  * ```ts import.meta.vitest
@@ -17966,6 +18136,11 @@ export const annotateCurrentSpan: {
17966
18136
  /**
17967
18137
  * Adds an annotation to the current span if available.
17968
18138
  *
18139
+ * **Details**
18140
+ *
18141
+ * Does nothing when there is no current span or when the nearest parent span is
18142
+ * an `ExternalSpan`.
18143
+ *
17969
18144
  * **Example** (Annotating the current span)
17970
18145
  *
17971
18146
  * ```ts import.meta.vitest
@@ -17995,8 +18170,9 @@ export const annotateCurrentSpan: {
17995
18170
  *
17996
18171
  * **Details**
17997
18172
  *
17998
- * The effect fails with `NoSuchElementError` when there is no active local
17999
- * `Span`.
18173
+ * The effect fails with `NoSuchElementError` when there is no parent span or
18174
+ * when the nearest parent span is an `ExternalSpan`. Use `currentParentSpan` to
18175
+ * read either kind.
18000
18176
  *
18001
18177
  * **Example** (Reading the current span)
18002
18178
  *
package/src/Equal.ts CHANGED
@@ -12,8 +12,16 @@
12
12
  */
13
13
  import type { Equivalence } from "./Equivalence.ts"
14
14
  import * as Hash from "./Hash.ts"
15
- import { bufferBytes, byReferenceInstances, getAllObjectKeys, isArrayBufferLike, viewBytes } from "./internal/equal.ts"
16
- import { hasProperty } from "./Predicate.ts"
15
+ import {
16
+ addBackEdge,
17
+ backEdges,
18
+ byReferenceInstances,
19
+ getAllObjectKeys,
20
+ hashCache,
21
+ objectKind,
22
+ toBytes
23
+ } from "./internal/equal.ts"
24
+ import { hasProperty } from "./internal/predicate.ts"
17
25
 
18
26
  /**
19
27
  * Defines the unique string identifier for the `Equal` interface.
@@ -133,14 +141,14 @@ export interface Equal extends Hash.Hash {
133
141
  * Functions without an `Equal` implementation compare by reference. Circular
134
142
  * structures use coinductive equality.
135
143
  *
136
- * Hash values are checked first as a fast-path rejection. The function also
137
- * supports dual data-last usage: call it with one argument to get a curried
138
- * predicate.
144
+ * Custom `Hash` implementations and already-cached structural hashes are
145
+ * checked first as a fast-path rejection. The function also supports dual
146
+ * data-last usage: call it with one argument to get a curried predicate.
139
147
  *
140
148
  * **Gotchas**
141
149
  *
142
150
  * - Object-pair results are cached in a WeakMap. **Objects must not be
143
- * be mutated after their first comparison.**
151
+ * mutated after their first comparison.**
144
152
  * - Map and Set entries are matched within groups of equal hashes, so they
145
153
  * are O(n) for well-distributed hashes and O(n²) when every hash collides.
146
154
  *
@@ -184,114 +192,121 @@ export function equals(): any {
184
192
  }
185
193
 
186
194
  function compareBoth(self: unknown, that: unknown): boolean {
187
- if (self === that) return true
188
- if (self == null || that == null) return false
195
+ if (self == null || that == null) return self === that
189
196
  const selfType = typeof self
190
- if (selfType !== typeof that) {
191
- return false
197
+ if (selfType !== "object" && selfType !== "function") {
198
+ return self === that || (self !== self && that !== that)
192
199
  }
193
- // Special case for NaN: NaN should be considered equal to NaN
194
- if (selfType === "number" && self !== self && that !== that) {
200
+ if (self === that) {
201
+ // A shared reference can close a cycle on one side; hashing records any back-edge.
202
+ if (pathLeft.length > 0 && !hashCache.has(self)) Hash.hash(self)
195
203
  return true
196
204
  }
197
- if (selfType !== "object" && selfType !== "function") {
198
- return false
199
- }
200
-
201
- if (byReferenceInstances.has(self) || byReferenceInstances.has(that)) {
205
+ if (selfType !== typeof that || byReferenceInstances.has(self) || byReferenceInstances.has(that)) {
202
206
  return false
203
207
  }
204
-
205
208
  return compareObjects(self, that)
206
209
  }
207
210
 
208
211
  function compareObjects(self: object, that: object): boolean {
209
212
  const depth = pathLeft.length
210
- // A repeated pair closes a cycle under coinductive equality.
213
+ const prev = seen.get(self)
214
+ if (prev === that) return true
215
+ let known: WeakMap<object, boolean> | undefined
216
+ if (!depth || prev !== undefined) {
217
+ known = results.get(self)
218
+ const cached = known?.get(that)
219
+ if (cached !== undefined) return cached
220
+ }
221
+ let revisited = false
211
222
  for (let i = depth; i-- > 0;) {
212
- if (pathLeft[i] === self && pathRight[i] === that) return true
223
+ const sameLeft = pathLeft[i] === self
224
+ if (sameLeft || pathRight[i] === that) {
225
+ addBackEdge()
226
+ // A repeated pair closes a cycle under coinductive equality.
227
+ if (sameLeft && pathRight[i] === that) return true
228
+ revisited = true
229
+ }
213
230
  }
214
- if (depth) return compareOnPath(self, that)
215
- // Only outermost results are independent of path assumptions.
216
- let known = results.get(self)
217
- if (!known) results.set(self, known = new WeakMap())
218
- let result = known.get(that)
219
- if (result === undefined) known.set(that, result = compareOnPath(self, that))
220
- return result
221
- }
222
-
223
- function compareOnPath(self: object, that: object): boolean {
231
+ // Reject mismatched cycle lengths instead of unrolling both loops.
232
+ if (revisited && Hash.hash(self) !== Hash.hash(that)) return false
233
+ const seenBack = backEdges
224
234
  pathLeft.push(self)
225
235
  pathRight.push(that)
236
+ let result: boolean
226
237
  try {
227
- return compareStructure(self, that)
238
+ result = compareStructure(self, that)
228
239
  } finally {
229
240
  pathLeft.pop()
230
241
  pathRight.pop()
242
+ if (!depth) seen.clear()
243
+ }
244
+ // Cyclic hashes depend on entry point; verify hash agreement.
245
+ if (seenBack !== backEdges) return result && Hash.hash(self) === Hash.hash(that)
246
+ // Only cache acyclic results so nested lookups never skip a back-edge.
247
+ if (depth && prev === undefined) {
248
+ if (result) seen.set(self, that)
249
+ } else {
250
+ if (!known) results.set(self, known = new WeakMap())
251
+ known.set(that, result)
231
252
  }
253
+ return result
232
254
  }
233
255
 
234
256
  // The pairs on the current comparison's path (the coinductive assumptions).
235
257
  const pathLeft: Array<object> = []
236
258
  const pathRight: Array<object> = []
259
+ const seen = new Map<object, object>()
237
260
  const results = new WeakMap<object, WeakMap<object, boolean>>()
238
261
 
239
262
  function compareStructure(self: object, that: object): boolean {
240
- if (Hash.hash(self) !== Hash.hash(that)) {
241
- return false
242
- } else if (self instanceof Date) {
243
- if (!(that instanceof Date)) return false
244
- const selfTime = self.getTime()
245
- const thatTime = that.getTime()
246
- return selfTime === thatTime || (Number.isNaN(selfTime) && Number.isNaN(thatTime))
247
- } else if (self instanceof RegExp) {
248
- return that instanceof RegExp && self.toString() === that.toString()
263
+ const selfHash = hashCache.get(self)
264
+ if (selfHash !== undefined && selfHash !== (hashCache.get(that) ?? selfHash)) return false
265
+ const kind = objectKind(self)
266
+ if (kind === 1 || kind === 2) {
267
+ if (objectKind(that) !== kind) return false
268
+ if (kind === 2) return self.toString() === that.toString()
269
+ if (Hash.hash(self) !== Hash.hash(that)) return false
270
+ const a = (self as Date).getTime()
271
+ const b = (that as Date).getTime()
272
+ return a === b || (a !== a && b !== b)
249
273
  }
250
274
  const bothEquals = isEqual(self)
251
275
  if (bothEquals !== isEqual(that) || (typeof self === "function" && !bothEquals)) {
252
276
  return false
253
- } else if (bothEquals) {
277
+ }
278
+ if ((bothEquals || Hash.isHash(self) || Hash.isHash(that)) && Hash.hash(self) !== Hash.hash(that)) {
279
+ return false
280
+ }
281
+ if (bothEquals) {
254
282
  return (self as Equal)[symbol](that as Equal)
255
- } else if (Array.isArray(self)) {
256
- if (!Array.isArray(that) || self.length !== that.length) {
257
- return false
258
- }
259
- return compareArrays(self, that)
260
- } else if (isArrayBufferLike(self)) {
261
- if (!isArrayBufferLike(that) || (self instanceof ArrayBuffer) !== (that instanceof ArrayBuffer)) {
262
- return false
263
- }
264
- const selfBytes = bufferBytes(self)
265
- const thatBytes = bufferBytes(that)
283
+ }
284
+ if (kind !== objectKind(that)) {
285
+ return false
286
+ }
287
+ if (kind >= 7) {
288
+ const selfBytes = toBytes(self as ArrayBufferLike | DataView, kind)
289
+ const thatBytes = toBytes(that as ArrayBufferLike | DataView, kind)
266
290
  return selfBytes !== undefined && thatBytes !== undefined && compareTypedArrays(selfBytes, thatBytes)
267
- } else if (ArrayBuffer.isView(self)) {
268
- const selfIsDataView = self instanceof DataView
269
- if (
270
- !ArrayBuffer.isView(that) ||
271
- self.byteLength !== that.byteLength ||
272
- selfIsDataView !== (that instanceof DataView)
273
- ) {
274
- return false
275
- }
276
- if (selfIsDataView) {
277
- return compareTypedArrays(viewBytes(self), viewBytes(that as DataView))
278
- }
279
- return compareTypedArrays(self as Uint8Array, that as Uint8Array)
280
- } else if (self instanceof Map) {
281
- if (!(that instanceof Map) || self.size !== that.size) {
282
- return false
283
- }
284
- return compareHashed(self, that, entryHash, equalEntries)
285
- } else if (self instanceof Set) {
286
- if (!(that instanceof Set) || self.size !== that.size) {
287
- return false
288
- }
289
- return compareHashed(self, that, Hash.hash, compareBoth)
291
+ } else if (kind === 5) {
292
+ return compareArrays(self as Array<unknown>, that as Array<unknown>)
293
+ } else if (kind === 6) {
294
+ return (self as ArrayBufferView).byteLength === (that as ArrayBufferView).byteLength &&
295
+ compareTypedArrays(self as Uint8Array, that as Uint8Array)
296
+ } else if (kind === 3) {
297
+ return (self as Map<unknown, unknown>).size === (that as Map<unknown, unknown>).size &&
298
+ compareHashed(self as Map<unknown, unknown>, that as Map<unknown, unknown>, entryHash, equalEntries)
299
+ } else if (kind === 4) {
300
+ return (self as Set<unknown>).size === (that as Set<unknown>).size &&
301
+ compareHashed(self as Set<unknown>, that as Set<unknown>, Hash.hash, compareBoth)
290
302
  }
291
303
  return compareRecords(self as any, that as any)
292
304
  }
293
305
 
294
306
  function compareArrays(self: Array<unknown>, that: Array<unknown>): boolean {
307
+ if (self.length !== that.length) {
308
+ return false
309
+ }
295
310
  for (let i = 0; i < self.length; i++) {
296
311
  if (!compareBoth(self[i], that[i])) {
297
312
  return false
@@ -319,17 +334,15 @@ function compareRecords(
319
334
  ): boolean {
320
335
  const selfKeys = getAllObjectKeys(self)
321
336
  const thatKeys = getAllObjectKeys(that)
322
-
323
- if (selfKeys.size !== thatKeys.size) {
337
+ const thatIsSet = thatKeys instanceof Set
338
+ if ((selfKeys instanceof Set ? selfKeys.size : selfKeys.length) !== (thatIsSet ? thatKeys.size : thatKeys.length)) {
324
339
  return false
325
340
  }
326
-
327
341
  for (const key of selfKeys) {
328
- if (!(thatKeys.has(key)) || !compareBoth(self[key], that[key])) {
342
+ if (!(thatIsSet ? thatKeys.has(key) : Object.hasOwn(that, key)) || !compareBoth(self[key], that[key])) {
329
343
  return false
330
344
  }
331
345
  }
332
-
333
346
  return true
334
347
  }
335
348
 
package/src/Formatter.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * @stability stable
11
11
  * @since 4.0.0
12
12
  */
13
- import * as Predicate from "./Predicate.ts"
13
+ import { hasProperty } from "./internal/predicate.ts"
14
14
  import { getRedacted, redact, symbolRedactable } from "./Redactable.ts"
15
15
 
16
16
  /**
@@ -168,7 +168,7 @@ export function format(input: unknown, options?: {
168
168
  output = formatDate(v)
169
169
  } else if (
170
170
  !options?.ignoreToString &&
171
- Predicate.hasProperty(v, "toString") &&
171
+ hasProperty(v, "toString") &&
172
172
  typeof v["toString"] === "function" &&
173
173
  v["toString"] !== Object.prototype.toString &&
174
174
  v["toString"] !== Array.prototype.toString
@@ -316,7 +316,7 @@ export function formatJson(input: unknown, options?: {
316
316
  input,
317
317
  function(this: object, key: string, value: unknown) {
318
318
  const original = Object.getOwnPropertyDescriptor(sources.get(this) ?? this, key)?.value
319
- const redacted = Predicate.hasProperty(original, symbolRedactable)
319
+ const redacted = hasProperty(original, symbolRedactable)
320
320
  ? redact(original)
321
321
  : redact(value)
322
322
  if (typeof redacted === "bigint") {
@@ -325,7 +325,7 @@ export function formatJson(input: unknown, options?: {
325
325
  if (typeof redacted !== "object" || redacted === null) {
326
326
  return redacted
327
327
  }
328
- const current = redacted instanceof Error && !Predicate.hasProperty(redacted, "toJSON")
328
+ const current = redacted instanceof Error && !hasProperty(redacted, "toJSON")
329
329
  ? { ...redacted, name: redacted.name, message: redacted.message }
330
330
  : redacted
331
331
  while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {