effect 4.0.0-beta.98 → 4.0.0-rc.108

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 (1848) hide show
  1. package/AGENTS.md +381 -0
  2. package/CLAUDE.md +381 -0
  3. package/README.md +13 -20
  4. package/ai-docs/README.md +44 -0
  5. package/ai-docs/package.json +36 -0
  6. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  7. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
  8. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  9. package/ai-docs/src/01_effect/01_basics/index.md +5 -0
  10. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  11. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  12. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  13. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  14. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  15. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  16. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  17. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  18. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  19. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  20. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  21. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  22. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  23. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  24. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  25. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  26. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  27. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  28. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  29. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  30. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  31. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  32. package/ai-docs/src/03_stream/30_encoding.ts +165 -0
  33. package/ai-docs/src/03_stream/index.md +4 -0
  34. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  35. package/ai-docs/src/04_integration/index.md +5 -0
  36. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  37. package/ai-docs/src/05_batching/index.md +3 -0
  38. package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
  39. package/ai-docs/src/06_schedule/index.md +3 -0
  40. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  41. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  42. package/ai-docs/src/07_datetime/index.md +5 -0
  43. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  44. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  45. package/ai-docs/src/08_observability/index.md +7 -0
  46. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  47. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  48. package/ai-docs/src/09_testing/index.md +1 -0
  49. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  50. package/ai-docs/src/10_predicate/index.md +9 -0
  51. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  52. package/ai-docs/src/50_http-client/index.md +3 -0
  53. package/ai-docs/src/51_http-server/10_basics.ts +116 -0
  54. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  55. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  56. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  57. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
  58. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
  59. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  60. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
  61. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
  62. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
  63. package/ai-docs/src/51_http-server/index.md +3 -0
  64. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  65. package/ai-docs/src/60_child-process/index.md +3 -0
  66. package/ai-docs/src/70_cli/10_basics.ts +136 -0
  67. package/ai-docs/src/70_cli/index.md +5 -0
  68. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  69. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  70. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  71. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  72. package/ai-docs/src/71_ai/index.md +5 -0
  73. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  74. package/ai-docs/src/80_cluster/index.md +4 -0
  75. package/ai-docs/src/index.md +10 -0
  76. package/ai-docs/tsconfig.json +24 -0
  77. package/dist/Array.d.ts +971 -1037
  78. package/dist/Array.d.ts.map +1 -1
  79. package/dist/Array.js +463 -413
  80. package/dist/Array.js.map +1 -1
  81. package/dist/BigDecimal.d.ts +433 -756
  82. package/dist/BigDecimal.d.ts.map +1 -1
  83. package/dist/BigDecimal.js +200 -325
  84. package/dist/BigDecimal.js.map +1 -1
  85. package/dist/BigInt.d.ts +207 -267
  86. package/dist/BigInt.d.ts.map +1 -1
  87. package/dist/BigInt.js +107 -135
  88. package/dist/BigInt.js.map +1 -1
  89. package/dist/Boolean.d.ts +146 -188
  90. package/dist/Boolean.d.ts.map +1 -1
  91. package/dist/Boolean.js +64 -84
  92. package/dist/Boolean.js.map +1 -1
  93. package/dist/Brand.d.ts +3 -3
  94. package/dist/Brand.d.ts.map +1 -1
  95. package/dist/Brand.js +4 -3
  96. package/dist/Brand.js.map +1 -1
  97. package/dist/Cache.d.ts +409 -256
  98. package/dist/Cache.d.ts.map +1 -1
  99. package/dist/Cache.js +213 -134
  100. package/dist/Cache.js.map +1 -1
  101. package/dist/Cause.d.ts +167 -277
  102. package/dist/Cause.d.ts.map +1 -1
  103. package/dist/Cause.js +122 -176
  104. package/dist/Cause.js.map +1 -1
  105. package/dist/Channel.d.ts +756 -769
  106. package/dist/Channel.d.ts.map +1 -1
  107. package/dist/Channel.js +588 -449
  108. package/dist/Channel.js.map +1 -1
  109. package/dist/ChannelSchema.d.ts +1 -1
  110. package/dist/ChannelSchema.d.ts.map +1 -1
  111. package/dist/ChannelSchema.js.map +1 -1
  112. package/dist/Chunk.d.ts +834 -1173
  113. package/dist/Chunk.d.ts.map +1 -1
  114. package/dist/Chunk.js +326 -439
  115. package/dist/Chunk.js.map +1 -1
  116. package/dist/Clock.d.ts +180 -49
  117. package/dist/Clock.d.ts.map +1 -1
  118. package/dist/Clock.js +96 -31
  119. package/dist/Clock.js.map +1 -1
  120. package/dist/Combiner.d.ts +20 -33
  121. package/dist/Combiner.d.ts.map +1 -1
  122. package/dist/Combiner.js +18 -30
  123. package/dist/Combiner.js.map +1 -1
  124. package/dist/Config.d.ts +226 -174
  125. package/dist/Config.d.ts.map +1 -1
  126. package/dist/Config.js +361 -267
  127. package/dist/Config.js.map +1 -1
  128. package/dist/ConfigProvider.d.ts +229 -71
  129. package/dist/ConfigProvider.d.ts.map +1 -1
  130. package/dist/ConfigProvider.js +164 -95
  131. package/dist/ConfigProvider.js.map +1 -1
  132. package/dist/Console.d.ts +233 -33
  133. package/dist/Console.d.ts.map +1 -1
  134. package/dist/Console.js +232 -32
  135. package/dist/Console.js.map +1 -1
  136. package/dist/Context.d.ts +153 -277
  137. package/dist/Context.d.ts.map +1 -1
  138. package/dist/Context.js +172 -236
  139. package/dist/Context.js.map +1 -1
  140. package/dist/Cron.d.ts +144 -176
  141. package/dist/Cron.d.ts.map +1 -1
  142. package/dist/Cron.js +227 -162
  143. package/dist/Cron.js.map +1 -1
  144. package/dist/Crypto.d.ts +13 -15
  145. package/dist/Crypto.d.ts.map +1 -1
  146. package/dist/Crypto.js +22 -15
  147. package/dist/Crypto.js.map +1 -1
  148. package/dist/Data.d.ts +60 -80
  149. package/dist/Data.d.ts.map +1 -1
  150. package/dist/Data.js +18 -24
  151. package/dist/Data.js.map +1 -1
  152. package/dist/DateTime.d.ts +562 -660
  153. package/dist/DateTime.d.ts.map +1 -1
  154. package/dist/DateTime.js +307 -362
  155. package/dist/DateTime.js.map +1 -1
  156. package/dist/Deferred.d.ts +253 -256
  157. package/dist/Deferred.d.ts.map +1 -1
  158. package/dist/Deferred.js +110 -98
  159. package/dist/Deferred.js.map +1 -1
  160. package/dist/Duration.d.ts +216 -308
  161. package/dist/Duration.d.ts.map +1 -1
  162. package/dist/Duration.js +157 -188
  163. package/dist/Duration.js.map +1 -1
  164. package/dist/Effect.d.ts +3142 -3345
  165. package/dist/Effect.d.ts.map +1 -1
  166. package/dist/Effect.js +1452 -1570
  167. package/dist/Effect.js.map +1 -1
  168. package/dist/Effectable.js.map +1 -1
  169. package/dist/Encoding.d.ts +22 -40
  170. package/dist/Encoding.d.ts.map +1 -1
  171. package/dist/Encoding.js +22 -40
  172. package/dist/Encoding.js.map +1 -1
  173. package/dist/Equal.d.ts +33 -37
  174. package/dist/Equal.d.ts.map +1 -1
  175. package/dist/Equal.js +39 -23
  176. package/dist/Equal.js.map +1 -1
  177. package/dist/Equivalence.d.ts +103 -105
  178. package/dist/Equivalence.d.ts.map +1 -1
  179. package/dist/Equivalence.js +77 -79
  180. package/dist/Equivalence.js.map +1 -1
  181. package/dist/ErrorReporter.d.ts +51 -27
  182. package/dist/ErrorReporter.d.ts.map +1 -1
  183. package/dist/ErrorReporter.js +50 -26
  184. package/dist/ErrorReporter.js.map +1 -1
  185. package/dist/ExecutionPlan.d.ts +86 -55
  186. package/dist/ExecutionPlan.d.ts.map +1 -1
  187. package/dist/ExecutionPlan.js +8 -29
  188. package/dist/ExecutionPlan.js.map +1 -1
  189. package/dist/Exit.d.ts +116 -192
  190. package/dist/Exit.d.ts.map +1 -1
  191. package/dist/Exit.js +82 -130
  192. package/dist/Exit.js.map +1 -1
  193. package/dist/Fiber.d.ts +83 -147
  194. package/dist/Fiber.d.ts.map +1 -1
  195. package/dist/Fiber.js +48 -87
  196. package/dist/Fiber.js.map +1 -1
  197. package/dist/FiberHandle.d.ts +152 -105
  198. package/dist/FiberHandle.d.ts.map +1 -1
  199. package/dist/FiberHandle.js +109 -75
  200. package/dist/FiberHandle.js.map +1 -1
  201. package/dist/FiberMap.d.ts +213 -168
  202. package/dist/FiberMap.d.ts.map +1 -1
  203. package/dist/FiberMap.js +114 -89
  204. package/dist/FiberMap.js.map +1 -1
  205. package/dist/FiberSet.d.ts +123 -81
  206. package/dist/FiberSet.d.ts.map +1 -1
  207. package/dist/FiberSet.js +86 -60
  208. package/dist/FiberSet.js.map +1 -1
  209. package/dist/FileSystem.d.ts +154 -265
  210. package/dist/FileSystem.d.ts.map +1 -1
  211. package/dist/FileSystem.js +42 -147
  212. package/dist/FileSystem.js.map +1 -1
  213. package/dist/Filter.d.ts +61 -33
  214. package/dist/Filter.d.ts.map +1 -1
  215. package/dist/Filter.js +26 -15
  216. package/dist/Filter.js.map +1 -1
  217. package/dist/Formatter.d.ts +24 -32
  218. package/dist/Formatter.d.ts.map +1 -1
  219. package/dist/Formatter.js +55 -60
  220. package/dist/Formatter.js.map +1 -1
  221. package/dist/Function.d.ts +106 -148
  222. package/dist/Function.d.ts.map +1 -1
  223. package/dist/Function.js +81 -62
  224. package/dist/Function.js.map +1 -1
  225. package/dist/Graph.d.ts +1412 -775
  226. package/dist/Graph.d.ts.map +1 -1
  227. package/dist/Graph.js +1180 -561
  228. package/dist/Graph.js.map +1 -1
  229. package/dist/HKT.d.ts +12 -6
  230. package/dist/HKT.d.ts.map +1 -1
  231. package/dist/Hash.d.ts +47 -83
  232. package/dist/Hash.d.ts.map +1 -1
  233. package/dist/Hash.js +46 -68
  234. package/dist/Hash.js.map +1 -1
  235. package/dist/HashMap.d.ts +319 -411
  236. package/dist/HashMap.d.ts.map +1 -1
  237. package/dist/HashMap.js +122 -166
  238. package/dist/HashMap.js.map +1 -1
  239. package/dist/HashRing.d.ts.map +1 -1
  240. package/dist/HashRing.js +1 -0
  241. package/dist/HashRing.js.map +1 -1
  242. package/dist/HashSet.d.ts +177 -284
  243. package/dist/HashSet.d.ts.map +1 -1
  244. package/dist/HashSet.js +68 -109
  245. package/dist/HashSet.js.map +1 -1
  246. package/dist/Inspectable.d.ts +19 -18
  247. package/dist/Inspectable.d.ts.map +1 -1
  248. package/dist/Inspectable.js +20 -16
  249. package/dist/Inspectable.js.map +1 -1
  250. package/dist/Iterable.d.ts +620 -786
  251. package/dist/Iterable.d.ts.map +1 -1
  252. package/dist/Iterable.js +282 -318
  253. package/dist/Iterable.js.map +1 -1
  254. package/dist/JsonPatch.d.ts +11 -13
  255. package/dist/JsonPatch.d.ts.map +1 -1
  256. package/dist/JsonPatch.js +46 -103
  257. package/dist/JsonPatch.js.map +1 -1
  258. package/dist/JsonPointer.d.ts +8 -8
  259. package/dist/JsonPointer.js +8 -8
  260. package/dist/JsonPointer.js.map +1 -1
  261. package/dist/JsonSchema.d.ts +98 -44
  262. package/dist/JsonSchema.d.ts.map +1 -1
  263. package/dist/JsonSchema.js +319 -241
  264. package/dist/JsonSchema.js.map +1 -1
  265. package/dist/Latch.d.ts +23 -35
  266. package/dist/Latch.d.ts.map +1 -1
  267. package/dist/Latch.js +16 -28
  268. package/dist/Latch.js.map +1 -1
  269. package/dist/Layer.d.ts +359 -260
  270. package/dist/Layer.d.ts.map +1 -1
  271. package/dist/Layer.js +202 -180
  272. package/dist/Layer.js.map +1 -1
  273. package/dist/LayerMap.d.ts +42 -29
  274. package/dist/LayerMap.d.ts.map +1 -1
  275. package/dist/LayerMap.js +31 -21
  276. package/dist/LayerMap.js.map +1 -1
  277. package/dist/LayerRef.d.ts +6 -2
  278. package/dist/LayerRef.d.ts.map +1 -1
  279. package/dist/LayerRef.js +6 -2
  280. package/dist/LayerRef.js.map +1 -1
  281. package/dist/LogLevel.d.ts +114 -214
  282. package/dist/LogLevel.d.ts.map +1 -1
  283. package/dist/LogLevel.js +41 -76
  284. package/dist/LogLevel.js.map +1 -1
  285. package/dist/Logger.d.ts +218 -467
  286. package/dist/Logger.d.ts.map +1 -1
  287. package/dist/Logger.js +208 -453
  288. package/dist/Logger.js.map +1 -1
  289. package/dist/ManagedRuntime.d.ts +16 -5
  290. package/dist/ManagedRuntime.d.ts.map +1 -1
  291. package/dist/ManagedRuntime.js +10 -5
  292. package/dist/ManagedRuntime.js.map +1 -1
  293. package/dist/Match.d.ts +217 -252
  294. package/dist/Match.d.ts.map +1 -1
  295. package/dist/Match.js +150 -183
  296. package/dist/Match.js.map +1 -1
  297. package/dist/Metric.d.ts +442 -993
  298. package/dist/Metric.d.ts.map +1 -1
  299. package/dist/Metric.js +202 -645
  300. package/dist/Metric.js.map +1 -1
  301. package/dist/MutableHashMap.d.ts +144 -173
  302. package/dist/MutableHashMap.d.ts.map +1 -1
  303. package/dist/MutableHashMap.js +68 -79
  304. package/dist/MutableHashMap.js.map +1 -1
  305. package/dist/MutableHashSet.d.ts +84 -89
  306. package/dist/MutableHashSet.d.ts.map +1 -1
  307. package/dist/MutableHashSet.js +44 -47
  308. package/dist/MutableHashSet.js.map +1 -1
  309. package/dist/MutableList.d.ts +71 -370
  310. package/dist/MutableList.d.ts.map +1 -1
  311. package/dist/MutableList.js +63 -284
  312. package/dist/MutableList.js.map +1 -1
  313. package/dist/MutableRef.d.ts +420 -243
  314. package/dist/MutableRef.d.ts.map +1 -1
  315. package/dist/MutableRef.js +209 -120
  316. package/dist/MutableRef.js.map +1 -1
  317. package/dist/Newtype.d.ts +21 -14
  318. package/dist/Newtype.d.ts.map +1 -1
  319. package/dist/Newtype.js +15 -13
  320. package/dist/Newtype.js.map +1 -1
  321. package/dist/NonEmptyIterable.d.ts +7 -137
  322. package/dist/NonEmptyIterable.d.ts.map +1 -1
  323. package/dist/NonEmptyIterable.js +5 -93
  324. package/dist/NonEmptyIterable.js.map +1 -1
  325. package/dist/Number.d.ts +196 -233
  326. package/dist/Number.d.ts.map +1 -1
  327. package/dist/Number.js +90 -109
  328. package/dist/Number.js.map +1 -1
  329. package/dist/Optic.d.ts +132 -210
  330. package/dist/Optic.d.ts.map +1 -1
  331. package/dist/Optic.js +221 -324
  332. package/dist/Optic.js.map +1 -1
  333. package/dist/Option.d.ts +447 -812
  334. package/dist/Option.d.ts.map +1 -1
  335. package/dist/Option.js +213 -393
  336. package/dist/Option.js.map +1 -1
  337. package/dist/Order.d.ts +109 -109
  338. package/dist/Order.js +91 -91
  339. package/dist/Order.js.map +1 -1
  340. package/dist/Ordering.d.ts +20 -23
  341. package/dist/Ordering.d.ts.map +1 -1
  342. package/dist/Ordering.js +8 -9
  343. package/dist/Ordering.js.map +1 -1
  344. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  345. package/dist/PartitionedSemaphore.js +1 -4
  346. package/dist/PartitionedSemaphore.js.map +1 -1
  347. package/dist/Path.d.ts +38 -41
  348. package/dist/Path.d.ts.map +1 -1
  349. package/dist/Path.js +3 -4
  350. package/dist/Path.js.map +1 -1
  351. package/dist/Pipeable.d.ts +6 -5
  352. package/dist/Pipeable.d.ts.map +1 -1
  353. package/dist/Pipeable.js +2 -2
  354. package/dist/Pipeable.js.map +1 -1
  355. package/dist/PlatformError.d.ts +4 -4
  356. package/dist/PlatformError.js +3 -3
  357. package/dist/PlatformError.js.map +1 -1
  358. package/dist/Pool.d.ts +4 -2
  359. package/dist/Pool.d.ts.map +1 -1
  360. package/dist/Pool.js +4 -2
  361. package/dist/Pool.js.map +1 -1
  362. package/dist/Predicate.d.ts +200 -181
  363. package/dist/Predicate.d.ts.map +1 -1
  364. package/dist/Predicate.js +100 -108
  365. package/dist/Predicate.js.map +1 -1
  366. package/dist/PrimaryKey.d.ts +7 -7
  367. package/dist/PrimaryKey.js +5 -5
  368. package/dist/PrimaryKey.js.map +1 -1
  369. package/dist/PubSub.d.ts +425 -494
  370. package/dist/PubSub.d.ts.map +1 -1
  371. package/dist/PubSub.js +373 -362
  372. package/dist/PubSub.js.map +1 -1
  373. package/dist/Pull.d.ts +24 -18
  374. package/dist/Pull.d.ts.map +1 -1
  375. package/dist/Pull.js +11 -9
  376. package/dist/Pull.js.map +1 -1
  377. package/dist/Queue.d.ts +200 -159
  378. package/dist/Queue.d.ts.map +1 -1
  379. package/dist/Queue.js +166 -138
  380. package/dist/Queue.js.map +1 -1
  381. package/dist/Random.d.ts +49 -74
  382. package/dist/Random.d.ts.map +1 -1
  383. package/dist/Random.js +35 -54
  384. package/dist/Random.js.map +1 -1
  385. package/dist/RcMap.d.ts +121 -63
  386. package/dist/RcMap.d.ts.map +1 -1
  387. package/dist/RcMap.js +42 -21
  388. package/dist/RcMap.js.map +1 -1
  389. package/dist/RcRef.d.ts +24 -13
  390. package/dist/RcRef.d.ts.map +1 -1
  391. package/dist/RcRef.js +15 -9
  392. package/dist/RcRef.js.map +1 -1
  393. package/dist/Record.d.ts +361 -466
  394. package/dist/Record.d.ts.map +1 -1
  395. package/dist/Record.js +163 -216
  396. package/dist/Record.js.map +1 -1
  397. package/dist/Redactable.d.ts +6 -2
  398. package/dist/Redactable.d.ts.map +1 -1
  399. package/dist/Redactable.js +7 -2
  400. package/dist/Redactable.js.map +1 -1
  401. package/dist/Redacted.d.ts +25 -25
  402. package/dist/Redacted.d.ts.map +1 -1
  403. package/dist/Redacted.js +19 -20
  404. package/dist/Redacted.js.map +1 -1
  405. package/dist/Reducer.d.ts +8 -15
  406. package/dist/Reducer.d.ts.map +1 -1
  407. package/dist/Reducer.js +6 -12
  408. package/dist/Reducer.js.map +1 -1
  409. package/dist/Ref.d.ts +95 -165
  410. package/dist/Ref.d.ts.map +1 -1
  411. package/dist/Ref.js +75 -122
  412. package/dist/Ref.js.map +1 -1
  413. package/dist/References.d.ts +102 -213
  414. package/dist/References.d.ts.map +1 -1
  415. package/dist/References.js +102 -213
  416. package/dist/References.js.map +1 -1
  417. package/dist/RegExp.d.ts +10 -14
  418. package/dist/RegExp.d.ts.map +1 -1
  419. package/dist/RegExp.js +10 -14
  420. package/dist/RegExp.js.map +1 -1
  421. package/dist/Request.d.ts +31 -21
  422. package/dist/Request.d.ts.map +1 -1
  423. package/dist/Request.js +25 -19
  424. package/dist/Request.js.map +1 -1
  425. package/dist/RequestResolver.d.ts +201 -90
  426. package/dist/RequestResolver.d.ts.map +1 -1
  427. package/dist/RequestResolver.js +87 -41
  428. package/dist/RequestResolver.js.map +1 -1
  429. package/dist/Resource.js.map +1 -1
  430. package/dist/Result.d.ts +302 -470
  431. package/dist/Result.d.ts.map +1 -1
  432. package/dist/Result.js +135 -218
  433. package/dist/Result.js.map +1 -1
  434. package/dist/Runtime.d.ts +50 -75
  435. package/dist/Runtime.d.ts.map +1 -1
  436. package/dist/Runtime.js +39 -60
  437. package/dist/Runtime.js.map +1 -1
  438. package/dist/Schedule.d.ts +292 -1638
  439. package/dist/Schedule.d.ts.map +1 -1
  440. package/dist/Schedule.js +164 -805
  441. package/dist/Schedule.js.map +1 -1
  442. package/dist/Scheduler.d.ts +5 -5
  443. package/dist/Scheduler.d.ts.map +1 -1
  444. package/dist/Scheduler.js +18 -6
  445. package/dist/Scheduler.js.map +1 -1
  446. package/dist/Schema.d.ts +2056 -1269
  447. package/dist/Schema.d.ts.map +1 -1
  448. package/dist/Schema.js +2869 -1136
  449. package/dist/Schema.js.map +1 -1
  450. package/dist/SchemaAST.d.ts +64 -72
  451. package/dist/SchemaAST.d.ts.map +1 -1
  452. package/dist/SchemaAST.js +698 -468
  453. package/dist/SchemaAST.js.map +1 -1
  454. package/dist/SchemaGetter.d.ts +236 -188
  455. package/dist/SchemaGetter.d.ts.map +1 -1
  456. package/dist/SchemaGetter.js +281 -234
  457. package/dist/SchemaGetter.js.map +1 -1
  458. package/dist/SchemaIssue.d.ts +219 -190
  459. package/dist/SchemaIssue.d.ts.map +1 -1
  460. package/dist/SchemaIssue.js +303 -309
  461. package/dist/SchemaIssue.js.map +1 -1
  462. package/dist/SchemaParser.d.ts +32 -2
  463. package/dist/SchemaParser.d.ts.map +1 -1
  464. package/dist/SchemaParser.js +170 -118
  465. package/dist/SchemaParser.js.map +1 -1
  466. package/dist/SchemaRepresentation.d.ts +433 -1511
  467. package/dist/SchemaRepresentation.d.ts.map +1 -1
  468. package/dist/SchemaRepresentation.js +301 -2854
  469. package/dist/SchemaRepresentation.js.map +1 -1
  470. package/dist/SchemaTransformation.d.ts +117 -77
  471. package/dist/SchemaTransformation.d.ts.map +1 -1
  472. package/dist/SchemaTransformation.js +139 -104
  473. package/dist/SchemaTransformation.js.map +1 -1
  474. package/dist/Scope.d.ts +123 -151
  475. package/dist/Scope.d.ts.map +1 -1
  476. package/dist/Scope.js +72 -92
  477. package/dist/Scope.js.map +1 -1
  478. package/dist/ScopedCache.js +1 -1
  479. package/dist/ScopedCache.js.map +1 -1
  480. package/dist/ScopedRef.d.ts +3 -3
  481. package/dist/ScopedRef.d.ts.map +1 -1
  482. package/dist/ScopedRef.js +2 -2
  483. package/dist/ScopedRef.js.map +1 -1
  484. package/dist/Semaphore.d.ts +101 -13
  485. package/dist/Semaphore.d.ts.map +1 -1
  486. package/dist/Semaphore.js +78 -39
  487. package/dist/Semaphore.js.map +1 -1
  488. package/dist/Sink.d.ts +118 -108
  489. package/dist/Sink.d.ts.map +1 -1
  490. package/dist/Sink.js +107 -100
  491. package/dist/Sink.js.map +1 -1
  492. package/dist/Stdio.d.ts +18 -5
  493. package/dist/Stdio.d.ts.map +1 -1
  494. package/dist/Stdio.js +6 -3
  495. package/dist/Stdio.js.map +1 -1
  496. package/dist/Stream.d.ts +2467 -2962
  497. package/dist/Stream.d.ts.map +1 -1
  498. package/dist/Stream.js +1154 -1413
  499. package/dist/Stream.js.map +1 -1
  500. package/dist/String.d.ts +262 -308
  501. package/dist/String.d.ts.map +1 -1
  502. package/dist/String.js +184 -215
  503. package/dist/String.js.map +1 -1
  504. package/dist/Struct.d.ts +109 -114
  505. package/dist/Struct.d.ts.map +1 -1
  506. package/dist/Struct.js +46 -54
  507. package/dist/Struct.js.map +1 -1
  508. package/dist/SubscriptionRef.d.ts +282 -250
  509. package/dist/SubscriptionRef.d.ts.map +1 -1
  510. package/dist/SubscriptionRef.js +104 -92
  511. package/dist/SubscriptionRef.js.map +1 -1
  512. package/dist/Symbol.d.ts +3 -3
  513. package/dist/Symbol.js +3 -3
  514. package/dist/Symbol.js.map +1 -1
  515. package/dist/SynchronizedRef.js +1 -1
  516. package/dist/SynchronizedRef.js.map +1 -1
  517. package/dist/Take.js.map +1 -1
  518. package/dist/Terminal.d.ts +2 -2
  519. package/dist/Terminal.js +2 -2
  520. package/dist/Terminal.js.map +1 -1
  521. package/dist/Tracer.d.ts +100 -54
  522. package/dist/Tracer.d.ts.map +1 -1
  523. package/dist/Tracer.js +41 -24
  524. package/dist/Tracer.js.map +1 -1
  525. package/dist/Trie.d.ts +287 -679
  526. package/dist/Trie.d.ts.map +1 -1
  527. package/dist/Trie.js +109 -251
  528. package/dist/Trie.js.map +1 -1
  529. package/dist/Tuple.d.ts +98 -131
  530. package/dist/Tuple.d.ts.map +1 -1
  531. package/dist/Tuple.js +42 -57
  532. package/dist/Tuple.js.map +1 -1
  533. package/dist/TxChunk.d.ts +201 -121
  534. package/dist/TxChunk.d.ts.map +1 -1
  535. package/dist/TxChunk.js +85 -56
  536. package/dist/TxChunk.js.map +1 -1
  537. package/dist/TxDeferred.d.ts +62 -46
  538. package/dist/TxDeferred.d.ts.map +1 -1
  539. package/dist/TxDeferred.js +30 -22
  540. package/dist/TxDeferred.js.map +1 -1
  541. package/dist/TxHashMap.d.ts +631 -779
  542. package/dist/TxHashMap.d.ts.map +1 -1
  543. package/dist/TxHashMap.js +268 -330
  544. package/dist/TxHashMap.js.map +1 -1
  545. package/dist/TxHashSet.d.ts +297 -236
  546. package/dist/TxHashSet.d.ts.map +1 -1
  547. package/dist/TxHashSet.js +130 -100
  548. package/dist/TxHashSet.js.map +1 -1
  549. package/dist/TxPriorityQueue.d.ts +126 -95
  550. package/dist/TxPriorityQueue.d.ts.map +1 -1
  551. package/dist/TxPriorityQueue.js +74 -56
  552. package/dist/TxPriorityQueue.js.map +1 -1
  553. package/dist/TxPubSub.d.ts +101 -88
  554. package/dist/TxPubSub.d.ts.map +1 -1
  555. package/dist/TxPubSub.js +87 -66
  556. package/dist/TxPubSub.js.map +1 -1
  557. package/dist/TxQueue.d.ts +200 -180
  558. package/dist/TxQueue.d.ts.map +1 -1
  559. package/dist/TxQueue.js +161 -137
  560. package/dist/TxQueue.js.map +1 -1
  561. package/dist/TxReentrantLock.d.ts +89 -114
  562. package/dist/TxReentrantLock.d.ts.map +1 -1
  563. package/dist/TxReentrantLock.js +75 -53
  564. package/dist/TxReentrantLock.js.map +1 -1
  565. package/dist/TxRef.d.ts +51 -32
  566. package/dist/TxRef.d.ts.map +1 -1
  567. package/dist/TxRef.js +23 -15
  568. package/dist/TxRef.js.map +1 -1
  569. package/dist/TxSemaphore.d.ts +129 -95
  570. package/dist/TxSemaphore.d.ts.map +1 -1
  571. package/dist/TxSemaphore.js +85 -70
  572. package/dist/TxSemaphore.js.map +1 -1
  573. package/dist/TxSubscriptionRef.d.ts +97 -70
  574. package/dist/TxSubscriptionRef.d.ts.map +1 -1
  575. package/dist/TxSubscriptionRef.js +44 -34
  576. package/dist/TxSubscriptionRef.js.map +1 -1
  577. package/dist/Types.d.ts +127 -70
  578. package/dist/Types.d.ts.map +1 -1
  579. package/dist/UndefinedOr.js.map +1 -1
  580. package/dist/Unify.d.ts +45 -65
  581. package/dist/Unify.d.ts.map +1 -1
  582. package/dist/Unify.js +6 -9
  583. package/dist/Unify.js.map +1 -1
  584. package/dist/Utils.d.ts +23 -16
  585. package/dist/Utils.d.ts.map +1 -1
  586. package/dist/Utils.js +3 -7
  587. package/dist/Utils.js.map +1 -1
  588. package/dist/index.d.ts +0 -8
  589. package/dist/index.d.ts.map +1 -1
  590. package/dist/index.js +0 -8
  591. package/dist/index.js.map +1 -1
  592. package/dist/internal/array.js.map +1 -1
  593. package/dist/internal/core.js +4 -3
  594. package/dist/internal/core.js.map +1 -1
  595. package/dist/internal/dateTime.js +5 -1
  596. package/dist/internal/dateTime.js.map +1 -1
  597. package/dist/internal/doNotation.js.map +1 -1
  598. package/dist/internal/effect.js +261 -111
  599. package/dist/internal/effect.js.map +1 -1
  600. package/dist/internal/equal.js.map +1 -1
  601. package/dist/internal/errors.js.map +1 -1
  602. package/dist/internal/executionPlan.js +52 -3
  603. package/dist/internal/executionPlan.js.map +1 -1
  604. package/dist/internal/hashMap.js +12 -8
  605. package/dist/internal/hashMap.js.map +1 -1
  606. package/dist/internal/hashSet.js.map +1 -1
  607. package/dist/internal/layer.js.map +1 -1
  608. package/dist/internal/matcher.js +2 -2
  609. package/dist/internal/matcher.js.map +1 -1
  610. package/dist/internal/metric.js.map +1 -1
  611. package/dist/internal/option.js.map +1 -1
  612. package/dist/internal/persistence.d.ts +2 -0
  613. package/dist/internal/persistence.d.ts.map +1 -0
  614. package/dist/internal/persistence.js +3 -0
  615. package/dist/internal/persistence.js.map +1 -0
  616. package/dist/internal/random.js.map +1 -1
  617. package/dist/internal/rcRef.js +18 -13
  618. package/dist/internal/rcRef.js.map +1 -1
  619. package/dist/internal/record.d.ts +0 -3
  620. package/dist/internal/record.d.ts.map +1 -1
  621. package/dist/internal/record.js +10 -5
  622. package/dist/internal/record.js.map +1 -1
  623. package/dist/internal/redacted.js.map +1 -1
  624. package/dist/internal/references.js +3 -4
  625. package/dist/internal/references.js.map +1 -1
  626. package/dist/internal/request.js.map +1 -1
  627. package/dist/internal/result.js.map +1 -1
  628. package/dist/internal/schedule.js.map +1 -1
  629. package/dist/internal/schema/annotations.js +15 -1
  630. package/dist/internal/schema/annotations.js.map +1 -1
  631. package/dist/internal/schema/cause.js.map +1 -1
  632. package/dist/internal/schema/fromJsonSchemaDocument.d.ts +2 -0
  633. package/dist/internal/schema/fromJsonSchemaDocument.d.ts.map +1 -0
  634. package/dist/internal/schema/fromJsonSchemaDocument.js +761 -0
  635. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -0
  636. package/dist/internal/schema/fromRepresentation.d.ts +2 -0
  637. package/dist/internal/schema/fromRepresentation.d.ts.map +1 -0
  638. package/dist/internal/schema/fromRepresentation.js +245 -0
  639. package/dist/internal/schema/fromRepresentation.js.map +1 -0
  640. package/dist/internal/schema/parser.d.ts +14 -0
  641. package/dist/internal/schema/parser.d.ts.map +1 -0
  642. package/dist/internal/schema/parser.js +13 -0
  643. package/dist/internal/schema/parser.js.map +1 -0
  644. package/dist/internal/schema/schema.js +29 -49
  645. package/dist/internal/schema/schema.js.map +1 -1
  646. package/dist/internal/schema/toArbitrary.d.ts +2 -0
  647. package/dist/internal/schema/toArbitrary.d.ts.map +1 -0
  648. package/dist/internal/schema/{arbitrary.js → toArbitrary.js} +8 -83
  649. package/dist/internal/schema/toArbitrary.js.map +1 -0
  650. package/dist/internal/schema/toCodeDocument.d.ts +2 -0
  651. package/dist/internal/schema/toCodeDocument.d.ts.map +1 -0
  652. package/dist/internal/schema/toCodeDocument.js +438 -0
  653. package/dist/internal/schema/toCodeDocument.js.map +1 -0
  654. package/dist/internal/schema/toEquivalence.d.ts +2 -0
  655. package/dist/internal/schema/toEquivalence.d.ts.map +1 -0
  656. package/dist/internal/schema/{equivalence.js → toEquivalence.js} +15 -13
  657. package/dist/internal/schema/toEquivalence.js.map +1 -0
  658. package/dist/internal/schema/toJsonSchemaDocument.d.ts +2 -0
  659. package/dist/internal/schema/toJsonSchemaDocument.d.ts.map +1 -0
  660. package/dist/internal/schema/toJsonSchemaDocument.js +522 -0
  661. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -0
  662. package/dist/internal/schema/toRepresentation.d.ts +2 -0
  663. package/dist/internal/schema/toRepresentation.d.ts.map +1 -0
  664. package/dist/internal/schema/toRepresentation.js +351 -0
  665. package/dist/internal/schema/toRepresentation.js.map +1 -0
  666. package/dist/internal/stackTraceLimit.js +3 -6
  667. package/dist/internal/stackTraceLimit.js.map +1 -1
  668. package/dist/internal/stream.js.map +1 -1
  669. package/dist/internal/tracer.js.map +1 -1
  670. package/dist/internal/trie.js +24 -10
  671. package/dist/internal/trie.js.map +1 -1
  672. package/dist/testing/FastCheck.d.ts +8 -7
  673. package/dist/testing/FastCheck.d.ts.map +1 -1
  674. package/dist/testing/FastCheck.js +8 -7
  675. package/dist/testing/FastCheck.js.map +1 -1
  676. package/dist/testing/TestClock.d.ts +57 -28
  677. package/dist/testing/TestClock.d.ts.map +1 -1
  678. package/dist/testing/TestClock.js +65 -20
  679. package/dist/testing/TestClock.js.map +1 -1
  680. package/dist/testing/TestConsole.d.ts +32 -31
  681. package/dist/testing/TestConsole.d.ts.map +1 -1
  682. package/dist/testing/TestConsole.js +24 -22
  683. package/dist/testing/TestConsole.js.map +1 -1
  684. package/dist/testing/TestSchema.d.ts +31 -31
  685. package/dist/testing/TestSchema.d.ts.map +1 -1
  686. package/dist/testing/TestSchema.js +35 -34
  687. package/dist/testing/TestSchema.js.map +1 -1
  688. package/dist/testing/index.js.map +1 -1
  689. package/dist/unstable/ai/AiError.d.ts +121 -144
  690. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  691. package/dist/unstable/ai/AiError.js +118 -140
  692. package/dist/unstable/ai/AiError.js.map +1 -1
  693. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +22 -7
  694. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  695. package/dist/unstable/ai/AnthropicStructuredOutput.js +87 -317
  696. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  697. package/dist/unstable/ai/Chat.d.ts +132 -97
  698. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  699. package/dist/unstable/ai/Chat.js +56 -52
  700. package/dist/unstable/ai/Chat.js.map +1 -1
  701. package/dist/unstable/ai/EmbeddingModel.d.ts +1 -1
  702. package/dist/unstable/ai/EmbeddingModel.js +1 -1
  703. package/dist/unstable/ai/EmbeddingModel.js.map +1 -1
  704. package/dist/unstable/ai/IdGenerator.d.ts +32 -28
  705. package/dist/unstable/ai/IdGenerator.d.ts.map +1 -1
  706. package/dist/unstable/ai/IdGenerator.js +26 -21
  707. package/dist/unstable/ai/IdGenerator.js.map +1 -1
  708. package/dist/unstable/ai/LanguageModel.d.ts +111 -68
  709. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  710. package/dist/unstable/ai/LanguageModel.js +127 -83
  711. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  712. package/dist/unstable/ai/McpProtocol.d.ts +30 -0
  713. package/dist/unstable/ai/McpProtocol.d.ts.map +1 -0
  714. package/dist/unstable/ai/McpProtocol.js +20 -0
  715. package/dist/unstable/ai/McpProtocol.js.map +1 -0
  716. package/dist/unstable/ai/McpSchema.d.ts +198 -132
  717. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  718. package/dist/unstable/ai/McpSchema.js +79 -71
  719. package/dist/unstable/ai/McpSchema.js.map +1 -1
  720. package/dist/unstable/ai/McpServer.d.ts +71 -62
  721. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  722. package/dist/unstable/ai/McpServer.js +777 -245
  723. package/dist/unstable/ai/McpServer.js.map +1 -1
  724. package/dist/unstable/ai/Model.d.ts +8 -19
  725. package/dist/unstable/ai/Model.d.ts.map +1 -1
  726. package/dist/unstable/ai/Model.js +9 -20
  727. package/dist/unstable/ai/Model.js.map +1 -1
  728. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +33 -11
  729. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  730. package/dist/unstable/ai/OpenAiStructuredOutput.js +194 -378
  731. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  732. package/dist/unstable/ai/Prompt.d.ts +131 -44
  733. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  734. package/dist/unstable/ai/Prompt.js +100 -36
  735. package/dist/unstable/ai/Prompt.js.map +1 -1
  736. package/dist/unstable/ai/Response.d.ts +47 -33
  737. package/dist/unstable/ai/Response.d.ts.map +1 -1
  738. package/dist/unstable/ai/Response.js +23 -18
  739. package/dist/unstable/ai/Response.js.map +1 -1
  740. package/dist/unstable/ai/ResponseIdTracker.js.map +1 -1
  741. package/dist/unstable/ai/Telemetry.d.ts +46 -13
  742. package/dist/unstable/ai/Telemetry.d.ts.map +1 -1
  743. package/dist/unstable/ai/Telemetry.js +18 -7
  744. package/dist/unstable/ai/Telemetry.js.map +1 -1
  745. package/dist/unstable/ai/Tokenizer.d.ts +14 -3
  746. package/dist/unstable/ai/Tokenizer.d.ts.map +1 -1
  747. package/dist/unstable/ai/Tokenizer.js +10 -2
  748. package/dist/unstable/ai/Tokenizer.js.map +1 -1
  749. package/dist/unstable/ai/Tool.d.ts +63 -44
  750. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  751. package/dist/unstable/ai/Tool.js +70 -55
  752. package/dist/unstable/ai/Tool.js.map +1 -1
  753. package/dist/unstable/ai/Toolkit.d.ts +35 -9
  754. package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
  755. package/dist/unstable/ai/Toolkit.js +32 -14
  756. package/dist/unstable/ai/Toolkit.js.map +1 -1
  757. package/dist/unstable/ai/index.d.ts +4 -0
  758. package/dist/unstable/ai/index.d.ts.map +1 -1
  759. package/dist/unstable/ai/index.js +4 -0
  760. package/dist/unstable/ai/index.js.map +1 -1
  761. package/dist/unstable/ai/internal/codec-transformer.js +15 -12
  762. package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
  763. package/dist/unstable/ai/internal/mcpProtocol.d.ts +21 -0
  764. package/dist/unstable/ai/internal/mcpProtocol.d.ts.map +1 -0
  765. package/dist/unstable/ai/internal/mcpProtocol.js +22 -0
  766. package/dist/unstable/ai/internal/mcpProtocol.js.map +1 -0
  767. package/dist/unstable/ai/internal/mcpProtocolRegistry.d.ts +2 -0
  768. package/dist/unstable/ai/internal/mcpProtocolRegistry.d.ts.map +1 -0
  769. package/dist/unstable/ai/internal/mcpProtocolRegistry.js +32 -0
  770. package/dist/unstable/ai/internal/mcpProtocolRegistry.js.map +1 -0
  771. package/dist/unstable/ai/internal/structured-output.d.ts +2 -0
  772. package/dist/unstable/ai/internal/structured-output.d.ts.map +1 -0
  773. package/dist/unstable/ai/internal/structured-output.js +315 -0
  774. package/dist/unstable/ai/internal/structured-output.js.map +1 -0
  775. package/dist/unstable/cli/Argument.d.ts +279 -72
  776. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  777. package/dist/unstable/cli/Argument.js +113 -34
  778. package/dist/unstable/cli/Argument.js.map +1 -1
  779. package/dist/unstable/cli/CliConfig.d.ts +76 -0
  780. package/dist/unstable/cli/CliConfig.d.ts.map +1 -0
  781. package/dist/unstable/cli/CliConfig.js +63 -0
  782. package/dist/unstable/cli/CliConfig.js.map +1 -0
  783. package/dist/unstable/cli/CliError.d.ts +126 -76
  784. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  785. package/dist/unstable/cli/CliError.js +138 -75
  786. package/dist/unstable/cli/CliError.js.map +1 -1
  787. package/dist/unstable/cli/CliOutput.d.ts +35 -54
  788. package/dist/unstable/cli/CliOutput.d.ts.map +1 -1
  789. package/dist/unstable/cli/CliOutput.js +26 -42
  790. package/dist/unstable/cli/CliOutput.js.map +1 -1
  791. package/dist/unstable/cli/Command.d.ts +765 -109
  792. package/dist/unstable/cli/Command.d.ts.map +1 -1
  793. package/dist/unstable/cli/Command.js +335 -52
  794. package/dist/unstable/cli/Command.js.map +1 -1
  795. package/dist/unstable/cli/Completions.js.map +1 -1
  796. package/dist/unstable/cli/Flag.d.ts +418 -138
  797. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  798. package/dist/unstable/cli/Flag.js +197 -71
  799. package/dist/unstable/cli/Flag.js.map +1 -1
  800. package/dist/unstable/cli/GlobalFlag.d.ts +24 -3
  801. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  802. package/dist/unstable/cli/GlobalFlag.js +20 -4
  803. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  804. package/dist/unstable/cli/HelpDoc.d.ts +12 -4
  805. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  806. package/dist/unstable/cli/Param.d.ts +299 -83
  807. package/dist/unstable/cli/Param.d.ts.map +1 -1
  808. package/dist/unstable/cli/Param.js +152 -62
  809. package/dist/unstable/cli/Param.js.map +1 -1
  810. package/dist/unstable/cli/Primitive.d.ts +370 -149
  811. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  812. package/dist/unstable/cli/Primitive.js +377 -162
  813. package/dist/unstable/cli/Primitive.js.map +1 -1
  814. package/dist/unstable/cli/Prompt.d.ts +23 -14
  815. package/dist/unstable/cli/Prompt.d.ts.map +1 -1
  816. package/dist/unstable/cli/Prompt.js +54 -31
  817. package/dist/unstable/cli/Prompt.js.map +1 -1
  818. package/dist/unstable/cli/index.d.ts +4 -0
  819. package/dist/unstable/cli/index.d.ts.map +1 -1
  820. package/dist/unstable/cli/index.js +4 -0
  821. package/dist/unstable/cli/index.js.map +1 -1
  822. package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
  823. package/dist/unstable/cli/internal/ansi.js +4 -2
  824. package/dist/unstable/cli/internal/ansi.js.map +1 -1
  825. package/dist/unstable/cli/internal/auto-suggest.js.map +1 -1
  826. package/dist/unstable/cli/internal/command.d.ts +5 -3
  827. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  828. package/dist/unstable/cli/internal/command.js +21 -13
  829. package/dist/unstable/cli/internal/command.js.map +1 -1
  830. package/dist/unstable/cli/internal/completions/bash.js +69 -9
  831. package/dist/unstable/cli/internal/completions/bash.js.map +1 -1
  832. package/dist/unstable/cli/internal/completions/descriptor.js +24 -18
  833. package/dist/unstable/cli/internal/completions/descriptor.js.map +1 -1
  834. package/dist/unstable/cli/internal/completions/fish.js +5 -5
  835. package/dist/unstable/cli/internal/completions/fish.js.map +1 -1
  836. package/dist/unstable/cli/internal/completions/zsh.js.map +1 -1
  837. package/dist/unstable/cli/internal/config.d.ts +0 -48
  838. package/dist/unstable/cli/internal/config.d.ts.map +1 -1
  839. package/dist/unstable/cli/internal/config.js +8 -10
  840. package/dist/unstable/cli/internal/config.js.map +1 -1
  841. package/dist/unstable/cli/internal/help.d.ts.map +1 -1
  842. package/dist/unstable/cli/internal/help.js +4 -2
  843. package/dist/unstable/cli/internal/help.js.map +1 -1
  844. package/dist/unstable/cli/internal/lexer.js +17 -7
  845. package/dist/unstable/cli/internal/lexer.js.map +1 -1
  846. package/dist/unstable/cli/internal/parser.js +16 -7
  847. package/dist/unstable/cli/internal/parser.js.map +1 -1
  848. package/dist/unstable/cli/internal/wizard.d.ts +13 -0
  849. package/dist/unstable/cli/internal/wizard.d.ts.map +1 -0
  850. package/dist/unstable/cli/internal/wizard.js +212 -0
  851. package/dist/unstable/cli/internal/wizard.js.map +1 -0
  852. package/dist/unstable/cluster/ClusterCron.js.map +1 -1
  853. package/dist/unstable/cluster/ClusterError.js +7 -7
  854. package/dist/unstable/cluster/ClusterError.js.map +1 -1
  855. package/dist/unstable/cluster/ClusterMetrics.js.map +1 -1
  856. package/dist/unstable/cluster/ClusterSchema.d.ts +8 -8
  857. package/dist/unstable/cluster/ClusterSchema.js +8 -8
  858. package/dist/unstable/cluster/ClusterSchema.js.map +1 -1
  859. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  860. package/dist/unstable/cluster/ClusterWorkflowEngine.js +32 -16
  861. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  862. package/dist/unstable/cluster/DeliverAt.js.map +1 -1
  863. package/dist/unstable/cluster/Entity.d.ts +12 -12
  864. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  865. package/dist/unstable/cluster/Entity.js +9 -9
  866. package/dist/unstable/cluster/Entity.js.map +1 -1
  867. package/dist/unstable/cluster/EntityAddress.js.map +1 -1
  868. package/dist/unstable/cluster/EntityId.js.map +1 -1
  869. package/dist/unstable/cluster/EntityProxy.d.ts +7 -5
  870. package/dist/unstable/cluster/EntityProxy.d.ts.map +1 -1
  871. package/dist/unstable/cluster/EntityProxy.js +8 -5
  872. package/dist/unstable/cluster/EntityProxy.js.map +1 -1
  873. package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
  874. package/dist/unstable/cluster/EntityResource.d.ts +2 -2
  875. package/dist/unstable/cluster/EntityResource.js +2 -2
  876. package/dist/unstable/cluster/EntityResource.js.map +1 -1
  877. package/dist/unstable/cluster/EntityType.js.map +1 -1
  878. package/dist/unstable/cluster/Envelope.d.ts +3 -3
  879. package/dist/unstable/cluster/Envelope.d.ts.map +1 -1
  880. package/dist/unstable/cluster/Envelope.js +5 -4
  881. package/dist/unstable/cluster/Envelope.js.map +1 -1
  882. package/dist/unstable/cluster/HttpRunner.d.ts +2 -2
  883. package/dist/unstable/cluster/HttpRunner.d.ts.map +1 -1
  884. package/dist/unstable/cluster/HttpRunner.js +6 -4
  885. package/dist/unstable/cluster/HttpRunner.js.map +1 -1
  886. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  887. package/dist/unstable/cluster/MachineId.js.map +1 -1
  888. package/dist/unstable/cluster/Message.d.ts +9 -9
  889. package/dist/unstable/cluster/Message.js +6 -6
  890. package/dist/unstable/cluster/Message.js.map +1 -1
  891. package/dist/unstable/cluster/MessageStorage.d.ts +15 -15
  892. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  893. package/dist/unstable/cluster/MessageStorage.js +13 -6
  894. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  895. package/dist/unstable/cluster/Reply.d.ts +8 -0
  896. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  897. package/dist/unstable/cluster/Reply.js +17 -5
  898. package/dist/unstable/cluster/Reply.js.map +1 -1
  899. package/dist/unstable/cluster/Runner.d.ts +1 -1
  900. package/dist/unstable/cluster/Runner.js +1 -1
  901. package/dist/unstable/cluster/Runner.js.map +1 -1
  902. package/dist/unstable/cluster/RunnerAddress.d.ts +1 -1
  903. package/dist/unstable/cluster/RunnerAddress.js +1 -1
  904. package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
  905. package/dist/unstable/cluster/RunnerHealth.d.ts +1 -1
  906. package/dist/unstable/cluster/RunnerHealth.js +1 -1
  907. package/dist/unstable/cluster/RunnerHealth.js.map +1 -1
  908. package/dist/unstable/cluster/RunnerServer.d.ts +2 -1
  909. package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
  910. package/dist/unstable/cluster/RunnerServer.js +29 -23
  911. package/dist/unstable/cluster/RunnerServer.js.map +1 -1
  912. package/dist/unstable/cluster/RunnerStorage.d.ts +3 -4
  913. package/dist/unstable/cluster/RunnerStorage.d.ts.map +1 -1
  914. package/dist/unstable/cluster/RunnerStorage.js +9 -8
  915. package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
  916. package/dist/unstable/cluster/Runners.d.ts +11 -15
  917. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  918. package/dist/unstable/cluster/Runners.js +32 -22
  919. package/dist/unstable/cluster/Runners.js.map +1 -1
  920. package/dist/unstable/cluster/ShardId.js +1 -1
  921. package/dist/unstable/cluster/ShardId.js.map +1 -1
  922. package/dist/unstable/cluster/Sharding.d.ts +2 -2
  923. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  924. package/dist/unstable/cluster/Sharding.js +164 -31
  925. package/dist/unstable/cluster/Sharding.js.map +1 -1
  926. package/dist/unstable/cluster/ShardingConfig.d.ts +13 -5
  927. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  928. package/dist/unstable/cluster/ShardingConfig.js +3 -3
  929. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  930. package/dist/unstable/cluster/ShardingRegistrationEvent.js.map +1 -1
  931. package/dist/unstable/cluster/SingleRunner.d.ts +4 -2
  932. package/dist/unstable/cluster/SingleRunner.d.ts.map +1 -1
  933. package/dist/unstable/cluster/SingleRunner.js +2 -1
  934. package/dist/unstable/cluster/SingleRunner.js.map +1 -1
  935. package/dist/unstable/cluster/Singleton.js.map +1 -1
  936. package/dist/unstable/cluster/SingletonAddress.d.ts +1 -1
  937. package/dist/unstable/cluster/SingletonAddress.js +1 -1
  938. package/dist/unstable/cluster/SingletonAddress.js.map +1 -1
  939. package/dist/unstable/cluster/Snowflake.d.ts +8 -8
  940. package/dist/unstable/cluster/Snowflake.js +8 -8
  941. package/dist/unstable/cluster/Snowflake.js.map +1 -1
  942. package/dist/unstable/cluster/SocketRunner.js.map +1 -1
  943. package/dist/unstable/cluster/SqlMessageStorage.d.ts +7 -4
  944. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  945. package/dist/unstable/cluster/SqlMessageStorage.js +56 -25
  946. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  947. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  948. package/dist/unstable/cluster/SqlRunnerStorage.js +141 -79
  949. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  950. package/dist/unstable/cluster/TestRunner.js.map +1 -1
  951. package/dist/unstable/cluster/index.js.map +1 -1
  952. package/dist/unstable/cluster/internal/entityManager.js +25 -13
  953. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  954. package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
  955. package/dist/unstable/cluster/internal/hash.js.map +1 -1
  956. package/dist/unstable/cluster/internal/interruptors.js.map +1 -1
  957. package/dist/unstable/cluster/internal/resourceMap.js +2 -2
  958. package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
  959. package/dist/unstable/cluster/internal/resourceRef.js +17 -0
  960. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  961. package/dist/unstable/cluster/internal/shardLock.d.ts +2 -0
  962. package/dist/unstable/cluster/internal/shardLock.d.ts.map +1 -0
  963. package/dist/unstable/cluster/internal/shardLock.js +4 -0
  964. package/dist/unstable/cluster/internal/shardLock.js.map +1 -0
  965. package/dist/unstable/devtools/DevTools.js.map +1 -1
  966. package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
  967. package/dist/unstable/devtools/DevToolsClient.js +7 -2
  968. package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
  969. package/dist/unstable/devtools/DevToolsSchema.d.ts +20 -20
  970. package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
  971. package/dist/unstable/devtools/DevToolsSchema.js +8 -5
  972. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  973. package/dist/unstable/devtools/DevToolsServer.js.map +1 -1
  974. package/dist/unstable/devtools/index.js.map +1 -1
  975. package/dist/unstable/encoding/Ini.d.ts +20 -0
  976. package/dist/unstable/encoding/Ini.d.ts.map +1 -0
  977. package/dist/unstable/encoding/Ini.js +153 -0
  978. package/dist/unstable/encoding/Ini.js.map +1 -0
  979. package/dist/unstable/encoding/Msgpack.d.ts +2 -1
  980. package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
  981. package/dist/unstable/encoding/Msgpack.js +31 -19
  982. package/dist/unstable/encoding/Msgpack.js.map +1 -1
  983. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  984. package/dist/unstable/encoding/Ndjson.js +7 -1
  985. package/dist/unstable/encoding/Ndjson.js.map +1 -1
  986. package/dist/unstable/encoding/Sse.d.ts +72 -8
  987. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  988. package/dist/unstable/encoding/Sse.js +72 -31
  989. package/dist/unstable/encoding/Sse.js.map +1 -1
  990. package/dist/unstable/encoding/Toml.d.ts +19 -0
  991. package/dist/unstable/encoding/Toml.d.ts.map +1 -0
  992. package/dist/unstable/encoding/Toml.js +434 -0
  993. package/dist/unstable/encoding/Toml.js.map +1 -0
  994. package/dist/unstable/encoding/Yaml.d.ts +19 -0
  995. package/dist/unstable/encoding/Yaml.d.ts.map +1 -0
  996. package/dist/unstable/encoding/Yaml.js +461 -0
  997. package/dist/unstable/encoding/Yaml.js.map +1 -0
  998. package/dist/unstable/encoding/index.d.ts +12 -0
  999. package/dist/unstable/encoding/index.d.ts.map +1 -1
  1000. package/dist/unstable/encoding/index.js +12 -0
  1001. package/dist/unstable/encoding/index.js.map +1 -1
  1002. package/dist/unstable/eventlog/Event.d.ts +20 -20
  1003. package/dist/unstable/eventlog/Event.js.map +1 -1
  1004. package/dist/unstable/eventlog/EventGroup.d.ts +4 -4
  1005. package/dist/unstable/eventlog/EventGroup.js.map +1 -1
  1006. package/dist/unstable/eventlog/EventJournal.d.ts +17 -17
  1007. package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
  1008. package/dist/unstable/eventlog/EventJournal.js +27 -19
  1009. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  1010. package/dist/unstable/eventlog/EventLog.d.ts +3 -3
  1011. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  1012. package/dist/unstable/eventlog/EventLog.js +18 -14
  1013. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  1014. package/dist/unstable/eventlog/EventLogEncryption.d.ts +8 -7
  1015. package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
  1016. package/dist/unstable/eventlog/EventLogEncryption.js +16 -14
  1017. package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
  1018. package/dist/unstable/eventlog/EventLogMessage.d.ts +31 -31
  1019. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  1020. package/dist/unstable/eventlog/EventLogMessage.js +12 -8
  1021. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  1022. package/dist/unstable/eventlog/EventLogRemote.d.ts +15 -15
  1023. package/dist/unstable/eventlog/EventLogRemote.js +5 -5
  1024. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  1025. package/dist/unstable/eventlog/EventLogServer.d.ts +11 -2
  1026. package/dist/unstable/eventlog/EventLogServer.d.ts.map +1 -1
  1027. package/dist/unstable/eventlog/EventLogServer.js +45 -21
  1028. package/dist/unstable/eventlog/EventLogServer.js.map +1 -1
  1029. package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts +4 -4
  1030. package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
  1031. package/dist/unstable/eventlog/EventLogServerEncrypted.js +16 -7
  1032. package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
  1033. package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts +5 -5
  1034. package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts.map +1 -1
  1035. package/dist/unstable/eventlog/EventLogServerUnencrypted.js +15 -7
  1036. package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -1
  1037. package/dist/unstable/eventlog/EventLogSessionAuth.d.ts +1 -1
  1038. package/dist/unstable/eventlog/EventLogSessionAuth.js +1 -1
  1039. package/dist/unstable/eventlog/EventLogSessionAuth.js.map +1 -1
  1040. package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
  1041. package/dist/unstable/eventlog/SqlEventJournal.js +3 -6
  1042. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  1043. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +1 -1
  1044. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  1045. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +3 -3
  1046. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  1047. package/dist/unstable/eventlog/index.js.map +1 -1
  1048. package/dist/unstable/eventlog/internal/identityRootSecretDerivation.js.map +1 -1
  1049. package/dist/unstable/http/Cookies.d.ts +2 -2
  1050. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  1051. package/dist/unstable/http/Cookies.js +54 -40
  1052. package/dist/unstable/http/Cookies.js.map +1 -1
  1053. package/dist/unstable/http/Etag.d.ts +1 -1
  1054. package/dist/unstable/http/Etag.js +1 -1
  1055. package/dist/unstable/http/Etag.js.map +1 -1
  1056. package/dist/unstable/http/FetchHttpClient.d.ts.map +1 -1
  1057. package/dist/unstable/http/FetchHttpClient.js.map +1 -1
  1058. package/dist/unstable/http/FindMyWay/internal/queryString.d.ts +11 -0
  1059. package/dist/unstable/http/FindMyWay/internal/queryString.d.ts.map +1 -0
  1060. package/dist/unstable/http/FindMyWay/internal/queryString.js +259 -0
  1061. package/dist/unstable/http/FindMyWay/internal/queryString.js.map +1 -0
  1062. package/dist/unstable/http/FindMyWay/internal/router.d.ts +2 -0
  1063. package/dist/unstable/http/FindMyWay/internal/router.d.ts.map +1 -0
  1064. package/dist/unstable/http/FindMyWay/internal/router.js +665 -0
  1065. package/dist/unstable/http/FindMyWay/internal/router.js.map +1 -0
  1066. package/dist/unstable/http/FindMyWay.d.ts +33 -8
  1067. package/dist/unstable/http/FindMyWay.d.ts.map +1 -1
  1068. package/dist/unstable/http/FindMyWay.js +4 -7
  1069. package/dist/unstable/http/FindMyWay.js.map +1 -1
  1070. package/dist/unstable/http/Headers.d.ts +2 -2
  1071. package/dist/unstable/http/Headers.js +10 -10
  1072. package/dist/unstable/http/Headers.js.map +1 -1
  1073. package/dist/unstable/http/HttpBody.d.ts +5 -3
  1074. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  1075. package/dist/unstable/http/HttpBody.js +11 -5
  1076. package/dist/unstable/http/HttpBody.js.map +1 -1
  1077. package/dist/unstable/http/HttpClient.d.ts +110 -47
  1078. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  1079. package/dist/unstable/http/HttpClient.js +79 -36
  1080. package/dist/unstable/http/HttpClient.js.map +1 -1
  1081. package/dist/unstable/http/HttpClientError.js +1 -1
  1082. package/dist/unstable/http/HttpClientError.js.map +1 -1
  1083. package/dist/unstable/http/HttpClientRequest.d.ts +44 -0
  1084. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  1085. package/dist/unstable/http/HttpClientRequest.js +16 -12
  1086. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  1087. package/dist/unstable/http/HttpClientResponse.d.ts +4 -4
  1088. package/dist/unstable/http/HttpClientResponse.js +3 -18
  1089. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  1090. package/dist/unstable/http/HttpEffect.d.ts +7 -9
  1091. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  1092. package/dist/unstable/http/HttpEffect.js +7 -8
  1093. package/dist/unstable/http/HttpEffect.js.map +1 -1
  1094. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  1095. package/dist/unstable/http/HttpMethod.d.ts +6 -9
  1096. package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
  1097. package/dist/unstable/http/HttpMethod.js +6 -9
  1098. package/dist/unstable/http/HttpMethod.js.map +1 -1
  1099. package/dist/unstable/http/HttpMiddleware.d.ts +75 -9
  1100. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  1101. package/dist/unstable/http/HttpMiddleware.js +164 -39
  1102. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  1103. package/dist/unstable/http/HttpPlatform.d.ts +76 -0
  1104. package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
  1105. package/dist/unstable/http/HttpPlatform.js +53 -3
  1106. package/dist/unstable/http/HttpPlatform.js.map +1 -1
  1107. package/dist/unstable/http/HttpRouter.d.ts +91 -92
  1108. package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
  1109. package/dist/unstable/http/HttpRouter.js +78 -79
  1110. package/dist/unstable/http/HttpRouter.js.map +1 -1
  1111. package/dist/unstable/http/HttpServer.d.ts +13 -13
  1112. package/dist/unstable/http/HttpServer.js +6 -6
  1113. package/dist/unstable/http/HttpServer.js.map +1 -1
  1114. package/dist/unstable/http/HttpServerError.d.ts +2 -2
  1115. package/dist/unstable/http/HttpServerError.js +2 -2
  1116. package/dist/unstable/http/HttpServerError.js.map +1 -1
  1117. package/dist/unstable/http/HttpServerRequest.d.ts +4 -4
  1118. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  1119. package/dist/unstable/http/HttpServerRequest.js +23 -15
  1120. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  1121. package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
  1122. package/dist/unstable/http/HttpServerResponse.d.ts +22 -0
  1123. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  1124. package/dist/unstable/http/HttpServerResponse.js +17 -5
  1125. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  1126. package/dist/unstable/http/HttpStaticServer.d.ts +35 -7
  1127. package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -1
  1128. package/dist/unstable/http/HttpStaticServer.js +35 -7
  1129. package/dist/unstable/http/HttpStaticServer.js.map +1 -1
  1130. package/dist/unstable/http/HttpTraceContext.js.map +1 -1
  1131. package/dist/unstable/http/Multipart.d.ts +28 -9
  1132. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  1133. package/dist/unstable/http/Multipart.js +68 -36
  1134. package/dist/unstable/http/Multipart.js.map +1 -1
  1135. package/dist/unstable/http/MultipartParser/HeadersParser.d.ts +53 -0
  1136. package/dist/unstable/http/MultipartParser/HeadersParser.d.ts.map +1 -0
  1137. package/dist/unstable/http/MultipartParser/HeadersParser.js +14 -0
  1138. package/dist/unstable/http/MultipartParser/HeadersParser.js.map +1 -0
  1139. package/dist/unstable/http/MultipartParser/Search.d.ts +11 -0
  1140. package/dist/unstable/http/MultipartParser/Search.d.ts.map +1 -0
  1141. package/dist/unstable/http/MultipartParser/Search.js +14 -0
  1142. package/dist/unstable/http/MultipartParser/Search.js.map +1 -0
  1143. package/dist/unstable/http/MultipartParser/internal/contentType.d.ts +5 -0
  1144. package/dist/unstable/http/MultipartParser/internal/contentType.d.ts.map +1 -0
  1145. package/dist/unstable/http/MultipartParser/internal/contentType.js +82 -0
  1146. package/dist/unstable/http/MultipartParser/internal/contentType.js.map +1 -0
  1147. package/dist/unstable/http/MultipartParser/internal/headers.d.ts +3 -0
  1148. package/dist/unstable/http/MultipartParser/internal/headers.d.ts.map +1 -0
  1149. package/dist/unstable/http/MultipartParser/internal/headers.js +208 -0
  1150. package/dist/unstable/http/MultipartParser/internal/headers.js.map +1 -0
  1151. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts +8 -0
  1152. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -0
  1153. package/dist/unstable/http/MultipartParser/internal/multipart.js +241 -0
  1154. package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -0
  1155. package/dist/unstable/http/MultipartParser/internal/search.d.ts +5 -0
  1156. package/dist/unstable/http/MultipartParser/internal/search.d.ts.map +1 -0
  1157. package/dist/unstable/http/MultipartParser/internal/search.js +120 -0
  1158. package/dist/unstable/http/MultipartParser/internal/search.js.map +1 -0
  1159. package/dist/unstable/http/MultipartParser.d.ts +98 -0
  1160. package/dist/unstable/http/MultipartParser.d.ts.map +1 -0
  1161. package/dist/unstable/http/MultipartParser.js +23 -0
  1162. package/dist/unstable/http/MultipartParser.js.map +1 -0
  1163. package/dist/unstable/http/Template.d.ts.map +1 -1
  1164. package/dist/unstable/http/Template.js +3 -3
  1165. package/dist/unstable/http/Template.js.map +1 -1
  1166. package/dist/unstable/http/Url.d.ts +33 -63
  1167. package/dist/unstable/http/Url.d.ts.map +1 -1
  1168. package/dist/unstable/http/Url.js +14 -28
  1169. package/dist/unstable/http/Url.js.map +1 -1
  1170. package/dist/unstable/http/UrlParams.d.ts +10 -18
  1171. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  1172. package/dist/unstable/http/UrlParams.js +26 -31
  1173. package/dist/unstable/http/UrlParams.js.map +1 -1
  1174. package/dist/unstable/http/index.d.ts +1 -1
  1175. package/dist/unstable/http/index.d.ts.map +1 -1
  1176. package/dist/unstable/http/index.js +1 -1
  1177. package/dist/unstable/http/index.js.map +1 -1
  1178. package/dist/unstable/http/internal/compression.d.ts +2 -0
  1179. package/dist/unstable/http/internal/compression.d.ts.map +1 -0
  1180. package/dist/unstable/http/internal/compression.js +155 -0
  1181. package/dist/unstable/http/internal/compression.js.map +1 -0
  1182. package/dist/unstable/http/internal/httpBody.d.ts +2 -0
  1183. package/dist/unstable/http/internal/httpBody.d.ts.map +1 -0
  1184. package/dist/unstable/http/internal/httpBody.js +10 -0
  1185. package/dist/unstable/http/internal/httpBody.js.map +1 -0
  1186. package/dist/unstable/http/internal/preResponseHandler.js.map +1 -1
  1187. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  1188. package/dist/unstable/httpapi/HttpApi.js +9 -9
  1189. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  1190. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +2 -2
  1191. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  1192. package/dist/unstable/httpapi/HttpApiBuilder.js +82 -30
  1193. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  1194. package/dist/unstable/httpapi/HttpApiClient.d.ts +4 -5
  1195. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  1196. package/dist/unstable/httpapi/HttpApiClient.js +89 -51
  1197. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  1198. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +48 -46
  1199. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  1200. package/dist/unstable/httpapi/HttpApiEndpoint.js +73 -16
  1201. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  1202. package/dist/unstable/httpapi/HttpApiError.d.ts +18 -18
  1203. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  1204. package/dist/unstable/httpapi/HttpApiError.js +30 -30
  1205. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  1206. package/dist/unstable/httpapi/HttpApiGroup.d.ts +15 -15
  1207. package/dist/unstable/httpapi/HttpApiGroup.js +2 -2
  1208. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  1209. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +71 -24
  1210. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  1211. package/dist/unstable/httpapi/HttpApiMiddleware.js +57 -10
  1212. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  1213. package/dist/unstable/httpapi/HttpApiScalar.d.ts +0 -12
  1214. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  1215. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  1216. package/dist/unstable/httpapi/HttpApiSchema.d.ts +225 -6
  1217. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  1218. package/dist/unstable/httpapi/HttpApiSchema.js +174 -4
  1219. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  1220. package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
  1221. package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
  1222. package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
  1223. package/dist/unstable/httpapi/OpenApi.d.ts +21 -13
  1224. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  1225. package/dist/unstable/httpapi/OpenApi.js +110 -57
  1226. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  1227. package/dist/unstable/httpapi/index.js.map +1 -1
  1228. package/dist/unstable/httpapi/internal/html.js.map +1 -1
  1229. package/dist/unstable/httpapi/internal/httpApiScalar.js.map +1 -1
  1230. package/dist/unstable/httpapi/internal/httpApiSwagger.js.map +1 -1
  1231. package/dist/unstable/httpapi/internal/mediaType.js.map +1 -1
  1232. package/dist/unstable/observability/Otlp.js.map +1 -1
  1233. package/dist/unstable/observability/OtlpExporter.d.ts +71 -2
  1234. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  1235. package/dist/unstable/observability/OtlpExporter.js +86 -7
  1236. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  1237. package/dist/unstable/observability/OtlpLogger.d.ts +4 -3
  1238. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  1239. package/dist/unstable/observability/OtlpLogger.js +4 -4
  1240. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  1241. package/dist/unstable/observability/OtlpMetrics.d.ts +11 -4
  1242. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  1243. package/dist/unstable/observability/OtlpMetrics.js +31 -15
  1244. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  1245. package/dist/unstable/observability/OtlpResource.d.ts +16 -7
  1246. package/dist/unstable/observability/OtlpResource.d.ts.map +1 -1
  1247. package/dist/unstable/observability/OtlpResource.js +21 -12
  1248. package/dist/unstable/observability/OtlpResource.js.map +1 -1
  1249. package/dist/unstable/observability/OtlpSerialization.js.map +1 -1
  1250. package/dist/unstable/observability/OtlpTracer.d.ts +4 -3
  1251. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  1252. package/dist/unstable/observability/OtlpTracer.js +3 -3
  1253. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  1254. package/dist/unstable/observability/PrometheusMetrics.d.ts +13 -4
  1255. package/dist/unstable/observability/PrometheusMetrics.d.ts.map +1 -1
  1256. package/dist/unstable/observability/PrometheusMetrics.js +10 -3
  1257. package/dist/unstable/observability/PrometheusMetrics.js.map +1 -1
  1258. package/dist/unstable/observability/index.js.map +1 -1
  1259. package/dist/unstable/observability/internal/otlpEnv.js +1 -1
  1260. package/dist/unstable/observability/internal/otlpEnv.js.map +1 -1
  1261. package/dist/unstable/observability/internal/otlpProtobuf.js.map +1 -1
  1262. package/dist/unstable/observability/internal/protobuf.js +3 -0
  1263. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  1264. package/dist/unstable/persistence/KeyValueStore.d.ts +8 -3
  1265. package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
  1266. package/dist/unstable/persistence/KeyValueStore.js +22 -13
  1267. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  1268. package/dist/unstable/persistence/Persistable.d.ts +8 -8
  1269. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  1270. package/dist/unstable/persistence/Persistable.js +2 -1
  1271. package/dist/unstable/persistence/Persistable.js.map +1 -1
  1272. package/dist/unstable/persistence/PersistedCache.js.map +1 -1
  1273. package/dist/unstable/persistence/PersistedQueue.d.ts +6 -6
  1274. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  1275. package/dist/unstable/persistence/PersistedQueue.js +15 -15
  1276. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  1277. package/dist/unstable/persistence/Persistence.d.ts +3 -3
  1278. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  1279. package/dist/unstable/persistence/Persistence.js +108 -22
  1280. package/dist/unstable/persistence/Persistence.js.map +1 -1
  1281. package/dist/unstable/persistence/RateLimiter.d.ts +47 -26
  1282. package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
  1283. package/dist/unstable/persistence/RateLimiter.js +31 -47
  1284. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  1285. package/dist/unstable/persistence/Redis.d.ts +2 -2
  1286. package/dist/unstable/persistence/Redis.d.ts.map +1 -1
  1287. package/dist/unstable/persistence/Redis.js +9 -7
  1288. package/dist/unstable/persistence/Redis.js.map +1 -1
  1289. package/dist/unstable/persistence/index.js.map +1 -1
  1290. package/dist/unstable/process/ChildProcess.d.ts +72 -21
  1291. package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
  1292. package/dist/unstable/process/ChildProcess.js +14 -5
  1293. package/dist/unstable/process/ChildProcess.js.map +1 -1
  1294. package/dist/unstable/process/ChildProcessSpawner.d.ts +21 -10
  1295. package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
  1296. package/dist/unstable/process/ChildProcessSpawner.js +4 -2
  1297. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  1298. package/dist/unstable/process/index.js.map +1 -1
  1299. package/dist/unstable/reactivity/AsyncResult.d.ts +8 -8
  1300. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  1301. package/dist/unstable/reactivity/AsyncResult.js +14 -13
  1302. package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
  1303. package/dist/unstable/reactivity/Atom.d.ts +131 -30
  1304. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  1305. package/dist/unstable/reactivity/Atom.js +53 -34
  1306. package/dist/unstable/reactivity/Atom.js.map +1 -1
  1307. package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
  1308. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  1309. package/dist/unstable/reactivity/AtomHttpApi.js +4 -1
  1310. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  1311. package/dist/unstable/reactivity/AtomRef.js.map +1 -1
  1312. package/dist/unstable/reactivity/AtomRegistry.js +25 -4
  1313. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  1314. package/dist/unstable/reactivity/AtomRpc.d.ts +1 -1
  1315. package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
  1316. package/dist/unstable/reactivity/AtomRpc.js +4 -1
  1317. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  1318. package/dist/unstable/reactivity/Hydration.d.ts +1 -1
  1319. package/dist/unstable/reactivity/Hydration.js +1 -1
  1320. package/dist/unstable/reactivity/Hydration.js.map +1 -1
  1321. package/dist/unstable/reactivity/Reactivity.js.map +1 -1
  1322. package/dist/unstable/reactivity/index.js.map +1 -1
  1323. package/dist/unstable/rpc/Rpc.d.ts +35 -33
  1324. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  1325. package/dist/unstable/rpc/Rpc.js +4 -2
  1326. package/dist/unstable/rpc/Rpc.js.map +1 -1
  1327. package/dist/unstable/rpc/RpcClient.d.ts +26 -12
  1328. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  1329. package/dist/unstable/rpc/RpcClient.js +40 -22
  1330. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  1331. package/dist/unstable/rpc/RpcClientError.js +2 -2
  1332. package/dist/unstable/rpc/RpcClientError.js.map +1 -1
  1333. package/dist/unstable/rpc/RpcGroup.d.ts +8 -8
  1334. package/dist/unstable/rpc/RpcGroup.js +1 -1
  1335. package/dist/unstable/rpc/RpcGroup.js.map +1 -1
  1336. package/dist/unstable/rpc/RpcMessage.d.ts +31 -30
  1337. package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
  1338. package/dist/unstable/rpc/RpcMessage.js +6 -6
  1339. package/dist/unstable/rpc/RpcMessage.js.map +1 -1
  1340. package/dist/unstable/rpc/RpcMiddleware.d.ts +10 -10
  1341. package/dist/unstable/rpc/RpcMiddleware.js +1 -1
  1342. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  1343. package/dist/unstable/rpc/RpcSchema.d.ts +4 -4
  1344. package/dist/unstable/rpc/RpcSchema.js +3 -3
  1345. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  1346. package/dist/unstable/rpc/RpcSerialization.d.ts +58 -7
  1347. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  1348. package/dist/unstable/rpc/RpcSerialization.js +177 -96
  1349. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  1350. package/dist/unstable/rpc/RpcServer.d.ts +13 -13
  1351. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  1352. package/dist/unstable/rpc/RpcServer.js +20 -15
  1353. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  1354. package/dist/unstable/rpc/RpcTest.js.map +1 -1
  1355. package/dist/unstable/rpc/RpcWorker.d.ts +5 -5
  1356. package/dist/unstable/rpc/RpcWorker.js +4 -4
  1357. package/dist/unstable/rpc/RpcWorker.js.map +1 -1
  1358. package/dist/unstable/rpc/Utils.js.map +1 -1
  1359. package/dist/unstable/rpc/index.js.map +1 -1
  1360. package/dist/unstable/schema/Model.d.ts +53 -51
  1361. package/dist/unstable/schema/Model.d.ts.map +1 -1
  1362. package/dist/unstable/schema/Model.js +35 -33
  1363. package/dist/unstable/schema/Model.js.map +1 -1
  1364. package/dist/unstable/schema/VariantSchema.d.ts +11 -12
  1365. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  1366. package/dist/unstable/schema/VariantSchema.js +28 -17
  1367. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  1368. package/dist/unstable/schema/index.js.map +1 -1
  1369. package/dist/unstable/socket/Socket.d.ts +12 -4
  1370. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  1371. package/dist/unstable/socket/Socket.js +38 -17
  1372. package/dist/unstable/socket/Socket.js.map +1 -1
  1373. package/dist/unstable/socket/SocketServer.js.map +1 -1
  1374. package/dist/unstable/socket/index.js.map +1 -1
  1375. package/dist/unstable/sql/Migrator.d.ts +9 -1
  1376. package/dist/unstable/sql/Migrator.d.ts.map +1 -1
  1377. package/dist/unstable/sql/Migrator.js +15 -2
  1378. package/dist/unstable/sql/Migrator.js.map +1 -1
  1379. package/dist/unstable/sql/SqlClient.d.ts +2 -3
  1380. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  1381. package/dist/unstable/sql/SqlClient.js +8 -4
  1382. package/dist/unstable/sql/SqlClient.js.map +1 -1
  1383. package/dist/unstable/sql/SqlConnection.js.map +1 -1
  1384. package/dist/unstable/sql/SqlError.d.ts +2 -2
  1385. package/dist/unstable/sql/SqlError.js +15 -15
  1386. package/dist/unstable/sql/SqlError.js.map +1 -1
  1387. package/dist/unstable/sql/SqlModel.d.ts +2 -2
  1388. package/dist/unstable/sql/SqlModel.js +2 -2
  1389. package/dist/unstable/sql/SqlModel.js.map +1 -1
  1390. package/dist/unstable/sql/SqlResolver.d.ts +5 -5
  1391. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  1392. package/dist/unstable/sql/SqlResolver.js +30 -24
  1393. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  1394. package/dist/unstable/sql/SqlSchema.js.map +1 -1
  1395. package/dist/unstable/sql/SqlStream.js.map +1 -1
  1396. package/dist/unstable/sql/Statement.d.ts +6 -6
  1397. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  1398. package/dist/unstable/sql/Statement.js +30 -27
  1399. package/dist/unstable/sql/Statement.js.map +1 -1
  1400. package/dist/unstable/sql/index.js.map +1 -1
  1401. package/dist/unstable/workers/Transferable.d.ts +1 -1
  1402. package/dist/unstable/workers/Transferable.js +1 -1
  1403. package/dist/unstable/workers/Transferable.js.map +1 -1
  1404. package/dist/unstable/workers/Worker.d.ts +2 -2
  1405. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  1406. package/dist/unstable/workers/Worker.js +13 -14
  1407. package/dist/unstable/workers/Worker.js.map +1 -1
  1408. package/dist/unstable/workers/WorkerError.d.ts +7 -7
  1409. package/dist/unstable/workers/WorkerError.js +11 -11
  1410. package/dist/unstable/workers/WorkerError.js.map +1 -1
  1411. package/dist/unstable/workers/WorkerRunner.d.ts +1 -1
  1412. package/dist/unstable/workers/WorkerRunner.js +1 -1
  1413. package/dist/unstable/workers/WorkerRunner.js.map +1 -1
  1414. package/dist/unstable/workers/index.js.map +1 -1
  1415. package/dist/unstable/workflow/Activity.d.ts +2 -2
  1416. package/dist/unstable/workflow/Activity.js +2 -2
  1417. package/dist/unstable/workflow/Activity.js.map +1 -1
  1418. package/dist/unstable/workflow/DurableClock.d.ts +1 -1
  1419. package/dist/unstable/workflow/DurableClock.js +1 -1
  1420. package/dist/unstable/workflow/DurableClock.js.map +1 -1
  1421. package/dist/unstable/workflow/DurableDeferred.d.ts +10 -10
  1422. package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
  1423. package/dist/unstable/workflow/DurableDeferred.js +13 -8
  1424. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  1425. package/dist/unstable/workflow/DurableQueue.d.ts +22 -20
  1426. package/dist/unstable/workflow/DurableQueue.d.ts.map +1 -1
  1427. package/dist/unstable/workflow/DurableQueue.js +22 -20
  1428. package/dist/unstable/workflow/DurableQueue.js.map +1 -1
  1429. package/dist/unstable/workflow/Workflow.d.ts +21 -21
  1430. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  1431. package/dist/unstable/workflow/Workflow.js +13 -14
  1432. package/dist/unstable/workflow/Workflow.js.map +1 -1
  1433. package/dist/unstable/workflow/WorkflowEngine.d.ts +26 -3
  1434. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  1435. package/dist/unstable/workflow/WorkflowEngine.js +72 -6
  1436. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  1437. package/dist/unstable/workflow/WorkflowProxy.d.ts +4 -2
  1438. package/dist/unstable/workflow/WorkflowProxy.d.ts.map +1 -1
  1439. package/dist/unstable/workflow/WorkflowProxy.js +4 -2
  1440. package/dist/unstable/workflow/WorkflowProxy.js.map +1 -1
  1441. package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
  1442. package/dist/unstable/workflow/index.js.map +1 -1
  1443. package/dist/unstable/workflow/internal/crypto.js.map +1 -1
  1444. package/package.json +12 -16
  1445. package/src/Array.ts +1069 -1071
  1446. package/src/BigDecimal.ts +433 -756
  1447. package/src/BigInt.ts +213 -269
  1448. package/src/Boolean.ts +146 -188
  1449. package/src/Brand.ts +4 -4
  1450. package/src/Cache.ts +469 -851
  1451. package/src/Cause.ts +167 -277
  1452. package/src/Channel.ts +982 -831
  1453. package/src/ChannelSchema.ts +1 -1
  1454. package/src/Chunk.ts +841 -1181
  1455. package/src/Clock.ts +181 -49
  1456. package/src/Combiner.ts +20 -33
  1457. package/src/Config.ts +642 -335
  1458. package/src/ConfigProvider.ts +267 -135
  1459. package/src/Console.ts +289 -39
  1460. package/src/Context.ts +323 -404
  1461. package/src/Cron.ts +271 -219
  1462. package/src/Crypto.ts +30 -23
  1463. package/src/Data.ts +63 -82
  1464. package/src/DateTime.ts +564 -660
  1465. package/src/Deferred.ts +259 -258
  1466. package/src/Duration.ts +244 -311
  1467. package/src/Effect.ts +3215 -3394
  1468. package/src/Encoding.ts +22 -40
  1469. package/src/Equal.ts +59 -41
  1470. package/src/Equivalence.ts +103 -105
  1471. package/src/ErrorReporter.ts +51 -27
  1472. package/src/ExecutionPlan.ts +91 -56
  1473. package/src/Exit.ts +116 -192
  1474. package/src/Fiber.ts +82 -149
  1475. package/src/FiberHandle.ts +155 -107
  1476. package/src/FiberMap.ts +225 -174
  1477. package/src/FiberSet.ts +125 -83
  1478. package/src/FileSystem.ts +156 -264
  1479. package/src/Filter.ts +61 -33
  1480. package/src/Formatter.ts +69 -76
  1481. package/src/Function.ts +119 -151
  1482. package/src/Graph.ts +3258 -1102
  1483. package/src/HKT.ts +12 -6
  1484. package/src/Hash.ts +52 -83
  1485. package/src/HashMap.ts +319 -411
  1486. package/src/HashRing.ts +1 -0
  1487. package/src/HashSet.ts +177 -284
  1488. package/src/Inspectable.ts +22 -20
  1489. package/src/Iterable.ts +665 -799
  1490. package/src/JsonPatch.ts +60 -113
  1491. package/src/JsonPointer.ts +8 -8
  1492. package/src/JsonSchema.ts +408 -251
  1493. package/src/Latch.ts +23 -35
  1494. package/src/Layer.ts +366 -265
  1495. package/src/LayerMap.ts +49 -29
  1496. package/src/LayerRef.ts +6 -2
  1497. package/src/LogLevel.ts +114 -214
  1498. package/src/Logger.ts +348 -700
  1499. package/src/ManagedRuntime.ts +20 -5
  1500. package/src/Match.ts +217 -252
  1501. package/src/Metric.ts +520 -1092
  1502. package/src/MutableHashMap.ts +218 -255
  1503. package/src/MutableHashSet.ts +84 -89
  1504. package/src/MutableList.ts +77 -370
  1505. package/src/MutableRef.ts +420 -243
  1506. package/src/Newtype.ts +21 -14
  1507. package/src/NonEmptyIterable.ts +7 -137
  1508. package/src/Number.ts +196 -233
  1509. package/src/Optic.ts +303 -441
  1510. package/src/Option.ts +449 -813
  1511. package/src/Order.ts +109 -109
  1512. package/src/Ordering.ts +20 -23
  1513. package/src/PartitionedSemaphore.ts +1 -4
  1514. package/src/Path.ts +38 -41
  1515. package/src/Pipeable.ts +6 -5
  1516. package/src/PlatformError.ts +4 -4
  1517. package/src/Pool.ts +4 -2
  1518. package/src/Predicate.ts +200 -181
  1519. package/src/PrimaryKey.ts +7 -7
  1520. package/src/PubSub.ts +526 -552
  1521. package/src/Pull.ts +24 -18
  1522. package/src/Queue.ts +204 -165
  1523. package/src/Random.ts +49 -74
  1524. package/src/RcMap.ts +121 -63
  1525. package/src/RcRef.ts +24 -13
  1526. package/src/Record.ts +387 -487
  1527. package/src/Redactable.ts +10 -3
  1528. package/src/Redacted.ts +25 -25
  1529. package/src/Reducer.ts +8 -15
  1530. package/src/Ref.ts +221 -361
  1531. package/src/References.ts +102 -214
  1532. package/src/RegExp.ts +10 -14
  1533. package/src/Request.ts +36 -28
  1534. package/src/RequestResolver.ts +202 -91
  1535. package/src/Result.ts +314 -485
  1536. package/src/Runtime.ts +50 -75
  1537. package/src/Schedule.ts +311 -1737
  1538. package/src/Scheduler.ts +20 -7
  1539. package/src/Schema.ts +3476 -1914
  1540. package/src/SchemaAST.ts +902 -573
  1541. package/src/SchemaGetter.ts +351 -233
  1542. package/src/SchemaIssue.ts +367 -334
  1543. package/src/SchemaParser.ts +254 -148
  1544. package/src/SchemaRepresentation.ts +732 -3414
  1545. package/src/SchemaTransformation.ts +186 -97
  1546. package/src/Scope.ts +123 -151
  1547. package/src/ScopedCache.ts +1 -1
  1548. package/src/ScopedRef.ts +6 -4
  1549. package/src/Semaphore.ts +157 -54
  1550. package/src/Sink.ts +129 -114
  1551. package/src/Stdio.ts +24 -5
  1552. package/src/Stream.ts +2745 -3173
  1553. package/src/String.ts +275 -312
  1554. package/src/Struct.ts +114 -118
  1555. package/src/SubscriptionRef.ts +284 -252
  1556. package/src/Symbol.ts +3 -3
  1557. package/src/SynchronizedRef.ts +1 -1
  1558. package/src/Terminal.ts +3 -3
  1559. package/src/Tracer.ts +102 -55
  1560. package/src/Trie.ts +287 -679
  1561. package/src/Tuple.ts +99 -131
  1562. package/src/TxChunk.ts +201 -121
  1563. package/src/TxDeferred.ts +62 -46
  1564. package/src/TxHashMap.ts +645 -799
  1565. package/src/TxHashSet.ts +443 -356
  1566. package/src/TxPriorityQueue.ts +130 -98
  1567. package/src/TxPubSub.ts +107 -80
  1568. package/src/TxQueue.ts +215 -184
  1569. package/src/TxReentrantLock.ts +136 -101
  1570. package/src/TxRef.ts +51 -32
  1571. package/src/TxSemaphore.ts +129 -95
  1572. package/src/TxSubscriptionRef.ts +97 -70
  1573. package/src/Types.ts +127 -70
  1574. package/src/Unify.ts +45 -65
  1575. package/src/Utils.ts +23 -16
  1576. package/src/index.ts +0 -10
  1577. package/src/internal/core.ts +6 -5
  1578. package/src/internal/dateTime.ts +7 -1
  1579. package/src/internal/effect.ts +313 -137
  1580. package/src/internal/executionPlan.ts +106 -10
  1581. package/src/internal/hashMap.ts +20 -14
  1582. package/src/internal/matcher.ts +3 -3
  1583. package/src/internal/persistence.ts +2 -0
  1584. package/src/internal/rcRef.ts +24 -16
  1585. package/src/internal/record.ts +11 -7
  1586. package/src/internal/references.ts +3 -7
  1587. package/src/internal/schedule.ts +4 -4
  1588. package/src/internal/schema/annotations.ts +48 -1
  1589. package/src/internal/schema/fromJsonSchemaDocument.ts +977 -0
  1590. package/src/internal/schema/fromRepresentation.ts +339 -0
  1591. package/src/internal/schema/parser.ts +22 -0
  1592. package/src/internal/schema/schema.ts +46 -63
  1593. package/src/internal/schema/{arbitrary.ts → toArbitrary.ts} +9 -81
  1594. package/src/internal/schema/toCodeDocument.ts +572 -0
  1595. package/src/internal/schema/{equivalence.ts → toEquivalence.ts} +12 -7
  1596. package/src/internal/schema/toJsonSchemaDocument.ts +549 -0
  1597. package/src/internal/schema/toRepresentation.ts +404 -0
  1598. package/src/internal/stackTraceLimit.ts +3 -7
  1599. package/src/internal/trie.ts +21 -12
  1600. package/src/testing/FastCheck.ts +8 -7
  1601. package/src/testing/TestClock.ts +86 -32
  1602. package/src/testing/TestConsole.ts +32 -31
  1603. package/src/testing/TestSchema.ts +40 -40
  1604. package/src/unstable/ai/AiError.ts +119 -141
  1605. package/src/unstable/ai/AnthropicStructuredOutput.ts +103 -334
  1606. package/src/unstable/ai/Chat.ts +133 -98
  1607. package/src/unstable/ai/EmbeddingModel.ts +1 -1
  1608. package/src/unstable/ai/IdGenerator.ts +32 -28
  1609. package/src/unstable/ai/LanguageModel.ts +141 -97
  1610. package/src/unstable/ai/McpProtocol.ts +48 -0
  1611. package/src/unstable/ai/McpSchema.ts +92 -81
  1612. package/src/unstable/ai/McpServer.ts +1057 -303
  1613. package/src/unstable/ai/Model.ts +9 -20
  1614. package/src/unstable/ai/OpenAiStructuredOutput.ts +231 -396
  1615. package/src/unstable/ai/Prompt.ts +212 -63
  1616. package/src/unstable/ai/Response.ts +52 -38
  1617. package/src/unstable/ai/Telemetry.ts +46 -13
  1618. package/src/unstable/ai/Tokenizer.ts +14 -3
  1619. package/src/unstable/ai/Tool.ts +94 -64
  1620. package/src/unstable/ai/Toolkit.ts +45 -15
  1621. package/src/unstable/ai/index.ts +5 -0
  1622. package/src/unstable/ai/internal/codec-transformer.ts +13 -7
  1623. package/src/unstable/ai/internal/mcpProtocol.ts +85 -0
  1624. package/src/unstable/ai/internal/mcpProtocolRegistry.ts +70 -0
  1625. package/src/unstable/ai/internal/structured-output.ts +453 -0
  1626. package/src/unstable/cli/Argument.ts +279 -72
  1627. package/src/unstable/cli/CliConfig.ts +85 -0
  1628. package/src/unstable/cli/CliError.ts +161 -90
  1629. package/src/unstable/cli/CliOutput.ts +44 -58
  1630. package/src/unstable/cli/Command.ts +839 -123
  1631. package/src/unstable/cli/Flag.ts +418 -138
  1632. package/src/unstable/cli/GlobalFlag.ts +34 -6
  1633. package/src/unstable/cli/HelpDoc.ts +12 -4
  1634. package/src/unstable/cli/Param.ts +351 -103
  1635. package/src/unstable/cli/Primitive.ts +383 -156
  1636. package/src/unstable/cli/Prompt.ts +64 -34
  1637. package/src/unstable/cli/index.ts +5 -0
  1638. package/src/unstable/cli/internal/ansi.ts +5 -2
  1639. package/src/unstable/cli/internal/command.ts +28 -15
  1640. package/src/unstable/cli/internal/completions/bash.ts +59 -9
  1641. package/src/unstable/cli/internal/completions/descriptor.ts +14 -20
  1642. package/src/unstable/cli/internal/completions/fish.ts +5 -7
  1643. package/src/unstable/cli/internal/config.ts +8 -10
  1644. package/src/unstable/cli/internal/help.ts +4 -2
  1645. package/src/unstable/cli/internal/lexer.ts +8 -2
  1646. package/src/unstable/cli/internal/parser.ts +19 -7
  1647. package/src/unstable/cli/internal/wizard.ts +283 -0
  1648. package/src/unstable/cluster/ClusterError.ts +7 -7
  1649. package/src/unstable/cluster/ClusterSchema.ts +8 -8
  1650. package/src/unstable/cluster/ClusterWorkflowEngine.ts +36 -20
  1651. package/src/unstable/cluster/Entity.ts +23 -19
  1652. package/src/unstable/cluster/EntityProxy.ts +16 -7
  1653. package/src/unstable/cluster/EntityResource.ts +2 -2
  1654. package/src/unstable/cluster/Envelope.ts +5 -4
  1655. package/src/unstable/cluster/HttpRunner.ts +6 -4
  1656. package/src/unstable/cluster/Message.ts +9 -9
  1657. package/src/unstable/cluster/MessageStorage.ts +24 -20
  1658. package/src/unstable/cluster/Reply.ts +26 -7
  1659. package/src/unstable/cluster/Runner.ts +1 -1
  1660. package/src/unstable/cluster/RunnerAddress.ts +1 -1
  1661. package/src/unstable/cluster/RunnerHealth.ts +1 -1
  1662. package/src/unstable/cluster/RunnerServer.ts +45 -18
  1663. package/src/unstable/cluster/RunnerStorage.ts +12 -10
  1664. package/src/unstable/cluster/Runners.ts +48 -26
  1665. package/src/unstable/cluster/ShardId.ts +1 -1
  1666. package/src/unstable/cluster/Sharding.ts +223 -55
  1667. package/src/unstable/cluster/ShardingConfig.ts +8 -4
  1668. package/src/unstable/cluster/SingleRunner.ts +4 -2
  1669. package/src/unstable/cluster/SingletonAddress.ts +1 -1
  1670. package/src/unstable/cluster/Snowflake.ts +8 -8
  1671. package/src/unstable/cluster/SqlMessageStorage.ts +84 -36
  1672. package/src/unstable/cluster/SqlRunnerStorage.ts +223 -133
  1673. package/src/unstable/cluster/internal/entityManager.ts +43 -26
  1674. package/src/unstable/cluster/internal/resourceMap.ts +5 -2
  1675. package/src/unstable/cluster/internal/resourceRef.ts +27 -5
  1676. package/src/unstable/cluster/internal/shardLock.ts +9 -0
  1677. package/src/unstable/devtools/DevToolsClient.ts +3 -2
  1678. package/src/unstable/devtools/DevToolsSchema.ts +10 -5
  1679. package/src/unstable/encoding/Ini.ts +174 -0
  1680. package/src/unstable/encoding/Msgpack.ts +61 -40
  1681. package/src/unstable/encoding/Ndjson.ts +9 -1
  1682. package/src/unstable/encoding/Sse.ts +109 -37
  1683. package/src/unstable/encoding/Toml.ts +504 -0
  1684. package/src/unstable/encoding/Yaml.ts +541 -0
  1685. package/src/unstable/encoding/index.ts +15 -0
  1686. package/src/unstable/eventlog/Event.ts +20 -20
  1687. package/src/unstable/eventlog/EventGroup.ts +4 -4
  1688. package/src/unstable/eventlog/EventJournal.ts +30 -22
  1689. package/src/unstable/eventlog/EventLog.ts +24 -14
  1690. package/src/unstable/eventlog/EventLogEncryption.ts +17 -18
  1691. package/src/unstable/eventlog/EventLogMessage.ts +15 -9
  1692. package/src/unstable/eventlog/EventLogRemote.ts +5 -5
  1693. package/src/unstable/eventlog/EventLogServer.ts +41 -7
  1694. package/src/unstable/eventlog/EventLogServerEncrypted.ts +15 -7
  1695. package/src/unstable/eventlog/EventLogServerUnencrypted.ts +15 -7
  1696. package/src/unstable/eventlog/EventLogSessionAuth.ts +1 -1
  1697. package/src/unstable/eventlog/SqlEventJournal.ts +8 -6
  1698. package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +1 -1
  1699. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +6 -3
  1700. package/src/unstable/http/Cookies.ts +64 -45
  1701. package/src/unstable/http/Etag.ts +1 -1
  1702. package/src/unstable/http/FetchHttpClient.ts +3 -1
  1703. package/src/unstable/http/FindMyWay/internal/queryString.ts +420 -0
  1704. package/src/unstable/http/FindMyWay/internal/router.ts +950 -0
  1705. package/src/unstable/http/FindMyWay.ts +65 -6
  1706. package/src/unstable/http/Headers.ts +10 -10
  1707. package/src/unstable/http/HttpBody.ts +20 -5
  1708. package/src/unstable/http/HttpClient.ts +215 -78
  1709. package/src/unstable/http/HttpClientError.ts +1 -1
  1710. package/src/unstable/http/HttpClientRequest.ts +59 -12
  1711. package/src/unstable/http/HttpClientResponse.ts +5 -21
  1712. package/src/unstable/http/HttpEffect.ts +20 -19
  1713. package/src/unstable/http/HttpMethod.ts +6 -9
  1714. package/src/unstable/http/HttpMiddleware.ts +202 -39
  1715. package/src/unstable/http/HttpPlatform.ts +129 -6
  1716. package/src/unstable/http/HttpRouter.ts +109 -101
  1717. package/src/unstable/http/HttpServer.ts +13 -13
  1718. package/src/unstable/http/HttpServerError.ts +2 -2
  1719. package/src/unstable/http/HttpServerRequest.ts +31 -17
  1720. package/src/unstable/http/HttpServerResponse.ts +38 -6
  1721. package/src/unstable/http/HttpStaticServer.ts +35 -7
  1722. package/src/unstable/http/Multipart.ts +70 -37
  1723. package/src/unstable/http/MultipartParser/HeadersParser.ts +68 -0
  1724. package/src/unstable/http/MultipartParser/Search.ts +17 -0
  1725. package/src/unstable/http/MultipartParser/internal/contentType.ts +103 -0
  1726. package/src/unstable/http/MultipartParser/internal/headers.ts +244 -0
  1727. package/src/unstable/http/MultipartParser/internal/multipart.ts +279 -0
  1728. package/src/unstable/http/MultipartParser/internal/search.ts +167 -0
  1729. package/src/unstable/http/MultipartParser.ts +115 -0
  1730. package/src/unstable/http/Template.ts +7 -6
  1731. package/src/unstable/http/Url.ts +33 -63
  1732. package/src/unstable/http/UrlParams.ts +27 -32
  1733. package/src/unstable/http/index.ts +1 -1
  1734. package/src/unstable/http/internal/compression.ts +196 -0
  1735. package/src/unstable/http/internal/httpBody.ts +15 -0
  1736. package/src/unstable/httpapi/HttpApi.ts +10 -11
  1737. package/src/unstable/httpapi/HttpApiBuilder.ts +155 -34
  1738. package/src/unstable/httpapi/HttpApiClient.ts +142 -61
  1739. package/src/unstable/httpapi/HttpApiEndpoint.ts +159 -71
  1740. package/src/unstable/httpapi/HttpApiError.ts +46 -52
  1741. package/src/unstable/httpapi/HttpApiGroup.ts +17 -17
  1742. package/src/unstable/httpapi/HttpApiMiddleware.ts +71 -24
  1743. package/src/unstable/httpapi/HttpApiScalar.ts +0 -12
  1744. package/src/unstable/httpapi/HttpApiSchema.ts +359 -6
  1745. package/src/unstable/httpapi/OpenApi.ts +153 -62
  1746. package/src/unstable/observability/OtlpExporter.ts +130 -12
  1747. package/src/unstable/observability/OtlpLogger.ts +8 -6
  1748. package/src/unstable/observability/OtlpMetrics.ts +42 -21
  1749. package/src/unstable/observability/OtlpResource.ts +26 -17
  1750. package/src/unstable/observability/OtlpTracer.ts +9 -5
  1751. package/src/unstable/observability/PrometheusMetrics.ts +13 -4
  1752. package/src/unstable/observability/internal/otlpEnv.ts +1 -1
  1753. package/src/unstable/observability/internal/protobuf.ts +3 -0
  1754. package/src/unstable/persistence/KeyValueStore.ts +72 -49
  1755. package/src/unstable/persistence/Persistable.ts +11 -10
  1756. package/src/unstable/persistence/PersistedQueue.ts +18 -15
  1757. package/src/unstable/persistence/Persistence.ts +153 -26
  1758. package/src/unstable/persistence/RateLimiter.ts +79 -45
  1759. package/src/unstable/persistence/Redis.ts +14 -9
  1760. package/src/unstable/process/ChildProcess.ts +72 -21
  1761. package/src/unstable/process/ChildProcessSpawner.ts +22 -11
  1762. package/src/unstable/reactivity/AsyncResult.ts +23 -18
  1763. package/src/unstable/reactivity/Atom.ts +161 -47
  1764. package/src/unstable/reactivity/AtomHttpApi.ts +5 -4
  1765. package/src/unstable/reactivity/AtomRegistry.ts +25 -4
  1766. package/src/unstable/reactivity/AtomRpc.ts +5 -4
  1767. package/src/unstable/reactivity/Hydration.ts +1 -1
  1768. package/src/unstable/rpc/Rpc.ts +35 -33
  1769. package/src/unstable/rpc/RpcClient.ts +65 -29
  1770. package/src/unstable/rpc/RpcClientError.ts +2 -2
  1771. package/src/unstable/rpc/RpcGroup.ts +8 -8
  1772. package/src/unstable/rpc/RpcMessage.ts +31 -30
  1773. package/src/unstable/rpc/RpcMiddleware.ts +10 -10
  1774. package/src/unstable/rpc/RpcSchema.ts +4 -4
  1775. package/src/unstable/rpc/RpcSerialization.ts +167 -68
  1776. package/src/unstable/rpc/RpcServer.ts +22 -17
  1777. package/src/unstable/rpc/RpcWorker.ts +5 -5
  1778. package/src/unstable/schema/Model.ts +52 -50
  1779. package/src/unstable/schema/VariantSchema.ts +51 -43
  1780. package/src/unstable/socket/Socket.ts +42 -19
  1781. package/src/unstable/sql/Migrator.ts +22 -9
  1782. package/src/unstable/sql/SqlClient.ts +65 -58
  1783. package/src/unstable/sql/SqlError.ts +15 -15
  1784. package/src/unstable/sql/SqlModel.ts +2 -2
  1785. package/src/unstable/sql/SqlResolver.ts +41 -31
  1786. package/src/unstable/sql/Statement.ts +44 -37
  1787. package/src/unstable/workers/Transferable.ts +1 -1
  1788. package/src/unstable/workers/Worker.ts +15 -16
  1789. package/src/unstable/workers/WorkerError.ts +12 -12
  1790. package/src/unstable/workers/WorkerRunner.ts +1 -1
  1791. package/src/unstable/workflow/Activity.ts +2 -2
  1792. package/src/unstable/workflow/DurableClock.ts +1 -1
  1793. package/src/unstable/workflow/DurableDeferred.ts +18 -13
  1794. package/src/unstable/workflow/DurableQueue.ts +22 -20
  1795. package/src/unstable/workflow/Workflow.ts +23 -26
  1796. package/src/unstable/workflow/WorkflowEngine.ts +111 -8
  1797. package/src/unstable/workflow/WorkflowProxy.ts +4 -2
  1798. package/dist/SchemaError.d.ts +0 -53
  1799. package/dist/SchemaError.d.ts.map +0 -1
  1800. package/dist/SchemaError.js +0 -61
  1801. package/dist/SchemaError.js.map +0 -1
  1802. package/dist/SchemaUtils.d.ts +0 -28
  1803. package/dist/SchemaUtils.d.ts.map +0 -1
  1804. package/dist/SchemaUtils.js +0 -45
  1805. package/dist/SchemaUtils.js.map +0 -1
  1806. package/dist/internal/schema/arbitrary.d.ts +0 -5
  1807. package/dist/internal/schema/arbitrary.d.ts.map +0 -1
  1808. package/dist/internal/schema/arbitrary.js.map +0 -1
  1809. package/dist/internal/schema/equivalence.d.ts +0 -2
  1810. package/dist/internal/schema/equivalence.d.ts.map +0 -1
  1811. package/dist/internal/schema/equivalence.js.map +0 -1
  1812. package/dist/internal/schema/representation.d.ts +0 -2
  1813. package/dist/internal/schema/representation.d.ts.map +0 -1
  1814. package/dist/internal/schema/representation.js +0 -865
  1815. package/dist/internal/schema/representation.js.map +0 -1
  1816. package/dist/internal/version.d.ts +0 -3
  1817. package/dist/internal/version.d.ts.map +0 -1
  1818. package/dist/internal/version.js +0 -2
  1819. package/dist/internal/version.js.map +0 -1
  1820. package/dist/unstable/http/Multipasta/HeadersParser.d.ts +0 -14
  1821. package/dist/unstable/http/Multipasta/HeadersParser.d.ts.map +0 -1
  1822. package/dist/unstable/http/Multipasta/HeadersParser.js +0 -14
  1823. package/dist/unstable/http/Multipasta/HeadersParser.js.map +0 -1
  1824. package/dist/unstable/http/Multipasta/Node.d.ts +0 -14
  1825. package/dist/unstable/http/Multipasta/Node.d.ts.map +0 -1
  1826. package/dist/unstable/http/Multipasta/Node.js +0 -14
  1827. package/dist/unstable/http/Multipasta/Node.js.map +0 -1
  1828. package/dist/unstable/http/Multipasta/Search.d.ts +0 -14
  1829. package/dist/unstable/http/Multipasta/Search.d.ts.map +0 -1
  1830. package/dist/unstable/http/Multipasta/Search.js +0 -14
  1831. package/dist/unstable/http/Multipasta/Search.js.map +0 -1
  1832. package/dist/unstable/http/Multipasta/Web.d.ts +0 -14
  1833. package/dist/unstable/http/Multipasta/Web.d.ts.map +0 -1
  1834. package/dist/unstable/http/Multipasta/Web.js +0 -14
  1835. package/dist/unstable/http/Multipasta/Web.js.map +0 -1
  1836. package/dist/unstable/http/Multipasta.d.ts +0 -15
  1837. package/dist/unstable/http/Multipasta.d.ts.map +0 -1
  1838. package/dist/unstable/http/Multipasta.js +0 -15
  1839. package/dist/unstable/http/Multipasta.js.map +0 -1
  1840. package/src/SchemaError.ts +0 -64
  1841. package/src/SchemaUtils.ts +0 -51
  1842. package/src/internal/schema/representation.ts +0 -795
  1843. package/src/internal/version.ts +0 -2
  1844. package/src/unstable/http/Multipasta/HeadersParser.ts +0 -14
  1845. package/src/unstable/http/Multipasta/Node.ts +0 -14
  1846. package/src/unstable/http/Multipasta/Search.ts +0 -14
  1847. package/src/unstable/http/Multipasta/Web.ts +0 -14
  1848. package/src/unstable/http/Multipasta.ts +0 -15
package/dist/Graph.js CHANGED
@@ -13,6 +13,7 @@ import * as Equal from "./Equal.js";
13
13
  import { dual } from "./Function.js";
14
14
  import * as Hash from "./Hash.js";
15
15
  import { NodeInspectSymbol } from "./Inspectable.js";
16
+ import * as MutableHashMap from "./MutableHashMap.js";
16
17
  import * as Option from "./Option.js";
17
18
  import { pipeArguments } from "./Pipeable.js";
18
19
  import { hasProperty } from "./Predicate.js";
@@ -33,12 +34,29 @@ const TypeId = "~effect/collections/Graph";
33
34
  * @since 3.18.0
34
35
  */
35
36
  export class Edge extends Data.Class {}
37
+ /** @internal */
38
+ const graphImpl = graph => graph;
39
+ /** @internal */
40
+ const cloneAdjacency = adjacency => {
41
+ const cloned = new Map();
42
+ for (const [nodeIndex, edges] of adjacency) {
43
+ cloned.set(nodeIndex, [...edges]);
44
+ }
45
+ return cloned;
46
+ };
36
47
  // =============================================================================
37
48
  // Proto Objects
38
49
  // =============================================================================
39
50
  /** @internal */
51
+ const edgeEquals = (type, self, that) => (type === "directed" ? self.source === that.source && self.target === that.target : self.source === that.source && self.target === that.target || self.source === that.target && self.target === that.source) && Equal.equals(self.data, that.data);
52
+ /** @internal */
53
+ const edgeHash = (type, edge) => type === "directed" ? Hash.hash(edge) : Hash.optimize(Hash.hash(edge.data) ^ Hash.hash(edge.source) + Hash.hash(edge.target));
54
+ /** @internal */
40
55
  const ProtoGraph = {
41
- [TypeId]: TypeId,
56
+ [TypeId]: {
57
+ _N: _ => _,
58
+ _E: _ => _
59
+ },
42
60
  [Symbol.iterator]() {
43
61
  return this.nodes[Symbol.iterator]();
44
62
  },
@@ -47,26 +65,27 @@ const ProtoGraph = {
47
65
  },
48
66
  [Equal.symbol](that) {
49
67
  if (isGraph(that)) {
50
- if (this.nodes.size !== that.nodes.size || this.edges.size !== that.edges.size || this.type !== that.type) {
68
+ const thatImpl = graphImpl(that);
69
+ if (this.nodes.size !== thatImpl.nodes.size || this.edges.size !== thatImpl.edges.size || this.nextNodeIndex !== thatImpl.nextNodeIndex || this.nextEdgeIndex !== thatImpl.nextEdgeIndex || this.type !== thatImpl.type) {
51
70
  return false;
52
71
  }
53
72
  // Compare nodes
54
73
  for (const [nodeIndex, nodeData] of this.nodes) {
55
- if (!that.nodes.has(nodeIndex)) {
74
+ if (!thatImpl.nodes.has(nodeIndex)) {
56
75
  return false;
57
76
  }
58
- const otherNodeData = that.nodes.get(nodeIndex);
77
+ const otherNodeData = thatImpl.nodes.get(nodeIndex);
59
78
  if (!Equal.equals(nodeData, otherNodeData)) {
60
79
  return false;
61
80
  }
62
81
  }
63
82
  // Compare edges
64
83
  for (const [edgeIndex, edgeData] of this.edges) {
65
- if (!that.edges.has(edgeIndex)) {
84
+ if (!thatImpl.edges.has(edgeIndex)) {
66
85
  return false;
67
86
  }
68
- const otherEdge = that.edges.get(edgeIndex);
69
- if (!Equal.equals(edgeData, otherEdge)) {
87
+ const otherEdge = thatImpl.edges.get(edgeIndex);
88
+ if (!edgeEquals(this.type, edgeData, otherEdge)) {
70
89
  return false;
71
90
  }
72
91
  }
@@ -79,11 +98,13 @@ const ProtoGraph = {
79
98
  hash = hash ^ Hash.string(this.type);
80
99
  hash = hash ^ Hash.number(this.nodes.size);
81
100
  hash = hash ^ Hash.number(this.edges.size);
101
+ hash = hash ^ Hash.number(this.nextNodeIndex);
102
+ hash = hash ^ Hash.number(this.nextEdgeIndex);
82
103
  for (const [nodeIndex, nodeData] of this.nodes) {
83
104
  hash = hash ^ Hash.hash(nodeIndex) + Hash.hash(nodeData);
84
105
  }
85
106
  for (const [edgeIndex, edgeData] of this.edges) {
86
- hash = hash ^ Hash.hash(edgeIndex) + Hash.hash(edgeData);
107
+ hash = hash ^ Hash.hash(edgeIndex) + edgeHash(this.type, edgeData);
87
108
  }
88
109
  return hash;
89
110
  },
@@ -124,12 +145,20 @@ export class GraphError extends /*#__PURE__*/Data.TaggedError("GraphError") {}
124
145
  const missingNode = node => new GraphError({
125
146
  message: `Node ${node} does not exist`
126
147
  });
148
+ /** @internal */
149
+ function assertMutable(graph) {
150
+ if (!graph.mutable) {
151
+ throw new GraphError({
152
+ message: "Graph is not mutable"
153
+ });
154
+ }
155
+ }
127
156
  // =============================================================================
128
157
  // Constructors
129
158
  // =============================================================================
130
159
  /**
131
160
  * Returns `true` if a value has the graph runtime type identifier, narrowing
132
- * it to a `Graph`.
161
+ * it to an immutable or mutable graph.
133
162
  *
134
163
  * **When to use**
135
164
  *
@@ -138,36 +167,42 @@ const missingNode = node => new GraphError({
138
167
  * **Gotchas**
139
168
  *
140
169
  * This guard checks the shared graph runtime type identifier and does not
141
- * distinguish immutable graphs from mutable graphs.
170
+ * distinguish immutable graphs from mutable graphs or directed graphs from
171
+ * undirected graphs.
142
172
  *
143
173
  * @category guards
144
174
  * @since 4.0.0
145
175
  */
146
176
  export const isGraph = u => hasProperty(u, TypeId);
147
177
  /**
148
- * Creates a directed graph, optionally with initial mutations.
178
+ * Creates a graph constructor for the specified graph kind.
149
179
  *
150
- * **Example** (Creating a directed graph)
180
+ * **When to use**
151
181
  *
152
- * ```ts
182
+ * Use when the graph kind is selected dynamically. Prefer `directed` or
183
+ * `undirected` when the kind is known statically.
184
+ *
185
+ * **Example** (Constructing by kind)
186
+ *
187
+ * ```ts import.meta.vitest
153
188
  * import { Graph } from "effect"
154
189
  *
155
- * // Directed graph with initial nodes and edges
156
- * const graph = Graph.directed<string, string>((mutable) => {
157
- * const a = Graph.addNode(mutable, "A")
158
- * const b = Graph.addNode(mutable, "B")
159
- * const c = Graph.addNode(mutable, "C")
160
- * Graph.addEdge(mutable, a, b, "A->B")
161
- * Graph.addEdge(mutable, b, c, "B->C")
190
+ * const makeGraph = Graph.make("directed")
191
+ * const graph = makeGraph<string, number>((mutable) => {
192
+ * Graph.addNode(mutable, "A")
162
193
  * })
194
+ *
195
+ * graph.type // => "directed"
163
196
  * ```
164
197
  *
198
+ * @see {@link directed} for constructing a directed graph directly
199
+ * @see {@link undirected} for constructing an undirected graph directly
165
200
  * @category constructors
166
- * @since 3.18.0
201
+ * @since 4.0.0
167
202
  */
168
- export const directed = mutate => {
203
+ export const make = type => mutate => {
169
204
  const graph = Object.create(ProtoGraph);
170
- graph.type = "directed";
205
+ graph.type = type;
171
206
  graph.nodes = new Map();
172
207
  graph.edges = new Map();
173
208
  graph.adjacency = new Map();
@@ -175,20 +210,43 @@ export const directed = mutate => {
175
210
  graph.nextNodeIndex = 0;
176
211
  graph.nextEdgeIndex = 0;
177
212
  graph.acyclic = Option.some(true);
178
- graph.mutable = false;
179
- if (mutate) {
180
- const mutable = beginMutation(graph);
181
- mutate(mutable);
182
- return endMutation(mutable);
213
+ if (mutate === undefined) {
214
+ graph.mutable = false;
215
+ return graph;
183
216
  }
184
- return graph;
217
+ graph.mutable = true;
218
+ const mutable = Equal.byReferenceUnsafe(graph);
219
+ return mutateScoped(mutable, mutate);
185
220
  };
221
+ /**
222
+ * Creates a directed graph, optionally with initial mutations.
223
+ *
224
+ * **Example** (Creating a directed graph)
225
+ *
226
+ * ```ts import.meta.vitest
227
+ * import { Graph } from "effect"
228
+ *
229
+ * // Directed graph with initial nodes and edges
230
+ * const graph = Graph.directed<string, string>((mutable) => {
231
+ * const a = Graph.addNode(mutable, "A")
232
+ * const b = Graph.addNode(mutable, "B")
233
+ * const c = Graph.addNode(mutable, "C")
234
+ * Graph.addEdge(mutable, a, b, "A->B")
235
+ * Graph.addEdge(mutable, b, c, "B->C")
236
+ * })
237
+ * Array.of(Graph.nodeCount(graph), Graph.edgeCount(graph)) // => [3, 2]
238
+ * ```
239
+ *
240
+ * @category constructors
241
+ * @since 3.18.0
242
+ */
243
+ export const directed = /*#__PURE__*/make("directed");
186
244
  /**
187
245
  * Creates an undirected graph, optionally with initial mutations.
188
246
  *
189
247
  * **Example** (Creating an undirected graph)
190
248
  *
191
- * ```ts
249
+ * ```ts import.meta.vitest
192
250
  * import { Graph } from "effect"
193
251
  *
194
252
  * // Undirected graph with initial nodes and edges
@@ -199,29 +257,13 @@ export const directed = mutate => {
199
257
  * Graph.addEdge(mutable, a, b, "A-B")
200
258
  * Graph.addEdge(mutable, b, c, "B-C")
201
259
  * })
260
+ * Array.of(Graph.nodeCount(graph), Graph.edgeCount(graph)) // => [3, 2]
202
261
  * ```
203
262
  *
204
263
  * @category constructors
205
264
  * @since 3.18.0
206
265
  */
207
- export const undirected = mutate => {
208
- const graph = Object.create(ProtoGraph);
209
- graph.type = "undirected";
210
- graph.nodes = new Map();
211
- graph.edges = new Map();
212
- graph.adjacency = new Map();
213
- graph.reverseAdjacency = new Map();
214
- graph.nextNodeIndex = 0;
215
- graph.nextEdgeIndex = 0;
216
- graph.acyclic = Option.some(true);
217
- graph.mutable = false;
218
- if (mutate) {
219
- const mutable = beginMutation(graph);
220
- mutate(mutable);
221
- return endMutation(mutable);
222
- }
223
- return graph;
224
- };
266
+ export const undirected = /*#__PURE__*/make("undirected");
225
267
  // =============================================================================
226
268
  // Scoped Mutable API
227
269
  // =============================================================================
@@ -230,67 +272,80 @@ export const undirected = mutate => {
230
272
  *
231
273
  * **Example** (Beginning a mutation scope)
232
274
  *
233
- * ```ts
275
+ * ```ts import.meta.vitest
234
276
  * import { Graph } from "effect"
235
277
  *
236
278
  * const graph = Graph.directed<string, number>()
237
279
  * const mutable = Graph.beginMutation(graph)
238
280
  * // Now mutable can be safely modified without affecting original graph
281
+ * Array.of(Graph.nodeCount(mutable), Graph.nodeCount(graph)) // => [0, 0]
239
282
  * ```
240
283
  *
241
284
  * @category mutations
242
285
  * @since 3.18.0
243
286
  */
244
287
  export const beginMutation = graph => {
245
- // Copy adjacency maps with deep cloned arrays
246
- const adjacency = new Map();
247
- const reverseAdjacency = new Map();
248
- for (const [nodeIndex, edges] of graph.adjacency) {
249
- adjacency.set(nodeIndex, [...edges]);
250
- }
251
- for (const [nodeIndex, edges] of graph.reverseAdjacency) {
252
- reverseAdjacency.set(nodeIndex, [...edges]);
253
- }
288
+ const source = graphImpl(graph);
289
+ const adjacency = cloneAdjacency(source.adjacency);
290
+ const reverseAdjacency = cloneAdjacency(source.reverseAdjacency);
254
291
  const mutable = Object.create(ProtoGraph);
255
- mutable.type = graph.type;
256
- mutable.nodes = new Map(graph.nodes);
257
- mutable.edges = new Map(graph.edges);
292
+ mutable.type = source.type;
293
+ mutable.nodes = new Map(source.nodes);
294
+ mutable.edges = new Map(source.edges);
258
295
  mutable.adjacency = adjacency;
259
296
  mutable.reverseAdjacency = reverseAdjacency;
260
- mutable.nextNodeIndex = graph.nextNodeIndex;
261
- mutable.nextEdgeIndex = graph.nextEdgeIndex;
262
- mutable.acyclic = graph.acyclic;
297
+ mutable.nextNodeIndex = source.nextNodeIndex;
298
+ mutable.nextEdgeIndex = source.nextEdgeIndex;
299
+ mutable.acyclic = source.acyclic;
263
300
  mutable.mutable = true;
264
- return mutable;
301
+ return Equal.byReferenceUnsafe(mutable);
265
302
  };
266
303
  /**
267
304
  * Converts a mutable graph back to an immutable graph, ending the mutation scope.
268
305
  *
306
+ * **Details**
307
+ *
308
+ * Finalizes the mutable handle. Later public mutation operations on that handle
309
+ * fail with a `GraphError`.
310
+ *
269
311
  * **Example** (Ending a mutation scope)
270
312
  *
271
- * ```ts
313
+ * ```ts import.meta.vitest
272
314
  * import { Graph } from "effect"
273
315
  *
274
316
  * const graph = Graph.directed<string, number>()
275
317
  * const mutable = Graph.beginMutation(graph)
276
318
  * // ... perform mutations on mutable ...
277
- * const newGraph = Graph.endMutation(mutable)
319
+ * Graph.nodeCount(Graph.endMutation(mutable)) // => 0
278
320
  * ```
279
321
  *
280
322
  * @category mutations
281
323
  * @since 3.18.0
282
324
  */
283
325
  export const endMutation = mutable => {
326
+ assertMutable(mutable);
327
+ const source = graphImpl(mutable);
284
328
  const graph = Object.create(ProtoGraph);
285
- graph.type = mutable.type;
286
- graph.nodes = new Map(mutable.nodes);
287
- graph.edges = new Map(mutable.edges);
288
- graph.adjacency = mutable.adjacency;
289
- graph.reverseAdjacency = mutable.reverseAdjacency;
290
- graph.nextNodeIndex = mutable.nextNodeIndex;
291
- graph.nextEdgeIndex = mutable.nextEdgeIndex;
292
- graph.acyclic = mutable.acyclic;
329
+ graph.type = source.type;
330
+ graph.nodes = new Map(source.nodes);
331
+ graph.edges = new Map(source.edges);
332
+ graph.adjacency = cloneAdjacency(source.adjacency);
333
+ graph.reverseAdjacency = cloneAdjacency(source.reverseAdjacency);
334
+ graph.nextNodeIndex = source.nextNodeIndex;
335
+ graph.nextEdgeIndex = source.nextEdgeIndex;
336
+ graph.acyclic = source.acyclic;
293
337
  graph.mutable = false;
338
+ source.mutable = false;
339
+ return graph;
340
+ };
341
+ /** @internal */
342
+ const mutateScoped = (mutable, f) => {
343
+ let graph;
344
+ try {
345
+ f(mutable);
346
+ } finally {
347
+ graph = endMutation(mutable);
348
+ }
294
349
  return graph;
295
350
  };
296
351
  /**
@@ -298,7 +353,7 @@ export const endMutation = mutable => {
298
353
  *
299
354
  * **Example** (Applying scoped mutations)
300
355
  *
301
- * ```ts
356
+ * ```ts import.meta.vitest
302
357
  * import { Graph } from "effect"
303
358
  *
304
359
  * const graph = Graph.directed<string, number>()
@@ -308,8 +363,8 @@ export const endMutation = mutable => {
308
363
  * Graph.addEdge(mutable, nodeA, nodeB, 1)
309
364
  * })
310
365
  *
311
- * console.log(Graph.nodeCount(newGraph)) // 2
312
- * console.log(Graph.edgeCount(newGraph)) // 1
366
+ * Graph.nodeCount(newGraph) // => 2
367
+ * Graph.edgeCount(newGraph) // => 1
313
368
  * ```
314
369
  *
315
370
  * @category mutations
@@ -317,8 +372,529 @@ export const endMutation = mutable => {
317
372
  */
318
373
  export const mutate = /*#__PURE__*/dual(2, (graph, f) => {
319
374
  const mutable = beginMutation(graph);
320
- f(mutable);
321
- return endMutation(mutable);
375
+ return mutateScoped(mutable, f);
376
+ });
377
+ /** @internal */
378
+ class EdgeIdentity {
379
+ type;
380
+ source;
381
+ target;
382
+ identity;
383
+ constructor(type, source, target, identity) {
384
+ this.type = type;
385
+ this.source = source;
386
+ this.target = target;
387
+ this.identity = identity;
388
+ }
389
+ [Equal.symbol](that) {
390
+ if (!(that instanceof EdgeIdentity) || this.type !== that.type || !Equal.equals(this.identity, that.identity)) {
391
+ return false;
392
+ }
393
+ if (this.type === "directed") {
394
+ return Equal.equals(this.source, that.source) && Equal.equals(this.target, that.target);
395
+ }
396
+ return Equal.equals(this.source, that.source) && Equal.equals(this.target, that.target) || Equal.equals(this.source, that.target) && Equal.equals(this.target, that.source);
397
+ }
398
+ [Hash.symbol]() {
399
+ const hash = Hash.hash(this.identity);
400
+ return this.type === "directed" ? Hash.combine(Hash.hash(this.target))(Hash.combine(Hash.hash(this.source))(hash)) : Hash.optimize(hash ^ Hash.hash(this.source) + Hash.hash(this.target));
401
+ }
402
+ }
403
+ /** @internal */
404
+ const buildNodeMaps = (graph, identity) => {
405
+ const impl = graphImpl(graph);
406
+ const byIdentity = MutableHashMap.empty();
407
+ const byIndex = new Map();
408
+ for (const [index, data] of impl.nodes) {
409
+ const nodeIdentity = identity(data);
410
+ MutableHashMap.set(byIdentity, nodeIdentity, data);
411
+ byIndex.set(index, nodeIdentity);
412
+ }
413
+ return {
414
+ byIdentity,
415
+ byIndex
416
+ };
417
+ };
418
+ /** @internal */
419
+ const nodeIdentityAt = (maps, index) => maps.byIndex.get(index);
420
+ /** @internal */
421
+ const buildEdgeMap = (graph, nodeMaps, identity) => {
422
+ const impl = graphImpl(graph);
423
+ const edges = MutableHashMap.empty();
424
+ for (const edge of impl.edges.values()) {
425
+ const sourceIdentity = nodeIdentityAt(nodeMaps, edge.source);
426
+ const targetIdentity = nodeIdentityAt(nodeMaps, edge.target);
427
+ MutableHashMap.set(edges, new EdgeIdentity(graph.type, sourceIdentity, targetIdentity, identity(edge.data)), edge.data);
428
+ }
429
+ return edges;
430
+ };
431
+ /** @internal */
432
+ const addNodesByIdentity = (mutable, nodes) => {
433
+ const indexByIdentity = MutableHashMap.empty();
434
+ for (const [identity, data] of nodes) {
435
+ MutableHashMap.set(indexByIdentity, identity, addNode(mutable, data));
436
+ }
437
+ return indexByIdentity;
438
+ };
439
+ /** @internal */
440
+ const addEdgeByIdentity = (mutable, indexByIdentity, identity, data) => {
441
+ const sourceIndex = Option.getOrUndefined(MutableHashMap.get(indexByIdentity, identity.source));
442
+ const targetIndex = Option.getOrUndefined(MutableHashMap.get(indexByIdentity, identity.target));
443
+ if (sourceIndex !== undefined && targetIndex !== undefined) {
444
+ addEdge(mutable, sourceIndex, targetIndex, data);
445
+ }
446
+ };
447
+ /** @internal */
448
+ const assertSameKind = (self, that) => {
449
+ if (self.type !== that.type) {
450
+ throw new GraphError({
451
+ message: `Cannot combine ${self.type} and ${that.type} graphs`
452
+ });
453
+ }
454
+ };
455
+ /**
456
+ * Composes two graphs, merging nodes by identity.
457
+ *
458
+ * **Details**
459
+ *
460
+ * Nodes and edges present in both graphs use data from `that`. The result has
461
+ * the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
462
+ * not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
463
+ * edge data. Edge identity also includes the endpoint identities.
464
+ *
465
+ * `G1 ∪ G2 = {V1 ∪ V2, E1 ∪ E2}`
466
+ *
467
+ * **Gotchas**
468
+ *
469
+ * Nodes with equal identities in one input graph are coalesced. The last node
470
+ * supplies the data, and redirected edges can collapse or become self-loops.
471
+ * Parallel edges with equal identities are also coalesced, with the last edge
472
+ * supplying the data.
473
+ *
474
+ * **Example** (Combining graphs)
475
+ *
476
+ * ```ts import.meta.vitest
477
+ * import { Graph } from "effect"
478
+ *
479
+ * const left = Graph.directed<{ id: string }, string>((mutable) => {
480
+ * const a = Graph.addNode(mutable, { id: "A" })
481
+ * const b = Graph.addNode(mutable, { id: "B" })
482
+ * Graph.addEdge(mutable, a, b, "A-B")
483
+ * })
484
+ *
485
+ * const right = Graph.directed<{ id: string }, string>((mutable) => {
486
+ * const b = Graph.addNode(mutable, { id: "B" })
487
+ * const c = Graph.addNode(mutable, { id: "C" })
488
+ * Graph.addEdge(mutable, b, c, "B-C")
489
+ * })
490
+ *
491
+ * const result = Graph.compose(left, right, {
492
+ * nodeIdentity: (node) => node.id
493
+ * })
494
+ *
495
+ * Graph.nodeCount(result) // => 3
496
+ * Graph.edgeCount(result) // => 2
497
+ * ```
498
+ *
499
+ * @category set operations
500
+ * @since 4.0.0
501
+ */
502
+ export const compose = /*#__PURE__*/dual(args => isGraph(args[0]) && isGraph(args[1]), (self, that, options) => {
503
+ assertSameKind(self, that);
504
+ const getNodeIdentity = options?.nodeIdentity ?? (node => node);
505
+ const getEdgeIdentity = options?.edgeIdentity ?? (edge => edge);
506
+ const selfMaps = buildNodeMaps(self, getNodeIdentity);
507
+ const thatMaps = buildNodeMaps(that, getNodeIdentity);
508
+ const nodes = MutableHashMap.empty();
509
+ const edges = buildEdgeMap(self, selfMaps, getEdgeIdentity);
510
+ for (const [identity, data] of selfMaps.byIdentity) {
511
+ MutableHashMap.set(nodes, identity, data);
512
+ }
513
+ for (const [identity, data] of thatMaps.byIdentity) {
514
+ MutableHashMap.set(nodes, identity, data);
515
+ }
516
+ for (const [identity, data] of buildEdgeMap(that, thatMaps, getEdgeIdentity)) {
517
+ MutableHashMap.set(edges, identity, data);
518
+ }
519
+ return make(self.type)(mutable => {
520
+ const indexByIdentity = addNodesByIdentity(mutable, nodes);
521
+ for (const [identity, data] of edges) {
522
+ addEdgeByIdentity(mutable, indexByIdentity, identity, data);
523
+ }
524
+ });
525
+ });
526
+ /**
527
+ * Returns the intersection of two graphs, matching nodes by identity.
528
+ *
529
+ * **Details**
530
+ *
531
+ * Node data comes from `self`, and edge data comes from `that`. The result has
532
+ * the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
533
+ * not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
534
+ * edge data. Edge identity also includes the endpoint identities.
535
+ *
536
+ * `G1 ∩ G2 = {V1 ∩ V2, E1 ∩ E2}`
537
+ *
538
+ * **Gotchas**
539
+ *
540
+ * Nodes with equal identities in one input graph are coalesced. The last node
541
+ * supplies the data, and redirected edges can collapse or become self-loops.
542
+ * The result contains at most one edge for each shared edge identity.
543
+ *
544
+ * **Example** (Finding shared structure)
545
+ *
546
+ * ```ts import.meta.vitest
547
+ * import { Graph } from "effect"
548
+ *
549
+ * const left = Graph.directed<string, string>((mutable) => {
550
+ * const a = Graph.addNode(mutable, "A")
551
+ * const b = Graph.addNode(mutable, "B")
552
+ * Graph.addEdge(mutable, a, b, "shared")
553
+ * })
554
+ *
555
+ * const right = Graph.directed<string, string>((mutable) => {
556
+ * const a = Graph.addNode(mutable, "A")
557
+ * const b = Graph.addNode(mutable, "B")
558
+ * Graph.addEdge(mutable, a, b, "shared")
559
+ * })
560
+ *
561
+ * const result = Graph.intersection(left, right)
562
+ *
563
+ * Graph.nodeCount(result) // => 2
564
+ * Graph.edgeCount(result) // => 1
565
+ * ```
566
+ *
567
+ * @category set operations
568
+ * @since 4.0.0
569
+ */
570
+ export const intersection = /*#__PURE__*/dual(args => isGraph(args[0]) && isGraph(args[1]), (self, that, options) => {
571
+ assertSameKind(self, that);
572
+ const thatImpl = graphImpl(that);
573
+ const getNodeIdentity = options?.nodeIdentity ?? (node => node);
574
+ const getEdgeIdentity = options?.edgeIdentity ?? (edge => edge);
575
+ const selfMaps = buildNodeMaps(self, getNodeIdentity);
576
+ const thatMaps = buildNodeMaps(that, getNodeIdentity);
577
+ const nodes = MutableHashMap.empty();
578
+ const selfEdges = buildEdgeMap(self, selfMaps, getEdgeIdentity);
579
+ const thatEdges = MutableHashMap.empty();
580
+ for (const [identity, data] of selfMaps.byIdentity) {
581
+ if (MutableHashMap.has(thatMaps.byIdentity, identity)) {
582
+ MutableHashMap.set(nodes, identity, data);
583
+ }
584
+ }
585
+ for (const edge of thatImpl.edges.values()) {
586
+ const sourceIdentity = nodeIdentityAt(thatMaps, edge.source);
587
+ const targetIdentity = nodeIdentityAt(thatMaps, edge.target);
588
+ if (MutableHashMap.has(nodes, sourceIdentity) && MutableHashMap.has(nodes, targetIdentity)) {
589
+ const edgeIdentity = new EdgeIdentity(that.type, sourceIdentity, targetIdentity, getEdgeIdentity(edge.data));
590
+ MutableHashMap.set(thatEdges, edgeIdentity, edge.data);
591
+ }
592
+ }
593
+ return make(self.type)(mutable => {
594
+ const indexByIdentity = addNodesByIdentity(mutable, nodes);
595
+ for (const [identity, data] of thatEdges) {
596
+ if (MutableHashMap.has(selfEdges, identity)) {
597
+ addEdgeByIdentity(mutable, indexByIdentity, identity, data);
598
+ }
599
+ }
600
+ });
601
+ });
602
+ /**
603
+ * Returns `self` without edges also present in `that`.
604
+ *
605
+ * **Details**
606
+ *
607
+ * All nodes from `self` are preserved. Edges are matched by endpoint and edge
608
+ * identities. The result has the same graph kind as `self`. Throws a
609
+ * `GraphError` when the graph kinds do not match. `nodeIdentity` and
610
+ * `edgeIdentity` default to the complete node and edge data.
611
+ *
612
+ * `G1 \ G2 = {V1, E1 \ E2}`
613
+ *
614
+ * **Gotchas**
615
+ *
616
+ * Nodes with equal identities in one input graph are coalesced. The last node
617
+ * supplies the data, and redirected edges can collapse or become self-loops.
618
+ * If `that` contains an edge identity, every parallel edge with that identity
619
+ * is removed from `self`.
620
+ *
621
+ * **Example** (Removing shared edges)
622
+ *
623
+ * ```ts import.meta.vitest
624
+ * import { Graph } from "effect"
625
+ *
626
+ * const left = Graph.directed<string, string>((mutable) => {
627
+ * const a = Graph.addNode(mutable, "A")
628
+ * const b = Graph.addNode(mutable, "B")
629
+ * const c = Graph.addNode(mutable, "C")
630
+ * Graph.addEdge(mutable, a, b, "A-B")
631
+ * Graph.addEdge(mutable, b, c, "B-C")
632
+ * })
633
+ *
634
+ * const right = Graph.directed<string, string>((mutable) => {
635
+ * const b = Graph.addNode(mutable, "B")
636
+ * const c = Graph.addNode(mutable, "C")
637
+ * Graph.addEdge(mutable, b, c, "B-C")
638
+ * })
639
+ *
640
+ * const result = Graph.difference(left, right)
641
+ *
642
+ * Graph.nodeCount(result) // => 3
643
+ * Graph.edgeCount(result) // => 1
644
+ * ```
645
+ *
646
+ * @category set operations
647
+ * @since 4.0.0
648
+ */
649
+ export const difference = /*#__PURE__*/dual(args => isGraph(args[0]) && isGraph(args[1]), (self, that, options) => {
650
+ assertSameKind(self, that);
651
+ const selfImpl = graphImpl(self);
652
+ const getNodeIdentity = options?.nodeIdentity ?? (node => node);
653
+ const getEdgeIdentity = options?.edgeIdentity ?? (edge => edge);
654
+ const selfMaps = buildNodeMaps(self, getNodeIdentity);
655
+ const thatMaps = buildNodeMaps(that, getNodeIdentity);
656
+ const thatEdges = buildEdgeMap(that, thatMaps, getEdgeIdentity);
657
+ return make(self.type)(mutable => {
658
+ const indexByIdentity = addNodesByIdentity(mutable, selfMaps.byIdentity);
659
+ for (const edge of selfImpl.edges.values()) {
660
+ const sourceIdentity = nodeIdentityAt(selfMaps, edge.source);
661
+ const targetIdentity = nodeIdentityAt(selfMaps, edge.target);
662
+ const edgeIdentity = new EdgeIdentity(self.type, sourceIdentity, targetIdentity, getEdgeIdentity(edge.data));
663
+ if (!MutableHashMap.has(thatEdges, edgeIdentity)) {
664
+ addEdgeByIdentity(mutable, indexByIdentity, edgeIdentity, edge.data);
665
+ }
666
+ }
667
+ });
668
+ });
669
+ /**
670
+ * Returns edges present in exactly one of two graphs.
671
+ *
672
+ * **Details**
673
+ *
674
+ * Keeps nodes from both graphs. Overlapping nodes use data from `that`. The
675
+ * result has the same graph kind as `self`. Throws a `GraphError` when the
676
+ * graph kinds do not match. `nodeIdentity` and `edgeIdentity` default to the
677
+ * complete node and edge data. Edge identity also includes the endpoint
678
+ * identities.
679
+ *
680
+ * `G1 Δ G2 = {V1 ∪ V2, (E1 ∪ E2) \ (E1 ∩ E2)}`
681
+ *
682
+ * **Gotchas**
683
+ *
684
+ * Edges with different projected identities are distinct.
685
+ * Nodes with equal identities in one input graph are coalesced. The last node
686
+ * supplies the data, and redirected edges can collapse or become self-loops.
687
+ * Parallel edges with equal identities are coalesced before the graphs are
688
+ * compared.
689
+ *
690
+ * **Example** (Finding differing edges)
691
+ *
692
+ * ```ts import.meta.vitest
693
+ * import { Graph } from "effect"
694
+ *
695
+ * const left = Graph.directed<string, string>((mutable) => {
696
+ * const a = Graph.addNode(mutable, "A")
697
+ * const b = Graph.addNode(mutable, "B")
698
+ * const c = Graph.addNode(mutable, "C")
699
+ * Graph.addEdge(mutable, a, b, "A-B")
700
+ * Graph.addEdge(mutable, b, c, "B-C")
701
+ * })
702
+ *
703
+ * const right = Graph.directed<string, string>((mutable) => {
704
+ * const b = Graph.addNode(mutable, "B")
705
+ * const c = Graph.addNode(mutable, "C")
706
+ * const d = Graph.addNode(mutable, "D")
707
+ * Graph.addEdge(mutable, b, c, "B-C")
708
+ * Graph.addEdge(mutable, c, d, "C-D")
709
+ * })
710
+ *
711
+ * const result = Graph.symmetricDifference(left, right)
712
+ *
713
+ * Graph.nodeCount(result) // => 4
714
+ * Graph.edgeCount(result) // => 2
715
+ * ```
716
+ *
717
+ * @category set operations
718
+ * @since 4.0.0
719
+ */
720
+ export const symmetricDifference = /*#__PURE__*/dual(args => isGraph(args[0]) && isGraph(args[1]), (self, that, options) => {
721
+ assertSameKind(self, that);
722
+ const getNodeIdentity = options?.nodeIdentity ?? (node => node);
723
+ const getEdgeIdentity = options?.edgeIdentity ?? (edge => edge);
724
+ const selfMaps = buildNodeMaps(self, getNodeIdentity);
725
+ const thatMaps = buildNodeMaps(that, getNodeIdentity);
726
+ const nodes = MutableHashMap.empty();
727
+ const selfEdges = buildEdgeMap(self, selfMaps, getEdgeIdentity);
728
+ const thatEdges = buildEdgeMap(that, thatMaps, getEdgeIdentity);
729
+ for (const [identity, data] of selfMaps.byIdentity) {
730
+ MutableHashMap.set(nodes, identity, data);
731
+ }
732
+ for (const [identity, data] of thatMaps.byIdentity) {
733
+ MutableHashMap.set(nodes, identity, data);
734
+ }
735
+ return make(self.type)(mutable => {
736
+ const indexByIdentity = addNodesByIdentity(mutable, nodes);
737
+ for (const [identity, data] of selfEdges) {
738
+ if (!MutableHashMap.has(thatEdges, identity)) {
739
+ addEdgeByIdentity(mutable, indexByIdentity, identity, data);
740
+ }
741
+ }
742
+ for (const [identity, data] of thatEdges) {
743
+ if (!MutableHashMap.has(selfEdges, identity)) {
744
+ addEdgeByIdentity(mutable, indexByIdentity, identity, data);
745
+ }
746
+ }
747
+ });
748
+ });
749
+ /**
750
+ * Returns the complement over the existing node set.
751
+ *
752
+ * **Details**
753
+ *
754
+ * Adds every missing edge between distinct nodes. The `createEdge` function
755
+ * receives the source and target node data for each added edge. The result has
756
+ * the same graph kind as `self`.
757
+ *
758
+ * `G' = {V, (V x V) \ E}`
759
+ *
760
+ * **Example** (Finding missing relationships)
761
+ *
762
+ * ```ts import.meta.vitest
763
+ * import { Graph } from "effect"
764
+ *
765
+ * const graph = Graph.directed<string, string>((mutable) => {
766
+ * const a = Graph.addNode(mutable, "A")
767
+ * const b = Graph.addNode(mutable, "B")
768
+ * Graph.addEdge(mutable, a, b, "A-B")
769
+ * })
770
+ *
771
+ * const result = Graph.complement(graph, (source, target) => `${source}-${target}`)
772
+ *
773
+ * Graph.edgeCount(result) // => 1
774
+ * ```
775
+ *
776
+ * @category set operations
777
+ * @since 4.0.0
778
+ */
779
+ export const complement = /*#__PURE__*/dual(2, (self, createEdge) => {
780
+ const selfImpl = graphImpl(self);
781
+ const nodeEntries = Array.from(selfImpl.nodes);
782
+ return make(self.type)(mutable => {
783
+ const newIndexMap = new Map();
784
+ for (const [oldIndex, data] of nodeEntries) {
785
+ newIndexMap.set(oldIndex, addNode(mutable, data));
786
+ }
787
+ for (let i = 0; i < nodeEntries.length; i++) {
788
+ const [sourceOldIndex, sourceData] = nodeEntries[i];
789
+ const start = self.type === "undirected" ? i + 1 : 0;
790
+ for (let j = start; j < nodeEntries.length; j++) {
791
+ const [targetOldIndex, targetData] = nodeEntries[j];
792
+ if (sourceOldIndex === targetOldIndex || hasEdge(self, sourceOldIndex, targetOldIndex)) {
793
+ continue;
794
+ }
795
+ const sourceIndex = newIndexMap.get(sourceOldIndex);
796
+ const targetIndex = newIndexMap.get(targetOldIndex);
797
+ if (sourceIndex !== undefined && targetIndex !== undefined) {
798
+ addEdge(mutable, sourceIndex, targetIndex, createEdge(sourceData, targetData));
799
+ }
800
+ }
801
+ }
802
+ });
803
+ });
804
+ /**
805
+ * Returns the induced subgraph containing nodes within a radius of a node.
806
+ *
807
+ * **Details**
808
+ *
809
+ * The `radius` option is the maximum edge distance from `nodeIndex` and
810
+ * defaults to `1`. The `direction` option controls directed graph traversal and
811
+ * defaults to `"outgoing"`. The result has the same graph kind as `self` and
812
+ * keeps all original edges whose endpoints are both reached. `"undirected"`
813
+ * ignores edge direction while finding reachable nodes.
814
+ *
815
+ * **Example** (Getting a local neighborhood)
816
+ *
817
+ * ```ts import.meta.vitest
818
+ * import { Graph } from "effect"
819
+ *
820
+ * const graph = Graph.directed<string, string>((mutable) => {
821
+ * const a = Graph.addNode(mutable, "A")
822
+ * const b = Graph.addNode(mutable, "B")
823
+ * const c = Graph.addNode(mutable, "C")
824
+ * Graph.addEdge(mutable, a, b, "A-B")
825
+ * Graph.addEdge(mutable, b, c, "B-C")
826
+ * })
827
+ *
828
+ * const result = Graph.neighborhood(graph, 1, { radius: 1 })
829
+ *
830
+ * Graph.nodeCount(result) // => 2
831
+ * ```
832
+ *
833
+ * @category set operations
834
+ * @since 4.0.0
835
+ */
836
+ export const neighborhood = /*#__PURE__*/dual(args => isGraph(args[0]), (self, nodeIndex, options) => {
837
+ const selfImpl = graphImpl(self);
838
+ const radius = options?.radius ?? 1;
839
+ const direction = options?.direction ?? "outgoing";
840
+ const reached = new Set();
841
+ for (const index of indices(bfs(self, {
842
+ start: [nodeIndex],
843
+ direction,
844
+ radius
845
+ }))) {
846
+ reached.add(index);
847
+ }
848
+ return make(self.type)(mutable => {
849
+ const newIndexMap = new Map();
850
+ for (const oldIndex of reached) {
851
+ newIndexMap.set(oldIndex, addNode(mutable, Option.getOrThrow(getNode(self, oldIndex))));
852
+ }
853
+ for (const edge of selfImpl.edges.values()) {
854
+ if (reached.has(edge.source) && reached.has(edge.target)) {
855
+ const sourceIndex = newIndexMap.get(edge.source);
856
+ const targetIndex = newIndexMap.get(edge.target);
857
+ if (sourceIndex !== undefined && targetIndex !== undefined) {
858
+ addEdge(mutable, sourceIndex, targetIndex, edge.data);
859
+ }
860
+ }
861
+ }
862
+ });
863
+ });
864
+ /**
865
+ * Returns the disjoint union of two graphs.
866
+ *
867
+ * **Details**
868
+ *
869
+ * Copies all nodes and edges from both graphs without merging equal node data.
870
+ * The result has the same graph kind as `self`. Throws a `GraphError` when the
871
+ * graph kinds do not match.
872
+ *
873
+ * `G1 + G2 = {disjoint V1 + V2, disjoint E1 + E2}`
874
+ *
875
+ * @category set operations
876
+ * @since 4.0.0
877
+ */
878
+ export const sum = /*#__PURE__*/dual(2, (self, that) => {
879
+ assertSameKind(self, that);
880
+ return make(self.type)(mutable => {
881
+ const copyInto = graph => {
882
+ const impl = graphImpl(graph);
883
+ const indexMap = new Map();
884
+ for (const [oldIndex, data] of impl.nodes) {
885
+ indexMap.set(oldIndex, addNode(mutable, data));
886
+ }
887
+ for (const edge of impl.edges.values()) {
888
+ const sourceIndex = indexMap.get(edge.source);
889
+ const targetIndex = indexMap.get(edge.target);
890
+ if (sourceIndex !== undefined && targetIndex !== undefined) {
891
+ addEdge(mutable, sourceIndex, targetIndex, edge.data);
892
+ }
893
+ }
894
+ };
895
+ copyInto(self);
896
+ copyInto(that);
897
+ });
322
898
  });
323
899
  // =============================================================================
324
900
  // Basic Node Operations
@@ -343,14 +919,12 @@ export const mutate = /*#__PURE__*/dual(2, (graph, f) => {
343
919
  *
344
920
  * **Example** (Adding nodes)
345
921
  *
346
- * ```ts
922
+ * ```ts import.meta.vitest
347
923
  * import { Graph } from "effect"
348
924
  *
349
- * const result = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
350
- * const nodeA = Graph.addNode(mutable, "Node A")
351
- * const nodeB = Graph.addNode(mutable, "Node B")
352
- * console.log(nodeA) // NodeIndex with value 0
353
- * console.log(nodeB) // NodeIndex with value 1
925
+ * Graph.mutate(Graph.directed<string, number>(), (mutable) => {
926
+ * Graph.addNode(mutable, "Node A") // => 0
927
+ * Graph.addNode(mutable, "Node B") // => 1
354
928
  * })
355
929
  * ```
356
930
  *
@@ -362,14 +936,16 @@ export const mutate = /*#__PURE__*/dual(2, (graph, f) => {
362
936
  * @since 3.18.0
363
937
  */
364
938
  export const addNode = (mutable, data) => {
365
- const nodeIndex = mutable.nextNodeIndex;
939
+ assertMutable(mutable);
940
+ const impl = graphImpl(mutable);
941
+ const nodeIndex = impl.nextNodeIndex;
366
942
  // Add node data
367
- mutable.nodes.set(nodeIndex, data);
943
+ impl.nodes.set(nodeIndex, data);
368
944
  // Initialize empty adjacency lists
369
- mutable.adjacency.set(nodeIndex, []);
370
- mutable.reverseAdjacency.set(nodeIndex, []);
945
+ impl.adjacency.set(nodeIndex, []);
946
+ impl.reverseAdjacency.set(nodeIndex, []);
371
947
  // Update graph allocators
372
- mutable.nextNodeIndex = mutable.nextNodeIndex + 1;
948
+ impl.nextNodeIndex = impl.nextNodeIndex + 1;
373
949
  return nodeIndex;
374
950
  };
375
951
  /**
@@ -377,60 +953,53 @@ export const addNode = (mutable, data) => {
377
953
  *
378
954
  * **Example** (Getting node data)
379
955
  *
380
- * ```ts
956
+ * ```ts import.meta.vitest
381
957
  * import { Graph, Option } from "effect"
382
958
  *
383
959
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
384
960
  * Graph.addNode(mutable, "Node A")
385
961
  * })
386
962
  *
387
- * const nodeIndex = 0
388
- * const nodeData = Graph.getNode(graph, nodeIndex)
389
- *
390
- * if (Option.isSome(nodeData)) {
391
- * console.log(nodeData.value) // "Node A"
392
- * }
963
+ * Graph.getNode(graph, 0) // => Option.some("Node A")
393
964
  * ```
394
965
  *
395
966
  * @category getters
396
967
  * @since 3.18.0
397
968
  */
398
- export const getNode = /*#__PURE__*/dual(2, (graph, nodeIndex) => graph.nodes.has(nodeIndex) ? Option.some(graph.nodes.get(nodeIndex)) : Option.none());
969
+ export const getNode = /*#__PURE__*/dual(2, (graph, nodeIndex) => {
970
+ const impl = graphImpl(graph);
971
+ return impl.nodes.has(nodeIndex) ? Option.some(impl.nodes.get(nodeIndex)) : Option.none();
972
+ });
399
973
  /**
400
974
  * Checks whether a node with the given index exists in the graph.
401
975
  *
402
976
  * **Example** (Checking node existence)
403
977
  *
404
- * ```ts
978
+ * ```ts import.meta.vitest
405
979
  * import { Graph } from "effect"
406
980
  *
407
981
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
408
982
  * Graph.addNode(mutable, "Node A")
409
983
  * })
410
984
  *
411
- * const nodeIndex = 0
412
- * const exists = Graph.hasNode(graph, nodeIndex)
413
- * console.log(exists) // true
414
- *
415
- * const nonExistentIndex = 999
416
- * const notExists = Graph.hasNode(graph, nonExistentIndex)
417
- * console.log(notExists) // false
985
+ * Graph.hasNode(graph, 0) // => true
986
+ * Graph.hasNode(graph, 999) // => false
418
987
  * ```
419
988
  *
420
989
  * @category getters
421
990
  * @since 3.18.0
422
991
  */
423
- export const hasNode = /*#__PURE__*/dual(2, (graph, nodeIndex) => graph.nodes.has(nodeIndex));
992
+ export const hasNode = /*#__PURE__*/dual(2, (graph, nodeIndex) => graphImpl(graph).nodes.has(nodeIndex));
424
993
  /**
425
994
  * Returns the number of nodes in the graph.
426
995
  *
427
996
  * **Example** (Counting nodes)
428
997
  *
429
- * ```ts
998
+ * ```ts import.meta.vitest
430
999
  * import { Graph } from "effect"
431
1000
  *
432
1001
  * const emptyGraph = Graph.directed<string, number>()
433
- * console.log(Graph.nodeCount(emptyGraph)) // 0
1002
+ * Graph.nodeCount(emptyGraph) // => 0
434
1003
  *
435
1004
  * const graphWithNodes = Graph.mutate(emptyGraph, (mutable) => {
436
1005
  * Graph.addNode(mutable, "Node A")
@@ -438,20 +1007,20 @@ export const hasNode = /*#__PURE__*/dual(2, (graph, nodeIndex) => graph.nodes.ha
438
1007
  * Graph.addNode(mutable, "Node C")
439
1008
  * })
440
1009
  *
441
- * console.log(Graph.nodeCount(graphWithNodes)) // 3
1010
+ * Graph.nodeCount(graphWithNodes) // => 3
442
1011
  * ```
443
1012
  *
444
1013
  * @category getters
445
1014
  * @since 3.18.0
446
1015
  */
447
- export const nodeCount = graph => graph.nodes.size;
1016
+ export const nodeCount = graph => graphImpl(graph).nodes.size;
448
1017
  /**
449
1018
  * Finds the first node that matches the given predicate.
450
1019
  *
451
1020
  * **Example** (Finding the first matching node)
452
1021
  *
453
- * ```ts
454
- * import { Graph } from "effect"
1022
+ * ```ts import.meta.vitest
1023
+ * import { Graph, Option } from "effect"
455
1024
  *
456
1025
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
457
1026
  * Graph.addNode(mutable, "Node A")
@@ -459,18 +1028,16 @@ export const nodeCount = graph => graph.nodes.size;
459
1028
  * Graph.addNode(mutable, "Node C")
460
1029
  * })
461
1030
  *
462
- * const result = Graph.findNode(graph, (data) => data.startsWith("Node B"))
463
- * console.log(result) // Option.some(1)
464
- *
465
- * const notFound = Graph.findNode(graph, (data) => data === "Node D")
466
- * console.log(notFound) // Option.none()
1031
+ * Graph.findNode(graph, (data) => data.startsWith("Node B")) // => Option.some(1)
1032
+ * Graph.findNode(graph, (data) => data === "Node D") // => Option.none()
467
1033
  * ```
468
1034
  *
469
1035
  * @category getters
470
1036
  * @since 3.18.0
471
1037
  */
472
1038
  export const findNode = /*#__PURE__*/dual(2, (graph, predicate) => {
473
- for (const [index, data] of graph.nodes) {
1039
+ const impl = graphImpl(graph);
1040
+ for (const [index, data] of impl.nodes) {
474
1041
  if (predicate(data)) {
475
1042
  return Option.some(index);
476
1043
  }
@@ -482,7 +1049,7 @@ export const findNode = /*#__PURE__*/dual(2, (graph, predicate) => {
482
1049
  *
483
1050
  * **Example** (Finding matching nodes)
484
1051
  *
485
- * ```ts
1052
+ * ```ts import.meta.vitest
486
1053
  * import { Graph } from "effect"
487
1054
  *
488
1055
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
@@ -491,19 +1058,17 @@ export const findNode = /*#__PURE__*/dual(2, (graph, predicate) => {
491
1058
  * Graph.addNode(mutable, "Start C")
492
1059
  * })
493
1060
  *
494
- * const result = Graph.findNodes(graph, (data) => data.startsWith("Start"))
495
- * console.log(result) // [0, 2]
496
- *
497
- * const empty = Graph.findNodes(graph, (data) => data === "Not Found")
498
- * console.log(empty) // []
1061
+ * Graph.findNodes(graph, (data) => data.startsWith("Start")) // => [0, 2]
1062
+ * Graph.findNodes(graph, (data) => data === "Not Found") // => []
499
1063
  * ```
500
1064
  *
501
1065
  * @category getters
502
1066
  * @since 3.18.0
503
1067
  */
504
1068
  export const findNodes = /*#__PURE__*/dual(2, (graph, predicate) => {
1069
+ const impl = graphImpl(graph);
505
1070
  const results = [];
506
- for (const [index, data] of graph.nodes) {
1071
+ for (const [index, data] of impl.nodes) {
507
1072
  if (predicate(data)) {
508
1073
  results.push(index);
509
1074
  }
@@ -515,8 +1080,8 @@ export const findNodes = /*#__PURE__*/dual(2, (graph, predicate) => {
515
1080
  *
516
1081
  * **Example** (Finding the first matching edge)
517
1082
  *
518
- * ```ts
519
- * import { Graph } from "effect"
1083
+ * ```ts import.meta.vitest
1084
+ * import { Graph, Option } from "effect"
520
1085
  *
521
1086
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
522
1087
  * const nodeA = Graph.addNode(mutable, "Node A")
@@ -526,18 +1091,16 @@ export const findNodes = /*#__PURE__*/dual(2, (graph, predicate) => {
526
1091
  * Graph.addEdge(mutable, nodeB, nodeC, 20)
527
1092
  * })
528
1093
  *
529
- * const result = Graph.findEdge(graph, (data) => data > 15)
530
- * console.log(result) // Option.some(1)
531
- *
532
- * const notFound = Graph.findEdge(graph, (data) => data > 100)
533
- * console.log(notFound) // Option.none()
1094
+ * Graph.findEdge(graph, (data) => data > 15) // => Option.some(1)
1095
+ * Graph.findEdge(graph, (data) => data > 100) // => Option.none()
534
1096
  * ```
535
1097
  *
536
1098
  * @category getters
537
1099
  * @since 3.18.0
538
1100
  */
539
1101
  export const findEdge = /*#__PURE__*/dual(2, (graph, predicate) => {
540
- for (const [edgeIndex, edgeData] of graph.edges) {
1102
+ const impl = graphImpl(graph);
1103
+ for (const [edgeIndex, edgeData] of impl.edges) {
541
1104
  if (predicate(edgeData.data, edgeData.source, edgeData.target)) {
542
1105
  return Option.some(edgeIndex);
543
1106
  }
@@ -549,7 +1112,7 @@ export const findEdge = /*#__PURE__*/dual(2, (graph, predicate) => {
549
1112
  *
550
1113
  * **Example** (Finding matching edges)
551
1114
  *
552
- * ```ts
1115
+ * ```ts import.meta.vitest
553
1116
  * import { Graph } from "effect"
554
1117
  *
555
1118
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
@@ -561,19 +1124,17 @@ export const findEdge = /*#__PURE__*/dual(2, (graph, predicate) => {
561
1124
  * Graph.addEdge(mutable, nodeC, nodeA, 30)
562
1125
  * })
563
1126
  *
564
- * const result = Graph.findEdges(graph, (data) => data >= 20)
565
- * console.log(result) // [1, 2]
566
- *
567
- * const empty = Graph.findEdges(graph, (data) => data > 100)
568
- * console.log(empty) // []
1127
+ * Graph.findEdges(graph, (data) => data >= 20) // => [1, 2]
1128
+ * Graph.findEdges(graph, (data) => data > 100) // => []
569
1129
  * ```
570
1130
  *
571
1131
  * @category getters
572
1132
  * @since 3.18.0
573
1133
  */
574
1134
  export const findEdges = /*#__PURE__*/dual(2, (graph, predicate) => {
1135
+ const impl = graphImpl(graph);
575
1136
  const results = [];
576
- for (const [edgeIndex, edgeData] of graph.edges) {
1137
+ for (const [edgeIndex, edgeData] of impl.edges) {
577
1138
  if (predicate(edgeData.data, edgeData.source, edgeData.target)) {
578
1139
  results.push(edgeIndex);
579
1140
  }
@@ -585,8 +1146,8 @@ export const findEdges = /*#__PURE__*/dual(2, (graph, predicate) => {
585
1146
  *
586
1147
  * **Example** (Updating node data)
587
1148
  *
588
- * ```ts
589
- * import { Graph } from "effect"
1149
+ * ```ts import.meta.vitest
1150
+ * import { Graph, Option } from "effect"
590
1151
  *
591
1152
  * const graph = Graph.directed<string, number>((mutable) => {
592
1153
  * Graph.addNode(mutable, "Node A")
@@ -594,28 +1155,29 @@ export const findEdges = /*#__PURE__*/dual(2, (graph, predicate) => {
594
1155
  * Graph.updateNode(mutable, 0, (data) => data.toUpperCase())
595
1156
  * })
596
1157
  *
597
- * const nodeData = Graph.getNode(graph, 0)
598
- * console.log(nodeData) // Option.some("NODE A")
1158
+ * Graph.getNode(graph, 0) // => Option.some("NODE A")
599
1159
  * ```
600
1160
  *
601
1161
  * @category transforming
602
1162
  * @since 3.18.0
603
1163
  */
604
1164
  export const updateNode = (mutable, index, f) => {
605
- if (!mutable.nodes.has(index)) {
1165
+ assertMutable(mutable);
1166
+ const impl = graphImpl(mutable);
1167
+ if (!impl.nodes.has(index)) {
606
1168
  return;
607
1169
  }
608
- const currentData = mutable.nodes.get(index);
1170
+ const currentData = impl.nodes.get(index);
609
1171
  const newData = f(currentData);
610
- mutable.nodes.set(index, newData);
1172
+ impl.nodes.set(index, newData);
611
1173
  };
612
1174
  /**
613
1175
  * Updates a single edge's data by applying a transformation function.
614
1176
  *
615
1177
  * **Example** (Updating edge data)
616
1178
  *
617
- * ```ts
618
- * import { Graph } from "effect"
1179
+ * ```ts import.meta.vitest
1180
+ * import { Graph, Option } from "effect"
619
1181
  *
620
1182
  * const result = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
621
1183
  * const nodeA = Graph.addNode(mutable, "Node A")
@@ -624,20 +1186,21 @@ export const updateNode = (mutable, index, f) => {
624
1186
  * Graph.updateEdge(mutable, edgeIndex, (data) => data * 2)
625
1187
  * })
626
1188
  *
627
- * const edgeData = Graph.getEdge(result, 0)
628
- * console.log(edgeData) // Option.some(new Graph.Edge({ source: 0, target: 1, data: 20 }))
1189
+ * Option.map(Graph.getEdge(result, 0), (edge) => edge.data) // => Option.some(20)
629
1190
  * ```
630
1191
  *
631
1192
  * @category mutations
632
1193
  * @since 3.18.0
633
1194
  */
634
1195
  export const updateEdge = (mutable, edgeIndex, f) => {
635
- if (!mutable.edges.has(edgeIndex)) {
1196
+ assertMutable(mutable);
1197
+ const impl = graphImpl(mutable);
1198
+ if (!impl.edges.has(edgeIndex)) {
636
1199
  return;
637
1200
  }
638
- const currentEdge = mutable.edges.get(edgeIndex);
1201
+ const currentEdge = impl.edges.get(edgeIndex);
639
1202
  const newData = f(currentEdge.data);
640
- mutable.edges.set(edgeIndex, new Edge({
1203
+ impl.edges.set(edgeIndex, new Edge({
641
1204
  ...currentEdge,
642
1205
  data: newData
643
1206
  }));
@@ -652,8 +1215,8 @@ export const updateEdge = (mutable, edgeIndex, f) => {
652
1215
  *
653
1216
  * **Example** (Mapping node data)
654
1217
  *
655
- * ```ts
656
- * import { Graph } from "effect"
1218
+ * ```ts import.meta.vitest
1219
+ * import { Graph, Option } from "effect"
657
1220
  *
658
1221
  * const graph = Graph.directed<string, number>((mutable) => {
659
1222
  * Graph.addNode(mutable, "node a")
@@ -662,18 +1225,19 @@ export const updateEdge = (mutable, edgeIndex, f) => {
662
1225
  * Graph.mapNodes(mutable, (data) => data.toUpperCase())
663
1226
  * })
664
1227
  *
665
- * const nodeData = Graph.getNode(graph, 0)
666
- * console.log(nodeData) // Option.some("NODE A")
1228
+ * Graph.getNode(graph, 0) // => Option.some("NODE A")
667
1229
  * ```
668
1230
  *
669
1231
  * @category transforming
670
1232
  * @since 3.18.0
671
1233
  */
672
1234
  export const mapNodes = (mutable, f) => {
1235
+ assertMutable(mutable);
1236
+ const impl = graphImpl(mutable);
673
1237
  // Transform existing node data in place
674
- for (const [index, data] of mutable.nodes) {
1238
+ for (const [index, data] of impl.nodes) {
675
1239
  const newData = f(data);
676
- mutable.nodes.set(index, newData);
1240
+ impl.nodes.set(index, newData);
677
1241
  }
678
1242
  };
679
1243
  /**
@@ -681,8 +1245,8 @@ export const mapNodes = (mutable, f) => {
681
1245
  *
682
1246
  * **Example** (Mapping edge data)
683
1247
  *
684
- * ```ts
685
- * import { Graph } from "effect"
1248
+ * ```ts import.meta.vitest
1249
+ * import { Graph, Option } from "effect"
686
1250
  *
687
1251
  * const graph = Graph.directed<string, number>((mutable) => {
688
1252
  * const a = Graph.addNode(mutable, "A")
@@ -693,21 +1257,22 @@ export const mapNodes = (mutable, f) => {
693
1257
  * Graph.mapEdges(mutable, (data) => data * 2)
694
1258
  * })
695
1259
  *
696
- * const edgeData = Graph.getEdge(graph, 0)
697
- * console.log(edgeData) // Option.some(new Graph.Edge({ source: 0, target: 1, data: 20 }))
1260
+ * Option.map(Graph.getEdge(graph, 0), (edge) => edge.data) // => Option.some(20)
698
1261
  * ```
699
1262
  *
700
1263
  * @category transforming
701
1264
  * @since 3.18.0
702
1265
  */
703
1266
  export const mapEdges = (mutable, f) => {
1267
+ assertMutable(mutable);
1268
+ const impl = graphImpl(mutable);
704
1269
  // Transform existing edge data in place
705
- for (const [index, edgeData] of mutable.edges) {
1270
+ for (const [index, edgeData] of impl.edges) {
706
1271
  const newData = f(edgeData.data);
707
- mutable.edges.set(index, {
1272
+ impl.edges.set(index, new Edge({
708
1273
  ...edgeData,
709
1274
  data: newData
710
- });
1275
+ }));
711
1276
  }
712
1277
  };
713
1278
  /**
@@ -734,8 +1299,8 @@ const rebuildAdjacency = mutable => {
734
1299
  *
735
1300
  * **Example** (Reversing edge directions)
736
1301
  *
737
- * ```ts
738
- * import { Graph } from "effect"
1302
+ * ```ts import.meta.vitest
1303
+ * import { Graph, Option } from "effect"
739
1304
  *
740
1305
  * const graph = Graph.directed<string, number>((mutable) => {
741
1306
  * const a = Graph.addNode(mutable, "A")
@@ -746,28 +1311,29 @@ const rebuildAdjacency = mutable => {
746
1311
  * Graph.reverse(mutable) // Now B -> A, C -> B
747
1312
  * })
748
1313
  *
749
- * const edge0 = Graph.getEdge(graph, 0)
750
- * console.log(edge0) // Option.some(new Graph.Edge({ source: 1, target: 0, data: 1 }))
1314
+ * Option.map(Graph.getEdge(graph, 0), (edge) => edge.source) // => Option.some(1)
751
1315
  * ```
752
1316
  *
753
1317
  * @category transforming
754
1318
  * @since 3.18.0
755
1319
  */
756
1320
  export const reverse = mutable => {
757
- if (mutable.type === "undirected") {
1321
+ assertMutable(mutable);
1322
+ const impl = graphImpl(mutable);
1323
+ if (impl.type === "undirected") {
758
1324
  return;
759
1325
  }
760
1326
  // Reverse all edges by swapping source and target
761
- for (const [index, edgeData] of mutable.edges) {
762
- mutable.edges.set(index, new Edge({
1327
+ for (const [index, edgeData] of impl.edges) {
1328
+ impl.edges.set(index, new Edge({
763
1329
  source: edgeData.target,
764
1330
  target: edgeData.source,
765
1331
  data: edgeData.data
766
1332
  }));
767
1333
  }
768
- rebuildAdjacency(mutable);
1334
+ rebuildAdjacency(impl);
769
1335
  // Invalidate cycle flag since edge directions changed
770
- mutable.acyclic = Option.none();
1336
+ impl.acyclic = Option.none();
771
1337
  };
772
1338
  /**
773
1339
  * Filters and optionally transforms nodes in a mutable graph using a predicate function.
@@ -775,7 +1341,7 @@ export const reverse = mutable => {
775
1341
  *
776
1342
  * **Example** (Filtering and mapping nodes)
777
1343
  *
778
- * ```ts
1344
+ * ```ts import.meta.vitest
779
1345
  * import { Graph, Option } from "effect"
780
1346
  *
781
1347
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -793,20 +1359,22 @@ export const reverse = mutable => {
793
1359
  * )
794
1360
  * })
795
1361
  *
796
- * console.log(Graph.nodeCount(graph)) // 2 (only "active" nodes remain)
1362
+ * Graph.nodeCount(graph) // => 2
797
1363
  * ```
798
1364
  *
799
1365
  * @category transforming
800
1366
  * @since 3.18.0
801
1367
  */
802
1368
  export const filterMapNodes = (mutable, f) => {
1369
+ assertMutable(mutable);
1370
+ const impl = graphImpl(mutable);
803
1371
  const nodesToRemove = [];
804
1372
  // First pass: identify nodes to remove and transform data for nodes to keep
805
- for (const [index, data] of mutable.nodes) {
1373
+ for (const [index, data] of impl.nodes) {
806
1374
  const result = f(data);
807
1375
  if (Option.isSome(result)) {
808
1376
  // Transform node data
809
- mutable.nodes.set(index, result.value);
1377
+ impl.nodes.set(index, result.value);
810
1378
  } else {
811
1379
  // Mark for removal
812
1380
  nodesToRemove.push(index);
@@ -823,7 +1391,7 @@ export const filterMapNodes = (mutable, f) => {
823
1391
  *
824
1392
  * **Example** (Filtering and mapping edges)
825
1393
  *
826
- * ```ts
1394
+ * ```ts import.meta.vitest
827
1395
  * import { Graph, Option } from "effect"
828
1396
  *
829
1397
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -841,23 +1409,25 @@ export const filterMapNodes = (mutable, f) => {
841
1409
  * )
842
1410
  * })
843
1411
  *
844
- * console.log(Graph.edgeCount(graph)) // 2 (edges with weight 5 removed)
1412
+ * Graph.edgeCount(graph) // => 2
845
1413
  * ```
846
1414
  *
847
1415
  * @category transforming
848
1416
  * @since 3.18.0
849
1417
  */
850
1418
  export const filterMapEdges = (mutable, f) => {
1419
+ assertMutable(mutable);
1420
+ const impl = graphImpl(mutable);
851
1421
  const edgesToRemove = [];
852
1422
  // First pass: identify edges to remove and transform data for edges to keep
853
- for (const [index, edgeData] of mutable.edges) {
1423
+ for (const [index, edgeData] of impl.edges) {
854
1424
  const result = f(edgeData.data);
855
1425
  if (Option.isSome(result)) {
856
1426
  // Transform edge data
857
- mutable.edges.set(index, {
1427
+ impl.edges.set(index, new Edge({
858
1428
  ...edgeData,
859
1429
  data: result.value
860
- });
1430
+ }));
861
1431
  } else {
862
1432
  // Mark for removal
863
1433
  edgesToRemove.push(index);
@@ -874,7 +1444,7 @@ export const filterMapEdges = (mutable, f) => {
874
1444
  *
875
1445
  * **Example** (Filtering nodes)
876
1446
  *
877
- * ```ts
1447
+ * ```ts import.meta.vitest
878
1448
  * import { Graph } from "effect"
879
1449
  *
880
1450
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -887,16 +1457,18 @@ export const filterMapEdges = (mutable, f) => {
887
1457
  * Graph.filterNodes(mutable, (data) => data === "active")
888
1458
  * })
889
1459
  *
890
- * console.log(Graph.nodeCount(graph)) // 2 (only "active" nodes remain)
1460
+ * Graph.nodeCount(graph) // => 2
891
1461
  * ```
892
1462
  *
893
1463
  * @category transforming
894
1464
  * @since 3.18.0
895
1465
  */
896
1466
  export const filterNodes = (mutable, predicate) => {
1467
+ assertMutable(mutable);
1468
+ const impl = graphImpl(mutable);
897
1469
  const nodesToRemove = [];
898
1470
  // Identify nodes to remove
899
- for (const [index, data] of mutable.nodes) {
1471
+ for (const [index, data] of impl.nodes) {
900
1472
  if (!predicate(data)) {
901
1473
  nodesToRemove.push(index);
902
1474
  }
@@ -912,7 +1484,7 @@ export const filterNodes = (mutable, predicate) => {
912
1484
  *
913
1485
  * **Example** (Filtering edges)
914
1486
  *
915
- * ```ts
1487
+ * ```ts import.meta.vitest
916
1488
  * import { Graph } from "effect"
917
1489
  *
918
1490
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -928,16 +1500,18 @@ export const filterNodes = (mutable, predicate) => {
928
1500
  * Graph.filterEdges(mutable, (data) => data >= 10)
929
1501
  * })
930
1502
  *
931
- * console.log(Graph.edgeCount(graph)) // 2 (edge with weight 5 removed)
1503
+ * Graph.edgeCount(graph) // => 2
932
1504
  * ```
933
1505
  *
934
1506
  * @category transforming
935
1507
  * @since 3.18.0
936
1508
  */
937
1509
  export const filterEdges = (mutable, predicate) => {
1510
+ assertMutable(mutable);
1511
+ const impl = graphImpl(mutable);
938
1512
  const edgesToRemove = [];
939
1513
  // Identify edges to remove
940
- for (const [index, edgeData] of mutable.edges) {
1514
+ for (const [index, edgeData] of impl.edges) {
941
1515
  if (!predicate(edgeData.data)) {
942
1516
  edgesToRemove.push(index);
943
1517
  }
@@ -988,14 +1562,13 @@ const invalidateCycleFlagOnAddition = mutable => {
988
1562
  *
989
1563
  * **Example** (Adding edges)
990
1564
  *
991
- * ```ts
1565
+ * ```ts import.meta.vitest
992
1566
  * import { Graph } from "effect"
993
1567
  *
994
- * const result = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
1568
+ * Graph.mutate(Graph.directed<string, number>(), (mutable) => {
995
1569
  * const nodeA = Graph.addNode(mutable, "Node A")
996
1570
  * const nodeB = Graph.addNode(mutable, "Node B")
997
- * const edge = Graph.addEdge(mutable, nodeA, nodeB, 42)
998
- * console.log(edge) // EdgeIndex with value 0
1571
+ * Graph.addEdge(mutable, nodeA, nodeB, 42) // => 0
999
1572
  * })
1000
1573
  * ```
1001
1574
  *
@@ -1008,46 +1581,48 @@ const invalidateCycleFlagOnAddition = mutable => {
1008
1581
  * @since 3.18.0
1009
1582
  */
1010
1583
  export const addEdge = (mutable, source, target, data) => {
1584
+ assertMutable(mutable);
1585
+ const impl = graphImpl(mutable);
1011
1586
  // Validate that both nodes exist
1012
- if (!mutable.nodes.has(source)) {
1587
+ if (!impl.nodes.has(source)) {
1013
1588
  throw missingNode(source);
1014
1589
  }
1015
- if (!mutable.nodes.has(target)) {
1590
+ if (!impl.nodes.has(target)) {
1016
1591
  throw missingNode(target);
1017
1592
  }
1018
- const edgeIndex = mutable.nextEdgeIndex;
1593
+ const edgeIndex = impl.nextEdgeIndex;
1019
1594
  // Create edge data
1020
1595
  const edgeData = new Edge({
1021
1596
  source,
1022
1597
  target,
1023
1598
  data
1024
1599
  });
1025
- mutable.edges.set(edgeIndex, edgeData);
1600
+ impl.edges.set(edgeIndex, edgeData);
1026
1601
  // Update adjacency lists
1027
- const sourceAdjacency = mutable.adjacency.get(source);
1602
+ const sourceAdjacency = impl.adjacency.get(source);
1028
1603
  if (sourceAdjacency !== undefined) {
1029
1604
  sourceAdjacency.push(edgeIndex);
1030
1605
  }
1031
- const targetReverseAdjacency = mutable.reverseAdjacency.get(target);
1606
+ const targetReverseAdjacency = impl.reverseAdjacency.get(target);
1032
1607
  if (targetReverseAdjacency !== undefined) {
1033
1608
  targetReverseAdjacency.push(edgeIndex);
1034
1609
  }
1035
1610
  // For undirected graphs, add reverse connections
1036
- if (mutable.type === "undirected") {
1037
- const targetAdjacency = mutable.adjacency.get(target);
1611
+ if (impl.type === "undirected") {
1612
+ const targetAdjacency = impl.adjacency.get(target);
1038
1613
  if (targetAdjacency !== undefined) {
1039
1614
  targetAdjacency.push(edgeIndex);
1040
1615
  }
1041
- const sourceReverseAdjacency = mutable.reverseAdjacency.get(source);
1616
+ const sourceReverseAdjacency = impl.reverseAdjacency.get(source);
1042
1617
  if (sourceReverseAdjacency !== undefined) {
1043
1618
  sourceReverseAdjacency.push(edgeIndex);
1044
1619
  }
1045
1620
  }
1046
1621
  // Update allocators
1047
- mutable.nextEdgeIndex = mutable.nextEdgeIndex + 1;
1622
+ impl.nextEdgeIndex = impl.nextEdgeIndex + 1;
1048
1623
  // Only invalidate cycle flag if the graph was acyclic
1049
1624
  // Adding edges cannot remove cycles from cyclic graphs
1050
- invalidateCycleFlagOnAddition(mutable);
1625
+ invalidateCycleFlagOnAddition(impl);
1051
1626
  return edgeIndex;
1052
1627
  };
1053
1628
  /**
@@ -1055,7 +1630,7 @@ export const addEdge = (mutable, source, target, data) => {
1055
1630
  *
1056
1631
  * **Example** (Removing a node)
1057
1632
  *
1058
- * ```ts
1633
+ * ```ts import.meta.vitest
1059
1634
  * import { Graph } from "effect"
1060
1635
  *
1061
1636
  * const result = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
@@ -1066,27 +1641,30 @@ export const addEdge = (mutable, source, target, data) => {
1066
1641
  * // Remove nodeA and all edges connected to it
1067
1642
  * Graph.removeNode(mutable, nodeA)
1068
1643
  * })
1644
+ * Array.of(Graph.nodeCount(result), Graph.edgeCount(result)) // => [1, 0]
1069
1645
  * ```
1070
1646
  *
1071
1647
  * @category mutations
1072
1648
  * @since 3.18.0
1073
1649
  */
1074
1650
  export const removeNode = (mutable, nodeIndex) => {
1651
+ assertMutable(mutable);
1652
+ const impl = graphImpl(mutable);
1075
1653
  // Check if node exists
1076
- if (!mutable.nodes.has(nodeIndex)) {
1654
+ if (!impl.nodes.has(nodeIndex)) {
1077
1655
  return; // Node doesn't exist, nothing to remove
1078
1656
  }
1079
1657
  // Collect all incident edges for removal
1080
1658
  const edgesToRemove = [];
1081
1659
  // Get outgoing edges
1082
- const outgoingEdges = mutable.adjacency.get(nodeIndex);
1660
+ const outgoingEdges = impl.adjacency.get(nodeIndex);
1083
1661
  if (outgoingEdges !== undefined) {
1084
1662
  for (const edge of outgoingEdges) {
1085
1663
  edgesToRemove.push(edge);
1086
1664
  }
1087
1665
  }
1088
1666
  // Get incoming edges
1089
- const incomingEdges = mutable.reverseAdjacency.get(nodeIndex);
1667
+ const incomingEdges = impl.reverseAdjacency.get(nodeIndex);
1090
1668
  if (incomingEdges !== undefined) {
1091
1669
  for (const edge of incomingEdges) {
1092
1670
  edgesToRemove.push(edge);
@@ -1094,22 +1672,22 @@ export const removeNode = (mutable, nodeIndex) => {
1094
1672
  }
1095
1673
  // Remove all incident edges
1096
1674
  for (const edgeIndex of edgesToRemove) {
1097
- removeEdgeInternal(mutable, edgeIndex);
1675
+ removeEdgeInternal(impl, edgeIndex);
1098
1676
  }
1099
1677
  // Remove the node itself
1100
- mutable.nodes.delete(nodeIndex);
1101
- mutable.adjacency.delete(nodeIndex);
1102
- mutable.reverseAdjacency.delete(nodeIndex);
1678
+ impl.nodes.delete(nodeIndex);
1679
+ impl.adjacency.delete(nodeIndex);
1680
+ impl.reverseAdjacency.delete(nodeIndex);
1103
1681
  // Only invalidate cycle flag if the graph wasn't already known to be acyclic
1104
1682
  // Removing nodes cannot introduce cycles in an acyclic graph
1105
- invalidateCycleFlagOnRemoval(mutable);
1683
+ invalidateCycleFlagOnRemoval(impl);
1106
1684
  };
1107
1685
  /**
1108
1686
  * Removes an edge from a mutable graph.
1109
1687
  *
1110
1688
  * **Example** (Removing an edge)
1111
1689
  *
1112
- * ```ts
1690
+ * ```ts import.meta.vitest
1113
1691
  * import { Graph } from "effect"
1114
1692
  *
1115
1693
  * const result = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
@@ -1120,17 +1698,20 @@ export const removeNode = (mutable, nodeIndex) => {
1120
1698
  * // Remove the edge
1121
1699
  * Graph.removeEdge(mutable, edge)
1122
1700
  * })
1701
+ * Array.of(Graph.nodeCount(result), Graph.edgeCount(result)) // => [2, 0]
1123
1702
  * ```
1124
1703
  *
1125
1704
  * @category mutations
1126
1705
  * @since 3.18.0
1127
1706
  */
1128
1707
  export const removeEdge = (mutable, edgeIndex) => {
1129
- const wasRemoved = removeEdgeInternal(mutable, edgeIndex);
1708
+ assertMutable(mutable);
1709
+ const impl = graphImpl(mutable);
1710
+ const wasRemoved = removeEdgeInternal(impl, edgeIndex);
1130
1711
  // Only invalidate cycle flag if an edge was actually removed
1131
1712
  // and only if the graph wasn't already known to be acyclic
1132
1713
  if (wasRemoved) {
1133
- invalidateCycleFlagOnRemoval(mutable);
1714
+ invalidateCycleFlagOnRemoval(impl);
1134
1715
  }
1135
1716
  };
1136
1717
  /** @internal */
@@ -1188,8 +1769,8 @@ const removeEdgeInternal = (mutable, edgeIndex) => {
1188
1769
  *
1189
1770
  * **Example** (Getting edge data)
1190
1771
  *
1191
- * ```ts
1192
- * import { Graph } from "effect"
1772
+ * ```ts import.meta.vitest
1773
+ * import { Graph, Option } from "effect"
1193
1774
  *
1194
1775
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
1195
1776
  * const nodeA = Graph.addNode(mutable, "Node A")
@@ -1197,26 +1778,19 @@ const removeEdgeInternal = (mutable, edgeIndex) => {
1197
1778
  * Graph.addEdge(mutable, nodeA, nodeB, 42)
1198
1779
  * })
1199
1780
  *
1200
- * const edgeIndex = 0
1201
- * const edgeData = Graph.getEdge(graph, edgeIndex)
1202
- *
1203
- * if (edgeData._tag === "Some") {
1204
- * console.log(edgeData.value.data) // 42
1205
- * console.log(edgeData.value.source) // 0
1206
- * console.log(edgeData.value.target) // 1
1207
- * }
1781
+ * Graph.getEdge(graph, 0) // => Option.some(new Graph.Edge({ source: 0, target: 1, data: 42 }))
1208
1782
  * ```
1209
1783
  *
1210
1784
  * @category getters
1211
1785
  * @since 3.18.0
1212
1786
  */
1213
- export const getEdge = /*#__PURE__*/dual(2, (graph, edgeIndex) => Option.fromUndefinedOr(graph.edges.get(edgeIndex)));
1787
+ export const getEdge = /*#__PURE__*/dual(2, (graph, edgeIndex) => Option.fromUndefinedOr(graphImpl(graph).edges.get(edgeIndex)));
1214
1788
  /**
1215
1789
  * Checks whether an edge exists between two nodes in the graph.
1216
1790
  *
1217
1791
  * **Example** (Checking edge existence)
1218
1792
  *
1219
- * ```ts
1793
+ * ```ts import.meta.vitest
1220
1794
  * import { Graph } from "effect"
1221
1795
  *
1222
1796
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
@@ -1226,28 +1800,22 @@ export const getEdge = /*#__PURE__*/dual(2, (graph, edgeIndex) => Option.fromUnd
1226
1800
  * Graph.addEdge(mutable, nodeA, nodeB, 42)
1227
1801
  * })
1228
1802
  *
1229
- * const nodeA = 0
1230
- * const nodeB = 1
1231
- * const nodeC = 2
1232
- *
1233
- * const hasAB = Graph.hasEdge(graph, nodeA, nodeB)
1234
- * console.log(hasAB) // true
1235
- *
1236
- * const hasAC = Graph.hasEdge(graph, nodeA, nodeC)
1237
- * console.log(hasAC) // false
1803
+ * Graph.hasEdge(graph, 0, 1) // => true
1804
+ * Graph.hasEdge(graph, 0, 2) // => false
1238
1805
  * ```
1239
1806
  *
1240
1807
  * @category getters
1241
1808
  * @since 3.18.0
1242
1809
  */
1243
1810
  export const hasEdge = /*#__PURE__*/dual(3, (graph, source, target) => {
1244
- const adjacencyList = graph.adjacency.get(source);
1811
+ const impl = graphImpl(graph);
1812
+ const adjacencyList = impl.adjacency.get(source);
1245
1813
  if (adjacencyList === undefined) {
1246
1814
  return false;
1247
1815
  }
1248
1816
  // Check if any edge in the adjacency list connects to the target
1249
1817
  for (const edgeIndex of adjacencyList) {
1250
- const edge = graph.edges.get(edgeIndex);
1818
+ const edge = impl.edges.get(edgeIndex);
1251
1819
  if (edge !== undefined) {
1252
1820
  const neighbor = graph.type === "undirected" && edge.target === source ? edge.source : edge.target;
1253
1821
  if (neighbor === target) {
@@ -1262,11 +1830,11 @@ export const hasEdge = /*#__PURE__*/dual(3, (graph, source, target) => {
1262
1830
  *
1263
1831
  * **Example** (Counting edges)
1264
1832
  *
1265
- * ```ts
1833
+ * ```ts import.meta.vitest
1266
1834
  * import { Graph } from "effect"
1267
1835
  *
1268
1836
  * const emptyGraph = Graph.directed<string, number>()
1269
- * console.log(Graph.edgeCount(emptyGraph)) // 0
1837
+ * Graph.edgeCount(emptyGraph) // => 0
1270
1838
  *
1271
1839
  * const graphWithEdges = Graph.mutate(emptyGraph, (mutable) => {
1272
1840
  * const nodeA = Graph.addNode(mutable, "Node A")
@@ -1277,22 +1845,23 @@ export const hasEdge = /*#__PURE__*/dual(3, (graph, source, target) => {
1277
1845
  * Graph.addEdge(mutable, nodeC, nodeA, 3)
1278
1846
  * })
1279
1847
  *
1280
- * console.log(Graph.edgeCount(graphWithEdges)) // 3
1848
+ * Graph.edgeCount(graphWithEdges) // => 3
1281
1849
  * ```
1282
1850
  *
1283
1851
  * @category getters
1284
1852
  * @since 3.18.0
1285
1853
  */
1286
- export const edgeCount = graph => graph.edges.size;
1854
+ export const edgeCount = graph => graphImpl(graph).edges.size;
1287
1855
  const getDirectedNeighbors = (graph, nodeIndex, direction) => {
1288
- const adjacencyMap = direction === "incoming" ? graph.reverseAdjacency : graph.adjacency;
1856
+ const impl = graphImpl(graph);
1857
+ const adjacencyMap = direction === "incoming" ? impl.reverseAdjacency : impl.adjacency;
1289
1858
  const adjacencyList = adjacencyMap.get(nodeIndex);
1290
1859
  if (adjacencyList === undefined) {
1291
1860
  return [];
1292
1861
  }
1293
1862
  const result = [];
1294
1863
  for (const edgeIndex of adjacencyList) {
1295
- const edge = graph.edges.get(edgeIndex);
1864
+ const edge = impl.edges.get(edgeIndex);
1296
1865
  if (edge !== undefined) {
1297
1866
  result.push(direction === "incoming" ? edge.source : edge.target);
1298
1867
  }
@@ -1309,7 +1878,7 @@ const getDirectedNeighbors = (graph, nodeIndex, direction) => {
1309
1878
  *
1310
1879
  * **Example** (Getting outgoing neighbors)
1311
1880
  *
1312
- * ```ts
1881
+ * ```ts import.meta.vitest
1313
1882
  * import { Graph } from "effect"
1314
1883
  *
1315
1884
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
@@ -1320,15 +1889,8 @@ const getDirectedNeighbors = (graph, nodeIndex, direction) => {
1320
1889
  * Graph.addEdge(mutable, nodeA, nodeC, 2)
1321
1890
  * })
1322
1891
  *
1323
- * const nodeA = 0
1324
- * const nodeB = 1
1325
- * const nodeC = 2
1326
- *
1327
- * const neighborsA = Graph.neighbors(graph, nodeA)
1328
- * console.log(neighborsA) // [1, 2]
1329
- *
1330
- * const neighborsB = Graph.neighbors(graph, nodeB)
1331
- * console.log(neighborsB) // []
1892
+ * Graph.neighbors(graph, 0) // => [1, 2]
1893
+ * Graph.neighbors(graph, 1) // => []
1332
1894
  * ```
1333
1895
  *
1334
1896
  * @category getters
@@ -1356,7 +1918,7 @@ export const neighbors = /*#__PURE__*/dual(2, (graph, nodeIndex) => {
1356
1918
  * @see {@link predecessors} for incoming neighbors in a directed graph
1357
1919
  * @see {@link neighbors} for generic neighbor lookup across graph kinds
1358
1920
  *
1359
- * @category queries
1921
+ * @category getters
1360
1922
  * @since 4.0.0
1361
1923
  */
1362
1924
  export const successors = /*#__PURE__*/dual(2, (graph, nodeIndex) => {
@@ -1382,7 +1944,7 @@ export const successors = /*#__PURE__*/dual(2, (graph, nodeIndex) => {
1382
1944
  * @see {@link successors} for outgoing neighbors in a directed graph
1383
1945
  * @see {@link neighbors} for generic neighbor lookup across graph kinds
1384
1946
  *
1385
- * @category queries
1947
+ * @category getters
1386
1948
  * @since 4.0.0
1387
1949
  */
1388
1950
  export const predecessors = /*#__PURE__*/dual(2, (graph, nodeIndex) => {
@@ -1407,7 +1969,7 @@ export const predecessors = /*#__PURE__*/dual(2, (graph, nodeIndex) => {
1407
1969
  *
1408
1970
  * **Example** (Traversing directed neighbors)
1409
1971
  *
1410
- * ```ts
1972
+ * ```ts import.meta.vitest
1411
1973
  * import { Graph } from "effect"
1412
1974
  *
1413
1975
  * const graph = Graph.directed<string, string>((mutable) => {
@@ -1424,12 +1986,13 @@ export const predecessors = /*#__PURE__*/dual(2, (graph, nodeIndex) => {
1424
1986
  *
1425
1987
  * // Get incoming neighbors (nodes that point to nodeB)
1426
1988
  * const incoming = Graph.neighborsDirected(graph, nodeB, "incoming")
1989
+ * Array.of(outgoing, incoming) // => [[1], [0]]
1427
1990
  * ```
1428
1991
  *
1429
1992
  * @deprecated Use {@link successors} for outgoing neighbors or {@link predecessors} for incoming neighbors.
1430
1993
  * @see {@link successors} for outgoing neighbors in a directed graph
1431
1994
  * @see {@link predecessors} for incoming neighbors in a directed graph
1432
- * @category queries
1995
+ * @category getters
1433
1996
  * @since 3.18.0
1434
1997
  */
1435
1998
  export const neighborsDirected = /*#__PURE__*/dual(3, (graph, nodeIndex, direction) => {
@@ -1440,12 +2003,13 @@ export const neighborsDirected = /*#__PURE__*/dual(3, (graph, nodeIndex, directi
1440
2003
  }
1441
2004
  return getDirectedNeighbors(graph, nodeIndex, direction);
1442
2005
  });
2006
+ const escapeGraphVizString = value => value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\r\n|\r|\n/g, "\\n");
1443
2007
  /**
1444
2008
  * Exports a graph to GraphViz DOT format for visualization.
1445
2009
  *
1446
2010
  * **Example** (Exporting GraphViz DOT)
1447
2011
  *
1448
- * ```ts
2012
+ * ```ts import.meta.vitest
1449
2013
  * import { Graph } from "effect"
1450
2014
  *
1451
2015
  * const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
@@ -1457,22 +2021,14 @@ export const neighborsDirected = /*#__PURE__*/dual(3, (graph, nodeIndex, directi
1457
2021
  * Graph.addEdge(mutable, nodeC, nodeA, 3)
1458
2022
  * })
1459
2023
  *
1460
- * const dot = Graph.toGraphViz(graph)
1461
- * console.log(dot)
1462
- * // digraph G {
1463
- * // "0" [label="Node A"];
1464
- * // "1" [label="Node B"];
1465
- * // "2" [label="Node C"];
1466
- * // "0" -> "1" [label="1"];
1467
- * // "1" -> "2" [label="2"];
1468
- * // "2" -> "0" [label="3"];
1469
- * // }
2024
+ * Graph.toGraphViz(graph).split("\n") // => ['digraph "G" {', ' "0" [label="Node A"];', ' "1" [label="Node B"];', ' "2" [label="Node C"];', ' "0" -> "1" [label="1"];', ' "1" -> "2" [label="2"];', ' "2" -> "0" [label="3"];', "}"]
1470
2025
  * ```
1471
2026
  *
1472
2027
  * @category converting
1473
2028
  * @since 3.18.0
1474
2029
  */
1475
2030
  export const toGraphViz = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, options) => {
2031
+ const impl = graphImpl(graph);
1476
2032
  const {
1477
2033
  edgeLabel = data => String(data),
1478
2034
  graphName = "G",
@@ -1481,16 +2037,17 @@ export const toGraphViz = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, op
1481
2037
  const isDirected = graph.type === "directed";
1482
2038
  const graphType = isDirected ? "digraph" : "graph";
1483
2039
  const edgeOperator = isDirected ? "->" : "--";
2040
+ const graphId = `"${escapeGraphVizString(graphName)}"`;
1484
2041
  const lines = [];
1485
- lines.push(`${graphType} ${graphName} {`);
2042
+ lines.push(`${graphType} ${graphId} {`);
1486
2043
  // Add nodes
1487
- for (const [nodeIndex, nodeData] of graph.nodes) {
1488
- const label = nodeLabel(nodeData).replace(/"/g, "\\\"");
2044
+ for (const [nodeIndex, nodeData] of impl.nodes) {
2045
+ const label = escapeGraphVizString(nodeLabel(nodeData));
1489
2046
  lines.push(` "${nodeIndex}" [label="${label}"];`);
1490
2047
  }
1491
2048
  // Add edges
1492
- for (const [, edgeData] of graph.edges) {
1493
- const label = edgeLabel(edgeData.data).replace(/"/g, "\\\"");
2049
+ for (const [, edgeData] of impl.edges) {
2050
+ const label = escapeGraphVizString(edgeLabel(edgeData.data));
1494
2051
  lines.push(` "${edgeData.source}" ${edgeOperator} "${edgeData.target}" [label="${label}"];`);
1495
2052
  }
1496
2053
  lines.push("}");
@@ -1542,7 +2099,7 @@ const formatMermaidNode = (nodeId, label, shape) => {
1542
2099
  *
1543
2100
  * **Example** (Exporting a directed Mermaid diagram)
1544
2101
  *
1545
- * ```ts
2102
+ * ```ts import.meta.vitest
1546
2103
  * import { Graph } from "effect"
1547
2104
  *
1548
2105
  * // Basic directed graph export
@@ -1554,19 +2111,12 @@ const formatMermaidNode = (nodeId, label, shape) => {
1554
2111
  * Graph.addEdge(mutable, app, cache, 2)
1555
2112
  * })
1556
2113
  *
1557
- * const mermaid = Graph.toMermaid(graph)
1558
- * console.log(mermaid)
1559
- * // flowchart TD
1560
- * // 0["App"]
1561
- * // 1["Database"]
1562
- * // 2["Cache"]
1563
- * // 0 -->|"1"| 1
1564
- * // 0 -->|"2"| 2
2114
+ * Graph.toMermaid(graph).split("\n") // => ["flowchart TD", ' 0["App"]', ' 1["Database"]', ' 2["Cache"]', ' 0 -->|"1"| 1', ' 0 -->|"2"| 2']
1565
2115
  * ```
1566
2116
  *
1567
2117
  * **Example** (Exporting an undirected Mermaid diagram)
1568
2118
  *
1569
- * ```ts
2119
+ * ```ts import.meta.vitest
1570
2120
  * import { Graph } from "effect"
1571
2121
  *
1572
2122
  * // Undirected graph with custom labels and direction
@@ -1583,18 +2133,12 @@ const formatMermaidNode = (nodeId, label, shape) => {
1583
2133
  * edgeLabel: (relationship) => relationship,
1584
2134
  * direction: "LR"
1585
2135
  * })
1586
- * console.log(mermaid)
1587
- * // graph LR
1588
- * // 0["Alice"]
1589
- * // 1["Bob"]
1590
- * // 2["Charlie"]
1591
- * // 0 ---|"friends"| 1
1592
- * // 1 ---|"colleagues"| 2
2136
+ * mermaid.split("\n") // => ["graph LR", ' 0["Alice"]', ' 1["Bob"]', ' 2["Charlie"]', ' 0 ---|"friends"| 1', ' 1 ---|"colleagues"| 2']
1593
2137
  * ```
1594
2138
  *
1595
2139
  * **Example** (Customizing Mermaid node shapes)
1596
2140
  *
1597
- * ```ts
2141
+ * ```ts import.meta.vitest
1598
2142
  * import { Graph } from "effect"
1599
2143
  *
1600
2144
  * // Advanced styling with node shapes for flowchart
@@ -1633,20 +2177,12 @@ const formatMermaidNode = (nodeId, label, shape) => {
1633
2177
  * }
1634
2178
  * }
1635
2179
  * })
1636
- * console.log(mermaid)
1637
- * // flowchart TD
1638
- * // 0(["Begin"])
1639
- * // 1["Process Data"]
1640
- * // 2{"Valid?"}
1641
- * // 3(["Complete"])
1642
- * // 0 --> 1
1643
- * // 1 --> 2
1644
- * // 2 --> 3
2180
+ * mermaid.split("\n") // => ["flowchart TD", ' 0(["Begin"])', ' 1["Process Data"]', ' 2{"Valid?"}', ' 3(["Complete"])', " 0 --> 1", " 1 --> 2", ' 2 -->|"yes"| 3']
1645
2181
  * ```
1646
2182
  *
1647
2183
  * **Example** (Visualizing dependency graphs)
1648
2184
  *
1649
- * ```ts
2185
+ * ```ts import.meta.vitest
1650
2186
  * import { Graph } from "effect"
1651
2187
  *
1652
2188
  * // Real-world example: Software dependency graph
@@ -1661,22 +2197,22 @@ const formatMermaidNode = (nodeId, label, shape) => {
1661
2197
  * name: "MyApp",
1662
2198
  * version: "1.0.0",
1663
2199
  * type: "library"
1664
- * })
2200
+ * } satisfies Dependency)
1665
2201
  * const react = Graph.addNode(mutable, {
1666
2202
  * name: "React",
1667
2203
  * version: "18.0.0",
1668
2204
  * type: "framework"
1669
- * })
2205
+ * } satisfies Dependency)
1670
2206
  * const lodash = Graph.addNode(mutable, {
1671
2207
  * name: "Lodash",
1672
2208
  * version: "4.17.0",
1673
2209
  * type: "library"
1674
- * })
2210
+ * } satisfies Dependency)
1675
2211
  * const webpack = Graph.addNode(mutable, {
1676
2212
  * name: "Webpack",
1677
2213
  * version: "5.0.0",
1678
2214
  * type: "tool"
1679
- * })
2215
+ * } satisfies Dependency)
1680
2216
  *
1681
2217
  * Graph.addEdge(mutable, app, react, "depends on")
1682
2218
  * Graph.addEdge(mutable, app, lodash, "depends on")
@@ -1695,21 +2231,14 @@ const formatMermaidNode = (nodeId, label, shape) => {
1695
2231
  * direction: "TB"
1696
2232
  * })
1697
2233
  *
1698
- * console.log(dependencyDiagram)
1699
- * // flowchart TB
1700
- * // 0["MyApp\nv1.0.0"]
1701
- * // 1{{"React\nv18.0.0"}}
1702
- * // 2["Lodash\nv4.17.0"]
1703
- * // 3{"Webpack\nv5.0.0"}
1704
- * // 0 -->|"depends on"| 1
1705
- * // 0 -->|"depends on"| 2
1706
- * // 0 -->|"builds with"| 3
2234
+ * dependencyDiagram.split("\n") // => ["flowchart TB", ' 0["MyApp#92;nv1.0.0"]', ' 1{{"React#92;nv18.0.0"}}', ' 2["Lodash#92;nv4.17.0"]', ' 3{"Webpack#92;nv5.0.0"}', ' 0 -->|"depends on"| 1', ' 0 -->|"depends on"| 2', ' 0 -->|"builds with"| 3']
1707
2235
  * ```
1708
2236
  *
1709
2237
  * @category converting
1710
2238
  * @since 3.18.0
1711
2239
  */
1712
2240
  export const toMermaid = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, options) => {
2241
+ const impl = graphImpl(graph);
1713
2242
  // Extract and validate options with defaults
1714
2243
  const {
1715
2244
  diagramType,
@@ -1724,7 +2253,7 @@ export const toMermaid = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, opt
1724
2253
  const lines = [];
1725
2254
  lines.push(`${finalDiagramType} ${direction}`);
1726
2255
  // Add nodes
1727
- for (const [nodeIndex, nodeData] of graph.nodes) {
2256
+ for (const [nodeIndex, nodeData] of impl.nodes) {
1728
2257
  const nodeId = String(nodeIndex);
1729
2258
  const label = escapeMermaidLabel(nodeLabel(nodeData));
1730
2259
  const shape = nodeShape(nodeData);
@@ -1733,7 +2262,7 @@ export const toMermaid = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, opt
1733
2262
  }
1734
2263
  // Add edges
1735
2264
  const edgeOperator = finalDiagramType === "flowchart" ? "-->" : "---";
1736
- for (const [, edgeData] of graph.edges) {
2265
+ for (const [, edgeData] of impl.edges) {
1737
2266
  const sourceId = String(edgeData.source);
1738
2267
  const targetId = String(edgeData.target);
1739
2268
  const label = escapeMermaidLabel(edgeLabel(edgeData.data));
@@ -1755,11 +2284,12 @@ export const toMermaid = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, opt
1755
2284
  *
1756
2285
  * Uses depth-first search to detect back edges, which indicate cycles.
1757
2286
  * For directed graphs, any back edge creates a cycle. For undirected graphs,
1758
- * a back edge that doesn't go to the immediate parent creates a cycle.
2287
+ * a back edge that doesn't use the same edge used to enter the current node
2288
+ * creates a cycle.
1759
2289
  *
1760
2290
  * **Example** (Checking cycles)
1761
2291
  *
1762
- * ```ts
2292
+ * ```ts import.meta.vitest
1763
2293
  * import { Graph } from "effect"
1764
2294
  *
1765
2295
  * // Acyclic directed graph (DAG)
@@ -1770,7 +2300,7 @@ export const toMermaid = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, opt
1770
2300
  * Graph.addEdge(mutable, a, b, "A->B")
1771
2301
  * Graph.addEdge(mutable, b, c, "B->C")
1772
2302
  * })
1773
- * console.log(Graph.isAcyclic(dag)) // true
2303
+ * Graph.isAcyclic(dag) // => true
1774
2304
  *
1775
2305
  * // Cyclic directed graph
1776
2306
  * const cyclic = Graph.directed<string, string>((mutable) => {
@@ -1779,56 +2309,68 @@ export const toMermaid = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, opt
1779
2309
  * Graph.addEdge(mutable, a, b, "A->B")
1780
2310
  * Graph.addEdge(mutable, b, a, "B->A") // Creates cycle
1781
2311
  * })
1782
- * console.log(Graph.isAcyclic(cyclic)) // false
2312
+ * Graph.isAcyclic(cyclic) // => false
1783
2313
  * ```
1784
2314
  *
1785
2315
  * @category algorithms
1786
2316
  * @since 3.18.0
1787
2317
  */
1788
2318
  export const isAcyclic = graph => {
2319
+ const impl = graphImpl(graph);
1789
2320
  // Use existing cycle flag if available
1790
- if (Option.isSome(graph.acyclic)) {
1791
- return graph.acyclic.value;
2321
+ if (Option.isSome(impl.acyclic)) {
2322
+ return impl.acyclic.value;
1792
2323
  }
1793
2324
  if (graph.type === "undirected") {
1794
2325
  const visited = new Set();
1795
- for (const startNode of graph.nodes.keys()) {
2326
+ for (const startNode of impl.nodes.keys()) {
1796
2327
  if (visited.has(startNode)) {
1797
2328
  continue;
1798
2329
  }
1799
2330
  visited.add(startNode);
1800
2331
  const stack = [{
1801
2332
  node: startNode,
1802
- parent: null
2333
+ incoming: null
1803
2334
  }];
1804
2335
  while (stack.length > 0) {
1805
2336
  const {
1806
2337
  node,
1807
- parent
2338
+ incoming
1808
2339
  } = stack.pop();
1809
- const nodeNeighbors = getUndirectedNeighbors(graph, node);
1810
- for (const neighbor of nodeNeighbors) {
2340
+ const adjacencyList = impl.adjacency.get(node);
2341
+ if (adjacencyList === undefined) {
2342
+ continue;
2343
+ }
2344
+ for (const edgeIndex of adjacencyList) {
2345
+ if (edgeIndex === incoming) {
2346
+ continue;
2347
+ }
2348
+ const edge = impl.edges.get(edgeIndex);
2349
+ if (edge === undefined) {
2350
+ continue;
2351
+ }
2352
+ const neighbor = getTraversableNeighbor(graph, node, edge);
1811
2353
  if (!visited.has(neighbor)) {
1812
2354
  visited.add(neighbor);
1813
2355
  stack.push({
1814
2356
  node: neighbor,
1815
- parent: node
2357
+ incoming: edgeIndex
1816
2358
  });
1817
- } else if (neighbor !== parent) {
1818
- graph.acyclic = Option.some(false);
2359
+ } else {
2360
+ impl.acyclic = Option.some(false);
1819
2361
  return false;
1820
2362
  }
1821
2363
  }
1822
2364
  }
1823
2365
  }
1824
- graph.acyclic = Option.some(true);
2366
+ impl.acyclic = Option.some(true);
1825
2367
  return true;
1826
2368
  }
1827
2369
  // Stack-safe DFS cycle detection using iterative approach
1828
2370
  const visited = new Set();
1829
2371
  const recursionStack = new Set();
1830
2372
  // Get all nodes to handle disconnected components
1831
- for (const startNode of graph.nodes.keys()) {
2373
+ for (const startNode of impl.nodes.keys()) {
1832
2374
  if (visited.has(startNode)) {
1833
2375
  continue; // Already processed this component
1834
2376
  }
@@ -1840,7 +2382,7 @@ export const isAcyclic = graph => {
1840
2382
  if (isFirstVisit) {
1841
2383
  if (recursionStack.has(node)) {
1842
2384
  // Back edge found - cycle detected
1843
- graph.acyclic = Option.some(false);
2385
+ impl.acyclic = Option.some(false);
1844
2386
  return false;
1845
2387
  }
1846
2388
  if (visited.has(node)) {
@@ -1860,7 +2402,7 @@ export const isAcyclic = graph => {
1860
2402
  stack[stack.length - 1] = [node, neighbors, neighborIndex + 1, false];
1861
2403
  if (recursionStack.has(neighbor)) {
1862
2404
  // Back edge found - cycle detected
1863
- graph.acyclic = Option.some(false);
2405
+ impl.acyclic = Option.some(false);
1864
2406
  return false;
1865
2407
  }
1866
2408
  if (!visited.has(neighbor)) {
@@ -1874,7 +2416,7 @@ export const isAcyclic = graph => {
1874
2416
  }
1875
2417
  }
1876
2418
  // Cache the result
1877
- graph.acyclic = Option.some(true);
2419
+ impl.acyclic = Option.some(true);
1878
2420
  return true;
1879
2421
  };
1880
2422
  /**
@@ -1888,7 +2430,7 @@ export const isAcyclic = graph => {
1888
2430
  *
1889
2431
  * **Example** (Checking bipartite graphs)
1890
2432
  *
1891
- * ```ts
2433
+ * ```ts import.meta.vitest
1892
2434
  * import { Graph } from "effect"
1893
2435
  *
1894
2436
  * // Bipartite graph (alternating coloring possible)
@@ -1901,7 +2443,7 @@ export const isAcyclic = graph => {
1901
2443
  * Graph.addEdge(mutable, b, c, "edge")
1902
2444
  * Graph.addEdge(mutable, c, d, "edge")
1903
2445
  * })
1904
- * console.log(Graph.isBipartite(bipartite)) // true
2446
+ * Graph.isBipartite(bipartite) // => true
1905
2447
  *
1906
2448
  * // Non-bipartite graph (odd cycle)
1907
2449
  * const triangle = Graph.undirected<string, string>((mutable) => {
@@ -1912,18 +2454,19 @@ export const isAcyclic = graph => {
1912
2454
  * Graph.addEdge(mutable, b, c, "edge")
1913
2455
  * Graph.addEdge(mutable, c, a, "edge") // Triangle (3-cycle)
1914
2456
  * })
1915
- * console.log(Graph.isBipartite(triangle)) // false
2457
+ * Graph.isBipartite(triangle) // => false
1916
2458
  * ```
1917
2459
  *
1918
2460
  * @category algorithms
1919
2461
  * @since 3.18.0
1920
2462
  */
1921
2463
  export const isBipartite = graph => {
2464
+ const impl = graphImpl(graph);
1922
2465
  const coloring = new Map();
1923
2466
  const discovered = new Set();
1924
2467
  let isBipartiteGraph = true;
1925
2468
  // Get all nodes to handle disconnected components
1926
- for (const startNode of graph.nodes.keys()) {
2469
+ for (const startNode of impl.nodes.keys()) {
1927
2470
  if (!discovered.has(startNode)) {
1928
2471
  // Start BFS coloring from this component
1929
2472
  const queue = [startNode];
@@ -1963,12 +2506,13 @@ export const isBipartite = graph => {
1963
2506
  * For undirected graphs, we need to find the other endpoint of each edge incident to the node.
1964
2507
  */
1965
2508
  const getUndirectedNeighbors = (graph, nodeIndex) => {
2509
+ const impl = graphImpl(graph);
1966
2510
  const neighbors = new Set();
1967
2511
  // Check edges where this node is the source
1968
- const adjacencyList = graph.adjacency.get(nodeIndex);
2512
+ const adjacencyList = impl.adjacency.get(nodeIndex);
1969
2513
  if (adjacencyList !== undefined) {
1970
2514
  for (const edgeIndex of adjacencyList) {
1971
- const edge = graph.edges.get(edgeIndex);
2515
+ const edge = impl.edges.get(edgeIndex);
1972
2516
  if (edge !== undefined) {
1973
2517
  // For undirected graphs, the neighbor is the other endpoint
1974
2518
  const otherNode = edge.source === nodeIndex ? edge.target : edge.source;
@@ -1978,7 +2522,20 @@ const getUndirectedNeighbors = (graph, nodeIndex) => {
1978
2522
  }
1979
2523
  return Array.from(neighbors);
1980
2524
  };
1981
- const getTraversalNeighbors = (graph, nodeIndex, direction) => graph.type === "undirected" ? getUndirectedNeighbors(graph, nodeIndex) : getDirectedNeighbors(graph, nodeIndex, direction);
2525
+ const getTraversalNeighbors = (graph, nodeIndex, direction) => {
2526
+ if (graph.type === "undirected") {
2527
+ return getUndirectedNeighbors(graph, nodeIndex);
2528
+ }
2529
+ const directed = graph;
2530
+ if (direction !== "undirected") {
2531
+ return getDirectedNeighbors(directed, nodeIndex, direction);
2532
+ }
2533
+ const neighbors = new Set(getDirectedNeighbors(directed, nodeIndex, "outgoing"));
2534
+ for (const neighbor of getDirectedNeighbors(directed, nodeIndex, "incoming")) {
2535
+ neighbors.add(neighbor);
2536
+ }
2537
+ return Array.from(neighbors);
2538
+ };
1982
2539
  const getTraversableNeighbor = (graph, current, edge) => graph.type === "undirected" && edge.target === current ? edge.source : edge.target;
1983
2540
  /**
1984
2541
  * Finds connected components in an undirected graph.
@@ -1986,7 +2543,7 @@ const getTraversableNeighbor = (graph, current, edge) => graph.type === "undirec
1986
2543
  *
1987
2544
  * **Example** (Finding connected components)
1988
2545
  *
1989
- * ```ts
2546
+ * ```ts import.meta.vitest
1990
2547
  * import { Graph } from "effect"
1991
2548
  *
1992
2549
  * const graph = Graph.undirected<string, string>((mutable) => {
@@ -1998,17 +2555,17 @@ const getTraversableNeighbor = (graph, current, edge) => graph.type === "undirec
1998
2555
  * Graph.addEdge(mutable, c, d, "edge") // Component 2: C-D
1999
2556
  * })
2000
2557
  *
2001
- * const components = Graph.connectedComponents(graph)
2002
- * console.log(components) // [[0, 1], [2, 3]]
2558
+ * Graph.connectedComponents(graph) // => [[0, 1], [2, 3]]
2003
2559
  * ```
2004
2560
  *
2005
2561
  * @category algorithms
2006
2562
  * @since 3.18.0
2007
2563
  */
2008
2564
  export const connectedComponents = graph => {
2565
+ const impl = graphImpl(graph);
2009
2566
  const visited = new Set();
2010
2567
  const components = [];
2011
- for (const startNode of graph.nodes.keys()) {
2568
+ for (const startNode of impl.nodes.keys()) {
2012
2569
  if (!visited.has(startNode)) {
2013
2570
  // DFS to find all nodes in this component
2014
2571
  const component = [];
@@ -2042,7 +2599,7 @@ export const connectedComponents = graph => {
2042
2599
  *
2043
2600
  * **Example** (Finding strongly connected components)
2044
2601
  *
2045
- * ```ts
2602
+ * ```ts import.meta.vitest
2046
2603
  * import { Graph } from "effect"
2047
2604
  *
2048
2605
  * const graph = Graph.directed<string, string>((mutable) => {
@@ -2054,8 +2611,7 @@ export const connectedComponents = graph => {
2054
2611
  * Graph.addEdge(mutable, c, a, "C->A") // Creates SCC: A-B-C
2055
2612
  * })
2056
2613
  *
2057
- * const sccs = Graph.stronglyConnectedComponents(graph)
2058
- * console.log(sccs) // [[0, 1, 2]]
2614
+ * Graph.stronglyConnectedComponents(graph) // => [[0, 2, 1]]
2059
2615
  * ```
2060
2616
  *
2061
2617
  * @category algorithms
@@ -2067,9 +2623,10 @@ export const stronglyConnectedComponents = graph => {
2067
2623
  message: "Cannot find strongly connected components of undirected graph"
2068
2624
  });
2069
2625
  }
2626
+ const impl = graphImpl(graph);
2070
2627
  const visited = new Set();
2071
2628
  const finishOrder = [];
2072
- for (const startNode of graph.nodes.keys()) {
2629
+ for (const startNode of impl.nodes.keys()) {
2073
2630
  if (visited.has(startNode)) {
2074
2631
  continue;
2075
2632
  }
@@ -2118,10 +2675,10 @@ export const stronglyConnectedComponents = graph => {
2118
2675
  visited.add(node);
2119
2676
  scc.push(node);
2120
2677
  // Use reverse adjacency (transpose graph)
2121
- const reverseAdjacency = graph.reverseAdjacency.get(node);
2678
+ const reverseAdjacency = impl.reverseAdjacency.get(node);
2122
2679
  if (reverseAdjacency !== undefined) {
2123
2680
  for (const edgeIndex of reverseAdjacency) {
2124
- const edge = graph.edges.get(edgeIndex);
2681
+ const edge = impl.edges.get(edgeIndex);
2125
2682
  if (edge !== undefined) {
2126
2683
  const predecessor = edge.source;
2127
2684
  if (!visited.has(predecessor)) {
@@ -2135,18 +2692,42 @@ export const stronglyConnectedComponents = graph => {
2135
2692
  }
2136
2693
  return sccs;
2137
2694
  };
2138
- const validateNonNegativeEdgeWeights = (graph, cost, algorithm) => {
2139
- const edgeWeights = new Map();
2140
- for (const [edgeIndex, edgeData] of graph.edges) {
2141
- const weight = cost(edgeData.data);
2142
- if (weight < 0 || Number.isNaN(weight)) {
2143
- throw new GraphError({
2144
- message: `${algorithm} requires non-negative edge weights`
2145
- });
2695
+ const minHeapLessThan = (self, that) => self.priority < that.priority || self.priority === that.priority && self.sequence < that.sequence;
2696
+ const minHeapPush = (heap, entry) => {
2697
+ let index = heap.length;
2698
+ heap.push(entry);
2699
+ while (index > 0) {
2700
+ const parent = index - 1 >>> 1;
2701
+ if (!minHeapLessThan(entry, heap[parent])) {
2702
+ break;
2146
2703
  }
2147
- edgeWeights.set(edgeIndex, weight);
2704
+ heap[index] = heap[parent];
2705
+ index = parent;
2706
+ }
2707
+ heap[index] = entry;
2708
+ };
2709
+ const minHeapPop = heap => {
2710
+ const first = heap[0];
2711
+ const last = heap.pop();
2712
+ if (last === undefined || heap.length === 0) {
2713
+ return first;
2714
+ }
2715
+ let index = 0;
2716
+ while (true) {
2717
+ const left = index * 2 + 1;
2718
+ if (left >= heap.length) {
2719
+ break;
2720
+ }
2721
+ const right = left + 1;
2722
+ const child = right < heap.length && minHeapLessThan(heap[right], heap[left]) ? right : left;
2723
+ if (!minHeapLessThan(heap[child], last)) {
2724
+ break;
2725
+ }
2726
+ heap[index] = heap[child];
2727
+ index = child;
2148
2728
  }
2149
- return edgeWeights;
2729
+ heap[index] = last;
2730
+ return first;
2150
2731
  };
2151
2732
  /**
2152
2733
  * Finds the shortest path from the configured source node to the target node
@@ -2154,14 +2735,15 @@ const validateNonNegativeEdgeWeights = (graph, cost, algorithm) => {
2154
2735
  *
2155
2736
  * **Details**
2156
2737
  *
2157
- * Edge costs must be non-negative. Returns `Option.none()` when the target is
2158
- * not reachable, and throws a `GraphError` when either endpoint is missing or a
2159
- * negative edge cost is encountered.
2738
+ * Edge costs must be non-negative and not `NaN`. `Infinity` is allowed and
2739
+ * behaves like an impassable edge. Returns `Option.none()` when the target is
2740
+ * not reachable, and throws a `GraphError` when either endpoint is missing or an
2741
+ * edge cost is negative or `NaN`.
2160
2742
  *
2161
2743
  * **Example** (Finding shortest paths with Dijkstra)
2162
2744
  *
2163
- * ```ts
2164
- * import { Graph } from "effect"
2745
+ * ```ts import.meta.vitest
2746
+ * import { Graph, Option } from "effect"
2165
2747
  *
2166
2748
  * const graph = Graph.directed<string, number>((mutable) => {
2167
2749
  * const a = Graph.addNode(mutable, "A")
@@ -2178,24 +2760,31 @@ const validateNonNegativeEdgeWeights = (graph, cost, algorithm) => {
2178
2760
  * cost: (edgeData) => edgeData
2179
2761
  * })
2180
2762
  *
2181
- * if (result._tag === "Some") {
2182
- * console.log(result.value.path) // [0, 1, 2] - shortest path A->B->C
2183
- * console.log(result.value.distance) // 7 - total distance
2184
- * }
2763
+ * Option.map(result, ({ distance, path }) => [distance, path] as const) // => Option.some([7, [0, 1, 2]])
2185
2764
  * ```
2186
2765
  *
2187
2766
  * @category algorithms
2188
2767
  * @since 3.18.0
2189
2768
  */
2190
2769
  export const dijkstra = /*#__PURE__*/dual(2, (graph, config) => {
2770
+ const impl = graphImpl(graph);
2191
2771
  // Validate that source and target nodes exist
2192
- if (!graph.nodes.has(config.source)) {
2772
+ if (!impl.nodes.has(config.source)) {
2193
2773
  throw missingNode(config.source);
2194
2774
  }
2195
- if (!graph.nodes.has(config.target)) {
2775
+ if (!impl.nodes.has(config.target)) {
2196
2776
  throw missingNode(config.target);
2197
2777
  }
2198
- const edgeWeights = validateNonNegativeEdgeWeights(graph, config.cost, "Dijkstra's algorithm");
2778
+ const edgeWeights = new Map();
2779
+ for (const [edgeIndex, edgeData] of impl.edges) {
2780
+ const weight = config.cost(edgeData.data);
2781
+ if (Number.isNaN(weight) || weight < 0) {
2782
+ throw new GraphError({
2783
+ message: "Dijkstra's algorithm requires non-negative edge weights"
2784
+ });
2785
+ }
2786
+ edgeWeights.set(edgeIndex, weight);
2787
+ }
2199
2788
  // Early return if source equals target
2200
2789
  if (config.source === config.target) {
2201
2790
  return Option.some({
@@ -2210,24 +2799,19 @@ export const dijkstra = /*#__PURE__*/dual(2, (graph, config) => {
2210
2799
  const visited = new Set();
2211
2800
  // Initialize distances
2212
2801
  // Iterate directly over node keys
2213
- for (const node of graph.nodes.keys()) {
2802
+ for (const node of impl.nodes.keys()) {
2214
2803
  distances.set(node, node === config.source ? 0 : Infinity);
2215
2804
  previous.set(node, null);
2216
2805
  }
2217
- // Simple priority queue using array (can be optimized with proper heap)
2218
- const priorityQueue = [{
2806
+ const priorityQueue = [];
2807
+ let sequence = 0;
2808
+ minHeapPush(priorityQueue, {
2219
2809
  node: config.source,
2220
- distance: 0
2221
- }];
2810
+ priority: 0,
2811
+ sequence: sequence++
2812
+ });
2222
2813
  while (priorityQueue.length > 0) {
2223
- // Find minimum distance node (priority queue extract-min)
2224
- let minIndex = 0;
2225
- for (let i = 1; i < priorityQueue.length; i++) {
2226
- if (priorityQueue[i].distance < priorityQueue[minIndex].distance) {
2227
- minIndex = i;
2228
- }
2229
- }
2230
- const current = priorityQueue.splice(minIndex, 1)[0];
2814
+ const current = minHeapPop(priorityQueue);
2231
2815
  const currentNode = current.node;
2232
2816
  // Skip if already visited (can happen with duplicate entries)
2233
2817
  if (visited.has(currentNode)) {
@@ -2241,10 +2825,10 @@ export const dijkstra = /*#__PURE__*/dual(2, (graph, config) => {
2241
2825
  // Get current distance
2242
2826
  const currentDistance = distances.get(currentNode);
2243
2827
  // Examine all outgoing edges
2244
- const adjacencyList = graph.adjacency.get(currentNode);
2828
+ const adjacencyList = impl.adjacency.get(currentNode);
2245
2829
  if (adjacencyList !== undefined) {
2246
2830
  for (const edgeIndex of adjacencyList) {
2247
- const edge = graph.edges.get(edgeIndex);
2831
+ const edge = impl.edges.get(edgeIndex);
2248
2832
  if (edge !== undefined) {
2249
2833
  const neighbor = getTraversableNeighbor(graph, currentNode, edge);
2250
2834
  const cost = edgeWeights.get(edgeIndex);
@@ -2259,9 +2843,10 @@ export const dijkstra = /*#__PURE__*/dual(2, (graph, config) => {
2259
2843
  });
2260
2844
  // Add to priority queue if not visited
2261
2845
  if (!visited.has(neighbor)) {
2262
- priorityQueue.push({
2846
+ minHeapPush(priorityQueue, {
2263
2847
  node: neighbor,
2264
- distance: newDistance
2848
+ priority: newDistance,
2849
+ sequence: sequence++
2265
2850
  });
2266
2851
  }
2267
2852
  }
@@ -2301,12 +2886,13 @@ export const dijkstra = /*#__PURE__*/dual(2, (graph, config) => {
2301
2886
  * **Details**
2302
2887
  *
2303
2888
  * Computes distances, reconstructed node paths, and edge-data paths for every
2304
- * source and target pair in O(V^3) time. Negative edge weights are allowed, but
2305
- * a `GraphError` is thrown if any negative cycle is detected.
2889
+ * source and target pair in O(V^3) time. Negative edge weights are allowed, and
2890
+ * `Infinity` behaves like an impassable edge. A `GraphError` is thrown if any
2891
+ * edge weight is `NaN` or `-Infinity`, or if any negative cycle is detected.
2306
2892
  *
2307
2893
  * **Example** (Finding all-pairs shortest paths)
2308
2894
  *
2309
- * ```ts
2895
+ * ```ts import.meta.vitest
2310
2896
  * import { Graph } from "effect"
2311
2897
  *
2312
2898
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2319,16 +2905,17 @@ export const dijkstra = /*#__PURE__*/dual(2, (graph, config) => {
2319
2905
  * })
2320
2906
  *
2321
2907
  * const result = Graph.floydWarshall(graph, (edgeData) => edgeData)
2322
- * const distanceAToC = result.distances.get(0)?.get(2) // 5 (A->B->C)
2323
- * const pathAToC = result.paths.get(0)?.get(2) // [0, 1, 2]
2908
+ * const shortest = { distance: result.distances.get(0)?.get(2), path: result.paths.get(0)?.get(2) }
2909
+ * shortest // => { distance: 5, path: [0, 1, 2] }
2324
2910
  * ```
2325
2911
  *
2326
2912
  * @category algorithms
2327
2913
  * @since 3.18.0
2328
2914
  */
2329
2915
  export const floydWarshall = /*#__PURE__*/dual(2, (graph, cost) => {
2916
+ const impl = graphImpl(graph);
2330
2917
  // Get all nodes for Floyd-Warshall algorithm (needs array for nested iteration)
2331
- const allNodes = Array.from(graph.nodes.keys());
2918
+ const allNodes = Array.from(impl.nodes.keys());
2332
2919
  // Initialize distance matrix
2333
2920
  const distances = new Map();
2334
2921
  const next = new Map();
@@ -2340,13 +2927,16 @@ export const floydWarshall = /*#__PURE__*/dual(2, (graph, cost) => {
2340
2927
  edgeMatrix.set(i, new Map());
2341
2928
  for (const j of allNodes) {
2342
2929
  distances.get(i).set(j, i === j ? 0 : Infinity);
2343
- next.get(i).set(j, null);
2344
- edgeMatrix.get(i).set(j, null);
2345
2930
  }
2346
2931
  }
2347
2932
  // Set edge weights
2348
- for (const [, edgeData] of graph.edges) {
2933
+ for (const [, edgeData] of impl.edges) {
2349
2934
  const weight = cost(edgeData.data);
2935
+ if (Number.isNaN(weight) || weight === -Infinity) {
2936
+ throw new GraphError({
2937
+ message: "Floyd-Warshall algorithm does not support NaN or -Infinity edge weights"
2938
+ });
2939
+ }
2350
2940
  const i = edgeData.source;
2351
2941
  const j = edgeData.target;
2352
2942
  // Use minimum weight if multiple edges exist
@@ -2373,8 +2963,11 @@ export const floydWarshall = /*#__PURE__*/dual(2, (graph, cost) => {
2373
2963
  const distKJ = distances.get(k).get(j);
2374
2964
  const distIJ = distances.get(i).get(j);
2375
2965
  if (distIK !== Infinity && distKJ !== Infinity && distIK + distKJ < distIJ) {
2376
- distances.get(i).set(j, distIK + distKJ);
2377
- next.get(i).set(j, next.get(i).get(k));
2966
+ const nextIK = next.get(i).get(k);
2967
+ if (nextIK !== undefined) {
2968
+ distances.get(i).set(j, distIK + distKJ);
2969
+ next.get(i).set(j, nextIK);
2970
+ }
2378
2971
  }
2379
2972
  }
2380
2973
  }
@@ -2408,10 +3001,10 @@ export const floydWarshall = /*#__PURE__*/dual(2, (graph, cost) => {
2408
3001
  path.push(current);
2409
3002
  while (current !== j) {
2410
3003
  const nextNode = next.get(current).get(j);
2411
- if (nextNode === null) break;
2412
- const edgeData = edgeMatrix.get(current).get(nextNode);
2413
- if (edgeData !== null) {
2414
- weights.push(edgeData);
3004
+ if (nextNode === undefined) break;
3005
+ const edgeRow = edgeMatrix.get(current);
3006
+ if (edgeRow.has(nextNode)) {
3007
+ weights.push(edgeRow.get(nextNode));
2415
3008
  }
2416
3009
  current = nextNode;
2417
3010
  path.push(current);
@@ -2433,15 +3026,16 @@ export const floydWarshall = /*#__PURE__*/dual(2, (graph, cost) => {
2433
3026
  *
2434
3027
  * **Details**
2435
3028
  *
2436
- * The edge-cost function must return non-negative weights, and the heuristic
3029
+ * The edge-cost function must return non-negative weights and not `NaN`.
3030
+ * `Infinity` is allowed and behaves like an impassable edge. The heuristic
2437
3031
  * should be consistent to preserve shortest-path guarantees. Returns
2438
3032
  * `Option.none()` when the target is not reachable, and throws a `GraphError`
2439
- * when either endpoint is missing or a negative edge cost is encountered.
3033
+ * when either endpoint is missing or an edge cost is negative or `NaN`.
2440
3034
  *
2441
3035
  * **Example** (Finding shortest paths with A-star)
2442
3036
  *
2443
- * ```ts
2444
- * import { Graph } from "effect"
3037
+ * ```ts import.meta.vitest
3038
+ * import { Graph, Option } from "effect"
2445
3039
  *
2446
3040
  * const graph = Graph.directed<{ x: number; y: number }, number>((mutable) => {
2447
3041
  * const a = Graph.addNode(mutable, { x: 0, y: 0 })
@@ -2464,24 +3058,31 @@ export const floydWarshall = /*#__PURE__*/dual(2, (graph, cost) => {
2464
3058
  * heuristic
2465
3059
  * })
2466
3060
  *
2467
- * if (result._tag === "Some") {
2468
- * console.log(result.value.path) // [0, 1, 2] - shortest path
2469
- * console.log(result.value.distance) // 2 - total distance
2470
- * }
3061
+ * Option.map(result, ({ distance, path }) => [distance, path] as const) // => Option.some([2, [0, 1, 2]])
2471
3062
  * ```
2472
3063
  *
2473
3064
  * @category algorithms
2474
3065
  * @since 3.18.0
2475
3066
  */
2476
3067
  export const astar = /*#__PURE__*/dual(2, (graph, config) => {
3068
+ const impl = graphImpl(graph);
2477
3069
  // Validate that source and target nodes exist
2478
- if (!graph.nodes.has(config.source)) {
3070
+ if (!impl.nodes.has(config.source)) {
2479
3071
  throw missingNode(config.source);
2480
3072
  }
2481
- if (!graph.nodes.has(config.target)) {
3073
+ if (!impl.nodes.has(config.target)) {
2482
3074
  throw missingNode(config.target);
2483
3075
  }
2484
- const edgeWeights = validateNonNegativeEdgeWeights(graph, config.cost, "A* algorithm");
3076
+ const edgeWeights = new Map();
3077
+ for (const [edgeIndex, edgeData] of impl.edges) {
3078
+ const weight = config.cost(edgeData.data);
3079
+ if (Number.isNaN(weight) || weight < 0) {
3080
+ throw new GraphError({
3081
+ message: "A* algorithm requires non-negative edge weights"
3082
+ });
3083
+ }
3084
+ edgeWeights.set(edgeIndex, weight);
3085
+ }
2485
3086
  // Early return if source equals target
2486
3087
  if (config.source === config.target) {
2487
3088
  return Option.some({
@@ -2504,7 +3105,7 @@ export const astar = /*#__PURE__*/dual(2, (graph, config) => {
2504
3105
  const visited = new Set();
2505
3106
  // Initialize scores
2506
3107
  // Iterate directly over node keys
2507
- for (const node of graph.nodes.keys()) {
3108
+ for (const node of impl.nodes.keys()) {
2508
3109
  gScore.set(node, node === config.source ? 0 : Infinity);
2509
3110
  fScore.set(node, Infinity);
2510
3111
  previous.set(node, null);
@@ -2515,20 +3116,15 @@ export const astar = /*#__PURE__*/dual(2, (graph, config) => {
2515
3116
  const h = config.heuristic(sourceNodeData.value, targetNodeData.value);
2516
3117
  fScore.set(config.source, h);
2517
3118
  }
2518
- // Priority queue using f-score (total estimated cost)
2519
- const openSet = [{
3119
+ const openSet = [];
3120
+ let sequence = 0;
3121
+ minHeapPush(openSet, {
2520
3122
  node: config.source,
2521
- fScore: fScore.get(config.source)
2522
- }];
3123
+ priority: fScore.get(config.source),
3124
+ sequence: sequence++
3125
+ });
2523
3126
  while (openSet.length > 0) {
2524
- // Find node with lowest f-score
2525
- let minIndex = 0;
2526
- for (let i = 1; i < openSet.length; i++) {
2527
- if (openSet[i].fScore < openSet[minIndex].fScore) {
2528
- minIndex = i;
2529
- }
2530
- }
2531
- const current = openSet.splice(minIndex, 1)[0];
3127
+ const current = minHeapPop(openSet);
2532
3128
  const currentNode = current.node;
2533
3129
  // Skip if already visited
2534
3130
  if (visited.has(currentNode)) {
@@ -2542,10 +3138,10 @@ export const astar = /*#__PURE__*/dual(2, (graph, config) => {
2542
3138
  // Get current g-score
2543
3139
  const currentGScore = gScore.get(currentNode);
2544
3140
  // Examine all outgoing edges
2545
- const adjacencyList = graph.adjacency.get(currentNode);
3141
+ const adjacencyList = impl.adjacency.get(currentNode);
2546
3142
  if (adjacencyList !== undefined) {
2547
3143
  for (const edgeIndex of adjacencyList) {
2548
- const edge = graph.edges.get(edgeIndex);
3144
+ const edge = impl.edges.get(edgeIndex);
2549
3145
  if (edge !== undefined) {
2550
3146
  const neighbor = getTraversableNeighbor(graph, currentNode, edge);
2551
3147
  const weight = edgeWeights.get(edgeIndex);
@@ -2567,9 +3163,10 @@ export const astar = /*#__PURE__*/dual(2, (graph, config) => {
2567
3163
  fScore.set(neighbor, f);
2568
3164
  // Add to open set if not visited
2569
3165
  if (!visited.has(neighbor)) {
2570
- openSet.push({
3166
+ minHeapPush(openSet, {
2571
3167
  node: neighbor,
2572
- fScore: f
3168
+ priority: f,
3169
+ sequence: sequence++
2573
3170
  });
2574
3171
  }
2575
3172
  }
@@ -2609,14 +3206,15 @@ export const astar = /*#__PURE__*/dual(2, (graph, config) => {
2609
3206
  *
2610
3207
  * **Details**
2611
3208
  *
2612
- * Negative edge weights are allowed. Returns `Option.none()` when the target is
2613
- * unreachable or when a negative cycle affects the path to the target. Throws a
2614
- * `GraphError` when either endpoint is missing.
3209
+ * Negative edge weights are allowed, and `Infinity` behaves like an impassable
3210
+ * edge. Returns `Option.none()` when the target is unreachable or when a
3211
+ * negative cycle affects the path to the target. Throws a `GraphError` when
3212
+ * either endpoint is missing or an edge weight is `NaN` or `-Infinity`.
2615
3213
  *
2616
3214
  * **Example** (Finding shortest paths with Bellman-Ford)
2617
3215
  *
2618
- * ```ts
2619
- * import { Graph } from "effect"
3216
+ * ```ts import.meta.vitest
3217
+ * import { Graph, Option } from "effect"
2620
3218
  *
2621
3219
  * const graph = Graph.directed<string, number>((mutable) => {
2622
3220
  * const a = Graph.addNode(mutable, "A")
@@ -2633,43 +3231,38 @@ export const astar = /*#__PURE__*/dual(2, (graph, config) => {
2633
3231
  * cost: (edgeData) => edgeData
2634
3232
  * })
2635
3233
  *
2636
- * if (result._tag === "Some") {
2637
- * console.log(result.value.path) // [0, 1, 2] - shortest path A->B->C
2638
- * console.log(result.value.distance) // 2 - total distance
2639
- * }
3234
+ * Option.map(result, ({ distance, path }) => [distance, path] as const) // => Option.some([2, [0, 1, 2]])
2640
3235
  * ```
2641
3236
  *
2642
3237
  * @category algorithms
2643
3238
  * @since 3.18.0
2644
3239
  */
2645
3240
  export const bellmanFord = /*#__PURE__*/dual(2, (graph, config) => {
3241
+ const impl = graphImpl(graph);
2646
3242
  // Validate that source and target nodes exist
2647
- if (!graph.nodes.has(config.source)) {
3243
+ if (!impl.nodes.has(config.source)) {
2648
3244
  throw missingNode(config.source);
2649
3245
  }
2650
- if (!graph.nodes.has(config.target)) {
3246
+ if (!impl.nodes.has(config.target)) {
2651
3247
  throw missingNode(config.target);
2652
3248
  }
2653
- // Early return if source equals target
2654
- if (config.source === config.target) {
2655
- return Option.some({
2656
- path: [config.source],
2657
- distance: 0,
2658
- costs: []
2659
- });
2660
- }
2661
3249
  // Initialize distances and predecessors
2662
3250
  const distances = new Map();
2663
3251
  const previous = new Map();
2664
3252
  // Iterate directly over node keys
2665
- for (const node of graph.nodes.keys()) {
3253
+ for (const node of impl.nodes.keys()) {
2666
3254
  distances.set(node, node === config.source ? 0 : Infinity);
2667
3255
  previous.set(node, null);
2668
3256
  }
2669
3257
  // Collect all edges for relaxation
2670
3258
  const edges = [];
2671
- for (const [, edgeData] of graph.edges) {
3259
+ for (const [, edgeData] of impl.edges) {
2672
3260
  const weight = config.cost(edgeData.data);
3261
+ if (Number.isNaN(weight) || weight === -Infinity) {
3262
+ throw new GraphError({
3263
+ message: "Bellman-Ford algorithm does not support NaN or -Infinity edge weights"
3264
+ });
3265
+ }
2673
3266
  edges.push({
2674
3267
  source: edgeData.source,
2675
3268
  target: edgeData.target,
@@ -2686,7 +3279,7 @@ export const bellmanFord = /*#__PURE__*/dual(2, (graph, config) => {
2686
3279
  }
2687
3280
  }
2688
3281
  // Relax edges up to V-1 times
2689
- const nodeCount = graph.nodes.size;
3282
+ const nodeCount = impl.nodes.size;
2690
3283
  for (let i = 0; i < nodeCount - 1; i++) {
2691
3284
  let hasUpdate = false;
2692
3285
  for (const edge of edges) {
@@ -2766,7 +3359,7 @@ export const bellmanFord = /*#__PURE__*/dual(2, (graph, config) => {
2766
3359
  *
2767
3360
  * **Example** (Working with node walkers)
2768
3361
  *
2769
- * ```ts
3362
+ * ```ts import.meta.vitest
2770
3363
  * import { Graph } from "effect"
2771
3364
  *
2772
3365
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2785,8 +3378,8 @@ export const bellmanFord = /*#__PURE__*/dual(2, (graph, config) => {
2785
3378
  * }
2786
3379
  *
2787
3380
  * // Access node data using values() or entries()
2788
- * const nodeData = Array.from(Graph.values(dfsNodes)) // ["A", "B"]
2789
- * const nodeEntries = Array.from(Graph.entries(allNodes)) // [[0, "A"], [1, "B"]]
3381
+ * Array.from(Graph.values(dfsNodes)) // => ["A", "B"]
3382
+ * Array.from(Graph.entries(allNodes)) // => [[0, "A"], [1, "B"]]
2790
3383
  * ```
2791
3384
  *
2792
3385
  * @category models
@@ -2806,7 +3399,7 @@ export class Walker {
2806
3399
  *
2807
3400
  * **Example** (Visiting walker elements)
2808
3401
  *
2809
- * ```ts
3402
+ * ```ts import.meta.vitest
2810
3403
  * import { Graph } from "effect"
2811
3404
  *
2812
3405
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2818,14 +3411,10 @@ export class Walker {
2818
3411
  * const dfs = Graph.dfs(graph, { start: [0] })
2819
3412
  *
2820
3413
  * // Map to just the node data
2821
- * const values = Array.from(dfs.visit((index, data) => data))
2822
- * console.log(values) // ["A", "B"]
3414
+ * Array.from(dfs.visit((index, data) => data)) // => ["A", "B"]
2823
3415
  *
2824
3416
  * // Map to custom objects
2825
- * const custom = Array.from(
2826
- * dfs.visit((index, data) => ({ id: index, name: data }))
2827
- * )
2828
- * console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
3417
+ * Array.from(dfs.visit((index, data) => ({ id: index, name: data }))) // => [{ id: 0, name: "A" }, { id: 1, name: "B" }]
2829
3418
  * ```
2830
3419
  *
2831
3420
  * @since 4.0.0
@@ -2841,7 +3430,7 @@ export class Walker {
2841
3430
  *
2842
3431
  * **Example** (Visiting walker elements)
2843
3432
  *
2844
- * ```ts
3433
+ * ```ts import.meta.vitest
2845
3434
  * import { Graph } from "effect"
2846
3435
  *
2847
3436
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2853,14 +3442,10 @@ export class Walker {
2853
3442
  * const dfs = Graph.dfs(graph, { start: [0] })
2854
3443
  *
2855
3444
  * // Map to just the node data
2856
- * const values = Array.from(dfs.visit((index, data) => data))
2857
- * console.log(values) // ["A", "B"]
3445
+ * Array.from(dfs.visit((index, data) => data)) // => ["A", "B"]
2858
3446
  *
2859
3447
  * // Map to custom objects
2860
- * const custom = Array.from(
2861
- * dfs.visit((index, data) => ({ id: index, name: data }))
2862
- * )
2863
- * console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
3448
+ * Array.from(dfs.visit((index, data) => ({ id: index, name: data }))) // => [{ id: 0, name: "A" }, { id: 1, name: "B" }]
2864
3449
  * ```
2865
3450
  *
2866
3451
  * @category iterators
@@ -2868,7 +3453,7 @@ export class Walker {
2868
3453
  */
2869
3454
  visit) {
2870
3455
  this.visit = visit;
2871
- this[Symbol.iterator] = visit((index, data) => [index, data])[Symbol.iterator];
3456
+ this[Symbol.iterator] = () => visit((index, data) => [index, data])[Symbol.iterator]();
2872
3457
  }
2873
3458
  }
2874
3459
  /**
@@ -2876,7 +3461,7 @@ export class Walker {
2876
3461
  *
2877
3462
  * **Example** (Iterating walker indices)
2878
3463
  *
2879
- * ```ts
3464
+ * ```ts import.meta.vitest
2880
3465
  * import { Graph } from "effect"
2881
3466
  *
2882
3467
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2886,8 +3471,7 @@ export class Walker {
2886
3471
  * })
2887
3472
  *
2888
3473
  * const dfs = Graph.dfs(graph, { start: [0] })
2889
- * const indices = Array.from(Graph.indices(dfs))
2890
- * console.log(indices) // [0, 1]
3474
+ * Array.from(Graph.indices(dfs)) // => [0, 1]
2891
3475
  * ```
2892
3476
  *
2893
3477
  * @category iterators
@@ -2899,7 +3483,7 @@ export const indices = walker => walker.visit((index, _) => index);
2899
3483
  *
2900
3484
  * **Example** (Iterating walker values)
2901
3485
  *
2902
- * ```ts
3486
+ * ```ts import.meta.vitest
2903
3487
  * import { Graph } from "effect"
2904
3488
  *
2905
3489
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2909,8 +3493,7 @@ export const indices = walker => walker.visit((index, _) => index);
2909
3493
  * })
2910
3494
  *
2911
3495
  * const dfs = Graph.dfs(graph, { start: [0] })
2912
- * const values = Array.from(Graph.values(dfs))
2913
- * console.log(values) // ["A", "B"]
3496
+ * Array.from(Graph.values(dfs)) // => ["A", "B"]
2914
3497
  * ```
2915
3498
  *
2916
3499
  * @category iterators
@@ -2922,7 +3505,7 @@ export const values = walker => walker.visit((_, data) => data);
2922
3505
  *
2923
3506
  * **Example** (Iterating walker entries)
2924
3507
  *
2925
- * ```ts
3508
+ * ```ts import.meta.vitest
2926
3509
  * import { Graph } from "effect"
2927
3510
  *
2928
3511
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2932,8 +3515,7 @@ export const values = walker => walker.visit((_, data) => data);
2932
3515
  * })
2933
3516
  *
2934
3517
  * const dfs = Graph.dfs(graph, { start: [0] })
2935
- * const entries = Array.from(Graph.entries(dfs))
2936
- * console.log(entries) // [[0, "A"], [1, "B"]]
3518
+ * Array.from(Graph.entries(dfs)) // => [[0, "A"], [1, "B"]]
2937
3519
  * ```
2938
3520
  *
2939
3521
  * @category iterators
@@ -2947,12 +3529,13 @@ export const entries = walker => walker.visit((index, data) => [index, data]);
2947
3529
  * **Details**
2948
3530
  *
2949
3531
  * If no start nodes are supplied, the iterator is empty. The `direction` option
2950
- * chooses whether to follow outgoing or incoming edges. Throws a `GraphError`
3532
+ * chooses whether to follow outgoing or incoming edges. The `radius` option
3533
+ * limits traversal by edge distance from the start nodes. Throws a `GraphError`
2951
3534
  * if any configured start node does not exist.
2952
3535
  *
2953
3536
  * **Example** (Traversing depth-first)
2954
3537
  *
2955
- * ```ts
3538
+ * ```ts import.meta.vitest
2956
3539
  * import { Graph } from "effect"
2957
3540
  *
2958
3541
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -2964,14 +3547,10 @@ export const entries = walker => walker.visit((index, data) => [index, data]);
2964
3547
  * })
2965
3548
  *
2966
3549
  * // Start from a specific node
2967
- * const dfs1 = Graph.dfs(graph, { start: [0] })
2968
- * for (const nodeIndex of Graph.indices(dfs1)) {
2969
- * console.log(nodeIndex) // Traverses in DFS order: 0, 1, 2
2970
- * }
3550
+ * Array.from(Graph.indices(Graph.dfs(graph, { start: [0] }))) // => [0, 1, 2]
2971
3551
  *
2972
3552
  * // Empty iterator (no starting nodes)
2973
- * const dfs2 = Graph.dfs(graph)
2974
- * // Can be used programmatically
3553
+ * Graph.dfs(graph)
2975
3554
  * ```
2976
3555
  *
2977
3556
  * @category iterators
@@ -2980,6 +3559,7 @@ export const entries = walker => walker.visit((index, data) => [index, data]);
2980
3559
  export const dfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config = {}) => {
2981
3560
  const start = config.start ?? [];
2982
3561
  const direction = config.direction ?? "outgoing";
3562
+ const radius = config.radius ?? Infinity;
2983
3563
  // Validate that all start nodes exist
2984
3564
  for (const nodeIndex of start) {
2985
3565
  if (!hasNode(graph, nodeIndex)) {
@@ -2988,26 +3568,61 @@ export const dfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
2988
3568
  }
2989
3569
  return new Walker(f => ({
2990
3570
  [Symbol.iterator]: () => {
2991
- const stack = [...start];
2992
- const discovered = new Set();
3571
+ const depths = radius === Infinity ? undefined : new Map();
3572
+ const stack = [];
3573
+ const yielded = new Set();
3574
+ if (depths === undefined) {
3575
+ for (const node of start) {
3576
+ stack.push([node, 0]);
3577
+ }
3578
+ } else {
3579
+ const starts = new Set();
3580
+ for (let i = start.length - 1; i >= 0; i--) {
3581
+ const node = start[i];
3582
+ if (!starts.has(node)) {
3583
+ starts.add(node);
3584
+ stack.push([node, 0]);
3585
+ depths.set(node, 0);
3586
+ }
3587
+ }
3588
+ stack.reverse();
3589
+ }
2993
3590
  const nextMapped = () => {
2994
3591
  while (stack.length > 0) {
2995
- const current = stack.pop();
2996
- if (discovered.has(current)) {
3592
+ const [current, depth] = stack.pop();
3593
+ if (depths === undefined) {
3594
+ if (yielded.has(current)) {
3595
+ continue;
3596
+ }
3597
+ } else if (depths.get(current) !== depth) {
2997
3598
  continue;
2998
3599
  }
2999
- discovered.add(current);
3000
3600
  const nodeDataOption = getNode(graph, current);
3001
3601
  if (Option.isNone(nodeDataOption)) {
3002
3602
  continue;
3003
3603
  }
3004
- const neighbors = getTraversalNeighbors(graph, current, direction);
3005
- for (let i = neighbors.length - 1; i >= 0; i--) {
3006
- const neighbor = neighbors[i];
3007
- if (!discovered.has(neighbor)) {
3008
- stack.push(neighbor);
3604
+ if (depth < radius) {
3605
+ const neighbors = getTraversalNeighbors(graph, current, direction);
3606
+ for (let i = neighbors.length - 1; i >= 0; i--) {
3607
+ const neighbor = neighbors[i];
3608
+ const nextDepth = depth + 1;
3609
+ if (depths === undefined) {
3610
+ if (!yielded.has(neighbor)) {
3611
+ stack.push([neighbor, nextDepth]);
3612
+ }
3613
+ continue;
3614
+ }
3615
+ const neighborDepth = depths.get(neighbor);
3616
+ if (neighborDepth === undefined || nextDepth < neighborDepth) {
3617
+ depths.set(neighbor, nextDepth);
3618
+ stack.push([neighbor, nextDepth]);
3619
+ }
3009
3620
  }
3010
3621
  }
3622
+ if (yielded.has(current)) {
3623
+ continue;
3624
+ }
3625
+ yielded.add(current);
3011
3626
  return {
3012
3627
  done: false,
3013
3628
  value: f(current, nodeDataOption.value)
@@ -3031,12 +3646,13 @@ export const dfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3031
3646
  * **Details**
3032
3647
  *
3033
3648
  * If no start nodes are supplied, the iterator is empty. The `direction` option
3034
- * chooses whether to follow outgoing or incoming edges. Throws a `GraphError`
3649
+ * chooses whether to follow outgoing or incoming edges. The `radius` option
3650
+ * limits traversal by edge distance from the start nodes. Throws a `GraphError`
3035
3651
  * if any configured start node does not exist.
3036
3652
  *
3037
3653
  * **Example** (Traversing breadth-first)
3038
3654
  *
3039
- * ```ts
3655
+ * ```ts import.meta.vitest
3040
3656
  * import { Graph } from "effect"
3041
3657
  *
3042
3658
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -3048,14 +3664,10 @@ export const dfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3048
3664
  * })
3049
3665
  *
3050
3666
  * // Start from a specific node
3051
- * const bfs1 = Graph.bfs(graph, { start: [0] })
3052
- * for (const nodeIndex of Graph.indices(bfs1)) {
3053
- * console.log(nodeIndex) // Traverses in BFS order: 0, 1, 2
3054
- * }
3667
+ * Array.from(Graph.indices(Graph.bfs(graph, { start: [0] }))) // => [0, 1, 2]
3055
3668
  *
3056
3669
  * // Empty iterator (no starting nodes)
3057
- * const bfs2 = Graph.bfs(graph)
3058
- * // Can be used programmatically
3670
+ * Graph.bfs(graph)
3059
3671
  * ```
3060
3672
  *
3061
3673
  * @category iterators
@@ -3064,6 +3676,7 @@ export const dfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3064
3676
  export const bfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config = {}) => {
3065
3677
  const start = config.start ?? [];
3066
3678
  const direction = config.direction ?? "outgoing";
3679
+ const radius = config.radius ?? Infinity;
3067
3680
  // Validate that all start nodes exist
3068
3681
  for (const nodeIndex of start) {
3069
3682
  if (!hasNode(graph, nodeIndex)) {
@@ -3072,17 +3685,19 @@ export const bfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3072
3685
  }
3073
3686
  return new Walker(f => ({
3074
3687
  [Symbol.iterator]: () => {
3075
- const queue = [...start];
3688
+ const queue = start.map(node => [node, 0]);
3076
3689
  const discovered = new Set();
3077
3690
  const nextMapped = () => {
3078
3691
  while (queue.length > 0) {
3079
- const current = queue.shift();
3692
+ const [current, depth] = queue.shift();
3080
3693
  if (!discovered.has(current)) {
3081
3694
  discovered.add(current);
3082
- const neighbors = getTraversalNeighbors(graph, current, direction);
3083
- for (const neighbor of neighbors) {
3084
- if (!discovered.has(neighbor)) {
3085
- queue.push(neighbor);
3695
+ if (depth < radius) {
3696
+ const neighbors = getTraversalNeighbors(graph, current, direction);
3697
+ for (const neighbor of neighbors) {
3698
+ if (!discovered.has(neighbor)) {
3699
+ queue.push([neighbor, depth + 1]);
3700
+ }
3086
3701
  }
3087
3702
  }
3088
3703
  const nodeData = getNode(graph, current);
@@ -3092,7 +3707,7 @@ export const bfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3092
3707
  value: f(current, nodeData.value)
3093
3708
  };
3094
3709
  }
3095
- return nextMapped();
3710
+ continue;
3096
3711
  }
3097
3712
  }
3098
3713
  return {
@@ -3116,7 +3731,7 @@ export const bfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3116
3731
  *
3117
3732
  * **Example** (Sorting topologically)
3118
3733
  *
3119
- * ```ts
3734
+ * ```ts import.meta.vitest
3120
3735
  * import { Graph } from "effect"
3121
3736
  *
3122
3737
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -3128,13 +3743,10 @@ export const bfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3128
3743
  * })
3129
3744
  *
3130
3745
  * // Standard topological sort
3131
- * const topo1 = Graph.topo(graph)
3132
- * for (const nodeIndex of Graph.indices(topo1)) {
3133
- * console.log(nodeIndex) // 0, 1, 2 (topological order)
3134
- * }
3746
+ * Array.from(Graph.indices(Graph.topo(graph))) // => [0, 1, 2]
3135
3747
  *
3136
3748
  * // With initial nodes
3137
- * const topo2 = Graph.topo(graph, { initials: [0] })
3749
+ * Graph.topo(graph, { initials: [0] })
3138
3750
  *
3139
3751
  * // Check before sorting a cyclic graph
3140
3752
  * const cyclicGraph = Graph.directed<string, number>((mutable) => {
@@ -3144,9 +3756,7 @@ export const bfs = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3144
3756
  * Graph.addEdge(mutable, b, a, 2) // Creates cycle
3145
3757
  * })
3146
3758
  *
3147
- * if (!Graph.isAcyclic(cyclicGraph)) {
3148
- * console.log("cyclic graph") // cyclic graph
3149
- * }
3759
+ * Graph.isAcyclic(cyclicGraph) // => false
3150
3760
  * ```
3151
3761
  *
3152
3762
  * @category iterators
@@ -3173,17 +3783,18 @@ export const topo = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3173
3783
  }
3174
3784
  return new Walker(f => ({
3175
3785
  [Symbol.iterator]: () => {
3786
+ const impl = graphImpl(graph);
3176
3787
  const inDegree = new Map();
3177
3788
  const remaining = new Set();
3178
3789
  const initialSet = new Set(initials);
3179
3790
  const queue = [...initials];
3180
3791
  // Initialize in-degree counts
3181
- for (const [nodeIndex] of graph.nodes) {
3792
+ for (const [nodeIndex] of impl.nodes) {
3182
3793
  inDegree.set(nodeIndex, 0);
3183
3794
  remaining.add(nodeIndex);
3184
3795
  }
3185
3796
  // Calculate in-degrees
3186
- for (const [, edgeData] of graph.edges) {
3797
+ for (const [, edgeData] of impl.edges) {
3187
3798
  const currentInDegree = inDegree.get(edgeData.target) || 0;
3188
3799
  inDegree.set(edgeData.target, currentInDegree + 1);
3189
3800
  }
@@ -3225,9 +3836,14 @@ export const topo = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3225
3836
  value: f(current, nodeData.value)
3226
3837
  };
3227
3838
  }
3228
- return nextMapped();
3839
+ continue;
3229
3840
  }
3230
3841
  }
3842
+ if (remaining.size > 0) {
3843
+ throw new GraphError({
3844
+ message: "Cannot perform topological sort on cyclic graph"
3845
+ });
3846
+ }
3231
3847
  return {
3232
3848
  done: true,
3233
3849
  value: undefined
@@ -3247,11 +3863,18 @@ export const topo = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3247
3863
  *
3248
3864
  * Nodes are emitted after their reachable descendants have been processed. If
3249
3865
  * no start nodes are supplied, the iterator is empty. The `direction` option
3250
- * chooses whether to follow outgoing or incoming edges.
3866
+ * chooses whether to follow outgoing or incoming edges. The `radius` option
3867
+ * limits traversal by edge distance from the start nodes.
3868
+ *
3869
+ * **Gotchas**
3870
+ *
3871
+ * With a finite `radius`, iteration first performs a bounded breadth-first
3872
+ * traversal to determine shortest-distance membership before emitting nodes in
3873
+ * postorder.
3251
3874
  *
3252
3875
  * **Example** (Traversing in postorder)
3253
3876
  *
3254
- * ```ts
3877
+ * ```ts import.meta.vitest
3255
3878
  * import { Graph } from "effect"
3256
3879
  *
3257
3880
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -3263,10 +3886,7 @@ export const topo = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3263
3886
  * })
3264
3887
  *
3265
3888
  * // Postorder: children before parents
3266
- * const postOrder = Graph.dfsPostOrder(graph, { start: [0] })
3267
- * for (const node of postOrder) {
3268
- * console.log(node) // 1, 2, 0
3269
- * }
3889
+ * Array.from(Graph.indices(Graph.dfsPostOrder(graph, { start: [0] }))) // => [1, 2, 0]
3270
3890
  * ```
3271
3891
  *
3272
3892
  * @category iterators
@@ -3275,6 +3895,7 @@ export const topo = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config =
3275
3895
  export const dfsPostOrder = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, config = {}) => {
3276
3896
  const start = config.start ?? [];
3277
3897
  const direction = config.direction ?? "outgoing";
3898
+ const radius = config.radius ?? Infinity;
3278
3899
  // Validate that all start nodes exist
3279
3900
  for (const nodeIndex of start) {
3280
3901
  if (!hasNode(graph, nodeIndex)) {
@@ -3283,6 +3904,11 @@ export const dfsPostOrder = /*#__PURE__*/dual(args => isGraph(args[0]), (graph,
3283
3904
  }
3284
3905
  return new Walker(f => ({
3285
3906
  [Symbol.iterator]: () => {
3907
+ const reached = radius === Infinity ? undefined : new Set(indices(bfs(graph, {
3908
+ start,
3909
+ direction,
3910
+ radius
3911
+ })));
3286
3912
  const stack = [];
3287
3913
  const discovered = new Set();
3288
3914
  const finished = new Set();
@@ -3305,7 +3931,7 @@ export const dfsPostOrder = /*#__PURE__*/dual(args => isGraph(args[0]), (graph,
3305
3931
  const neighbors = getTraversalNeighbors(graph, current.node, direction);
3306
3932
  for (let i = neighbors.length - 1; i >= 0; i--) {
3307
3933
  const neighbor = neighbors[i];
3308
- if (!discovered.has(neighbor) && !finished.has(neighbor)) {
3934
+ if ((reached === undefined || reached.has(neighbor)) && !discovered.has(neighbor) && !finished.has(neighbor)) {
3309
3935
  stack.push({
3310
3936
  node: neighbor,
3311
3937
  visitedChildren: false
@@ -3323,7 +3949,7 @@ export const dfsPostOrder = /*#__PURE__*/dual(args => isGraph(args[0]), (graph,
3323
3949
  value: f(nodeToEmit, nodeData.value)
3324
3950
  };
3325
3951
  }
3326
- return nextMapped();
3952
+ continue;
3327
3953
  }
3328
3954
  }
3329
3955
  }
@@ -3348,7 +3974,7 @@ export const dfsPostOrder = /*#__PURE__*/dual(args => isGraph(args[0]), (graph,
3348
3974
  *
3349
3975
  * **Example** (Iterating all nodes)
3350
3976
  *
3351
- * ```ts
3977
+ * ```ts import.meta.vitest
3352
3978
  * import { Graph } from "effect"
3353
3979
  *
3354
3980
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -3358,8 +3984,7 @@ export const dfsPostOrder = /*#__PURE__*/dual(args => isGraph(args[0]), (graph,
3358
3984
  * Graph.addEdge(mutable, a, b, 1)
3359
3985
  * })
3360
3986
  *
3361
- * const indices = Array.from(Graph.indices(Graph.nodes(graph)))
3362
- * console.log(indices) // [0, 1, 2]
3987
+ * Array.from(Graph.indices(Graph.nodes(graph))) // => [0, 1, 2]
3363
3988
  * ```
3364
3989
  *
3365
3990
  * @category iterators
@@ -3367,7 +3992,7 @@ export const dfsPostOrder = /*#__PURE__*/dual(args => isGraph(args[0]), (graph,
3367
3992
  */
3368
3993
  export const nodes = graph => new Walker(f => ({
3369
3994
  [Symbol.iterator]() {
3370
- const nodeMap = graph.nodes;
3995
+ const nodeMap = graphImpl(graph).nodes;
3371
3996
  const iterator = nodeMap.entries();
3372
3997
  return {
3373
3998
  next() {
@@ -3397,7 +4022,7 @@ export const nodes = graph => new Walker(f => ({
3397
4022
  *
3398
4023
  * **Example** (Iterating all edges)
3399
4024
  *
3400
- * ```ts
4025
+ * ```ts import.meta.vitest
3401
4026
  * import { Graph } from "effect"
3402
4027
  *
3403
4028
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -3408,8 +4033,7 @@ export const nodes = graph => new Walker(f => ({
3408
4033
  * Graph.addEdge(mutable, b, c, 2)
3409
4034
  * })
3410
4035
  *
3411
- * const indices = Array.from(Graph.indices(Graph.edges(graph)))
3412
- * console.log(indices) // [0, 1]
4036
+ * Array.from(Graph.indices(Graph.edges(graph))) // => [0, 1]
3413
4037
  * ```
3414
4038
  *
3415
4039
  * @category iterators
@@ -3417,7 +4041,7 @@ export const nodes = graph => new Walker(f => ({
3417
4041
  */
3418
4042
  export const edges = graph => new Walker(f => ({
3419
4043
  [Symbol.iterator]() {
3420
- const edgeMap = graph.edges;
4044
+ const edgeMap = graphImpl(graph).edges;
3421
4045
  const iterator = edgeMap.entries();
3422
4046
  return {
3423
4047
  next() {
@@ -3448,7 +4072,7 @@ export const edges = graph => new Walker(f => ({
3448
4072
  *
3449
4073
  * **Example** (Iterating external nodes)
3450
4074
  *
3451
- * ```ts
4075
+ * ```ts import.meta.vitest
3452
4076
  * import { Graph } from "effect"
3453
4077
  *
3454
4078
  * const graph = Graph.directed<string, number>((mutable) => {
@@ -3462,16 +4086,10 @@ export const edges = graph => new Walker(f => ({
3462
4086
  * })
3463
4087
  *
3464
4088
  * // Nodes with no outgoing edges (sinks + isolated)
3465
- * const sinks = Array.from(
3466
- * Graph.indices(Graph.externals(graph, { direction: "outgoing" }))
3467
- * )
3468
- * console.log(sinks) // [2, 3]
4089
+ * Array.from(Graph.indices(Graph.externals(graph, { direction: "outgoing" }))) // => [2, 3]
3469
4090
  *
3470
4091
  * // Nodes with no incoming edges (sources + isolated)
3471
- * const sources = Array.from(
3472
- * Graph.indices(Graph.externals(graph, { direction: "incoming" }))
3473
- * )
3474
- * console.log(sources) // [0, 3]
4092
+ * Array.from(Graph.indices(Graph.externals(graph, { direction: "incoming" }))) // => [0, 3]
3475
4093
  * ```
3476
4094
  *
3477
4095
  * @category iterators
@@ -3481,8 +4099,9 @@ export const externals = /*#__PURE__*/dual(args => isGraph(args[0]), (graph, con
3481
4099
  const direction = config.direction ?? "outgoing";
3482
4100
  return new Walker(f => ({
3483
4101
  [Symbol.iterator]: () => {
3484
- const nodeMap = graph.nodes;
3485
- const adjacencyMap = direction === "incoming" ? graph.reverseAdjacency : graph.adjacency;
4102
+ const impl = graphImpl(graph);
4103
+ const nodeMap = impl.nodes;
4104
+ const adjacencyMap = direction === "incoming" ? impl.reverseAdjacency : impl.adjacency;
3486
4105
  const nodeIterator = nodeMap.entries();
3487
4106
  const nextMapped = () => {
3488
4107
  let current = nodeIterator.next();