effect 4.0.0-rc.112 → 4.0.0-rc.113

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 (1229) hide show
  1. package/AGENTS.md +24 -9
  2. package/CLAUDE.md +24 -9
  3. package/ai-docs/package.json +2 -2
  4. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +18 -5
  5. package/ai-docs/src/01_effect/01_basics/index.md +5 -3
  6. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +1 -1
  7. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +2 -2
  8. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +2 -2
  9. package/ai-docs/src/03_stream/30_encoding.ts +5 -7
  10. package/ai-docs/src/08_observability/10_logging.ts +1 -1
  11. package/ai-docs/src/70_cli/10_basics.ts +7 -7
  12. package/ai-docs/src/71_ai/10_language-model.ts +2 -2
  13. package/ai-docs/src/71_ai/20_tools.ts +1 -1
  14. package/ai-docs/src/71_ai/30_chat.ts +1 -1
  15. package/dist/Array.d.ts +86 -50
  16. package/dist/Array.d.ts.map +1 -1
  17. package/dist/Array.js +58 -32
  18. package/dist/Array.js.map +1 -1
  19. package/dist/BigDecimal.d.ts +5 -1
  20. package/dist/BigDecimal.d.ts.map +1 -1
  21. package/dist/BigDecimal.js +40 -23
  22. package/dist/BigDecimal.js.map +1 -1
  23. package/dist/ByteSize.d.ts +633 -0
  24. package/dist/ByteSize.d.ts.map +1 -0
  25. package/dist/ByteSize.js +524 -0
  26. package/dist/ByteSize.js.map +1 -0
  27. package/dist/Cache.d.ts.map +1 -1
  28. package/dist/Cache.js +17 -3
  29. package/dist/Cache.js.map +1 -1
  30. package/dist/Cause.d.ts +1 -1
  31. package/dist/Cause.d.ts.map +1 -1
  32. package/dist/Channel.d.ts +97 -24
  33. package/dist/Channel.d.ts.map +1 -1
  34. package/dist/Channel.js +66 -39
  35. package/dist/Channel.js.map +1 -1
  36. package/dist/Chunk.d.ts +49 -28
  37. package/dist/Chunk.d.ts.map +1 -1
  38. package/dist/Chunk.js +27 -18
  39. package/dist/Chunk.js.map +1 -1
  40. package/dist/Config.d.ts +162 -201
  41. package/dist/Config.d.ts.map +1 -1
  42. package/dist/Config.js +103 -212
  43. package/dist/Config.js.map +1 -1
  44. package/dist/ConfigProvider.d.ts +4 -4
  45. package/dist/ConfigProvider.d.ts.map +1 -1
  46. package/dist/ConfigProvider.js +7 -7
  47. package/dist/ConfigProvider.js.map +1 -1
  48. package/dist/Context.d.ts +31 -0
  49. package/dist/Context.d.ts.map +1 -1
  50. package/dist/Context.js.map +1 -1
  51. package/dist/Cron.d.ts +2 -2
  52. package/dist/Cron.d.ts.map +1 -1
  53. package/dist/Cron.js +2 -2
  54. package/dist/Cron.js.map +1 -1
  55. package/dist/Crypto.d.ts +1 -1
  56. package/dist/Crypto.d.ts.map +1 -1
  57. package/dist/Crypto.js +3 -2
  58. package/dist/Crypto.js.map +1 -1
  59. package/dist/DateTime.d.ts +2 -2
  60. package/dist/DateTime.d.ts.map +1 -1
  61. package/dist/Deferred.d.ts.map +1 -1
  62. package/dist/Deferred.js +6 -6
  63. package/dist/Deferred.js.map +1 -1
  64. package/dist/Duration.d.ts +1 -1
  65. package/dist/Duration.d.ts.map +1 -1
  66. package/dist/Duration.js +1 -1
  67. package/dist/Duration.js.map +1 -1
  68. package/dist/Effect.d.ts +220 -113
  69. package/dist/Effect.d.ts.map +1 -1
  70. package/dist/Effect.js +27 -26
  71. package/dist/Effect.js.map +1 -1
  72. package/dist/Effectable.d.ts +58 -2
  73. package/dist/Effectable.d.ts.map +1 -1
  74. package/dist/Effectable.js +58 -6
  75. package/dist/Effectable.js.map +1 -1
  76. package/dist/Encoding.d.ts +3 -1
  77. package/dist/Encoding.d.ts.map +1 -1
  78. package/dist/Encoding.js +40 -10
  79. package/dist/Encoding.js.map +1 -1
  80. package/dist/Equal.d.ts +1 -1
  81. package/dist/Equal.d.ts.map +1 -1
  82. package/dist/Equal.js +1 -1
  83. package/dist/Equal.js.map +1 -1
  84. package/dist/ExecutionPlan.d.ts.map +1 -1
  85. package/dist/ExecutionPlan.js +1 -0
  86. package/dist/ExecutionPlan.js.map +1 -1
  87. package/dist/Fiber.d.ts +32 -8
  88. package/dist/Fiber.d.ts.map +1 -1
  89. package/dist/Fiber.js.map +1 -1
  90. package/dist/FiberHandle.js +3 -3
  91. package/dist/FiberHandle.js.map +1 -1
  92. package/dist/FiberMap.d.ts +12 -6
  93. package/dist/FiberMap.d.ts.map +1 -1
  94. package/dist/FiberMap.js +11 -6
  95. package/dist/FiberMap.js.map +1 -1
  96. package/dist/FileSystem.d.ts +42 -210
  97. package/dist/FileSystem.d.ts.map +1 -1
  98. package/dist/FileSystem.js +16 -148
  99. package/dist/FileSystem.js.map +1 -1
  100. package/dist/Formatter.d.ts +1 -0
  101. package/dist/Formatter.d.ts.map +1 -1
  102. package/dist/Formatter.js +19 -3
  103. package/dist/Formatter.js.map +1 -1
  104. package/dist/Graph.d.ts +48 -20
  105. package/dist/Graph.d.ts.map +1 -1
  106. package/dist/Graph.js +20 -5
  107. package/dist/Graph.js.map +1 -1
  108. package/dist/Hash.d.ts +1 -1
  109. package/dist/Hash.d.ts.map +1 -1
  110. package/dist/Hash.js +5 -14
  111. package/dist/Hash.js.map +1 -1
  112. package/dist/HashMap.d.ts +1 -1
  113. package/dist/HashMap.d.ts.map +1 -1
  114. package/dist/HashRing.d.ts +6 -1
  115. package/dist/HashRing.d.ts.map +1 -1
  116. package/dist/HashRing.js +9 -2
  117. package/dist/HashRing.js.map +1 -1
  118. package/dist/HashSet.d.ts +1 -1
  119. package/dist/HashSet.d.ts.map +1 -1
  120. package/dist/HashSet.js.map +1 -1
  121. package/dist/Iterable.d.ts +33 -15
  122. package/dist/Iterable.d.ts.map +1 -1
  123. package/dist/Iterable.js +58 -45
  124. package/dist/Iterable.js.map +1 -1
  125. package/dist/JsonPatch.js +4 -4
  126. package/dist/JsonPatch.js.map +1 -1
  127. package/dist/JsonPointer.d.ts +68 -4
  128. package/dist/JsonPointer.d.ts.map +1 -1
  129. package/dist/JsonPointer.js +90 -4
  130. package/dist/JsonPointer.js.map +1 -1
  131. package/dist/JsonSchema.js +8 -22
  132. package/dist/JsonSchema.js.map +1 -1
  133. package/dist/Layer.d.ts +47 -4
  134. package/dist/Layer.d.ts.map +1 -1
  135. package/dist/Layer.js +4 -6
  136. package/dist/Layer.js.map +1 -1
  137. package/dist/LayerMap.d.ts +1 -3
  138. package/dist/LayerMap.d.ts.map +1 -1
  139. package/dist/LayerMap.js +7 -5
  140. package/dist/LayerMap.js.map +1 -1
  141. package/dist/LayerRef.d.ts.map +1 -1
  142. package/dist/LayerRef.js +7 -5
  143. package/dist/LayerRef.js.map +1 -1
  144. package/dist/Logger.d.ts +114 -9
  145. package/dist/Logger.d.ts.map +1 -1
  146. package/dist/Logger.js +109 -9
  147. package/dist/Logger.js.map +1 -1
  148. package/dist/ManagedRuntime.js +1 -1
  149. package/dist/ManagedRuntime.js.map +1 -1
  150. package/dist/Match.d.ts +43 -31
  151. package/dist/Match.d.ts.map +1 -1
  152. package/dist/Match.js +5 -2
  153. package/dist/Match.js.map +1 -1
  154. package/dist/Metric.d.ts +11 -4
  155. package/dist/Metric.d.ts.map +1 -1
  156. package/dist/Metric.js +14 -18
  157. package/dist/Metric.js.map +1 -1
  158. package/dist/MutableHashMap.d.ts +1 -1
  159. package/dist/MutableHashMap.d.ts.map +1 -1
  160. package/dist/MutableHashMap.js +1 -1
  161. package/dist/MutableHashMap.js.map +1 -1
  162. package/dist/MutableHashSet.d.ts +1 -1
  163. package/dist/MutableHashSet.d.ts.map +1 -1
  164. package/dist/MutableHashSet.js +1 -1
  165. package/dist/MutableHashSet.js.map +1 -1
  166. package/dist/MutableList.d.ts +13 -2
  167. package/dist/MutableList.d.ts.map +1 -1
  168. package/dist/MutableList.js +18 -2
  169. package/dist/MutableList.js.map +1 -1
  170. package/dist/Number.d.ts +6 -0
  171. package/dist/Number.d.ts.map +1 -1
  172. package/dist/Number.js +3 -1
  173. package/dist/Number.js.map +1 -1
  174. package/dist/Optic.d.ts.map +1 -1
  175. package/dist/Optic.js +5 -4
  176. package/dist/Optic.js.map +1 -1
  177. package/dist/Option.d.ts +1 -1
  178. package/dist/Option.d.ts.map +1 -1
  179. package/dist/Option.js +1 -1
  180. package/dist/Option.js.map +1 -1
  181. package/dist/Order.d.ts +1 -0
  182. package/dist/Order.d.ts.map +1 -1
  183. package/dist/Order.js +3 -1
  184. package/dist/Order.js.map +1 -1
  185. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  186. package/dist/PartitionedSemaphore.js +1 -2
  187. package/dist/PartitionedSemaphore.js.map +1 -1
  188. package/dist/Path.d.ts +1 -1
  189. package/dist/Path.d.ts.map +1 -1
  190. package/dist/Path.js +1 -1
  191. package/dist/Path.js.map +1 -1
  192. package/dist/PlatformError.d.ts +1 -1
  193. package/dist/PlatformError.d.ts.map +1 -1
  194. package/dist/PlatformError.js +1 -1
  195. package/dist/PlatformError.js.map +1 -1
  196. package/dist/Pool.d.ts +38 -1
  197. package/dist/Pool.d.ts.map +1 -1
  198. package/dist/Pool.js +81 -5
  199. package/dist/Pool.js.map +1 -1
  200. package/dist/PrimaryKey.d.ts +1 -1
  201. package/dist/PrimaryKey.d.ts.map +1 -1
  202. package/dist/PrimaryKey.js +1 -1
  203. package/dist/PrimaryKey.js.map +1 -1
  204. package/dist/PubSub.d.ts +21 -9
  205. package/dist/PubSub.d.ts.map +1 -1
  206. package/dist/PubSub.js +18 -14
  207. package/dist/PubSub.js.map +1 -1
  208. package/dist/Queue.d.ts +82 -6
  209. package/dist/Queue.d.ts.map +1 -1
  210. package/dist/Queue.js +116 -27
  211. package/dist/Queue.js.map +1 -1
  212. package/dist/Random.d.ts +17 -4
  213. package/dist/Random.d.ts.map +1 -1
  214. package/dist/Random.js +1 -1
  215. package/dist/Random.js.map +1 -1
  216. package/dist/RcMap.d.ts.map +1 -1
  217. package/dist/RcMap.js +15 -9
  218. package/dist/RcMap.js.map +1 -1
  219. package/dist/Redacted.d.ts +1 -1
  220. package/dist/Redacted.d.ts.map +1 -1
  221. package/dist/Redacted.js +1 -1
  222. package/dist/Redacted.js.map +1 -1
  223. package/dist/RequestResolver.d.ts +15 -9
  224. package/dist/RequestResolver.d.ts.map +1 -1
  225. package/dist/RequestResolver.js +33 -15
  226. package/dist/RequestResolver.js.map +1 -1
  227. package/dist/Result.d.ts +1 -1
  228. package/dist/Result.d.ts.map +1 -1
  229. package/dist/Result.js +1 -1
  230. package/dist/Result.js.map +1 -1
  231. package/dist/Scheduler.d.ts.map +1 -1
  232. package/dist/Scheduler.js +19 -10
  233. package/dist/Scheduler.js.map +1 -1
  234. package/dist/Schema.d.ts +2155 -2415
  235. package/dist/Schema.d.ts.map +1 -1
  236. package/dist/Schema.js +2755 -4174
  237. package/dist/Schema.js.map +1 -1
  238. package/dist/SchemaAST.d.ts +354 -183
  239. package/dist/SchemaAST.d.ts.map +1 -1
  240. package/dist/SchemaAST.js +277 -601
  241. package/dist/SchemaAST.js.map +1 -1
  242. package/dist/SchemaGetter.d.ts +46 -22
  243. package/dist/SchemaGetter.d.ts.map +1 -1
  244. package/dist/SchemaGetter.js +56 -53
  245. package/dist/SchemaGetter.js.map +1 -1
  246. package/dist/SchemaIssue.d.ts +122 -188
  247. package/dist/SchemaIssue.d.ts.map +1 -1
  248. package/dist/SchemaIssue.js +48 -263
  249. package/dist/SchemaIssue.js.map +1 -1
  250. package/dist/SchemaParser.js +2 -9
  251. package/dist/SchemaParser.js.map +1 -1
  252. package/dist/SchemaRepresentation.d.ts +1099 -16
  253. package/dist/SchemaRepresentation.d.ts.map +1 -1
  254. package/dist/SchemaRepresentation.js +1341 -20
  255. package/dist/SchemaRepresentation.js.map +1 -1
  256. package/dist/SchemaTransformation.d.ts +49 -16
  257. package/dist/SchemaTransformation.d.ts.map +1 -1
  258. package/dist/SchemaTransformation.js +75 -98
  259. package/dist/SchemaTransformation.js.map +1 -1
  260. package/dist/ScopedCache.d.ts.map +1 -1
  261. package/dist/ScopedCache.js +10 -3
  262. package/dist/ScopedCache.js.map +1 -1
  263. package/dist/Sink.d.ts +9 -4
  264. package/dist/Sink.d.ts.map +1 -1
  265. package/dist/Sink.js +49 -31
  266. package/dist/Sink.js.map +1 -1
  267. package/dist/Stream.d.ts +221 -35
  268. package/dist/Stream.d.ts.map +1 -1
  269. package/dist/Stream.js +168 -84
  270. package/dist/Stream.js.map +1 -1
  271. package/dist/String.d.ts +16 -6
  272. package/dist/String.d.ts.map +1 -1
  273. package/dist/String.js +12 -5
  274. package/dist/String.js.map +1 -1
  275. package/dist/Struct.d.ts.map +1 -1
  276. package/dist/Struct.js +7 -4
  277. package/dist/Struct.js.map +1 -1
  278. package/dist/SynchronizedRef.d.ts +3 -2
  279. package/dist/SynchronizedRef.d.ts.map +1 -1
  280. package/dist/SynchronizedRef.js.map +1 -1
  281. package/dist/Terminal.d.ts +3 -3
  282. package/dist/Terminal.d.ts.map +1 -1
  283. package/dist/Terminal.js +3 -3
  284. package/dist/Terminal.js.map +1 -1
  285. package/dist/Tracer.d.ts +27 -7
  286. package/dist/Tracer.d.ts.map +1 -1
  287. package/dist/Tracer.js +38 -13
  288. package/dist/Tracer.js.map +1 -1
  289. package/dist/Trie.d.ts +1 -1
  290. package/dist/Trie.d.ts.map +1 -1
  291. package/dist/Tuple.d.ts +2 -1
  292. package/dist/Tuple.d.ts.map +1 -1
  293. package/dist/Tuple.js.map +1 -1
  294. package/dist/TxChunk.d.ts +1 -1
  295. package/dist/TxChunk.d.ts.map +1 -1
  296. package/dist/TxChunk.js +1 -1
  297. package/dist/TxChunk.js.map +1 -1
  298. package/dist/TxDeferred.d.ts +1 -1
  299. package/dist/TxDeferred.d.ts.map +1 -1
  300. package/dist/TxDeferred.js +1 -1
  301. package/dist/TxDeferred.js.map +1 -1
  302. package/dist/TxHashMap.d.ts +1 -1
  303. package/dist/TxHashMap.d.ts.map +1 -1
  304. package/dist/TxHashMap.js +1 -1
  305. package/dist/TxHashMap.js.map +1 -1
  306. package/dist/TxHashSet.d.ts +1 -1
  307. package/dist/TxHashSet.d.ts.map +1 -1
  308. package/dist/TxHashSet.js +1 -1
  309. package/dist/TxHashSet.js.map +1 -1
  310. package/dist/TxPriorityQueue.d.ts +1 -1
  311. package/dist/TxPriorityQueue.d.ts.map +1 -1
  312. package/dist/TxPriorityQueue.js +1 -1
  313. package/dist/TxPriorityQueue.js.map +1 -1
  314. package/dist/TxPubSub.d.ts +1 -1
  315. package/dist/TxPubSub.d.ts.map +1 -1
  316. package/dist/TxPubSub.js +1 -1
  317. package/dist/TxPubSub.js.map +1 -1
  318. package/dist/TxQueue.d.ts +9 -9
  319. package/dist/TxQueue.d.ts.map +1 -1
  320. package/dist/TxQueue.js +93 -86
  321. package/dist/TxQueue.js.map +1 -1
  322. package/dist/TxReentrantLock.d.ts +29 -1
  323. package/dist/TxReentrantLock.d.ts.map +1 -1
  324. package/dist/TxReentrantLock.js +29 -1
  325. package/dist/TxReentrantLock.js.map +1 -1
  326. package/dist/TxRef.d.ts +1 -1
  327. package/dist/TxRef.d.ts.map +1 -1
  328. package/dist/TxRef.js +1 -1
  329. package/dist/TxRef.js.map +1 -1
  330. package/dist/TxSemaphore.d.ts +1 -1
  331. package/dist/TxSemaphore.d.ts.map +1 -1
  332. package/dist/TxSemaphore.js +1 -1
  333. package/dist/TxSemaphore.js.map +1 -1
  334. package/dist/TxSubscriptionRef.d.ts +1 -1
  335. package/dist/TxSubscriptionRef.d.ts.map +1 -1
  336. package/dist/TxSubscriptionRef.js +1 -1
  337. package/dist/TxSubscriptionRef.js.map +1 -1
  338. package/dist/Types.d.ts +33 -19
  339. package/dist/Types.d.ts.map +1 -1
  340. package/dist/Utils.d.ts.map +1 -1
  341. package/dist/Utils.js +2 -1
  342. package/dist/Utils.js.map +1 -1
  343. package/dist/index.d.ts +4 -0
  344. package/dist/index.d.ts.map +1 -1
  345. package/dist/index.js +4 -0
  346. package/dist/index.js.map +1 -1
  347. package/dist/internal/arbitrary/model.d.ts +2 -0
  348. package/dist/internal/arbitrary/model.d.ts.map +1 -0
  349. package/dist/internal/arbitrary/model.js +495 -0
  350. package/dist/internal/arbitrary/model.js.map +1 -0
  351. package/dist/internal/arbitrary/regexp.d.ts +2 -0
  352. package/dist/internal/arbitrary/regexp.d.ts.map +1 -0
  353. package/dist/internal/arbitrary/regexp.js +789 -0
  354. package/dist/internal/arbitrary/regexp.js.map +1 -0
  355. package/dist/internal/arbitrary/runner.d.ts +2 -0
  356. package/dist/internal/arbitrary/runner.d.ts.map +1 -0
  357. package/dist/internal/arbitrary/runner.js +496 -0
  358. package/dist/internal/arbitrary/runner.js.map +1 -0
  359. package/dist/internal/arbitrary/schema.d.ts.map +1 -0
  360. package/dist/internal/arbitrary/schema.js +1340 -0
  361. package/dist/internal/arbitrary/schema.js.map +1 -0
  362. package/dist/internal/core.js +27 -13
  363. package/dist/internal/core.js.map +1 -1
  364. package/dist/internal/count.d.ts +2 -0
  365. package/dist/internal/count.d.ts.map +1 -0
  366. package/dist/internal/count.js +14 -0
  367. package/dist/internal/count.js.map +1 -0
  368. package/dist/internal/dateTime.js +4 -10
  369. package/dist/internal/dateTime.js.map +1 -1
  370. package/dist/internal/effect.js +386 -251
  371. package/dist/internal/effect.js.map +1 -1
  372. package/dist/internal/graph.js +3 -1
  373. package/dist/internal/graph.js.map +1 -1
  374. package/dist/internal/hashMap.js +5 -3
  375. package/dist/internal/hashMap.js.map +1 -1
  376. package/dist/internal/hashSet.js +1 -1
  377. package/dist/internal/hashSet.js.map +1 -1
  378. package/dist/internal/matcher.js +1 -1
  379. package/dist/internal/matcher.js.map +1 -1
  380. package/dist/internal/metric.js +1 -1
  381. package/dist/internal/metric.js.map +1 -1
  382. package/dist/internal/option.js +6 -5
  383. package/dist/internal/option.js.map +1 -1
  384. package/dist/internal/random.js +17 -0
  385. package/dist/internal/random.js.map +1 -1
  386. package/dist/internal/rcRef.js +10 -7
  387. package/dist/internal/rcRef.js.map +1 -1
  388. package/dist/internal/references.js +1 -0
  389. package/dist/internal/references.js.map +1 -1
  390. package/dist/internal/request.js +13 -6
  391. package/dist/internal/request.js.map +1 -1
  392. package/dist/internal/result.js +11 -9
  393. package/dist/internal/result.js.map +1 -1
  394. package/dist/internal/schema/annotations.js +1 -1
  395. package/dist/internal/schema/annotations.js.map +1 -1
  396. package/dist/internal/schema/fromJsonSchemaDocument.js +14 -12
  397. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  398. package/dist/internal/schema/fromRepresentation.js +5 -5
  399. package/dist/internal/schema/fromRepresentation.js.map +1 -1
  400. package/dist/internal/schema/make.d.ts +2 -0
  401. package/dist/internal/schema/make.d.ts.map +1 -0
  402. package/dist/internal/schema/{schema.js → make.js} +1 -25
  403. package/dist/internal/schema/make.js.map +1 -0
  404. package/dist/internal/schema/parser.d.ts +0 -12
  405. package/dist/internal/schema/parser.d.ts.map +1 -1
  406. package/dist/internal/schema/parser.js +7 -0
  407. package/dist/internal/schema/parser.js.map +1 -1
  408. package/dist/internal/schema/standardSchema.d.ts +2 -0
  409. package/dist/internal/schema/standardSchema.d.ts.map +1 -0
  410. package/dist/internal/schema/standardSchema.js +112 -0
  411. package/dist/internal/schema/standardSchema.js.map +1 -0
  412. package/dist/internal/schema/toCodeDocument.js +34 -22
  413. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  414. package/dist/internal/schema/toCodec.d.ts +2 -0
  415. package/dist/internal/schema/toCodec.d.ts.map +1 -0
  416. package/dist/internal/schema/toCodec.js +242 -0
  417. package/dist/internal/schema/toCodec.js.map +1 -0
  418. package/dist/internal/schema/toDifferJsonPatch.d.ts +2 -0
  419. package/dist/internal/schema/toDifferJsonPatch.d.ts.map +1 -0
  420. package/dist/internal/schema/toDifferJsonPatch.js +20 -0
  421. package/dist/internal/schema/toDifferJsonPatch.js.map +1 -0
  422. package/dist/internal/schema/toEncoderXml.d.ts +2 -0
  423. package/dist/internal/schema/toEncoderXml.d.ts.map +1 -0
  424. package/dist/internal/schema/toEncoderXml.js +104 -0
  425. package/dist/internal/schema/toEncoderXml.js.map +1 -0
  426. package/dist/internal/schema/toEquivalence.js +66 -0
  427. package/dist/internal/schema/toEquivalence.js.map +1 -1
  428. package/dist/internal/schema/toFormatter.d.ts +2 -0
  429. package/dist/internal/schema/toFormatter.d.ts.map +1 -0
  430. package/dist/internal/schema/toFormatter.js +227 -0
  431. package/dist/internal/schema/toFormatter.js.map +1 -0
  432. package/dist/internal/schema/toIso.d.ts +2 -0
  433. package/dist/internal/schema/toIso.d.ts.map +1 -0
  434. package/dist/internal/schema/toIso.js +17 -0
  435. package/dist/internal/schema/toIso.js.map +1 -0
  436. package/dist/internal/schema/toJsonSchemaDocument.js +122 -71
  437. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  438. package/dist/internal/schema/toRepresentation.js +3 -1
  439. package/dist/internal/schema/toRepresentation.js.map +1 -1
  440. package/dist/internal/schemaError.d.ts +4 -0
  441. package/dist/internal/schemaError.d.ts.map +1 -0
  442. package/dist/internal/schemaError.js +6 -0
  443. package/dist/internal/schemaError.js.map +1 -0
  444. package/dist/internal/stream.js +5 -6
  445. package/dist/internal/stream.js.map +1 -1
  446. package/dist/internal/tracer.d.ts +1 -3
  447. package/dist/internal/tracer.d.ts.map +1 -1
  448. package/dist/internal/tracer.js +6 -0
  449. package/dist/internal/tracer.js.map +1 -1
  450. package/dist/internal/trie.js +2 -2
  451. package/dist/internal/trie.js.map +1 -1
  452. package/dist/internal/uuid.d.ts +1 -2
  453. package/dist/internal/uuid.d.ts.map +1 -1
  454. package/dist/internal/uuid.js +2 -0
  455. package/dist/internal/uuid.js.map +1 -1
  456. package/dist/testing/TestSchema.d.ts +9 -11
  457. package/dist/testing/TestSchema.d.ts.map +1 -1
  458. package/dist/testing/TestSchema.js +20 -18
  459. package/dist/testing/TestSchema.js.map +1 -1
  460. package/dist/testing/index.d.ts +0 -4
  461. package/dist/testing/index.d.ts.map +1 -1
  462. package/dist/testing/index.js +0 -4
  463. package/dist/testing/index.js.map +1 -1
  464. package/dist/unstable/ai/AiError.d.ts +74 -23
  465. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  466. package/dist/unstable/ai/AiError.js +59 -5
  467. package/dist/unstable/ai/AiError.js.map +1 -1
  468. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  469. package/dist/unstable/ai/AnthropicStructuredOutput.js +2 -1
  470. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  471. package/dist/unstable/ai/Chat.d.ts +27 -32
  472. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  473. package/dist/unstable/ai/Chat.js +10 -13
  474. package/dist/unstable/ai/Chat.js.map +1 -1
  475. package/dist/unstable/ai/EmbeddingModel.d.ts +23 -16
  476. package/dist/unstable/ai/EmbeddingModel.d.ts.map +1 -1
  477. package/dist/unstable/ai/EmbeddingModel.js +13 -11
  478. package/dist/unstable/ai/EmbeddingModel.js.map +1 -1
  479. package/dist/unstable/ai/LanguageModel.d.ts +48 -37
  480. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  481. package/dist/unstable/ai/LanguageModel.js +150 -47
  482. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  483. package/dist/unstable/ai/McpServer.d.ts +2 -2
  484. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  485. package/dist/unstable/ai/McpServer.js +21 -12
  486. package/dist/unstable/ai/McpServer.js.map +1 -1
  487. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  488. package/dist/unstable/ai/OpenAiStructuredOutput.js +2 -1
  489. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  490. package/dist/unstable/ai/Prompt.d.ts +1 -1
  491. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  492. package/dist/unstable/ai/Prompt.js +15 -4
  493. package/dist/unstable/ai/Prompt.js.map +1 -1
  494. package/dist/unstable/ai/Response.d.ts +37 -94
  495. package/dist/unstable/ai/Response.d.ts.map +1 -1
  496. package/dist/unstable/ai/Response.js +46 -96
  497. package/dist/unstable/ai/Response.js.map +1 -1
  498. package/dist/unstable/ai/Tokenizer.js +4 -5
  499. package/dist/unstable/ai/Tokenizer.js.map +1 -1
  500. package/dist/unstable/ai/Tool.d.ts +38 -20
  501. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  502. package/dist/unstable/ai/Tool.js +27 -1
  503. package/dist/unstable/ai/Tool.js.map +1 -1
  504. package/dist/unstable/ai/Toolkit.d.ts +1 -1
  505. package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
  506. package/dist/unstable/ai/Toolkit.js +30 -18
  507. package/dist/unstable/ai/Toolkit.js.map +1 -1
  508. package/dist/unstable/ai/internal/structured-output.js +8 -5
  509. package/dist/unstable/ai/internal/structured-output.js.map +1 -1
  510. package/dist/unstable/arbitrary/Arbitrary.d.ts +626 -0
  511. package/dist/unstable/arbitrary/Arbitrary.d.ts.map +1 -0
  512. package/dist/unstable/arbitrary/Arbitrary.js +238 -0
  513. package/dist/unstable/arbitrary/Arbitrary.js.map +1 -0
  514. package/dist/unstable/arbitrary/index.d.ts +8 -0
  515. package/dist/unstable/arbitrary/index.d.ts.map +1 -0
  516. package/dist/unstable/arbitrary/index.js +9 -0
  517. package/dist/unstable/arbitrary/index.js.map +1 -0
  518. package/dist/unstable/cli/Argument.d.ts +104 -108
  519. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  520. package/dist/unstable/cli/Argument.js +56 -57
  521. package/dist/unstable/cli/Argument.js.map +1 -1
  522. package/dist/unstable/cli/CliError.d.ts +2 -0
  523. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  524. package/dist/unstable/cli/CliError.js +2 -0
  525. package/dist/unstable/cli/CliError.js.map +1 -1
  526. package/dist/unstable/cli/CliOutput.js +26 -3
  527. package/dist/unstable/cli/CliOutput.js.map +1 -1
  528. package/dist/unstable/cli/Command.d.ts +73 -73
  529. package/dist/unstable/cli/Command.js +18 -18
  530. package/dist/unstable/cli/Completions.d.ts +4 -4
  531. package/dist/unstable/cli/Completions.d.ts.map +1 -1
  532. package/dist/unstable/cli/Flag.d.ts +150 -161
  533. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  534. package/dist/unstable/cli/Flag.js +79 -90
  535. package/dist/unstable/cli/Flag.js.map +1 -1
  536. package/dist/unstable/cli/GlobalFlag.d.ts +3 -3
  537. package/dist/unstable/cli/GlobalFlag.js +13 -13
  538. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  539. package/dist/unstable/cli/Param.d.ts +118 -126
  540. package/dist/unstable/cli/Param.d.ts.map +1 -1
  541. package/dist/unstable/cli/Param.js +104 -113
  542. package/dist/unstable/cli/Param.js.map +1 -1
  543. package/dist/unstable/cli/Primitive.d.ts +69 -58
  544. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  545. package/dist/unstable/cli/Primitive.js +65 -66
  546. package/dist/unstable/cli/Primitive.js.map +1 -1
  547. package/dist/unstable/cli/Prompt.d.ts +23 -24
  548. package/dist/unstable/cli/Prompt.d.ts.map +1 -1
  549. package/dist/unstable/cli/Prompt.js +68 -63
  550. package/dist/unstable/cli/Prompt.js.map +1 -1
  551. package/dist/unstable/cli/internal/completions/descriptor.js +23 -11
  552. package/dist/unstable/cli/internal/completions/descriptor.js.map +1 -1
  553. package/dist/unstable/cli/internal/completions/zsh.js +2 -2
  554. package/dist/unstable/cli/internal/completions/zsh.js.map +1 -1
  555. package/dist/unstable/cli/internal/config.js +4 -4
  556. package/dist/unstable/cli/internal/parser.js +1 -1
  557. package/dist/unstable/cli/internal/parser.js.map +1 -1
  558. package/dist/unstable/cli/internal/wizard.d.ts.map +1 -1
  559. package/dist/unstable/cli/internal/wizard.js +14 -13
  560. package/dist/unstable/cli/internal/wizard.js.map +1 -1
  561. package/dist/unstable/cluster/ClusterSchema.d.ts +13 -0
  562. package/dist/unstable/cluster/ClusterSchema.d.ts.map +1 -1
  563. package/dist/unstable/cluster/ClusterSchema.js +16 -1
  564. package/dist/unstable/cluster/ClusterSchema.js.map +1 -1
  565. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  566. package/dist/unstable/cluster/ClusterWorkflowEngine.js +57 -14
  567. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  568. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  569. package/dist/unstable/cluster/Entity.js +2 -0
  570. package/dist/unstable/cluster/Entity.js.map +1 -1
  571. package/dist/unstable/cluster/EntityProxyServer.d.ts +2 -2
  572. package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
  573. package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
  574. package/dist/unstable/cluster/Envelope.d.ts +4 -4
  575. package/dist/unstable/cluster/Envelope.d.ts.map +1 -1
  576. package/dist/unstable/cluster/Envelope.js +2 -3
  577. package/dist/unstable/cluster/Envelope.js.map +1 -1
  578. package/dist/unstable/cluster/HttpRunner.d.ts.map +1 -1
  579. package/dist/unstable/cluster/HttpRunner.js +5 -2
  580. package/dist/unstable/cluster/HttpRunner.js.map +1 -1
  581. package/dist/unstable/cluster/MessageStorage.d.ts +34 -4
  582. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  583. package/dist/unstable/cluster/MessageStorage.js +28 -9
  584. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  585. package/dist/unstable/cluster/Reply.d.ts +1 -1
  586. package/dist/unstable/cluster/Sharding.d.ts +1 -1
  587. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  588. package/dist/unstable/cluster/Sharding.js +32 -17
  589. package/dist/unstable/cluster/Sharding.js.map +1 -1
  590. package/dist/unstable/cluster/ShardingConfig.js +23 -23
  591. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  592. package/dist/unstable/cluster/SocketRunner.d.ts +2 -2
  593. package/dist/unstable/cluster/SocketRunner.d.ts.map +1 -1
  594. package/dist/unstable/cluster/SocketRunner.js +4 -3
  595. package/dist/unstable/cluster/SocketRunner.js.map +1 -1
  596. package/dist/unstable/cluster/SqlMessageStorage.js +11 -8
  597. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  598. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  599. package/dist/unstable/cluster/SqlRunnerStorage.js +11 -4
  600. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  601. package/dist/unstable/cluster/internal/clusterAbandon.d.ts +5 -0
  602. package/dist/unstable/cluster/internal/clusterAbandon.d.ts.map +1 -0
  603. package/dist/unstable/cluster/internal/clusterAbandon.js +9 -0
  604. package/dist/unstable/cluster/internal/clusterAbandon.js.map +1 -0
  605. package/dist/unstable/cluster/internal/entityManager.js +7 -4
  606. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  607. package/dist/unstable/cluster/internal/interruptors.js +30 -1
  608. package/dist/unstable/cluster/internal/interruptors.js.map +1 -1
  609. package/dist/unstable/cluster/internal/resourceRef.js +12 -7
  610. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  611. package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
  612. package/dist/unstable/devtools/DevToolsClient.js +12 -7
  613. package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
  614. package/dist/unstable/encoding/Ini.d.ts +2 -0
  615. package/dist/unstable/encoding/Ini.d.ts.map +1 -1
  616. package/dist/unstable/encoding/Ini.js +2 -0
  617. package/dist/unstable/encoding/Ini.js.map +1 -1
  618. package/dist/unstable/encoding/SchemaBinary.d.ts +27 -3
  619. package/dist/unstable/encoding/SchemaBinary.d.ts.map +1 -1
  620. package/dist/unstable/encoding/SchemaBinary.js +108 -39
  621. package/dist/unstable/encoding/SchemaBinary.js.map +1 -1
  622. package/dist/unstable/encoding/Sse.js +1 -1
  623. package/dist/unstable/encoding/Sse.js.map +1 -1
  624. package/dist/unstable/encoding/Toml.d.ts +2 -0
  625. package/dist/unstable/encoding/Toml.d.ts.map +1 -1
  626. package/dist/unstable/encoding/Toml.js +6 -4
  627. package/dist/unstable/encoding/Toml.js.map +1 -1
  628. package/dist/unstable/encoding/Yaml.d.ts +2 -0
  629. package/dist/unstable/encoding/Yaml.d.ts.map +1 -1
  630. package/dist/unstable/encoding/Yaml.js +16 -5
  631. package/dist/unstable/encoding/Yaml.js.map +1 -1
  632. package/dist/unstable/encoding/index.d.ts +0 -4
  633. package/dist/unstable/encoding/index.d.ts.map +1 -1
  634. package/dist/unstable/encoding/index.js +0 -4
  635. package/dist/unstable/encoding/index.js.map +1 -1
  636. package/dist/unstable/eventlog/Event.d.ts +5 -5
  637. package/dist/unstable/eventlog/Event.d.ts.map +1 -1
  638. package/dist/unstable/eventlog/Event.js +3 -3
  639. package/dist/unstable/eventlog/Event.js.map +1 -1
  640. package/dist/unstable/eventlog/EventJournal.d.ts +7 -7
  641. package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
  642. package/dist/unstable/eventlog/EventJournal.js +9 -9
  643. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  644. package/dist/unstable/eventlog/EventLog.d.ts +1 -1
  645. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  646. package/dist/unstable/eventlog/EventLog.js +4 -4
  647. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  648. package/dist/unstable/eventlog/EventLogMessage.d.ts +11 -5
  649. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  650. package/dist/unstable/eventlog/EventLogMessage.js +25 -15
  651. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  652. package/dist/unstable/eventlog/EventLogRemote.d.ts +7 -1
  653. package/dist/unstable/eventlog/EventLogRemote.d.ts.map +1 -1
  654. package/dist/unstable/eventlog/EventLogRemote.js +13 -3
  655. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  656. package/dist/unstable/eventlog/EventLogServerUnencrypted.js +2 -2
  657. package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -1
  658. package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
  659. package/dist/unstable/eventlog/SqlEventJournal.js +26 -13
  660. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  661. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -1
  662. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +5 -1
  663. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  664. package/dist/unstable/http/Cookies.d.ts +1 -45
  665. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  666. package/dist/unstable/http/Cookies.js +2 -64
  667. package/dist/unstable/http/Cookies.js.map +1 -1
  668. package/dist/unstable/http/FetchHttpClient.js +1 -1
  669. package/dist/unstable/http/FetchHttpClient.js.map +1 -1
  670. package/dist/unstable/http/FindMyWay/internal/router.js +124 -33
  671. package/dist/unstable/http/FindMyWay/internal/router.js.map +1 -1
  672. package/dist/unstable/http/FindMyWay.d.ts +15 -5
  673. package/dist/unstable/http/FindMyWay.d.ts.map +1 -1
  674. package/dist/unstable/http/FindMyWay.js +3 -1
  675. package/dist/unstable/http/FindMyWay.js.map +1 -1
  676. package/dist/unstable/http/Headers.d.ts +0 -22
  677. package/dist/unstable/http/Headers.d.ts.map +1 -1
  678. package/dist/unstable/http/Headers.js +3 -34
  679. package/dist/unstable/http/Headers.js.map +1 -1
  680. package/dist/unstable/http/HttpBody.d.ts +41 -10
  681. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  682. package/dist/unstable/http/HttpBody.js +64 -10
  683. package/dist/unstable/http/HttpBody.js.map +1 -1
  684. package/dist/unstable/http/HttpClient.d.ts +1 -1
  685. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  686. package/dist/unstable/http/HttpClient.js +28 -18
  687. package/dist/unstable/http/HttpClient.js.map +1 -1
  688. package/dist/unstable/http/HttpClientRequest.d.ts +28 -6
  689. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  690. package/dist/unstable/http/HttpClientRequest.js +8 -19
  691. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  692. package/dist/unstable/http/HttpClientResponse.d.ts +6 -1
  693. package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
  694. package/dist/unstable/http/HttpClientResponse.js +10 -6
  695. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  696. package/dist/unstable/http/HttpEffect.d.ts +16 -0
  697. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  698. package/dist/unstable/http/HttpEffect.js +121 -65
  699. package/dist/unstable/http/HttpEffect.js.map +1 -1
  700. package/dist/unstable/http/HttpIncomingMessage.d.ts +3 -3
  701. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  702. package/dist/unstable/http/HttpIncomingMessage.js +1 -13
  703. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  704. package/dist/unstable/http/HttpMiddleware.d.ts +1 -1
  705. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  706. package/dist/unstable/http/HttpMiddleware.js +29 -21
  707. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  708. package/dist/unstable/http/HttpPlatform.d.ts +12 -11
  709. package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
  710. package/dist/unstable/http/HttpPlatform.js +36 -10
  711. package/dist/unstable/http/HttpPlatform.js.map +1 -1
  712. package/dist/unstable/http/HttpRouter.d.ts +5 -1
  713. package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
  714. package/dist/unstable/http/HttpRouter.js +22 -8
  715. package/dist/unstable/http/HttpRouter.js.map +1 -1
  716. package/dist/unstable/http/HttpServer.d.ts +11 -42
  717. package/dist/unstable/http/HttpServer.d.ts.map +1 -1
  718. package/dist/unstable/http/HttpServer.js +16 -20
  719. package/dist/unstable/http/HttpServer.js.map +1 -1
  720. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  721. package/dist/unstable/http/HttpServerRequest.js +11 -11
  722. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  723. package/dist/unstable/http/HttpServerRespondable.js +1 -1
  724. package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
  725. package/dist/unstable/http/HttpServerResponse.d.ts +9 -13
  726. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  727. package/dist/unstable/http/HttpServerResponse.js +34 -44
  728. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  729. package/dist/unstable/http/HttpStaticServer.d.ts +2 -2
  730. package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -1
  731. package/dist/unstable/http/HttpStaticServer.js +19 -19
  732. package/dist/unstable/http/HttpStaticServer.js.map +1 -1
  733. package/dist/unstable/http/Mime.d.ts +28 -0
  734. package/dist/unstable/http/Mime.d.ts.map +1 -0
  735. package/dist/unstable/http/Mime.js +72 -0
  736. package/dist/unstable/http/Mime.js.map +1 -0
  737. package/dist/unstable/http/Multipart.d.ts +22 -9
  738. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  739. package/dist/unstable/http/Multipart.js +26 -10
  740. package/dist/unstable/http/Multipart.js.map +1 -1
  741. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts +1 -1
  742. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -1
  743. package/dist/unstable/http/MultipartParser/internal/multipart.js +8 -3
  744. package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -1
  745. package/dist/unstable/http/MultipartParser.d.ts +4 -3
  746. package/dist/unstable/http/MultipartParser.d.ts.map +1 -1
  747. package/dist/unstable/http/MultipartParser.js.map +1 -1
  748. package/dist/unstable/http/UrlParams.d.ts +0 -97
  749. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  750. package/dist/unstable/http/UrlParams.js +3 -104
  751. package/dist/unstable/http/UrlParams.js.map +1 -1
  752. package/dist/unstable/http/index.d.ts +4 -0
  753. package/dist/unstable/http/index.d.ts.map +1 -1
  754. package/dist/unstable/http/index.js +4 -0
  755. package/dist/unstable/http/index.js.map +1 -1
  756. package/dist/unstable/http/internal/compression.js +8 -11
  757. package/dist/unstable/http/internal/compression.js.map +1 -1
  758. package/dist/unstable/http/internal/headers.d.ts +2 -0
  759. package/dist/unstable/http/internal/headers.d.ts.map +1 -0
  760. package/dist/unstable/http/internal/headers.js +5 -0
  761. package/dist/unstable/http/internal/headers.js.map +1 -0
  762. package/dist/unstable/http/internal/httpBody.js +8 -0
  763. package/dist/unstable/http/internal/httpBody.js.map +1 -1
  764. package/dist/unstable/http/internal/mimeTypes.d.ts +361 -0
  765. package/dist/unstable/http/internal/mimeTypes.d.ts.map +1 -0
  766. package/dist/unstable/http/internal/mimeTypes.js +363 -0
  767. package/dist/unstable/http/internal/mimeTypes.js.map +1 -0
  768. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +13 -0
  769. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  770. package/dist/unstable/httpapi/HttpApiBuilder.js +23 -6
  771. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  772. package/dist/unstable/httpapi/HttpApiClient.d.ts +4 -3
  773. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  774. package/dist/unstable/httpapi/HttpApiClient.js +25 -13
  775. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  776. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +8 -3
  777. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  778. package/dist/unstable/httpapi/HttpApiEndpoint.js +9 -6
  779. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  780. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  781. package/dist/unstable/httpapi/HttpApiError.js +3 -1
  782. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  783. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  784. package/dist/unstable/httpapi/HttpApiMiddleware.js +7 -5
  785. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  786. package/dist/unstable/httpapi/HttpApiSchema.d.ts +12 -0
  787. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  788. package/dist/unstable/httpapi/HttpApiSchema.js +8 -10
  789. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  790. package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
  791. package/dist/unstable/httpapi/HttpApiTest.js +8 -2
  792. package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
  793. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  794. package/dist/unstable/httpapi/OpenApi.js +31 -20
  795. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  796. package/dist/unstable/net/IpInterface.d.ts +140 -0
  797. package/dist/unstable/net/IpInterface.d.ts.map +1 -0
  798. package/dist/unstable/net/IpInterface.js +149 -0
  799. package/dist/unstable/net/IpInterface.js.map +1 -0
  800. package/dist/unstable/net/IpNetwork.d.ts +227 -0
  801. package/dist/unstable/net/IpNetwork.d.ts.map +1 -0
  802. package/dist/unstable/net/IpNetwork.js +239 -0
  803. package/dist/unstable/net/IpNetwork.js.map +1 -0
  804. package/dist/unstable/net/NetAddress.d.ts +705 -0
  805. package/dist/unstable/net/NetAddress.d.ts.map +1 -0
  806. package/dist/unstable/net/NetAddress.js +956 -0
  807. package/dist/unstable/net/NetAddress.js.map +1 -0
  808. package/dist/unstable/net/index.d.ts +16 -0
  809. package/dist/unstable/net/index.d.ts.map +1 -0
  810. package/dist/unstable/net/index.js +17 -0
  811. package/dist/unstable/net/index.js.map +1 -0
  812. package/dist/unstable/observability/OtlpExporter.d.ts +1 -0
  813. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  814. package/dist/unstable/observability/OtlpExporter.js +4 -6
  815. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  816. package/dist/unstable/observability/OtlpLogger.js +9 -9
  817. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  818. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  819. package/dist/unstable/observability/OtlpMetrics.js +9 -8
  820. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  821. package/dist/unstable/observability/OtlpResource.d.ts.map +1 -1
  822. package/dist/unstable/observability/OtlpResource.js +2 -2
  823. package/dist/unstable/observability/OtlpResource.js.map +1 -1
  824. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  825. package/dist/unstable/observability/OtlpTracer.js +82 -55
  826. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  827. package/dist/unstable/observability/internal/otlpEnv.d.ts +1 -1
  828. package/dist/unstable/observability/internal/otlpEnv.d.ts.map +1 -1
  829. package/dist/unstable/observability/internal/otlpEnv.js +5 -9
  830. package/dist/unstable/observability/internal/otlpEnv.js.map +1 -1
  831. package/dist/unstable/persistence/PersistedCache.js +1 -1
  832. package/dist/unstable/persistence/PersistedCache.js.map +1 -1
  833. package/dist/unstable/persistence/PersistedQueue.d.ts +114 -14
  834. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  835. package/dist/unstable/persistence/PersistedQueue.js +799 -234
  836. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  837. package/dist/unstable/persistence/RateLimiter.d.ts +28 -15
  838. package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
  839. package/dist/unstable/persistence/RateLimiter.js +33 -41
  840. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  841. package/dist/unstable/process/ChildProcess.d.ts +8 -2
  842. package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
  843. package/dist/unstable/process/ChildProcess.js +7 -2
  844. package/dist/unstable/process/ChildProcess.js.map +1 -1
  845. package/dist/unstable/process/ChildProcessSpawner.d.ts +1 -1
  846. package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
  847. package/dist/unstable/process/ChildProcessSpawner.js +1 -1
  848. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  849. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  850. package/dist/unstable/reactivity/Atom.js +6 -3
  851. package/dist/unstable/reactivity/Atom.js.map +1 -1
  852. package/dist/unstable/reactivity/AtomHttpApi.d.ts +3 -6
  853. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  854. package/dist/unstable/reactivity/AtomHttpApi.js +6 -3
  855. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  856. package/dist/unstable/reactivity/AtomRegistry.js +2 -3
  857. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  858. package/dist/unstable/reactivity/AtomRpc.d.ts +2 -2
  859. package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
  860. package/dist/unstable/reactivity/AtomRpc.js +1 -1
  861. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  862. package/dist/unstable/reactivity/Hydration.d.ts +6 -4
  863. package/dist/unstable/reactivity/Hydration.d.ts.map +1 -1
  864. package/dist/unstable/reactivity/Hydration.js +20 -6
  865. package/dist/unstable/reactivity/Hydration.js.map +1 -1
  866. package/dist/unstable/reactivity/Reactivity.d.ts +26 -26
  867. package/dist/unstable/reactivity/Reactivity.d.ts.map +1 -1
  868. package/dist/unstable/reactivity/Reactivity.js +10 -12
  869. package/dist/unstable/reactivity/Reactivity.js.map +1 -1
  870. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  871. package/dist/unstable/rpc/RpcClient.js +64 -64
  872. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  873. package/dist/unstable/rpc/RpcClientError.d.ts +1 -1
  874. package/dist/unstable/rpc/RpcMessage.d.ts +3 -1
  875. package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
  876. package/dist/unstable/rpc/RpcMessage.js +1 -1
  877. package/dist/unstable/rpc/RpcMessage.js.map +1 -1
  878. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  879. package/dist/unstable/rpc/RpcMiddleware.js +7 -5
  880. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  881. package/dist/unstable/rpc/RpcSerialization.d.ts +5 -39
  882. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  883. package/dist/unstable/rpc/RpcSerialization.js +22 -115
  884. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  885. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  886. package/dist/unstable/rpc/RpcServer.js +104 -57
  887. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  888. package/dist/unstable/schema/Model.d.ts.map +1 -1
  889. package/dist/unstable/schema/Model.js +7 -6
  890. package/dist/unstable/schema/Model.js.map +1 -1
  891. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  892. package/dist/unstable/schema/VariantSchema.js +3 -0
  893. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  894. package/dist/unstable/socket/Socket.d.ts +287 -102
  895. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  896. package/dist/unstable/socket/Socket.js +408 -215
  897. package/dist/unstable/socket/Socket.js.map +1 -1
  898. package/dist/unstable/socket/SocketServer.d.ts +5 -32
  899. package/dist/unstable/socket/SocketServer.d.ts.map +1 -1
  900. package/dist/unstable/socket/SocketServer.js +3 -3
  901. package/dist/unstable/socket/SocketServer.js.map +1 -1
  902. package/dist/unstable/sql/SqlClient.d.ts +20 -0
  903. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  904. package/dist/unstable/sql/SqlClient.js +14 -7
  905. package/dist/unstable/sql/SqlClient.js.map +1 -1
  906. package/dist/unstable/sql/SqlConnection.d.ts +15 -0
  907. package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
  908. package/dist/unstable/sql/SqlConnection.js.map +1 -1
  909. package/dist/unstable/sql/SqlModel.d.ts +1 -1
  910. package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
  911. package/dist/unstable/sql/Statement.d.ts +13 -5
  912. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  913. package/dist/unstable/sql/Statement.js +29 -15
  914. package/dist/unstable/sql/Statement.js.map +1 -1
  915. package/dist/unstable/workers/Transferable.js +1 -1
  916. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  917. package/dist/unstable/workers/Worker.js +3 -1
  918. package/dist/unstable/workers/Worker.js.map +1 -1
  919. package/dist/unstable/workflow/Activity.d.ts +7 -0
  920. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  921. package/dist/unstable/workflow/Activity.js +14 -4
  922. package/dist/unstable/workflow/Activity.js.map +1 -1
  923. package/dist/unstable/workflow/DurableClock.js +1 -1
  924. package/dist/unstable/workflow/DurableClock.js.map +1 -1
  925. package/dist/unstable/workflow/DurableDeferred.d.ts +2 -2
  926. package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
  927. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  928. package/dist/unstable/workflow/DurableQueue.d.ts +8 -0
  929. package/dist/unstable/workflow/DurableQueue.d.ts.map +1 -1
  930. package/dist/unstable/workflow/DurableQueue.js +8 -0
  931. package/dist/unstable/workflow/DurableQueue.js.map +1 -1
  932. package/dist/unstable/workflow/Workflow.d.ts +5 -0
  933. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  934. package/dist/unstable/workflow/Workflow.js +70 -12
  935. package/dist/unstable/workflow/Workflow.js.map +1 -1
  936. package/dist/unstable/workflow/WorkflowEngine.d.ts +6 -0
  937. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  938. package/dist/unstable/workflow/WorkflowEngine.js +11 -0
  939. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  940. package/package.json +7 -9
  941. package/src/Array.ts +118 -67
  942. package/src/BigDecimal.ts +50 -28
  943. package/src/ByteSize.ts +838 -0
  944. package/src/Cache.ts +17 -3
  945. package/src/Cause.ts +1 -1
  946. package/src/Channel.ts +183 -48
  947. package/src/Chunk.ts +65 -36
  948. package/src/Config.ts +237 -248
  949. package/src/ConfigProvider.ts +7 -8
  950. package/src/Context.ts +31 -0
  951. package/src/Cron.ts +2 -2
  952. package/src/Crypto.ts +3 -2
  953. package/src/Deferred.ts +7 -6
  954. package/src/Duration.ts +1 -1
  955. package/src/Effect.ts +226 -122
  956. package/src/Effectable.ts +78 -9
  957. package/src/Encoding.ts +101 -11
  958. package/src/Equal.ts +1 -1
  959. package/src/ExecutionPlan.ts +3 -0
  960. package/src/Fiber.ts +33 -8
  961. package/src/FiberHandle.ts +3 -3
  962. package/src/FiberMap.ts +19 -10
  963. package/src/FileSystem.ts +55 -230
  964. package/src/Formatter.ts +21 -3
  965. package/src/Graph.ts +55 -25
  966. package/src/Hash.ts +5 -16
  967. package/src/HashRing.ts +9 -2
  968. package/src/HashSet.ts +56 -0
  969. package/src/Iterable.ts +66 -41
  970. package/src/JsonPatch.ts +4 -4
  971. package/src/JsonPointer.ts +97 -4
  972. package/src/JsonSchema.ts +8 -26
  973. package/src/Layer.ts +59 -18
  974. package/src/LayerMap.ts +8 -6
  975. package/src/LayerRef.ts +7 -5
  976. package/src/Logger.ts +125 -18
  977. package/src/ManagedRuntime.ts +1 -1
  978. package/src/Match.ts +33 -14
  979. package/src/Metric.ts +24 -21
  980. package/src/MutableHashMap.ts +1 -1
  981. package/src/MutableHashSet.ts +1 -1
  982. package/src/MutableList.ts +18 -2
  983. package/src/Number.ts +7 -1
  984. package/src/Optic.ts +8 -4
  985. package/src/Option.ts +1 -1
  986. package/src/Order.ts +3 -1
  987. package/src/PartitionedSemaphore.ts +1 -2
  988. package/src/Path.ts +1 -1
  989. package/src/PlatformError.ts +1 -1
  990. package/src/Pool.ts +125 -8
  991. package/src/PrimaryKey.ts +1 -1
  992. package/src/PubSub.ts +32 -20
  993. package/src/Queue.ts +119 -28
  994. package/src/Random.ts +20 -6
  995. package/src/RcMap.ts +20 -13
  996. package/src/Redacted.ts +1 -1
  997. package/src/RequestResolver.ts +49 -26
  998. package/src/Result.ts +1 -1
  999. package/src/Scheduler.ts +21 -11
  1000. package/src/Schema.ts +4809 -6368
  1001. package/src/SchemaAST.ts +1031 -284
  1002. package/src/SchemaGetter.ts +75 -21
  1003. package/src/SchemaIssue.ts +259 -15
  1004. package/src/SchemaParser.ts +2 -12
  1005. package/src/SchemaRepresentation.ts +1593 -29
  1006. package/src/SchemaTransformation.ts +145 -22
  1007. package/src/ScopedCache.ts +10 -3
  1008. package/src/Sink.ts +31 -15
  1009. package/src/Stream.ts +294 -76
  1010. package/src/String.ts +20 -9
  1011. package/src/Struct.ts +8 -4
  1012. package/src/SynchronizedRef.ts +3 -5
  1013. package/src/Terminal.ts +3 -3
  1014. package/src/Tracer.ts +43 -14
  1015. package/src/Tuple.ts +3 -1
  1016. package/src/TxChunk.ts +1 -1
  1017. package/src/TxDeferred.ts +1 -1
  1018. package/src/TxHashMap.ts +1 -1
  1019. package/src/TxHashSet.ts +92 -11
  1020. package/src/TxPriorityQueue.ts +1 -1
  1021. package/src/TxPubSub.ts +1 -1
  1022. package/src/TxQueue.ts +22 -17
  1023. package/src/TxReentrantLock.ts +29 -1
  1024. package/src/TxRef.ts +1 -1
  1025. package/src/TxSemaphore.ts +1 -1
  1026. package/src/TxSubscriptionRef.ts +1 -1
  1027. package/src/Types.ts +40 -17
  1028. package/src/Utils.ts +3 -1
  1029. package/src/index.ts +5 -0
  1030. package/src/internal/arbitrary/model.ts +701 -0
  1031. package/src/internal/arbitrary/regexp.ts +855 -0
  1032. package/src/internal/arbitrary/runner.ts +608 -0
  1033. package/src/internal/arbitrary/schema.ts +1800 -0
  1034. package/src/internal/core.ts +48 -22
  1035. package/src/internal/count.ts +14 -0
  1036. package/src/internal/dateTime.ts +8 -10
  1037. package/src/internal/effect.ts +475 -295
  1038. package/src/internal/graph.ts +6 -1
  1039. package/src/internal/hashMap.ts +5 -3
  1040. package/src/internal/hashSet.ts +1 -1
  1041. package/src/internal/matcher.ts +34 -19
  1042. package/src/internal/metric.ts +1 -1
  1043. package/src/internal/option.ts +8 -6
  1044. package/src/internal/random.ts +20 -7
  1045. package/src/internal/rcRef.ts +10 -7
  1046. package/src/internal/references.ts +1 -0
  1047. package/src/internal/request.ts +12 -7
  1048. package/src/internal/result.ts +15 -11
  1049. package/src/internal/schema/annotations.ts +3 -3
  1050. package/src/internal/schema/fromJsonSchemaDocument.ts +14 -29
  1051. package/src/internal/schema/fromRepresentation.ts +5 -3
  1052. package/src/internal/schema/{schema.ts → make.ts} +0 -40
  1053. package/src/internal/schema/parser.ts +8 -0
  1054. package/src/internal/schema/standardSchema.ts +125 -0
  1055. package/src/internal/schema/toCodeDocument.ts +58 -44
  1056. package/src/internal/schema/toCodec.ts +312 -0
  1057. package/src/internal/schema/toDifferJsonPatch.ts +24 -0
  1058. package/src/internal/schema/toEncoderXml.ts +110 -0
  1059. package/src/internal/schema/toEquivalence.ts +76 -0
  1060. package/src/internal/schema/toFormatter.ts +230 -0
  1061. package/src/internal/schema/toIso.ts +20 -0
  1062. package/src/internal/schema/toJsonSchemaDocument.ts +125 -67
  1063. package/src/internal/schema/toRepresentation.ts +1 -1
  1064. package/src/internal/schemaError.ts +8 -0
  1065. package/src/internal/stream.ts +14 -6
  1066. package/src/internal/tracer.ts +4 -0
  1067. package/src/internal/trie.ts +5 -2
  1068. package/src/internal/uuid.ts +4 -0
  1069. package/src/testing/TestSchema.ts +36 -30
  1070. package/src/testing/index.ts +0 -5
  1071. package/src/unstable/ai/AiError.ts +69 -5
  1072. package/src/unstable/ai/AnthropicStructuredOutput.ts +4 -1
  1073. package/src/unstable/ai/Chat.ts +35 -36
  1074. package/src/unstable/ai/EmbeddingModel.ts +27 -15
  1075. package/src/unstable/ai/LanguageModel.ts +283 -100
  1076. package/src/unstable/ai/McpServer.ts +36 -20
  1077. package/src/unstable/ai/OpenAiStructuredOutput.ts +4 -1
  1078. package/src/unstable/ai/Prompt.ts +19 -4
  1079. package/src/unstable/ai/Response.ts +107 -189
  1080. package/src/unstable/ai/Tokenizer.ts +4 -5
  1081. package/src/unstable/ai/Tool.ts +58 -35
  1082. package/src/unstable/ai/Toolkit.ts +43 -37
  1083. package/src/unstable/ai/internal/structured-output.ts +5 -5
  1084. package/src/unstable/arbitrary/Arbitrary.ts +715 -0
  1085. package/src/unstable/arbitrary/index.ts +10 -0
  1086. package/src/unstable/cli/Argument.ts +111 -115
  1087. package/src/unstable/cli/CliError.ts +2 -0
  1088. package/src/unstable/cli/CliOutput.ts +40 -3
  1089. package/src/unstable/cli/Command.ts +74 -74
  1090. package/src/unstable/cli/Completions.ts +4 -4
  1091. package/src/unstable/cli/Flag.ts +158 -169
  1092. package/src/unstable/cli/GlobalFlag.ts +13 -13
  1093. package/src/unstable/cli/Param.ts +150 -159
  1094. package/src/unstable/cli/Primitive.ts +75 -76
  1095. package/src/unstable/cli/Prompt.ts +88 -87
  1096. package/src/unstable/cli/internal/completions/descriptor.ts +23 -11
  1097. package/src/unstable/cli/internal/completions/zsh.ts +2 -2
  1098. package/src/unstable/cli/internal/config.ts +4 -4
  1099. package/src/unstable/cli/internal/parser.ts +1 -1
  1100. package/src/unstable/cli/internal/wizard.ts +18 -13
  1101. package/src/unstable/cluster/ClusterSchema.ts +19 -1
  1102. package/src/unstable/cluster/ClusterWorkflowEngine.ts +66 -16
  1103. package/src/unstable/cluster/Entity.ts +3 -0
  1104. package/src/unstable/cluster/EntityProxyServer.ts +6 -2
  1105. package/src/unstable/cluster/Envelope.ts +3 -3
  1106. package/src/unstable/cluster/HttpRunner.ts +7 -2
  1107. package/src/unstable/cluster/MessageStorage.ts +62 -21
  1108. package/src/unstable/cluster/Reply.ts +2 -2
  1109. package/src/unstable/cluster/Sharding.ts +44 -19
  1110. package/src/unstable/cluster/ShardingConfig.ts +23 -23
  1111. package/src/unstable/cluster/SocketRunner.ts +5 -4
  1112. package/src/unstable/cluster/SqlMessageStorage.ts +12 -8
  1113. package/src/unstable/cluster/SqlRunnerStorage.ts +18 -10
  1114. package/src/unstable/cluster/internal/clusterAbandon.ts +14 -0
  1115. package/src/unstable/cluster/internal/entityManager.ts +12 -4
  1116. package/src/unstable/cluster/internal/interruptors.ts +58 -1
  1117. package/src/unstable/cluster/internal/resourceRef.ts +15 -7
  1118. package/src/unstable/devtools/DevToolsClient.ts +13 -3
  1119. package/src/unstable/encoding/Ini.ts +2 -0
  1120. package/src/unstable/encoding/SchemaBinary.ts +150 -44
  1121. package/src/unstable/encoding/Sse.ts +1 -1
  1122. package/src/unstable/encoding/Toml.ts +7 -5
  1123. package/src/unstable/encoding/Yaml.ts +18 -5
  1124. package/src/unstable/encoding/index.ts +0 -5
  1125. package/src/unstable/eventlog/Event.ts +7 -7
  1126. package/src/unstable/eventlog/EventJournal.ts +9 -9
  1127. package/src/unstable/eventlog/EventLog.ts +5 -5
  1128. package/src/unstable/eventlog/EventLogMessage.ts +25 -15
  1129. package/src/unstable/eventlog/EventLogRemote.ts +15 -4
  1130. package/src/unstable/eventlog/EventLogServerUnencrypted.ts +2 -2
  1131. package/src/unstable/eventlog/SqlEventJournal.ts +32 -9
  1132. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +11 -1
  1133. package/src/unstable/http/Cookies.ts +2 -102
  1134. package/src/unstable/http/FetchHttpClient.ts +1 -1
  1135. package/src/unstable/http/FindMyWay/internal/router.ts +139 -33
  1136. package/src/unstable/http/FindMyWay.ts +15 -5
  1137. package/src/unstable/http/Headers.ts +3 -48
  1138. package/src/unstable/http/HttpBody.ts +107 -36
  1139. package/src/unstable/http/HttpClient.ts +41 -30
  1140. package/src/unstable/http/HttpClientRequest.ts +32 -18
  1141. package/src/unstable/http/HttpClientResponse.ts +16 -3
  1142. package/src/unstable/http/HttpEffect.ts +145 -73
  1143. package/src/unstable/http/HttpIncomingMessage.ts +4 -4
  1144. package/src/unstable/http/HttpMiddleware.ts +43 -24
  1145. package/src/unstable/http/HttpPlatform.ts +62 -20
  1146. package/src/unstable/http/HttpRouter.ts +27 -16
  1147. package/src/unstable/http/HttpServer.ts +18 -57
  1148. package/src/unstable/http/HttpServerRequest.ts +17 -15
  1149. package/src/unstable/http/HttpServerRespondable.ts +1 -1
  1150. package/src/unstable/http/HttpServerResponse.ts +49 -40
  1151. package/src/unstable/http/HttpStaticServer.ts +30 -28
  1152. package/src/unstable/http/Mime.ts +76 -0
  1153. package/src/unstable/http/Multipart.ts +35 -18
  1154. package/src/unstable/http/MultipartParser/internal/multipart.ts +10 -3
  1155. package/src/unstable/http/MultipartParser.ts +4 -3
  1156. package/src/unstable/http/UrlParams.ts +3 -161
  1157. package/src/unstable/http/index.ts +5 -0
  1158. package/src/unstable/http/internal/compression.ts +11 -12
  1159. package/src/unstable/http/internal/headers.ts +7 -0
  1160. package/src/unstable/http/internal/httpBody.ts +9 -0
  1161. package/src/unstable/http/internal/mimeTypes.ts +395 -0
  1162. package/src/unstable/httpapi/HttpApiBuilder.ts +52 -6
  1163. package/src/unstable/httpapi/HttpApiClient.ts +44 -24
  1164. package/src/unstable/httpapi/HttpApiEndpoint.ts +24 -11
  1165. package/src/unstable/httpapi/HttpApiError.ts +3 -1
  1166. package/src/unstable/httpapi/HttpApiMiddleware.ts +7 -5
  1167. package/src/unstable/httpapi/HttpApiSchema.ts +14 -7
  1168. package/src/unstable/httpapi/HttpApiTest.ts +6 -1
  1169. package/src/unstable/httpapi/OpenApi.ts +32 -22
  1170. package/src/unstable/net/IpInterface.ts +242 -0
  1171. package/src/unstable/net/IpNetwork.ts +357 -0
  1172. package/src/unstable/net/NetAddress.ts +1271 -0
  1173. package/src/unstable/net/index.ts +20 -0
  1174. package/src/unstable/observability/OtlpExporter.ts +5 -6
  1175. package/src/unstable/observability/OtlpLogger.ts +9 -9
  1176. package/src/unstable/observability/OtlpMetrics.ts +9 -8
  1177. package/src/unstable/observability/OtlpResource.ts +5 -4
  1178. package/src/unstable/observability/OtlpTracer.ts +103 -81
  1179. package/src/unstable/observability/internal/otlpEnv.ts +10 -13
  1180. package/src/unstable/persistence/PersistedCache.ts +1 -1
  1181. package/src/unstable/persistence/PersistedQueue.ts +1100 -291
  1182. package/src/unstable/persistence/RateLimiter.ts +64 -58
  1183. package/src/unstable/process/ChildProcess.ts +15 -4
  1184. package/src/unstable/process/ChildProcessSpawner.ts +1 -1
  1185. package/src/unstable/reactivity/Atom.ts +6 -3
  1186. package/src/unstable/reactivity/AtomHttpApi.ts +21 -10
  1187. package/src/unstable/reactivity/AtomRegistry.ts +2 -4
  1188. package/src/unstable/reactivity/AtomRpc.ts +6 -5
  1189. package/src/unstable/reactivity/Hydration.ts +26 -7
  1190. package/src/unstable/reactivity/Reactivity.ts +49 -36
  1191. package/src/unstable/rpc/RpcClient.ts +62 -59
  1192. package/src/unstable/rpc/RpcMessage.ts +3 -1
  1193. package/src/unstable/rpc/RpcMiddleware.ts +7 -5
  1194. package/src/unstable/rpc/RpcSerialization.ts +27 -117
  1195. package/src/unstable/rpc/RpcServer.ts +143 -80
  1196. package/src/unstable/schema/Model.ts +8 -7
  1197. package/src/unstable/schema/VariantSchema.ts +3 -0
  1198. package/src/unstable/socket/Socket.ts +714 -383
  1199. package/src/unstable/socket/SocketServer.ts +5 -35
  1200. package/src/unstable/sql/SqlClient.ts +42 -7
  1201. package/src/unstable/sql/SqlConnection.ts +18 -0
  1202. package/src/unstable/sql/SqlModel.ts +1 -1
  1203. package/src/unstable/sql/Statement.ts +46 -20
  1204. package/src/unstable/workers/Transferable.ts +1 -1
  1205. package/src/unstable/workers/Worker.ts +3 -1
  1206. package/src/unstable/workflow/Activity.ts +20 -9
  1207. package/src/unstable/workflow/DurableClock.ts +1 -1
  1208. package/src/unstable/workflow/DurableDeferred.ts +6 -0
  1209. package/src/unstable/workflow/DurableQueue.ts +8 -0
  1210. package/src/unstable/workflow/Workflow.ts +105 -28
  1211. package/src/unstable/workflow/WorkflowEngine.ts +22 -0
  1212. package/dist/internal/schema/schema.d.ts.map +0 -1
  1213. package/dist/internal/schema/schema.js.map +0 -1
  1214. package/dist/internal/schema/toArbitrary.d.ts +0 -2
  1215. package/dist/internal/schema/toArbitrary.d.ts.map +0 -1
  1216. package/dist/internal/schema/toArbitrary.js +0 -705
  1217. package/dist/internal/schema/toArbitrary.js.map +0 -1
  1218. package/dist/testing/FastCheck.d.ts +0 -90
  1219. package/dist/testing/FastCheck.d.ts.map +0 -1
  1220. package/dist/testing/FastCheck.js +0 -90
  1221. package/dist/testing/FastCheck.js.map +0 -1
  1222. package/dist/unstable/encoding/Msgpack.d.ts +0 -185
  1223. package/dist/unstable/encoding/Msgpack.d.ts.map +0 -1
  1224. package/dist/unstable/encoding/Msgpack.js +0 -227
  1225. package/dist/unstable/encoding/Msgpack.js.map +0 -1
  1226. package/src/internal/schema/toArbitrary.ts +0 -843
  1227. package/src/testing/FastCheck.ts +0 -90
  1228. package/src/unstable/encoding/Msgpack.ts +0 -432
  1229. /package/dist/internal/{schema → arbitrary}/schema.d.ts +0 -0
@@ -1,31 +1,31 @@
1
1
  /**
2
2
  * Models bidirectional socket connections in Effect.
3
3
  *
4
- * The `Socket` service runs handlers for binary, string, or raw frames and
5
- * provides a scoped writer for outgoing bytes, text, or close events. This
6
- * module also includes socket errors, channel adapters, WebSocket layers, and
7
- * transform-stream-backed sockets.
4
+ * A `Socket` exposes a pull-based `reader` and a scoped `writer`. Acquiring
5
+ * the reader dials the connection and returns an `Effect` that yields batches
6
+ * of incoming frames with end-to-end backpressure: nothing is read from the
7
+ * transport until the consumer pulls. Every termination, including clean
8
+ * closes, surfaces as a `SocketError`, so reconnecting is a plain
9
+ * `Effect.retry` around the scoped consume loop.
8
10
  *
9
11
  * @since 4.0.0
10
12
  */
11
- import type { NonEmptyReadonlyArray } from "../../Array.ts"
13
+ import type { NonEmptyArray, NonEmptyReadonlyArray } from "../../Array.ts"
12
14
  import type * as Cause from "../../Cause.ts"
13
15
  import * as Channel from "../../Channel.ts"
14
16
  import * as Context from "../../Context.ts"
15
- import * as Deferred from "../../Deferred.ts"
16
17
  import type * as Duration from "../../Duration.ts"
17
18
  import * as Effect from "../../Effect.ts"
18
19
  import * as Exit from "../../Exit.ts"
19
- import * as FiberSet from "../../FiberSet.ts"
20
20
  import { constVoid, dual, flow } from "../../Function.ts"
21
21
  import * as Latch from "../../Latch.ts"
22
22
  import * as Layer from "../../Layer.ts"
23
23
  import * as Predicate from "../../Predicate.ts"
24
24
  import * as Pull from "../../Pull.ts"
25
- import * as Queue from "../../Queue.ts"
26
- import * as Result from "../../Result.ts"
25
+ import type * as Redacted from "../../Redacted.ts"
27
26
  import * as Schema from "../../Schema.ts"
28
27
  import * as Scope from "../../Scope.ts"
28
+ import * as Stream from "../../Stream.ts"
29
29
 
30
30
  /**
31
31
  * Runtime type identifier attached to `Socket` services.
@@ -57,96 +57,202 @@ export const isSocket = (u: unknown): u is Socket => Predicate.hasProperty(u, Ty
57
57
  export const Socket: Context.Service<Socket, Socket> = Context.Service<Socket>("effect/socket/Socket")
58
58
 
59
59
  /**
60
- * Effect-based socket abstraction for running string or binary read handlers
61
- * and obtaining a scoped writer for outgoing frames and close events.
60
+ * Effect-based socket abstraction exposing a pull-based read side and a
61
+ * scoped writer.
62
+ *
63
+ * **Details**
64
+ *
65
+ * Acquiring `reader` establishes the connection; the scope of the acquisition
66
+ * owns the connection lifecycle. Its `pull` yields non-empty batches of incoming
67
+ * frames and never completes via `Cause.Done`: every termination, clean close
68
+ * included, fails with a `SocketError` wrapping the close reason. Code placed
69
+ * between the acquisition and the first pull runs exactly once per
70
+ * (re)connection, which makes handshakes plain code placement.
71
+ *
72
+ * Closing the acquisition scope must fail a pull that is currently suspended,
73
+ * rather than leaving it blocked. Consumers such as `toChannel` rely on this
74
+ * to shut a connection down without racing every pull against a separate
75
+ * failure signal.
76
+ *
77
+ * The writer is detached from any single connection: acquiring it cannot
78
+ * fail, and writes made while disconnected suspend until the next connection
79
+ * is established. Releasing the writer scope half-closes the write side
80
+ * where the transport supports it.
81
+ *
82
+ * **Example** (Consuming with automatic reconnect)
83
+ *
84
+ * ```ts skip-type-checking
85
+ * Effect.gen(function*() {
86
+ * const { pull } = yield* socket.reader
87
+ * while (true) {
88
+ * yield* handle(yield* pull)
89
+ * }
90
+ * }).pipe(
91
+ * Effect.scoped,
92
+ * Effect.retry({ schedule: Schedule.exponential(200) })
93
+ * )
94
+ * ```
62
95
  *
63
96
  * @category models
64
97
  * @since 4.0.0
65
98
  */
66
99
  export interface Socket {
67
100
  readonly [TypeId]: typeof TypeId
68
- readonly run: <_, E = never, R = never>(
69
- handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void,
70
- options?: {
71
- readonly onOpen?: Effect.Effect<void> | undefined
72
- }
73
- ) => Effect.Effect<void, SocketError | E, R>
74
- readonly runString: <_, E = never, R = never>(
75
- handler: (_: string) => Effect.Effect<_, E, R> | void,
76
- options?: {
77
- readonly onOpen?: Effect.Effect<void> | undefined
78
- }
79
- ) => Effect.Effect<void, SocketError | E, R>
80
- readonly runRaw: <_, E = never, R = never>(
81
- handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void,
82
- options?: {
83
- readonly onOpen?: Effect.Effect<void> | undefined
84
- }
85
- ) => Effect.Effect<void, SocketError | E, R>
86
- readonly writer: Effect.Effect<
87
- (chunk: Uint8Array | string | CloseEvent) => Effect.Effect<void, SocketError>,
88
- never,
89
- Scope.Scope
90
- >
101
+ readonly reader: Effect.Effect<Reader, SocketError, Scope.Scope>
102
+ readonly writer: Effect.Effect<Writer, never, Scope.Scope>
103
+ }
104
+
105
+ /**
106
+ * The read side of a live `Socket` connection.
107
+ *
108
+ * **Details**
109
+ *
110
+ * `pull` reads the next non-empty batch. `upgrade` wraps this connection with
111
+ * TLS when the transport supports it. Unsupported readers fail with a
112
+ * `SocketUpgradeError`. The upgrade also fails with `SocketUpgradeError` when
113
+ * the selected TLS role requires an identity but `key` and `cert` are not both
114
+ * provided. Calling `upgrade()` without an options object uses the adapter's
115
+ * client defaults.
116
+ *
117
+ * @category models
118
+ * @since 4.0.0
119
+ */
120
+ export interface Reader<A extends Uint8Array | string = Uint8Array | string> {
121
+ readonly pull: Effect.Effect<NonEmptyReadonlyArray<A>, SocketError>
122
+ readonly upgrade: (options?: TlsUpgradeOptions) => Effect.Effect<void, SocketError>
123
+ }
124
+
125
+ /**
126
+ * The write side of a `Socket`.
127
+ *
128
+ * **Details**
129
+ *
130
+ * `write` sends a single frame or a `CloseEvent`; `writeAll` sends a batch of
131
+ * frames, allowing transports to coalesce them into a single flush. Both
132
+ * apply the transport's native backpressure before succeeding.
133
+ *
134
+ * @category models
135
+ * @since 4.0.0
136
+ */
137
+ export interface Writer {
138
+ readonly write: (chunk: Uint8Array | string | CloseEvent) => Effect.Effect<void, SocketError>
139
+ readonly writeAll: (chunks: NonEmptyReadonlyArray<Uint8Array | string>) => Effect.Effect<void, SocketError>
140
+ }
141
+
142
+ /**
143
+ * TLS credentials and handshake settings used to upgrade a live socket.
144
+ *
145
+ * **Details**
146
+ *
147
+ * `key` and `cert` are optional for client upgrades that do not present a
148
+ * client certificate. Server upgrades require both, and providing only one is
149
+ * invalid. Missing or incomplete credentials fail the upgrade with a
150
+ * `SocketUpgradeError` when the adapter needs an identity.
151
+ *
152
+ * @category models
153
+ * @since 4.0.0
154
+ */
155
+ export interface TlsUpgradeOptions {
156
+ readonly key?:
157
+ | Redacted.Redacted<string | Uint8Array>
158
+ | ReadonlyArray<Redacted.Redacted<string | Uint8Array>>
159
+ | undefined
160
+ readonly cert?: string | Uint8Array | ReadonlyArray<string | Uint8Array> | undefined
161
+ readonly ca?: string | Uint8Array | ReadonlyArray<string | Uint8Array> | undefined
162
+ readonly passphrase?: Redacted.Redacted<string> | undefined
163
+ readonly alpnProtocols?: ReadonlyArray<string> | undefined
164
+ readonly requestCert?: boolean | undefined
165
+ readonly rejectUnauthorized?: boolean | undefined
91
166
  }
92
167
 
93
168
  /**
94
- * Constructs a `Socket` from a raw read loop and scoped writer, deriving binary
95
- * and string read loops when they are not provided.
169
+ * Constructs a `Socket` from a reader acquisition and a scoped writer.
170
+ *
171
+ * **Details**
172
+ *
173
+ * The reader must fail a suspended pull when its acquisition scope closes; see
174
+ * `Socket` for why. A reader that leaves a pull blocked forever will hang any
175
+ * consumer that shuts the socket down by closing that scope.
96
176
  *
97
177
  * @category constructors
98
178
  * @since 4.0.0
99
179
  */
100
180
  export const make = (options: {
101
- readonly runRaw: <_, E, R>(
102
- handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void,
103
- options?: {
104
- readonly onOpen?: Effect.Effect<void> | undefined
105
- }
106
- ) => Effect.Effect<void, SocketError | E, R>
107
- readonly run?: <_, E, R>(
108
- handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void,
109
- options?: {
110
- readonly onOpen?: Effect.Effect<void> | undefined
111
- }
112
- ) => Effect.Effect<void, SocketError | E, R>
113
- readonly runString?: <_, E, R>(
114
- handler: (_: string) => Effect.Effect<_, E, R> | void,
115
- options?: {
116
- readonly onOpen?: Effect.Effect<void> | undefined
117
- }
118
- ) => Effect.Effect<void, SocketError | E, R>
119
- readonly writer: Effect.Effect<
120
- (chunk: Uint8Array | string | CloseEvent) => Effect.Effect<void, SocketError>,
121
- never,
122
- Scope.Scope
123
- >
181
+ readonly reader: Socket["reader"]
182
+ readonly writer: Socket["writer"]
124
183
  }): Socket =>
125
184
  Socket.of({
126
185
  [TypeId]: TypeId,
127
- runRaw: options.runRaw,
128
- run: options.run ?? ((handler, opts) =>
129
- options.runRaw((data) =>
130
- typeof data === "string"
131
- ? handler(encoder.encode(data))
132
- : data instanceof Uint8Array
133
- ? handler(data)
134
- : handler(new Uint8Array(data)), opts)),
135
- runString: options.runString ??
136
- (options.run ?
137
- (handler, opts) => options.run!((data) => handler(decoder.decode(data)), opts) :
138
- (handler, opts) =>
139
- options.runRaw((data) =>
140
- typeof data === "string"
141
- ? handler(data)
142
- : data instanceof Uint8Array
143
- ? handler(decoder.decode(data))
144
- : handler(decoder.decode(new Uint8Array(data))), opts)),
186
+ reader: options.reader,
145
187
  writer: options.writer
146
188
  })
147
189
 
148
190
  const encoder = new TextEncoder()
149
- const decoder = new TextDecoder()
191
+
192
+ /**
193
+ * Acquires the socket's binary `pull`, encoding any string frames as UTF-8
194
+ * bytes.
195
+ *
196
+ * **Details**
197
+ *
198
+ * When a pulled batch contains no string frames it is returned as-is, so
199
+ * transports that only emit bytes (TCP) pay no per-chunk cost.
200
+ *
201
+ * @category combinators
202
+ * @since 4.0.0
203
+ */
204
+ export const readerBytes = (
205
+ self: Socket
206
+ ): Effect.Effect<
207
+ Effect.Effect<NonEmptyReadonlyArray<Uint8Array>, SocketError>,
208
+ SocketError,
209
+ Scope.Scope
210
+ > =>
211
+ Effect.map(self.reader, ({ pull }) =>
212
+ Effect.map(pull, (chunk) => {
213
+ for (let i = 0; i < chunk.length; i++) {
214
+ if (typeof chunk[i] === "string") {
215
+ const out = new Array<Uint8Array>(chunk.length) as NonEmptyArray<Uint8Array>
216
+ for (let j = 0; j < chunk.length; j++) {
217
+ const item = chunk[j]
218
+ out[j] = typeof item === "string" ? encoder.encode(item) : item
219
+ }
220
+ return out
221
+ }
222
+ }
223
+ return chunk as NonEmptyReadonlyArray<Uint8Array>
224
+ }))
225
+
226
+ /**
227
+ * Acquires the socket's string `pull`, decoding binary frames with the optional
228
+ * text encoding.
229
+ *
230
+ * **Details**
231
+ *
232
+ * The `TextDecoder` is created once per acquisition.
233
+ *
234
+ * @category combinators
235
+ * @since 4.0.0
236
+ */
237
+ export const readerString = (
238
+ self: Socket,
239
+ encoding?: string | undefined
240
+ ): Effect.Effect<
241
+ Effect.Effect<NonEmptyReadonlyArray<string>, SocketError>,
242
+ SocketError,
243
+ Scope.Scope
244
+ > =>
245
+ Effect.map(self.reader, ({ pull }) => {
246
+ const decoder = new TextDecoder(encoding)
247
+ return Effect.map(pull, (chunk) => {
248
+ const out = new Array<string>(chunk.length)
249
+ for (let i = 0; i < chunk.length; i++) {
250
+ const item = chunk[i]
251
+ out[i] = typeof item === "string" ? item : decoder.decode(item)
252
+ }
253
+ return out as unknown as NonEmptyReadonlyArray<string>
254
+ })
255
+ })
150
256
 
151
257
  const CloseEventTypeId = "~effect/socket/Socket/CloseEvent"
152
258
 
@@ -275,30 +381,51 @@ export class SocketOpenError extends Schema.Error<SocketOpenError>("effect/socke
275
381
  }
276
382
 
277
383
  /**
278
- * Typed error for a socket close event, carrying the close code and optional
279
- * close reason.
384
+ * Typed error for an unsupported or failed in-place TLS upgrade.
280
385
  *
281
386
  * @category errors
282
387
  * @since 4.0.0
283
388
  */
284
- export class SocketCloseError extends Schema.Error<SocketCloseError>("effect/socket/Socket/SocketCloseError")({
285
- _tag: Schema.tag("SocketCloseError"),
286
- code: Schema.Int,
287
- closeReason: Schema.optional(Schema.String)
389
+ export class SocketUpgradeError extends Schema.Error<SocketUpgradeError>(
390
+ "effect/socket/Socket/SocketUpgradeError"
391
+ )({
392
+ _tag: Schema.tag("SocketUpgradeError"),
393
+ cause: Schema.optional(Schema.Defect())
288
394
  }) {
289
395
  /**
290
- * Separates clean socket close errors from errors that should remain failures.
396
+ * An upgrade implementation for transports that cannot wrap the connection
397
+ * with TLS.
291
398
  *
292
399
  * @since 4.0.0
293
400
  */
294
- static filterClean(isClean: (code: number) => boolean): <E>(u: E) => Result.Result<SocketCloseError, E> {
295
- return function<E>(u: E) {
296
- return SocketError.is(u) && u.reason._tag === "SocketCloseError" && isClean(u.reason.code)
297
- ? Result.succeed(u.reason)
298
- : Result.fail(u)
299
- }
401
+ static readonly unsupported: Reader["upgrade"] = () =>
402
+ Effect.fail(new SocketError({ reason: new SocketUpgradeError({}) }))
403
+
404
+ override get message() {
405
+ return this.cause === undefined
406
+ ? `Socket does not support TLS upgrade`
407
+ : `An error occurred during TLS upgrade`
300
408
  }
409
+ }
301
410
 
411
+ /**
412
+ * Typed error for a socket close, carrying the close code and optional close
413
+ * reason.
414
+ *
415
+ * **Details**
416
+ *
417
+ * Sockets never classify closes: any close, whatever the code, fails the
418
+ * reader with a `SocketError` wrapping this reason. Consumers that treat a
419
+ * close as normal catch it.
420
+ *
421
+ * @category errors
422
+ * @since 4.0.0
423
+ */
424
+ export class SocketCloseError extends Schema.Error<SocketCloseError>("effect/socket/Socket/SocketCloseError")({
425
+ _tag: Schema.tag("SocketCloseError"),
426
+ code: Schema.Int,
427
+ closeReason: Schema.optional(Schema.String)
428
+ }) {
302
429
  override get message() {
303
430
  if (this.closeReason) {
304
431
  return `${this.code}: ${this.closeReason}`
@@ -317,11 +444,12 @@ export const SocketErrorReason = Schema.Union([
317
444
  SocketReadError,
318
445
  SocketWriteError,
319
446
  SocketOpenError,
447
+ SocketUpgradeError,
320
448
  SocketCloseError
321
449
  ])
322
450
 
323
451
  /**
324
- * Union of socket-specific read, write, open, and close error reasons.
452
+ * Union of socket-specific read, write, open, upgrade, and close error reasons.
325
453
  *
326
454
  * @category errors
327
455
  * @since 4.0.0
@@ -330,11 +458,12 @@ export type SocketErrorReason =
330
458
  | SocketReadError
331
459
  | SocketWriteError
332
460
  | SocketOpenError
461
+ | SocketUpgradeError
333
462
  | SocketCloseError
334
463
 
335
464
  /**
336
- * Tagged error that wraps socket read, write, open, and close failures while
337
- * preserving the underlying reason.
465
+ * Tagged error that wraps socket read, write, open, upgrade, and close failures
466
+ * while preserving the underlying reason.
338
467
  *
339
468
  * @category errors
340
469
  * @since 4.0.0
@@ -345,7 +474,7 @@ export class SocketError extends Schema.TaggedError<SocketError>(SocketErrorType
345
474
  }) {
346
475
  // @effect-diagnostics-next-line overriddenSchemaConstructor:off
347
476
  constructor(props: {
348
- readonly reason: SocketReadError | SocketWriteError | SocketOpenError | SocketCloseError
477
+ readonly reason: SocketReadError | SocketWriteError | SocketOpenError | SocketUpgradeError | SocketCloseError
349
478
  }) {
350
479
  if ("cause" in props.reason) {
351
480
  super({
@@ -376,16 +505,32 @@ export class SocketError extends Schema.TaggedError<SocketError>(SocketErrorType
376
505
  override readonly message = this.reason.message
377
506
  }
378
507
 
379
- /**
380
- * Converts a `Socket` into a bidirectional `Channel`, mapping incoming string
381
- * or binary frames and writing outgoing frame batches to the socket.
382
- *
383
- * @category combinators
384
- * @since 4.0.0
385
- */
386
- export const toChannelMap = <IE, A>(
508
+ const closeError = (code: number, closeReason?: string | undefined) =>
509
+ new SocketError({ reason: new SocketCloseError({ code, closeReason }) })
510
+
511
+ const writeChunk = (
512
+ writer: Writer,
513
+ chunk: NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>
514
+ ): Effect.Effect<void, SocketError> => {
515
+ for (let i = 0; i < chunk.length; i++) {
516
+ if (isCloseEvent(chunk[i])) {
517
+ return Effect.gen(function*() {
518
+ for (let index = 0; index <= i; index++) {
519
+ yield* writer.write(chunk[index])
520
+ }
521
+ })
522
+ }
523
+ }
524
+ return writer.writeAll(chunk as NonEmptyReadonlyArray<Uint8Array | string>)
525
+ }
526
+
527
+ const toChannelWithReader = <A extends Uint8Array | string, IE>(
387
528
  self: Socket,
388
- f: (data: Uint8Array | string) => A
529
+ reader: Effect.Effect<
530
+ Effect.Effect<NonEmptyReadonlyArray<A>, SocketError>,
531
+ SocketError,
532
+ Scope.Scope
533
+ >
389
534
  ): Channel.Channel<
390
535
  NonEmptyReadonlyArray<A>,
391
536
  SocketError | IE,
@@ -394,54 +539,57 @@ export const toChannelMap = <IE, A>(
394
539
  IE
395
540
  > =>
396
541
  Channel.fromTransform(Effect.fnUntraced(function*(upstream, scope) {
397
- const queue = yield* Queue.make<A, SocketError | IE | Cause.Done>()
398
-
542
+ const readScope = yield* Scope.fork(scope)
543
+ const pull = yield* Scope.provide(reader, readScope)
399
544
  const writeScope = yield* Scope.fork(scope)
400
- const write = yield* Scope.provide(self.writer, writeScope)
401
-
402
- let chunk: NonEmptyReadonlyArray<Uint8Array | string | CloseEvent> | undefined
403
- let index = 0
404
- const writeChunk = Effect.whileLoop({
405
- while: () => index < chunk!.length,
406
- body: () => write(chunk![index++]),
407
- step: constVoid
408
- })
545
+ const writer = yield* Scope.provide(self.writer, writeScope)
546
+
547
+ let writeFailure: Cause.Cause<SocketError | IE> | undefined
409
548
 
410
549
  yield* upstream.pipe(
411
- Effect.flatMap((arr) => {
412
- if (arr.length === 1) return write(arr[0])
413
- chunk = arr
414
- index = 0
415
- return writeChunk
416
- }),
550
+ Effect.flatMap((chunk) => writeChunk(writer, chunk)),
417
551
  Effect.forever({ disableYield: true }),
418
552
  Effect.catchCauseFilter(
419
553
  Pull.filterNoDone,
420
- (cause) => Queue.failCause(queue, cause)
554
+ (cause) =>
555
+ Effect.suspend(() => {
556
+ writeFailure = cause as Cause.Cause<SocketError | IE>
557
+ // closing the read scope fails a suspended pull, which is the
558
+ // reader contract, so the read side needs no per-pull failure race
559
+ return Scope.close(readScope, Exit.void)
560
+ })
421
561
  ),
422
562
  Effect.ensuring(Scope.close(writeScope, Exit.void)),
423
563
  Effect.forkIn(scope)
424
564
  )
425
565
 
426
- yield* self.runRaw((data) => {
427
- Queue.offerUnsafe(queue, f(data))
428
- }).pipe(
429
- Queue.into(queue),
430
- Effect.forkIn(scope)
431
- )
432
-
433
566
  // @effect-diagnostics-next-line returnEffectInGen:off
434
- return Queue.takeAll(queue)
567
+ return Effect.catchCause(
568
+ Effect.suspend(
569
+ (): Pull.Pull<NonEmptyReadonlyArray<A>, SocketError | IE> =>
570
+ writeFailure !== undefined ? Effect.failCause(writeFailure) : pull
571
+ ),
572
+ (cause) =>
573
+ Effect.failCause(
574
+ (writeFailure ?? cause) as Cause.Cause<SocketError | IE | Cause.Done<void>>
575
+ )
576
+ )
435
577
  }))
436
578
 
437
579
  /**
438
- * Converts a `Socket` into a binary `Channel`, encoding incoming string frames
439
- * as UTF-8 bytes.
580
+ * Converts a `Socket` into a bidirectional binary `Channel`, encoding
581
+ * incoming string frames as UTF-8 bytes and writing outgoing frame batches to
582
+ * the socket.
583
+ *
584
+ * **Details**
585
+ *
586
+ * The read side is the socket's pull, so the channel is backpressured
587
+ * end-to-end.
440
588
  *
441
589
  * @category combinators
442
590
  * @since 4.0.0
443
591
  */
444
- export const toChannel = <IE>(
592
+ export const toChannel = <IE = never>(
445
593
  self: Socket
446
594
  ): Channel.Channel<
447
595
  NonEmptyReadonlyArray<Uint8Array>,
@@ -449,22 +597,19 @@ export const toChannel = <IE>(
449
597
  void,
450
598
  NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>,
451
599
  IE
452
- > => {
453
- const encoder = new TextEncoder()
454
- return toChannelMap(self, (data) => typeof data === "string" ? encoder.encode(data) : data)
455
- }
600
+ > => toChannelWithReader<Uint8Array, IE>(self, readerBytes(self))
456
601
 
457
602
  /**
458
- * Converts a `Socket` into a string `Channel`, decoding binary frames with the
459
- * optional text encoding.
603
+ * Converts a `Socket` into a bidirectional string `Channel`, decoding binary
604
+ * frames with the optional text encoding.
460
605
  *
461
606
  * @category combinators
462
607
  * @since 4.0.0
463
608
  */
464
609
  export const toChannelString: {
465
610
  /**
466
- * Converts a `Socket` into a string `Channel`, decoding binary frames with the
467
- * optional text encoding.
611
+ * Converts a `Socket` into a bidirectional string `Channel`, decoding binary
612
+ * frames with the optional text encoding.
468
613
  *
469
614
  * @category combinators
470
615
  * @since 4.0.0
@@ -477,8 +622,8 @@ export const toChannelString: {
477
622
  IE
478
623
  >
479
624
  /**
480
- * Converts a `Socket` into a string `Channel`, decoding binary frames with the
481
- * optional text encoding.
625
+ * Converts a `Socket` into a bidirectional string `Channel`, decoding binary
626
+ * frames with the optional text encoding.
482
627
  *
483
628
  * @category combinators
484
629
  * @since 4.0.0
@@ -499,10 +644,21 @@ export const toChannelString: {
499
644
  void,
500
645
  NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>,
501
646
  IE
502
- > => {
503
- const decoder = new TextDecoder(encoding)
504
- return toChannelMap(self, (data) => typeof data === "string" ? data : decoder.decode(data))
505
- })
647
+ > => toChannelWithReader</**
648
+ * Converts a `Socket` into a bidirectional string `Channel`, decoding binary
649
+ * frames with the optional text encoding.
650
+ *
651
+ * @category combinators
652
+ * @since 4.0.0
653
+ */
654
+ string, /**
655
+ * Converts a `Socket` into a bidirectional string `Channel`, decoding binary
656
+ * frames with the optional text encoding.
657
+ *
658
+ * @category combinators
659
+ * @since 4.0.0
660
+ */
661
+ IE>(self, readerString(self, encoding)))
506
662
 
507
663
  /**
508
664
  * Creates a `Socket` to binary `Channel` adapter with a fixed upstream error
@@ -522,6 +678,18 @@ export const toChannelWith = <IE = never>() =>
522
678
  IE
523
679
  > => toChannel(self)
524
680
 
681
+ /**
682
+ * Converts a `Socket` into a read-only binary `Stream` backed by the socket's
683
+ * pull, so consumption is backpressured end-to-end.
684
+ *
685
+ * @category combinators
686
+ * @since 4.0.0
687
+ */
688
+ export const toStream = (self: Socket): Stream.Stream<Uint8Array, SocketError> =>
689
+ Stream.fromChannel(
690
+ Channel.fromTransform((_, scope) => Scope.provide(readerBytes(self), scope))
691
+ )
692
+
525
693
  /**
526
694
  * Creates a binary socket `Channel` from the `Socket` service in the
527
695
  * environment.
@@ -540,35 +708,104 @@ export const makeChannel = <IE = never>(): Channel.Channel<
540
708
  > => Channel.unwrap(Effect.map(Socket, toChannelWith<IE>()))
541
709
 
542
710
  /**
543
- * Default close-code classifier that treats every socket close code as an
544
- * error.
711
+ * Event payload exposed by a WebSocket implementation.
712
+ *
713
+ * **Details**
714
+ *
715
+ * The socket adapter only reads `data`, `code`, and `reason`; implementations
716
+ * may expose additional fields.
717
+ *
718
+ * @category models
719
+ * @since 4.0.0
720
+ */
721
+ export interface WebSocketEvent {
722
+ readonly type?: string
723
+ readonly data?: unknown
724
+ readonly code?: number
725
+ readonly reason?: string
726
+ }
727
+
728
+ /**
729
+ * The subset of the WebSocket API required by `Socket`.
730
+ *
731
+ * **Details**
732
+ *
733
+ * This structural interface is intentionally independent of the DOM
734
+ * `WebSocket` type. Node implementations such as `ws` expose the same
735
+ * event-target methods, but are not assignable to `globalThis.WebSocket`
736
+ * because their event payload types are runtime-specific.
737
+ *
738
+ * @category models
739
+ * @since 4.0.0
740
+ */
741
+ export interface WebSocketLike {
742
+ readonly readyState: number
743
+ addEventListener(
744
+ type: "open" | "message" | "error" | "close",
745
+ listener: (event: WebSocketEvent) => void,
746
+ options?: {
747
+ readonly once?: boolean
748
+ }
749
+ ): void
750
+ removeEventListener(
751
+ type: "open" | "message" | "error" | "close",
752
+ listener: (event: WebSocketEvent) => void
753
+ ): void
754
+ close(code?: number, reason?: string): void
755
+ send(data: string | Uint8Array<ArrayBuffer>): void
756
+ }
757
+
758
+ /**
759
+ * Common options understood by a WebSocket client implementation.
545
760
  *
546
- * @category predicates
761
+ * @category models
762
+ * @since 4.0.0
763
+ */
764
+ export interface WebSocketClientOptions {
765
+ /**
766
+ * Headers to include in the opening handshake.
767
+ *
768
+ * **Details**
769
+ *
770
+ * This is supported by Node and Bun WebSocket clients. Browser constructors
771
+ * cannot set arbitrary handshake headers and must reject this option.
772
+ */
773
+ readonly headers?: Readonly<Record<string, string>> | undefined
774
+ }
775
+
776
+ /**
777
+ * Options accepted by a `WebSocketConstructor`.
778
+ *
779
+ * **Details**
780
+ *
781
+ * Browser-compatible constructors accept a protocol string or list. Node and
782
+ * Bun constructors additionally accept `WebSocketClientOptions`.
783
+ *
784
+ * @category models
547
785
  * @since 4.0.0
548
786
  */
549
- export const defaultCloseCodeIsError = (_code: number) => true
787
+ export type WebSocketConstructorOptions = string | Array<string> | WebSocketClientOptions
550
788
 
551
789
  /**
552
- * Context service for the active `WebSocket` instance available while a
553
- * WebSocket-backed socket run is handling events.
790
+ * Context service for the active `WebSocket` instance.
554
791
  *
555
792
  * @category services
556
793
  * @since 4.0.0
557
794
  */
558
- export class WebSocket extends Context.Service<WebSocket, globalThis.WebSocket>()(
795
+ export class WebSocket extends Context.Service<WebSocket, WebSocketLike>()(
559
796
  "~effect/socket/Socket/WebSocket"
560
797
  ) {}
561
798
 
562
799
  /**
563
800
  * Context service for constructing `WebSocket` instances from a URL and
564
- * optional protocols.
801
+ * optional protocols or platform-specific options.
565
802
  *
566
803
  * @category services
567
804
  * @since 4.0.0
568
805
  */
569
806
  export class WebSocketConstructor extends Context.Service<
570
807
  WebSocketConstructor,
571
- (url: string, protocols?: string | Array<string> | undefined) => globalThis.WebSocket
808
+ (url: string, options?: WebSocketConstructorOptions | undefined) => WebSocketLike
572
809
  >()("@effect/platform/Socket/WebSocketConstructor") {}
573
810
 
574
811
  /**
@@ -578,21 +815,25 @@ export class WebSocketConstructor extends Context.Service<
578
815
  * @since 4.0.0
579
816
  */
580
817
  export const layerWebSocketConstructorGlobal: Layer.Layer<WebSocketConstructor> = Layer.succeed(WebSocketConstructor)(
581
- (url, protocols) => new globalThis.WebSocket(url, protocols)
818
+ (url, options) => {
819
+ if (options !== undefined && typeof options !== "string" && !Array.isArray(options)) {
820
+ throw new TypeError("WebSocket client options are not supported by the global WebSocket constructor")
821
+ }
822
+ return new globalThis.WebSocket(url, options)
823
+ }
582
824
  )
583
825
 
584
826
  /**
585
- * Creates a `Socket` backed by a `WebSocketConstructor`, acquiring the
586
- * WebSocket for each run and using the close-code classifier to decide which
587
- * closes fail the run.
827
+ * Creates a `Socket` backed by a `WebSocketConstructor`, dialing the
828
+ * WebSocket for each reader acquisition.
588
829
  *
589
830
  * @category constructors
590
831
  * @since 4.0.0
591
832
  */
592
833
  export const makeWebSocket = (url: string | Effect.Effect<string>, options?: {
593
- readonly closeCodeIsError?: ((code: number) => boolean) | undefined
594
834
  readonly openTimeout?: Duration.Input | undefined
595
835
  readonly protocols?: string | Array<string> | undefined
836
+ readonly highWaterMark?: number | undefined
596
837
  }): Effect.Effect<Socket, never, WebSocketConstructor> =>
597
838
  WebSocketConstructor.use((makeWs) =>
598
839
  fromWebSocket(
@@ -606,170 +847,271 @@ export const makeWebSocket = (url: string | Effect.Effect<string>, options?: {
606
847
  )
607
848
  )
608
849
 
850
+ interface Pausable {
851
+ pause(): void
852
+ resume(): void
853
+ }
854
+
855
+ const isPausable = (ws: WebSocketLike): ws is WebSocketLike & Pausable =>
856
+ "pause" in ws && typeof (ws as any).pause === "function"
857
+
609
858
  /**
610
- * Builds a `Socket` from a scoped WebSocket acquisition effect, waiting for the
611
- * socket to open, dispatching message handlers in fibers, and translating
612
- * open, read, and close events into `SocketError` values.
859
+ * Builds a `Socket` from a scoped WebSocket acquisition effect.
860
+ *
861
+ * **Details**
862
+ *
863
+ * Reader acquisition runs `acquire`, attaches event listeners, then waits for
864
+ * the socket to open. Implementations exposing `pause`/`resume` (the `ws`
865
+ * package) remain flowing until buffered frames reach the configured
866
+ * `highWaterMark` (64 KiB by default). Draining the buffer resumes the
867
+ * transport. Incoming frames that arrive in the same tick are coalesced into
868
+ * one batch. Implementations without pause (browsers) buffer incoming frames,
869
+ * optionally failing the socket with a `SocketReadError` when `highWaterMark`
870
+ * bytes are exceeded (default unbounded). Message boundaries survive: each
871
+ * pulled batch contains one element per frame.
613
872
  *
614
873
  * @category constructors
615
874
  * @since 4.0.0
616
875
  */
617
- export const fromWebSocket = <RO>(
618
- acquire: Effect.Effect<globalThis.WebSocket, SocketError, RO>,
876
+ export const fromWebSocket = <RO, WS extends WebSocketLike>(
877
+ acquire: Effect.Effect<WS, SocketError, RO>,
619
878
  options?: {
620
- readonly closeCodeIsError?: ((code: number) => boolean) | undefined
621
879
  readonly openTimeout?: Duration.Input | undefined
622
- /**
623
- * Replays buffered events on the first run after the socket opens and before
624
- * the run's `onOpen` effect.
625
- *
626
- * @category options
627
- * @since 4.0.0
628
- */
629
- readonly onInitialRun?: ((ws: globalThis.WebSocket) => ReadonlyArray<MessageEvent>) | undefined
880
+ readonly highWaterMark?: number | undefined
630
881
  } | undefined
631
882
  ): Effect.Effect<Socket, never, Exclude<RO, Scope.Scope>> =>
632
883
  Effect.withFiber((fiber) => {
633
- let currentWS: globalThis.WebSocket | undefined
634
- let initial = true
884
+ let currentWS: WebSocketLike | undefined
635
885
  const latch = Latch.makeUnsafe(false)
636
886
  const acquireContext = fiber.context as Context.Context<RO>
637
- const closeCodeIsError = options?.closeCodeIsError ?? defaultCloseCodeIsError
638
-
639
- const runRaw = <_, E, R>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void, opts?: {
640
- readonly onOpen?: Effect.Effect<void> | undefined
641
- }) =>
642
- Effect.scopedWith(Effect.fnUntraced(function*(scope) {
643
- const fiberSet = yield* FiberSet.make<any, E | SocketError>().pipe(
644
- Scope.provide(scope)
645
- )
646
- const ws = yield* Scope.provide(acquire, scope)
647
- const run = yield* Effect.provideService(FiberSet.runtime(fiberSet)<R>(), WebSocket, ws)
648
- let open = false
649
-
650
- function onMessage(event: MessageEvent) {
651
- if (event.data instanceof Blob) {
652
- const effect = Effect.flatMap(
653
- Effect.promise(() => event.data.arrayBuffer() as Promise<ArrayBuffer>),
654
- (buffer) => {
655
- const result = handler(new Uint8Array(buffer))
656
- return Effect.isEffect(result) ? result : Effect.void
657
- }
658
- )
659
- return run(effect)
660
- }
661
- const result = handler(event.data instanceof ArrayBuffer ? new Uint8Array(event.data) : event.data)
662
- if (Effect.isEffect(result)) {
663
- run(result)
664
- }
887
+
888
+ const reader: Socket["reader"] = Effect.gen(function*() {
889
+ const scope = yield* Effect.scope
890
+ const ws = yield* Scope.provide(acquire, scope)
891
+ if ("binaryType" in ws) {
892
+ ;(ws as { binaryType: string }).binaryType = "arraybuffer"
893
+ }
894
+ const pausable = isPausable(ws)
895
+ const highWaterMark = options?.highWaterMark ?? (pausable ? defaultHighWaterMark : undefined)
896
+
897
+ type ReadResume = (
898
+ effect: Effect.Effect<NonEmptyReadonlyArray<Uint8Array | string>, SocketError>
899
+ ) => void
900
+
901
+ let open = ws.readyState === 1
902
+ let paused = pausable && "isPaused" in ws && ws.isPaused === true
903
+ let buffer: Array<Uint8Array | string> = []
904
+ let bufferSize = 0
905
+ let error: SocketError | undefined
906
+ let waiter: ReadResume | undefined
907
+ let openWaiter:
908
+ | {
909
+ readonly resume: (effect: Effect.Effect<void, SocketError>) => void
910
+ readonly cleanup: () => void
665
911
  }
666
- function onError(cause: Event) {
667
- ws.removeEventListener("message", onMessage)
668
- ws.removeEventListener("close", onClose)
669
- Deferred.doneUnsafe(
670
- fiberSet.deferred,
671
- Effect.fail(
672
- new SocketError({
673
- reason: open ?
674
- new SocketReadError({
675
- cause
676
- }) :
677
- new SocketOpenError({
678
- kind: "Unknown",
679
- cause
680
- })
681
- })
682
- )
683
- )
912
+ | undefined
913
+
914
+ function pauseWebSocket() {
915
+ if (!pausable || paused) return
916
+ ws.pause()
917
+ paused = true
918
+ }
919
+
920
+ function resumeWebSocket() {
921
+ if (!pausable || !paused) return
922
+ ws.resume()
923
+ paused = false
924
+ }
925
+
926
+ function takeBuffer(): NonEmptyReadonlyArray<Uint8Array | string> {
927
+ const chunk = buffer
928
+ buffer = []
929
+ bufferSize = 0
930
+ if (error === undefined) resumeWebSocket()
931
+ return chunk as unknown as NonEmptyReadonlyArray<Uint8Array | string>
932
+ }
933
+
934
+ function deliver() {
935
+ if (waiter === undefined || buffer.length === 0) return
936
+ const resume = waiter
937
+ waiter = undefined
938
+ resume(Effect.succeed(takeBuffer()))
939
+ }
940
+
941
+ function push(data: Uint8Array | string) {
942
+ buffer.push(data)
943
+ if (highWaterMark !== undefined) {
944
+ bufferSize += typeof data === "string" ? encoder.encode(data).byteLength : data.byteLength
684
945
  }
685
- function onClose(event: globalThis.CloseEvent) {
686
- const code = typeof event.code === "number" ? event.code : 1001
687
- ws.removeEventListener("message", onMessage)
688
- ws.removeEventListener("error", onError)
689
- Deferred.doneUnsafe(
690
- fiberSet.deferred,
691
- Effect.fail(
692
- new SocketError({
693
- reason: new SocketCloseError({
694
- code,
695
- closeReason: event.reason
696
- })
946
+ if (waiter !== undefined) deliver()
947
+ if (pausable && bufferSize >= highWaterMark!) {
948
+ pauseWebSocket()
949
+ } else if (!pausable && !waiter && highWaterMark !== undefined && bufferSize > highWaterMark) {
950
+ fail(
951
+ new SocketError({
952
+ reason: new SocketReadError({
953
+ cause: new Error(`Socket highWaterMark of ${highWaterMark} bytes exceeded`)
697
954
  })
698
- )
955
+ })
699
956
  )
700
957
  }
958
+ }
701
959
 
702
- ws.addEventListener("close", onClose, { once: true })
703
- ws.addEventListener("error", onError, { once: true })
704
- ws.addEventListener("message", onMessage)
705
-
706
- if (ws.readyState !== 1) {
707
- const openDeferred = Deferred.makeUnsafe<void>()
708
- ws.addEventListener("open", () => {
709
- open = true
710
- Deferred.doneUnsafe(openDeferred, Effect.void)
711
- }, { once: true })
712
- yield* Deferred.await(openDeferred).pipe(
713
- Effect.timeoutOrElse({
714
- duration: options?.openTimeout ?? 10000,
715
- orElse: () =>
716
- Effect.fail(
717
- new SocketError({
718
- reason: new SocketOpenError({
719
- kind: "Timeout",
720
- cause: new Error("timeout waiting for \"open\"")
721
- })
722
- })
723
- )
724
- }),
725
- Effect.raceFirst(FiberSet.join(fiberSet))
726
- )
960
+ function fail(err: SocketError) {
961
+ if (error === undefined) error = err
962
+ if (openWaiter !== undefined) {
963
+ const { cleanup, resume } = openWaiter
964
+ openWaiter = undefined
965
+ cleanup()
966
+ resume(Effect.fail(error))
727
967
  }
728
- open = true
729
- currentWS = ws
730
- latch.openUnsafe()
731
- if (initial && options?.onInitialRun) {
732
- initial = false
733
- for (const event of options.onInitialRun(ws)) onMessage(event)
968
+ if (waiter !== undefined) {
969
+ const resume = waiter
970
+ waiter = undefined
971
+ resume(buffer.length > 0 ? Effect.succeed(takeBuffer()) : Effect.fail(error))
972
+ }
973
+ }
974
+
975
+ function onMessage(event: WebSocketEvent) {
976
+ const data = event.data as Uint8Array | ArrayBuffer | Blob | string
977
+ if (typeof Blob !== "undefined" && data instanceof Blob) {
978
+ data.arrayBuffer().then((buf) => push(new Uint8Array(buf)), (cause) => {
979
+ fail(new SocketError({ reason: new SocketReadError({ cause }) }))
980
+ })
981
+ return
734
982
  }
735
- if (opts?.onOpen) yield* opts.onOpen
736
- return yield* Effect.catchFilter(
737
- FiberSet.join(fiberSet),
738
- SocketCloseError.filterClean((_) => !closeCodeIsError(_)),
739
- () => Effect.void
983
+ push(data instanceof ArrayBuffer ? new Uint8Array(data) : data as Uint8Array | string)
984
+ }
985
+ function onError(event: WebSocketEvent) {
986
+ fail(
987
+ new SocketError({
988
+ reason: open
989
+ ? new SocketReadError({ cause: event })
990
+ : new SocketOpenError({ kind: "Unknown", cause: event })
991
+ })
740
992
  )
741
- })).pipe(
742
- Effect.updateContext((input: Context.Context<R>) => Context.merge(acquireContext, input)),
743
- Effect.ensuring(Effect.sync(() => {
744
- latch.closeUnsafe()
745
- currentWS = undefined
746
- }))
747
- )
993
+ }
994
+ function onClose(event: WebSocketEvent) {
995
+ fail(closeError(typeof event.code === "number" ? event.code : 1006, event.reason))
996
+ }
748
997
 
749
- const write = (chunk: Uint8Array | string | CloseEvent) =>
750
- latch.whenOpen(
751
- Effect.suspend(() => {
752
- try {
753
- const ws = currentWS!
754
- if (isCloseEvent(chunk)) {
755
- ws.close(chunk.code, chunk.reason)
756
- } else {
757
- ws.send(chunk as string | Uint8Array<ArrayBuffer>)
998
+ ws.addEventListener("message", onMessage)
999
+ ws.addEventListener("error", onError, { once: true })
1000
+ ws.addEventListener("close", onClose, { once: true })
1001
+ yield* Scope.addFinalizer(
1002
+ scope,
1003
+ Effect.sync(() => {
1004
+ // resume a pull blocked in another fiber before detaching
1005
+ fail(closeError(1006))
1006
+ ws.removeEventListener("message", onMessage)
1007
+ ws.removeEventListener("error", onError)
1008
+ ws.removeEventListener("close", onClose)
1009
+ // let the close handshake proceed once nothing is pulling
1010
+ if (pausable) {
1011
+ try {
1012
+ resumeWebSocket()
1013
+ } catch {
1014
+ // the underlying stream may already be gone
758
1015
  }
759
- return Effect.void
760
- } catch (cause) {
761
- return Effect.fail(new SocketError({ reason: new SocketWriteError({ cause }) }))
762
1016
  }
1017
+ latch.closeUnsafe()
1018
+ currentWS = undefined
763
1019
  })
764
1020
  )
765
- const writer = Effect.succeed(write)
766
1021
 
767
- return Effect.succeed(make({
768
- runRaw,
769
- writer
770
- }))
1022
+ if (ws.readyState >= 2) {
1023
+ // @effect-diagnostics-next-line unnecessaryFailYieldableError:off
1024
+ return yield* Effect.fail(error ?? closeError(1006))
1025
+ }
1026
+
1027
+ if (!open) {
1028
+ yield* Effect.callback<void, SocketError>((resume) => {
1029
+ const onOpen = () => {
1030
+ if (openWaiter?.resume !== resume) return
1031
+ openWaiter = undefined
1032
+ ws.removeEventListener("open", onOpen)
1033
+ resume(Effect.void)
1034
+ }
1035
+ const cleanup = () => ws.removeEventListener("open", onOpen)
1036
+ openWaiter = { resume, cleanup }
1037
+ ws.addEventListener("open", onOpen, { once: true })
1038
+ return Effect.sync(() => {
1039
+ if (openWaiter?.resume === resume) openWaiter = undefined
1040
+ cleanup()
1041
+ })
1042
+ }).pipe(
1043
+ Effect.timeoutOrElse({
1044
+ duration: options?.openTimeout ?? 10000,
1045
+ orElse: () =>
1046
+ Effect.fail(
1047
+ new SocketError({
1048
+ reason: new SocketOpenError({
1049
+ kind: "Timeout",
1050
+ cause: new Error("timeout waiting for \"open\"")
1051
+ })
1052
+ })
1053
+ )
1054
+ })
1055
+ )
1056
+ open = true
1057
+ }
1058
+
1059
+ if (error === undefined && bufferSize < highWaterMark!) resumeWebSocket()
1060
+ currentWS = ws
1061
+ latch.openUnsafe()
1062
+
1063
+ return {
1064
+ pull: Effect.callback<NonEmptyReadonlyArray<Uint8Array | string>, SocketError>((resume) => {
1065
+ if (buffer.length > 0) return resume(Effect.succeed(takeBuffer()))
1066
+ if (error !== undefined) return resume(Effect.fail(error))
1067
+ waiter = resume
1068
+ return Effect.sync(() => {
1069
+ if (waiter === resume) waiter = undefined
1070
+ })
1071
+ }),
1072
+ upgrade: SocketUpgradeError.unsupported
1073
+ }
1074
+ }).pipe(
1075
+ Effect.updateContext((input: Context.Context<Scope.Scope>) => Context.merge(acquireContext, input))
1076
+ ) as Socket["reader"]
1077
+
1078
+ const write = (chunk: Uint8Array | string | CloseEvent): Effect.Effect<void, SocketError> =>
1079
+ Effect.suspend(() => {
1080
+ const ws = currentWS
1081
+ if (ws === undefined) return latch.whenOpen(write(chunk))
1082
+ try {
1083
+ if (isCloseEvent(chunk)) {
1084
+ ws.close(chunk.code, chunk.reason)
1085
+ } else {
1086
+ ws.send(chunk as string | Uint8Array<ArrayBuffer>)
1087
+ }
1088
+ return Effect.void
1089
+ } catch (cause) {
1090
+ return Effect.fail(new SocketError({ reason: new SocketWriteError({ cause }) }))
1091
+ }
1092
+ })
1093
+ const writeAll = (
1094
+ chunks: NonEmptyReadonlyArray<Uint8Array | string>
1095
+ ): Effect.Effect<void, SocketError> =>
1096
+ Effect.suspend(() => {
1097
+ const ws = currentWS
1098
+ if (ws === undefined) return latch.whenOpen(writeAll(chunks))
1099
+ try {
1100
+ for (let i = 0; i < chunks.length; i++) {
1101
+ ws.send(chunks[i] as string | Uint8Array<ArrayBuffer>)
1102
+ }
1103
+ return Effect.void
1104
+ } catch (cause) {
1105
+ return Effect.fail(new SocketError({ reason: new SocketWriteError({ cause }) }))
1106
+ }
1107
+ })
1108
+ const writer: Socket["writer"] = Effect.succeed({ write, writeAll })
1109
+
1110
+ return Effect.succeed(make({ reader, writer }))
771
1111
  })
772
1112
 
1113
+ const defaultHighWaterMark = 64 * 1024
1114
+
773
1115
  /**
774
1116
  * Creates a binary `Channel` backed by a WebSocket URL, requiring a
775
1117
  * `WebSocketConstructor` service.
@@ -780,7 +1122,9 @@ export const fromWebSocket = <RO>(
780
1122
  export const makeWebSocketChannel = <IE = never>(
781
1123
  url: string,
782
1124
  options?: {
783
- readonly closeCodeIsError?: (code: number) => boolean
1125
+ readonly openTimeout?: Duration.Input | undefined
1126
+ readonly protocols?: string | Array<string> | undefined
1127
+ readonly highWaterMark?: number | undefined
784
1128
  }
785
1129
  ): Channel.Channel<
786
1130
  NonEmptyReadonlyArray<Uint8Array>,
@@ -805,22 +1149,12 @@ export const makeWebSocketChannel = <IE = never>(
805
1149
  export const layerWebSocket: (
806
1150
  url: string | Effect.Effect<string>,
807
1151
  options?: {
808
- readonly closeCodeIsError?: ((code: number) => boolean) | undefined
809
1152
  readonly openTimeout?: Duration.Input | undefined
810
1153
  readonly protocols?: string | Array<string> | undefined
1154
+ readonly highWaterMark?: number | undefined
811
1155
  } | undefined
812
1156
  ) => Layer.Layer<Socket, never, WebSocketConstructor> = flow(makeWebSocket, Layer.effect(Socket))
813
1157
 
814
- /**
815
- * Context reference for socket send queue capacity, defaulting to `16`.
816
- *
817
- * @category services
818
- * @since 4.0.0
819
- */
820
- export const SendQueueCapacity = Context.Reference<number>("~effect/socket/Socket/SendQueueCapacity", {
821
- defaultValue: () => 16
822
- })
823
-
824
1158
  /**
825
1159
  * Readable and writable stream pair used to adapt transform-style streams into
826
1160
  * a `Socket`.
@@ -834,75 +1168,23 @@ export interface InputTransformStream {
834
1168
  }
835
1169
 
836
1170
  /**
837
- * Builds a `Socket` from a scoped `InputTransformStream`, reading incoming
838
- * chunks through socket handlers and writing outgoing chunks to the writable
839
- * stream, encoding strings as UTF-8 and using close-code classification for
840
- * `CloseEvent` values.
1171
+ * Builds a `Socket` from a scoped `InputTransformStream`, pulling incoming
1172
+ * chunks from the readable side and writing outgoing chunks to the writable
1173
+ * stream, encoding strings as UTF-8.
841
1174
  *
842
1175
  * @category constructors
843
1176
  * @since 4.0.0
844
1177
  */
845
- export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStream, SocketError, R>, options?: {
846
- readonly closeCodeIsError?: (code: number) => boolean
847
- }): Effect.Effect<Socket, never, Exclude<R, Scope.Scope>> =>
1178
+ export const fromTransformStream = <R>(
1179
+ acquire: Effect.Effect<InputTransformStream, SocketError, R>
1180
+ ): Effect.Effect<Socket, never, Exclude<R, Scope.Scope>> =>
848
1181
  Effect.withFiber((fiber) => {
849
1182
  const latch = Latch.makeUnsafe(false)
850
1183
  let currentStream: {
851
1184
  readonly stream: InputTransformStream
852
- readonly fiberSet: FiberSet.FiberSet<any, any>
1185
+ readonly fail: (error: SocketError) => void
853
1186
  } | undefined
854
- const acquireServices = fiber.context as Context.Context<R>
855
- const closeCodeIsError = options?.closeCodeIsError ?? defaultCloseCodeIsError
856
- const runRaw = <_, E, R>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void, opts?: {
857
- readonly onOpen?: Effect.Effect<void> | undefined
858
- }) =>
859
- Effect.scopedWith(Effect.fnUntraced(function*(scope) {
860
- const stream = yield* Scope.provide(acquire, scope)
861
- const reader = stream.readable.getReader()
862
- yield* Scope.addFinalizer(scope, Effect.promise(() => reader.cancel()))
863
- const fiberSet = yield* FiberSet.make<any, E | SocketError>().pipe(
864
- Scope.provide(scope)
865
- )
866
- const runFork = yield* FiberSet.runtime(fiberSet)<R>()
867
-
868
- yield* Effect.tryPromise({
869
- try: async () => {
870
- while (true) {
871
- const { done, value } = await reader.read()
872
- if (done) {
873
- throw new SocketError({ reason: new SocketCloseError({ code: 1000 }) })
874
- }
875
- const result = handler(value)
876
- if (Effect.isEffect(result)) {
877
- runFork(result)
878
- }
879
- }
880
- },
881
- catch: (cause) =>
882
- isSocketError(cause) ? cause : new SocketError({
883
- reason: new SocketReadError({ cause })
884
- })
885
- }).pipe(
886
- FiberSet.run(fiberSet)
887
- )
888
-
889
- currentStream = { stream, fiberSet }
890
- yield* latch.open
891
- if (opts?.onOpen) yield* opts.onOpen
892
-
893
- return yield* Effect.catchFilter(
894
- FiberSet.join(fiberSet),
895
- SocketCloseError.filterClean((_) => !closeCodeIsError(_)),
896
- () => Effect.void
897
- )
898
- })).pipe(
899
- (_) => _,
900
- Effect.updateContext((input: Context.Context<R>) => Context.merge(acquireServices, input)),
901
- Effect.ensuring(Effect.sync(() => {
902
- latch.closeUnsafe()
903
- currentStream = undefined
904
- }))
905
- )
1187
+ const acquireContext = fiber.context as Context.Context<R>
906
1188
 
907
1189
  const writers = new WeakMap<InputTransformStream, WritableStreamDefaultWriter<Uint8Array>>()
908
1190
  const getWriter = (stream: InputTransformStream) => {
@@ -913,33 +1195,82 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
913
1195
  }
914
1196
  return writer
915
1197
  }
1198
+
1199
+ const reader: Socket["reader"] = Effect.gen(function*() {
1200
+ const scope = yield* Effect.scope
1201
+ const stream = yield* Scope.provide(acquire, scope)
1202
+ const readerHandle = (stream.readable as ReadableStream<Uint8Array | string>).getReader()
1203
+ let error: SocketError | undefined
1204
+ yield* Scope.addFinalizer(
1205
+ scope,
1206
+ Effect.suspend(() => {
1207
+ latch.closeUnsafe()
1208
+ currentStream = undefined
1209
+ return Effect.promise(() => readerHandle.cancel().catch(constVoid))
1210
+ })
1211
+ )
1212
+ currentStream = {
1213
+ stream,
1214
+ fail(err) {
1215
+ if (error === undefined) error = err
1216
+ readerHandle.cancel().catch(constVoid)
1217
+ }
1218
+ }
1219
+ latch.openUnsafe()
1220
+
1221
+ const read = Effect.tryPromise({
1222
+ try: () => readerHandle.read(),
1223
+ catch: (cause) =>
1224
+ error ?? new SocketError({
1225
+ reason: new SocketReadError({ cause })
1226
+ })
1227
+ })
1228
+ return {
1229
+ pull: Effect.suspend(() => {
1230
+ if (error !== undefined) return Effect.fail(error)
1231
+ return Effect.flatMap(read, ({ done, value }) =>
1232
+ done
1233
+ ? Effect.fail(error ?? closeError(1000))
1234
+ : Effect.succeed([value] as unknown as NonEmptyReadonlyArray<Uint8Array | string>))
1235
+ }),
1236
+ upgrade: SocketUpgradeError.unsupported
1237
+ }
1238
+ }).pipe(
1239
+ Effect.updateContext((input: Context.Context<Scope.Scope>) => Context.merge(acquireContext, input))
1240
+ ) as Socket["reader"]
1241
+
916
1242
  const write = (chunk: Uint8Array | string | CloseEvent) =>
917
1243
  latch.whenOpen(Effect.suspend(() => {
918
- const { fiberSet, stream } = currentStream!
1244
+ const current = currentStream!
919
1245
  if (isCloseEvent(chunk)) {
920
- return Deferred.fail(
921
- fiberSet.deferred,
922
- new SocketError({
923
- reason: new SocketCloseError({ code: chunk.code, closeReason: chunk.reason })
924
- })
925
- )
1246
+ return Effect.sync(() => {
1247
+ current.fail(closeError(chunk.code, chunk.reason))
1248
+ })
926
1249
  }
927
1250
  return Effect.tryPromise({
928
- try: () => getWriter(stream).write(typeof chunk === "string" ? encoder.encode(chunk) : chunk),
1251
+ try: () => getWriter(current.stream).write(typeof chunk === "string" ? encoder.encode(chunk) : chunk),
929
1252
  catch: (cause) => new SocketError({ reason: new SocketWriteError({ cause }) })
930
1253
  })
931
1254
  }))
932
- const writer = Effect.acquireRelease(
933
- Effect.succeed(write),
1255
+ const writeAll = (chunks: NonEmptyReadonlyArray<Uint8Array | string>) =>
1256
+ latch.whenOpen(Effect.tryPromise({
1257
+ try: async () => {
1258
+ const writer = getWriter(currentStream!.stream)
1259
+ for (let i = 0; i < chunks.length; i++) {
1260
+ const chunk = chunks[i]
1261
+ await writer.write(typeof chunk === "string" ? encoder.encode(chunk) : chunk)
1262
+ }
1263
+ },
1264
+ catch: (cause) => new SocketError({ reason: new SocketWriteError({ cause }) })
1265
+ }))
1266
+ const writer: Socket["writer"] = Effect.acquireRelease(
1267
+ Effect.succeed({ write, writeAll }),
934
1268
  () =>
935
1269
  Effect.promise(async () => {
936
1270
  if (!currentStream) return
937
- await getWriter(currentStream.stream).close()
1271
+ await getWriter(currentStream.stream).close().catch(constVoid)
938
1272
  })
939
1273
  )
940
1274
 
941
- return Effect.succeed(make({
942
- runRaw,
943
- writer
944
- }))
1275
+ return Effect.succeed(make({ reader, writer }))
945
1276
  })