effect 4.0.0-beta.3 → 4.0.0-beta.31

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 (1008) hide show
  1. package/dist/Array.d.ts +126 -299
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +102 -62
  4. package/dist/Array.js.map +1 -1
  5. package/dist/Brand.d.ts +1 -1
  6. package/dist/Brand.d.ts.map +1 -1
  7. package/dist/Brand.js +1 -1
  8. package/dist/Brand.js.map +1 -1
  9. package/dist/Cache.d.ts +2 -2
  10. package/dist/Cache.d.ts.map +1 -1
  11. package/dist/Cache.js +6 -5
  12. package/dist/Cache.js.map +1 -1
  13. package/dist/Cause.d.ts +2 -2
  14. package/dist/Cause.d.ts.map +1 -1
  15. package/dist/Channel.d.ts +118 -32
  16. package/dist/Channel.d.ts.map +1 -1
  17. package/dist/Channel.js +82 -37
  18. package/dist/Channel.js.map +1 -1
  19. package/dist/Chunk.d.ts +54 -247
  20. package/dist/Chunk.d.ts.map +1 -1
  21. package/dist/Chunk.js +36 -67
  22. package/dist/Chunk.js.map +1 -1
  23. package/dist/Combiner.d.ts +280 -13
  24. package/dist/Combiner.d.ts.map +1 -1
  25. package/dist/Combiner.js +198 -7
  26. package/dist/Combiner.js.map +1 -1
  27. package/dist/Config.d.ts +165 -9
  28. package/dist/Config.d.ts.map +1 -1
  29. package/dist/Config.js +65 -10
  30. package/dist/Config.js.map +1 -1
  31. package/dist/ConfigProvider.d.ts +1 -1
  32. package/dist/Cron.d.ts +1 -1
  33. package/dist/Cron.js +3 -3
  34. package/dist/Cron.js.map +1 -1
  35. package/dist/Data.d.ts +535 -366
  36. package/dist/Data.d.ts.map +1 -1
  37. package/dist/Data.js +132 -79
  38. package/dist/Data.js.map +1 -1
  39. package/dist/DateTime.d.ts +56 -238
  40. package/dist/DateTime.d.ts.map +1 -1
  41. package/dist/DateTime.js +7 -52
  42. package/dist/DateTime.js.map +1 -1
  43. package/dist/Duration.d.ts +39 -11
  44. package/dist/Duration.d.ts.map +1 -1
  45. package/dist/Duration.js +88 -59
  46. package/dist/Duration.js.map +1 -1
  47. package/dist/Effect.d.ts +1206 -924
  48. package/dist/Effect.d.ts.map +1 -1
  49. package/dist/Effect.js +390 -329
  50. package/dist/Effect.js.map +1 -1
  51. package/dist/Encoding.d.ts +194 -0
  52. package/dist/Encoding.d.ts.map +1 -0
  53. package/dist/Encoding.js +352 -0
  54. package/dist/Encoding.js.map +1 -0
  55. package/dist/Equal.d.ts +276 -109
  56. package/dist/Equal.d.ts.map +1 -1
  57. package/dist/Equal.js +124 -48
  58. package/dist/Equal.js.map +1 -1
  59. package/dist/ErrorReporter.d.ts +374 -0
  60. package/dist/ErrorReporter.d.ts.map +1 -0
  61. package/dist/ErrorReporter.js +244 -0
  62. package/dist/ErrorReporter.js.map +1 -0
  63. package/dist/Exit.d.ts +24 -12
  64. package/dist/Exit.d.ts.map +1 -1
  65. package/dist/Exit.js +8 -4
  66. package/dist/Exit.js.map +1 -1
  67. package/dist/Fiber.d.ts +3 -2
  68. package/dist/Fiber.d.ts.map +1 -1
  69. package/dist/Fiber.js.map +1 -1
  70. package/dist/FileSystem.d.ts +1 -1
  71. package/dist/FileSystem.d.ts.map +1 -1
  72. package/dist/FileSystem.js +5 -5
  73. package/dist/FileSystem.js.map +1 -1
  74. package/dist/Filter.d.ts +34 -38
  75. package/dist/Filter.d.ts.map +1 -1
  76. package/dist/Filter.js +15 -13
  77. package/dist/Filter.js.map +1 -1
  78. package/dist/Formatter.d.ts +131 -47
  79. package/dist/Formatter.d.ts.map +1 -1
  80. package/dist/Formatter.js +229 -51
  81. package/dist/Formatter.js.map +1 -1
  82. package/dist/Function.d.ts +1 -9
  83. package/dist/Function.d.ts.map +1 -1
  84. package/dist/Function.js +2 -10
  85. package/dist/Function.js.map +1 -1
  86. package/dist/Graph.d.ts +1 -1
  87. package/dist/Graph.d.ts.map +1 -1
  88. package/dist/Graph.js +5 -8
  89. package/dist/Graph.js.map +1 -1
  90. package/dist/HashMap.d.ts +15 -14
  91. package/dist/HashMap.d.ts.map +1 -1
  92. package/dist/HashMap.js +4 -4
  93. package/dist/HashMap.js.map +1 -1
  94. package/dist/Iterable.d.ts +39 -39
  95. package/dist/Iterable.d.ts.map +1 -1
  96. package/dist/Iterable.js +94 -22
  97. package/dist/Iterable.js.map +1 -1
  98. package/dist/JsonSchema.d.ts +299 -10
  99. package/dist/JsonSchema.d.ts.map +1 -1
  100. package/dist/JsonSchema.js +323 -4
  101. package/dist/JsonSchema.js.map +1 -1
  102. package/dist/Latch.d.ts +109 -0
  103. package/dist/Latch.d.ts.map +1 -0
  104. package/dist/Latch.js +72 -0
  105. package/dist/Latch.js.map +1 -0
  106. package/dist/Layer.d.ts +217 -127
  107. package/dist/Layer.d.ts.map +1 -1
  108. package/dist/Layer.js +51 -46
  109. package/dist/Layer.js.map +1 -1
  110. package/dist/LayerMap.d.ts +8 -8
  111. package/dist/LayerMap.d.ts.map +1 -1
  112. package/dist/LayerMap.js +3 -3
  113. package/dist/LogLevel.d.ts +32 -0
  114. package/dist/LogLevel.d.ts.map +1 -1
  115. package/dist/LogLevel.js +28 -100
  116. package/dist/LogLevel.js.map +1 -1
  117. package/dist/Logger.d.ts +29 -95
  118. package/dist/Logger.d.ts.map +1 -1
  119. package/dist/Logger.js +2 -3
  120. package/dist/Logger.js.map +1 -1
  121. package/dist/ManagedRuntime.d.ts +2 -2
  122. package/dist/ManagedRuntime.js +2 -2
  123. package/dist/Metric.d.ts +4 -6
  124. package/dist/Metric.d.ts.map +1 -1
  125. package/dist/Metric.js +3 -5
  126. package/dist/Metric.js.map +1 -1
  127. package/dist/Newtype.d.ts +291 -0
  128. package/dist/Newtype.d.ts.map +1 -0
  129. package/dist/Newtype.js +161 -0
  130. package/dist/Newtype.js.map +1 -0
  131. package/dist/Optic.d.ts +947 -18
  132. package/dist/Optic.d.ts.map +1 -1
  133. package/dist/Optic.js +454 -5
  134. package/dist/Optic.js.map +1 -1
  135. package/dist/Option.d.ts +23 -16
  136. package/dist/Option.d.ts.map +1 -1
  137. package/dist/Option.js +15 -9
  138. package/dist/Option.js.map +1 -1
  139. package/dist/Pipeable.d.ts +17 -0
  140. package/dist/Pipeable.d.ts.map +1 -1
  141. package/dist/Pipeable.js +19 -1
  142. package/dist/Pipeable.js.map +1 -1
  143. package/dist/PlatformError.d.ts +10 -9
  144. package/dist/PlatformError.d.ts.map +1 -1
  145. package/dist/PlatformError.js +2 -2
  146. package/dist/PlatformError.js.map +1 -1
  147. package/dist/Pool.d.ts +6 -4
  148. package/dist/Pool.d.ts.map +1 -1
  149. package/dist/Pool.js +7 -5
  150. package/dist/Pool.js.map +1 -1
  151. package/dist/PubSub.d.ts +3 -2
  152. package/dist/PubSub.d.ts.map +1 -1
  153. package/dist/PubSub.js +3 -2
  154. package/dist/PubSub.js.map +1 -1
  155. package/dist/Pull.d.ts.map +1 -1
  156. package/dist/Pull.js +1 -1
  157. package/dist/Pull.js.map +1 -1
  158. package/dist/Queue.d.ts.map +1 -1
  159. package/dist/Queue.js +0 -1
  160. package/dist/Queue.js.map +1 -1
  161. package/dist/Random.d.ts +35 -1
  162. package/dist/Random.d.ts.map +1 -1
  163. package/dist/Random.js +46 -12
  164. package/dist/Random.js.map +1 -1
  165. package/dist/RcMap.d.ts +2 -2
  166. package/dist/RcMap.d.ts.map +1 -1
  167. package/dist/RcMap.js +1 -1
  168. package/dist/RcMap.js.map +1 -1
  169. package/dist/RcRef.d.ts +1 -1
  170. package/dist/RcRef.d.ts.map +1 -1
  171. package/dist/Record.d.ts +23 -120
  172. package/dist/Record.d.ts.map +1 -1
  173. package/dist/Record.js +21 -41
  174. package/dist/Record.js.map +1 -1
  175. package/dist/Reducer.d.ts +166 -7
  176. package/dist/Reducer.d.ts.map +1 -1
  177. package/dist/Reducer.js +135 -1
  178. package/dist/Reducer.js.map +1 -1
  179. package/dist/References.d.ts +9 -4
  180. package/dist/References.d.ts.map +1 -1
  181. package/dist/References.js +6 -1
  182. package/dist/References.js.map +1 -1
  183. package/dist/Request.d.ts +1 -1
  184. package/dist/Request.d.ts.map +1 -1
  185. package/dist/Request.js +2 -1
  186. package/dist/Request.js.map +1 -1
  187. package/dist/RequestResolver.d.ts +25 -45
  188. package/dist/RequestResolver.d.ts.map +1 -1
  189. package/dist/RequestResolver.js +10 -30
  190. package/dist/RequestResolver.js.map +1 -1
  191. package/dist/Result.d.ts +1 -1
  192. package/dist/Result.d.ts.map +1 -1
  193. package/dist/Result.js +1 -2
  194. package/dist/Result.js.map +1 -1
  195. package/dist/Runtime.d.ts +66 -0
  196. package/dist/Runtime.d.ts.map +1 -1
  197. package/dist/Runtime.js +79 -6
  198. package/dist/Runtime.js.map +1 -1
  199. package/dist/Schedule.d.ts +191 -102
  200. package/dist/Schedule.d.ts.map +1 -1
  201. package/dist/Schedule.js +152 -66
  202. package/dist/Schedule.js.map +1 -1
  203. package/dist/Scheduler.d.ts +9 -0
  204. package/dist/Scheduler.d.ts.map +1 -1
  205. package/dist/Scheduler.js +11 -0
  206. package/dist/Scheduler.js.map +1 -1
  207. package/dist/Schema.d.ts +2647 -224
  208. package/dist/Schema.d.ts.map +1 -1
  209. package/dist/Schema.js +1863 -209
  210. package/dist/Schema.js.map +1 -1
  211. package/dist/SchemaAST.d.ts +2 -2
  212. package/dist/SchemaAST.d.ts.map +1 -1
  213. package/dist/SchemaAST.js +131 -25
  214. package/dist/SchemaAST.js.map +1 -1
  215. package/dist/SchemaGetter.d.ts +5 -5
  216. package/dist/SchemaGetter.d.ts.map +1 -1
  217. package/dist/SchemaGetter.js +12 -14
  218. package/dist/SchemaGetter.js.map +1 -1
  219. package/dist/SchemaParser.d.ts +5 -0
  220. package/dist/SchemaParser.d.ts.map +1 -1
  221. package/dist/SchemaParser.js +10 -0
  222. package/dist/SchemaParser.js.map +1 -1
  223. package/dist/SchemaRepresentation.d.ts +46 -45
  224. package/dist/SchemaRepresentation.d.ts.map +1 -1
  225. package/dist/SchemaRepresentation.js +49 -24
  226. package/dist/SchemaRepresentation.js.map +1 -1
  227. package/dist/SchemaTransformation.d.ts +107 -3
  228. package/dist/SchemaTransformation.d.ts.map +1 -1
  229. package/dist/SchemaTransformation.js +159 -4
  230. package/dist/SchemaTransformation.js.map +1 -1
  231. package/dist/ScopedCache.d.ts +2 -2
  232. package/dist/ScopedCache.d.ts.map +1 -1
  233. package/dist/ScopedCache.js +1 -1
  234. package/dist/ScopedCache.js.map +1 -1
  235. package/dist/Semaphore.d.ts +211 -0
  236. package/dist/Semaphore.d.ts.map +1 -0
  237. package/dist/{PartitionedSemaphore.js → Semaphore.js} +97 -13
  238. package/dist/Semaphore.js.map +1 -0
  239. package/dist/ServiceMap.d.ts +41 -31
  240. package/dist/ServiceMap.d.ts.map +1 -1
  241. package/dist/ServiceMap.js +3 -3
  242. package/dist/ServiceMap.js.map +1 -1
  243. package/dist/Sink.d.ts +13 -13
  244. package/dist/Sink.d.ts.map +1 -1
  245. package/dist/Sink.js +53 -6
  246. package/dist/Sink.js.map +1 -1
  247. package/dist/Stdio.d.ts +16 -4
  248. package/dist/Stdio.d.ts.map +1 -1
  249. package/dist/Stdio.js +18 -0
  250. package/dist/Stdio.js.map +1 -1
  251. package/dist/Stream.d.ts +250 -428
  252. package/dist/Stream.d.ts.map +1 -1
  253. package/dist/Stream.js +137 -82
  254. package/dist/Stream.js.map +1 -1
  255. package/dist/Struct.d.ts +16 -0
  256. package/dist/Struct.d.ts.map +1 -1
  257. package/dist/Struct.js +22 -0
  258. package/dist/Struct.js.map +1 -1
  259. package/dist/SubscriptionRef.d.ts +2 -1
  260. package/dist/SubscriptionRef.d.ts.map +1 -1
  261. package/dist/SubscriptionRef.js +2 -1
  262. package/dist/SubscriptionRef.js.map +1 -1
  263. package/dist/SynchronizedRef.d.ts +2 -1
  264. package/dist/SynchronizedRef.d.ts.map +1 -1
  265. package/dist/SynchronizedRef.js +2 -1
  266. package/dist/SynchronizedRef.js.map +1 -1
  267. package/dist/Trie.d.ts +18 -17
  268. package/dist/Trie.d.ts.map +1 -1
  269. package/dist/Trie.js +5 -5
  270. package/dist/Trie.js.map +1 -1
  271. package/dist/TxChunk.d.ts +37 -37
  272. package/dist/TxChunk.d.ts.map +1 -1
  273. package/dist/TxChunk.js +3 -3
  274. package/dist/TxChunk.js.map +1 -1
  275. package/dist/TxDeferred.d.ts +328 -0
  276. package/dist/TxDeferred.d.ts.map +1 -0
  277. package/dist/TxDeferred.js +196 -0
  278. package/dist/TxDeferred.js.map +1 -0
  279. package/dist/TxHashMap.d.ts +84 -83
  280. package/dist/TxHashMap.d.ts.map +1 -1
  281. package/dist/TxHashMap.js +24 -24
  282. package/dist/TxHashMap.js.map +1 -1
  283. package/dist/TxHashSet.d.ts +35 -35
  284. package/dist/TxHashSet.d.ts.map +1 -1
  285. package/dist/TxHashSet.js +14 -14
  286. package/dist/TxHashSet.js.map +1 -1
  287. package/dist/TxPriorityQueue.d.ts +609 -0
  288. package/dist/TxPriorityQueue.d.ts.map +1 -0
  289. package/dist/TxPriorityQueue.js +415 -0
  290. package/dist/TxPriorityQueue.js.map +1 -0
  291. package/dist/TxPubSub.d.ts +585 -0
  292. package/dist/TxPubSub.d.ts.map +1 -0
  293. package/dist/TxPubSub.js +521 -0
  294. package/dist/TxPubSub.js.map +1 -0
  295. package/dist/TxQueue.d.ts +32 -32
  296. package/dist/TxQueue.d.ts.map +1 -1
  297. package/dist/TxQueue.js +26 -26
  298. package/dist/TxQueue.js.map +1 -1
  299. package/dist/TxReentrantLock.d.ts +523 -0
  300. package/dist/TxReentrantLock.d.ts.map +1 -0
  301. package/dist/TxReentrantLock.js +504 -0
  302. package/dist/TxReentrantLock.js.map +1 -0
  303. package/dist/TxRef.d.ts +34 -34
  304. package/dist/TxRef.d.ts.map +1 -1
  305. package/dist/TxRef.js +21 -14
  306. package/dist/TxRef.js.map +1 -1
  307. package/dist/TxSemaphore.d.ts +8 -8
  308. package/dist/TxSemaphore.d.ts.map +1 -1
  309. package/dist/TxSemaphore.js +7 -7
  310. package/dist/TxSemaphore.js.map +1 -1
  311. package/dist/TxSubscriptionRef.d.ts +508 -0
  312. package/dist/TxSubscriptionRef.d.ts.map +1 -0
  313. package/dist/TxSubscriptionRef.js +293 -0
  314. package/dist/TxSubscriptionRef.js.map +1 -0
  315. package/dist/Types.d.ts +80 -23
  316. package/dist/Types.d.ts.map +1 -1
  317. package/dist/Utils.d.ts +137 -65
  318. package/dist/Utils.d.ts.map +1 -1
  319. package/dist/Utils.js +38 -66
  320. package/dist/Utils.js.map +1 -1
  321. package/dist/index.d.ts +718 -23
  322. package/dist/index.d.ts.map +1 -1
  323. package/dist/index.js +718 -23
  324. package/dist/index.js.map +1 -1
  325. package/dist/internal/core.js +11 -3
  326. package/dist/internal/core.js.map +1 -1
  327. package/dist/internal/dateTime.js +60 -61
  328. package/dist/internal/dateTime.js.map +1 -1
  329. package/dist/internal/effect.js +265 -127
  330. package/dist/internal/effect.js.map +1 -1
  331. package/dist/internal/hashMap.js +5 -4
  332. package/dist/internal/hashMap.js.map +1 -1
  333. package/dist/internal/random.d.ts +2 -0
  334. package/dist/internal/random.d.ts.map +1 -0
  335. package/dist/internal/random.js +13 -0
  336. package/dist/internal/random.js.map +1 -0
  337. package/dist/internal/rcRef.js +3 -2
  338. package/dist/internal/rcRef.js.map +1 -1
  339. package/dist/internal/request.js +2 -2
  340. package/dist/internal/request.js.map +1 -1
  341. package/dist/internal/schema/annotations.js +2 -0
  342. package/dist/internal/schema/annotations.js.map +1 -1
  343. package/dist/internal/schema/representation.js +47 -106
  344. package/dist/internal/schema/representation.js.map +1 -1
  345. package/dist/internal/schema/schema.js +1 -0
  346. package/dist/internal/schema/schema.js.map +1 -1
  347. package/dist/internal/schema/to-codec.js +7 -10
  348. package/dist/internal/schema/to-codec.js.map +1 -1
  349. package/dist/internal/trie.js +5 -4
  350. package/dist/internal/trie.js.map +1 -1
  351. package/dist/testing/TestClock.d.ts +8 -7
  352. package/dist/testing/TestClock.d.ts.map +1 -1
  353. package/dist/testing/TestClock.js +6 -4
  354. package/dist/testing/TestClock.js.map +1 -1
  355. package/dist/testing/TestSchema.d.ts +266 -32
  356. package/dist/testing/TestSchema.d.ts.map +1 -1
  357. package/dist/testing/TestSchema.js +296 -23
  358. package/dist/testing/TestSchema.js.map +1 -1
  359. package/dist/testing/index.d.ts +64 -1
  360. package/dist/testing/index.d.ts.map +1 -1
  361. package/dist/testing/index.js +64 -1
  362. package/dist/testing/index.js.map +1 -1
  363. package/dist/unstable/ai/AiError.d.ts +134 -51
  364. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  365. package/dist/unstable/ai/AiError.js +19 -16
  366. package/dist/unstable/ai/AiError.js.map +1 -1
  367. package/dist/unstable/ai/Chat.d.ts +7 -8
  368. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  369. package/dist/unstable/ai/Chat.js +38 -44
  370. package/dist/unstable/ai/Chat.js.map +1 -1
  371. package/dist/unstable/ai/LanguageModel.d.ts +45 -45
  372. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  373. package/dist/unstable/ai/LanguageModel.js +107 -124
  374. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  375. package/dist/unstable/ai/McpSchema.d.ts +183 -88
  376. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  377. package/dist/unstable/ai/McpSchema.js +57 -12
  378. package/dist/unstable/ai/McpSchema.js.map +1 -1
  379. package/dist/unstable/ai/McpServer.d.ts +66 -13
  380. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  381. package/dist/unstable/ai/McpServer.js +193 -51
  382. package/dist/unstable/ai/McpServer.js.map +1 -1
  383. package/dist/unstable/ai/Model.d.ts +25 -7
  384. package/dist/unstable/ai/Model.d.ts.map +1 -1
  385. package/dist/unstable/ai/Model.js +22 -6
  386. package/dist/unstable/ai/Model.js.map +1 -1
  387. package/dist/unstable/ai/Prompt.d.ts +20 -20
  388. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  389. package/dist/unstable/ai/Response.d.ts +26 -26
  390. package/dist/unstable/ai/Response.d.ts.map +1 -1
  391. package/dist/unstable/ai/Response.js +1 -1
  392. package/dist/unstable/ai/Response.js.map +1 -1
  393. package/dist/unstable/ai/Tool.d.ts +20 -4
  394. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  395. package/dist/unstable/ai/Tool.js +14 -9
  396. package/dist/unstable/ai/Tool.js.map +1 -1
  397. package/dist/unstable/ai/Toolkit.d.ts +1 -1
  398. package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
  399. package/dist/unstable/ai/Toolkit.js +4 -11
  400. package/dist/unstable/ai/Toolkit.js.map +1 -1
  401. package/dist/unstable/ai/index.d.ts +1 -1
  402. package/dist/unstable/ai/index.js +1 -1
  403. package/dist/unstable/ai/internal/codec-transformer.js +0 -5
  404. package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
  405. package/dist/unstable/cli/CliError.d.ts +27 -60
  406. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  407. package/dist/unstable/cli/CliError.js +25 -57
  408. package/dist/unstable/cli/CliError.js.map +1 -1
  409. package/dist/unstable/cli/CliOutput.js +59 -6
  410. package/dist/unstable/cli/CliOutput.js.map +1 -1
  411. package/dist/unstable/cli/Command.d.ts +368 -56
  412. package/dist/unstable/cli/Command.d.ts.map +1 -1
  413. package/dist/unstable/cli/Command.js +325 -64
  414. package/dist/unstable/cli/Command.js.map +1 -1
  415. package/dist/unstable/cli/Completions.d.ts +16 -0
  416. package/dist/unstable/cli/Completions.d.ts.map +1 -0
  417. package/dist/unstable/cli/Completions.js +23 -0
  418. package/dist/unstable/cli/Completions.js.map +1 -0
  419. package/dist/unstable/cli/GlobalFlag.d.ts +125 -0
  420. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -0
  421. package/dist/unstable/cli/GlobalFlag.js +118 -0
  422. package/dist/unstable/cli/GlobalFlag.js.map +1 -0
  423. package/dist/unstable/cli/HelpDoc.d.ts +70 -2
  424. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  425. package/dist/unstable/cli/Primitive.d.ts +1 -1
  426. package/dist/unstable/cli/Primitive.js +1 -1
  427. package/dist/unstable/cli/Prompt.js +35 -8
  428. package/dist/unstable/cli/Prompt.js.map +1 -1
  429. package/dist/unstable/cli/index.d.ts +8 -0
  430. package/dist/unstable/cli/index.d.ts.map +1 -1
  431. package/dist/unstable/cli/index.js +8 -0
  432. package/dist/unstable/cli/index.js.map +1 -1
  433. package/dist/unstable/cli/internal/command.d.ts +40 -14
  434. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  435. package/dist/unstable/cli/internal/command.js +72 -46
  436. package/dist/unstable/cli/internal/command.js.map +1 -1
  437. package/dist/unstable/cli/internal/completions/CommandDescriptor.js +7 -2
  438. package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
  439. package/dist/unstable/cli/internal/config.js +42 -0
  440. package/dist/unstable/cli/internal/config.js.map +1 -1
  441. package/dist/unstable/cli/internal/help.d.ts +33 -0
  442. package/dist/unstable/cli/internal/help.d.ts.map +1 -0
  443. package/dist/unstable/cli/internal/help.js +125 -0
  444. package/dist/unstable/cli/internal/help.js.map +1 -0
  445. package/dist/unstable/cli/internal/parser.js +55 -42
  446. package/dist/unstable/cli/internal/parser.js.map +1 -1
  447. package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
  448. package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
  449. package/dist/unstable/cluster/ClusterCron.js +1 -1
  450. package/dist/unstable/cluster/ClusterCron.js.map +1 -1
  451. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  452. package/dist/unstable/cluster/ClusterWorkflowEngine.js +5 -4
  453. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  454. package/dist/unstable/cluster/DeliverAt.js +1 -1
  455. package/dist/unstable/cluster/DeliverAt.js.map +1 -1
  456. package/dist/unstable/cluster/Entity.d.ts +7 -6
  457. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  458. package/dist/unstable/cluster/Entity.js.map +1 -1
  459. package/dist/unstable/cluster/EntityResource.d.ts +2 -2
  460. package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
  461. package/dist/unstable/cluster/Envelope.d.ts +1 -1
  462. package/dist/unstable/cluster/K8sHttpClient.d.ts +1 -1
  463. package/dist/unstable/cluster/K8sHttpClient.js +4 -4
  464. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  465. package/dist/unstable/cluster/Message.d.ts +10 -10
  466. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  467. package/dist/unstable/cluster/MessageStorage.js +2 -1
  468. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  469. package/dist/unstable/cluster/Reply.d.ts +6 -6
  470. package/dist/unstable/cluster/Runner.d.ts +1 -1
  471. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  472. package/dist/unstable/cluster/Runners.js +4 -3
  473. package/dist/unstable/cluster/Runners.js.map +1 -1
  474. package/dist/unstable/cluster/Sharding.d.ts +2 -2
  475. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  476. package/dist/unstable/cluster/Sharding.js +9 -7
  477. package/dist/unstable/cluster/Sharding.js.map +1 -1
  478. package/dist/unstable/cluster/ShardingConfig.d.ts +21 -21
  479. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  480. package/dist/unstable/cluster/ShardingConfig.js +20 -20
  481. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  482. package/dist/unstable/cluster/SqlRunnerStorage.js +1 -1
  483. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  484. package/dist/unstable/cluster/internal/entityManager.js +5 -4
  485. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  486. package/dist/unstable/cluster/internal/entityReaper.js +2 -1
  487. package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
  488. package/dist/unstable/cluster/internal/resourceRef.js +2 -1
  489. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  490. package/dist/unstable/devtools/DevToolsSchema.d.ts +36 -36
  491. package/dist/unstable/encoding/Msgpack.d.ts +1 -1
  492. package/dist/unstable/encoding/Ndjson.d.ts +9 -9
  493. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  494. package/dist/unstable/encoding/Ndjson.js.map +1 -1
  495. package/dist/unstable/encoding/Sse.d.ts +4 -4
  496. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  497. package/dist/unstable/encoding/Sse.js +1 -1
  498. package/dist/unstable/encoding/Sse.js.map +1 -1
  499. package/dist/unstable/eventlog/EventJournal.d.ts +2 -2
  500. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  501. package/dist/unstable/eventlog/EventLog.js +2 -1
  502. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  503. package/dist/unstable/eventlog/EventLogRemote.d.ts +6 -6
  504. package/dist/unstable/http/Cookies.d.ts +47 -3
  505. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  506. package/dist/unstable/http/Cookies.js +24 -2
  507. package/dist/unstable/http/Cookies.js.map +1 -1
  508. package/dist/unstable/http/Headers.d.ts +16 -0
  509. package/dist/unstable/http/Headers.d.ts.map +1 -1
  510. package/dist/unstable/http/Headers.js +38 -10
  511. package/dist/unstable/http/Headers.js.map +1 -1
  512. package/dist/unstable/http/HttpBody.d.ts +3 -3
  513. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  514. package/dist/unstable/http/HttpBody.js +6 -6
  515. package/dist/unstable/http/HttpBody.js.map +1 -1
  516. package/dist/unstable/http/HttpClient.d.ts +117 -15
  517. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  518. package/dist/unstable/http/HttpClient.js +189 -12
  519. package/dist/unstable/http/HttpClient.js.map +1 -1
  520. package/dist/unstable/http/HttpClientError.d.ts +7 -7
  521. package/dist/unstable/http/HttpClientRequest.d.ts +16 -11
  522. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  523. package/dist/unstable/http/HttpClientRequest.js +31 -20
  524. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  525. package/dist/unstable/http/HttpClientResponse.d.ts +2 -1
  526. package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
  527. package/dist/unstable/http/HttpClientResponse.js +4 -0
  528. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  529. package/dist/unstable/http/HttpEffect.d.ts +7 -5
  530. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  531. package/dist/unstable/http/HttpEffect.js +46 -54
  532. package/dist/unstable/http/HttpEffect.js.map +1 -1
  533. package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
  534. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  535. package/dist/unstable/http/HttpMethod.d.ts +4 -4
  536. package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
  537. package/dist/unstable/http/HttpMethod.js +3 -3
  538. package/dist/unstable/http/HttpMethod.js.map +1 -1
  539. package/dist/unstable/http/HttpMiddleware.d.ts +1 -6
  540. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  541. package/dist/unstable/http/HttpMiddleware.js +8 -17
  542. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  543. package/dist/unstable/http/HttpServerError.d.ts +20 -33
  544. package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
  545. package/dist/unstable/http/HttpServerError.js +37 -44
  546. package/dist/unstable/http/HttpServerError.js.map +1 -1
  547. package/dist/unstable/http/HttpServerRequest.d.ts +12 -1
  548. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  549. package/dist/unstable/http/HttpServerRequest.js +291 -1
  550. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  551. package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
  552. package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
  553. package/dist/unstable/http/HttpServerRespondable.js +5 -5
  554. package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
  555. package/dist/unstable/http/HttpServerResponse.d.ts +50 -3
  556. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  557. package/dist/unstable/http/HttpServerResponse.js +234 -1
  558. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  559. package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
  560. package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
  561. package/dist/unstable/http/HttpStaticServer.js +353 -0
  562. package/dist/unstable/http/HttpStaticServer.js.map +1 -0
  563. package/dist/unstable/http/Multipart.d.ts +3 -3
  564. package/dist/unstable/http/UrlParams.d.ts +14 -6
  565. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  566. package/dist/unstable/http/UrlParams.js +1 -1
  567. package/dist/unstable/http/UrlParams.js.map +1 -1
  568. package/dist/unstable/http/index.d.ts +4 -0
  569. package/dist/unstable/http/index.d.ts.map +1 -1
  570. package/dist/unstable/http/index.js +4 -0
  571. package/dist/unstable/http/index.js.map +1 -1
  572. package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
  573. package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
  574. package/dist/unstable/http/internal/preResponseHandler.js +10 -0
  575. package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
  576. package/dist/unstable/httpapi/HttpApi.d.ts +4 -4
  577. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  578. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  579. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +11 -5
  580. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  581. package/dist/unstable/httpapi/HttpApiBuilder.js +28 -18
  582. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  583. package/dist/unstable/httpapi/HttpApiClient.d.ts +66 -6
  584. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  585. package/dist/unstable/httpapi/HttpApiClient.js +40 -3
  586. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  587. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +41 -54
  588. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  589. package/dist/unstable/httpapi/HttpApiEndpoint.js +17 -26
  590. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  591. package/dist/unstable/httpapi/HttpApiError.d.ts +16 -14
  592. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  593. package/dist/unstable/httpapi/HttpApiError.js +44 -29
  594. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  595. package/dist/unstable/httpapi/HttpApiGroup.d.ts +4 -3
  596. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  597. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  598. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -4
  599. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  600. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  601. package/dist/unstable/httpapi/HttpApiScalar.d.ts +6 -0
  602. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  603. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  604. package/dist/unstable/httpapi/HttpApiSecurity.d.ts +2 -2
  605. package/dist/unstable/httpapi/HttpApiSecurity.d.ts.map +1 -1
  606. package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
  607. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  608. package/dist/unstable/httpapi/OpenApi.js +32 -21
  609. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  610. package/dist/unstable/observability/Otlp.d.ts +12 -12
  611. package/dist/unstable/observability/Otlp.d.ts.map +1 -1
  612. package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
  613. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  614. package/dist/unstable/observability/OtlpExporter.js +1 -1
  615. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  616. package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
  617. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  618. package/dist/unstable/observability/OtlpLogger.js +7 -4
  619. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  620. package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
  621. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  622. package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
  623. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  624. package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
  625. package/dist/unstable/persistence/KeyValueStore.js +6 -6
  626. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  627. package/dist/unstable/persistence/Persistable.d.ts +2 -2
  628. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  629. package/dist/unstable/persistence/Persistable.js +1 -1
  630. package/dist/unstable/persistence/Persistable.js.map +1 -1
  631. package/dist/unstable/persistence/PersistedCache.d.ts +6 -5
  632. package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
  633. package/dist/unstable/persistence/PersistedCache.js +2 -1
  634. package/dist/unstable/persistence/PersistedCache.js.map +1 -1
  635. package/dist/unstable/persistence/PersistedQueue.d.ts +12 -12
  636. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  637. package/dist/unstable/persistence/PersistedQueue.js +12 -11
  638. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  639. package/dist/unstable/persistence/Persistence.d.ts +1 -1
  640. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  641. package/dist/unstable/persistence/Persistence.js +2 -2
  642. package/dist/unstable/persistence/Persistence.js.map +1 -1
  643. package/dist/unstable/persistence/RateLimiter.d.ts +3 -3
  644. package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
  645. package/dist/unstable/persistence/RateLimiter.js +1 -1
  646. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  647. package/dist/unstable/process/ChildProcess.d.ts +5 -128
  648. package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
  649. package/dist/unstable/process/ChildProcess.js +1 -65
  650. package/dist/unstable/process/ChildProcess.js.map +1 -1
  651. package/dist/unstable/process/ChildProcessSpawner.d.ts +45 -7
  652. package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
  653. package/dist/unstable/process/ChildProcessSpawner.js +21 -1
  654. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  655. package/dist/unstable/reactivity/Atom.d.ts +73 -12
  656. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  657. package/dist/unstable/reactivity/Atom.js +107 -20
  658. package/dist/unstable/reactivity/Atom.js.map +1 -1
  659. package/dist/unstable/reactivity/AtomHttpApi.d.ts +10 -12
  660. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  661. package/dist/unstable/reactivity/AtomHttpApi.js +42 -12
  662. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  663. package/dist/unstable/reactivity/AtomRegistry.d.ts +6 -0
  664. package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
  665. package/dist/unstable/reactivity/AtomRegistry.js +50 -9
  666. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  667. package/dist/unstable/reactivity/AtomRpc.d.ts +9 -9
  668. package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
  669. package/dist/unstable/reactivity/AtomRpc.js +47 -21
  670. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  671. package/dist/unstable/reactivity/Hydration.d.ts +39 -0
  672. package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
  673. package/dist/unstable/reactivity/Hydration.js +76 -0
  674. package/dist/unstable/reactivity/Hydration.js.map +1 -0
  675. package/dist/unstable/reactivity/index.d.ts +4 -0
  676. package/dist/unstable/reactivity/index.d.ts.map +1 -1
  677. package/dist/unstable/reactivity/index.js +4 -0
  678. package/dist/unstable/reactivity/index.js.map +1 -1
  679. package/dist/unstable/rpc/Rpc.d.ts +5 -5
  680. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  681. package/dist/unstable/rpc/Rpc.js.map +1 -1
  682. package/dist/unstable/rpc/RpcClient.d.ts +5 -26
  683. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  684. package/dist/unstable/rpc/RpcClient.js +6 -13
  685. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  686. package/dist/unstable/rpc/RpcGroup.d.ts +3 -5
  687. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  688. package/dist/unstable/rpc/RpcGroup.js.map +1 -1
  689. package/dist/unstable/rpc/RpcMiddleware.d.ts +8 -8
  690. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  691. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  692. package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
  693. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  694. package/dist/unstable/rpc/RpcSchema.js +14 -0
  695. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  696. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  697. package/dist/unstable/rpc/RpcSerialization.js +34 -9
  698. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  699. package/dist/unstable/rpc/RpcServer.d.ts +5 -9
  700. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  701. package/dist/unstable/rpc/RpcServer.js +17 -17
  702. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  703. package/dist/unstable/rpc/Utils.d.ts.map +1 -1
  704. package/dist/unstable/rpc/Utils.js +3 -2
  705. package/dist/unstable/rpc/Utils.js.map +1 -1
  706. package/dist/unstable/schema/Model.d.ts +22 -1
  707. package/dist/unstable/schema/Model.d.ts.map +1 -1
  708. package/dist/unstable/schema/Model.js +15 -0
  709. package/dist/unstable/schema/Model.js.map +1 -1
  710. package/dist/unstable/schema/VariantSchema.d.ts +5 -5
  711. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  712. package/dist/unstable/schema/VariantSchema.js +6 -6
  713. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  714. package/dist/unstable/socket/Socket.d.ts +4 -4
  715. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  716. package/dist/unstable/socket/Socket.js +6 -5
  717. package/dist/unstable/socket/Socket.js.map +1 -1
  718. package/dist/unstable/socket/SocketServer.d.ts +3 -3
  719. package/dist/unstable/sql/Migrator.d.ts +1 -1
  720. package/dist/unstable/sql/SqlClient.d.ts +1 -1
  721. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  722. package/dist/unstable/sql/SqlError.d.ts +14 -14
  723. package/dist/unstable/sql/SqlError.d.ts.map +1 -1
  724. package/dist/unstable/sql/SqlError.js +9 -3
  725. package/dist/unstable/sql/SqlError.js.map +1 -1
  726. package/dist/unstable/sql/SqlModel.d.ts +2 -2
  727. package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
  728. package/dist/unstable/sql/SqlModel.js +3 -3
  729. package/dist/unstable/sql/SqlModel.js.map +1 -1
  730. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  731. package/dist/unstable/sql/SqlResolver.js +17 -8
  732. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  733. package/dist/unstable/sql/SqlSchema.d.ts +17 -6
  734. package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
  735. package/dist/unstable/sql/SqlSchema.js +17 -7
  736. package/dist/unstable/sql/SqlSchema.js.map +1 -1
  737. package/dist/unstable/sql/Statement.js +0 -1
  738. package/dist/unstable/sql/Statement.js.map +1 -1
  739. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  740. package/dist/unstable/workers/Worker.js +2 -1
  741. package/dist/unstable/workers/Worker.js.map +1 -1
  742. package/dist/unstable/workflow/DurableClock.d.ts +3 -3
  743. package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
  744. package/dist/unstable/workflow/DurableClock.js +3 -3
  745. package/dist/unstable/workflow/DurableClock.js.map +1 -1
  746. package/dist/unstable/workflow/DurableDeferred.js +2 -2
  747. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  748. package/dist/unstable/workflow/Workflow.d.ts +3 -3
  749. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  750. package/dist/unstable/workflow/Workflow.js +1 -1
  751. package/dist/unstable/workflow/Workflow.js.map +1 -1
  752. package/dist/unstable/workflow/WorkflowEngine.d.ts +12 -1
  753. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  754. package/dist/unstable/workflow/WorkflowEngine.js +137 -1
  755. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  756. package/package.json +2 -2
  757. package/src/Array.ts +192 -342
  758. package/src/Brand.ts +1 -1
  759. package/src/Cache.ts +9 -8
  760. package/src/Cause.ts +2 -2
  761. package/src/Channel.ts +557 -141
  762. package/src/Chunk.ts +81 -268
  763. package/src/Combiner.ts +280 -13
  764. package/src/Config.ts +186 -24
  765. package/src/Cron.ts +3 -3
  766. package/src/Data.ts +539 -376
  767. package/src/DateTime.ts +59 -241
  768. package/src/Duration.ts +91 -36
  769. package/src/Effect.ts +1477 -1126
  770. package/src/Encoding.ts +879 -0
  771. package/src/Equal.ts +278 -111
  772. package/src/ErrorReporter.ts +457 -0
  773. package/src/Exit.ts +24 -12
  774. package/src/Fiber.ts +10 -2
  775. package/src/FileSystem.ts +7 -8
  776. package/src/Filter.ts +52 -63
  777. package/src/Formatter.ts +253 -51
  778. package/src/Function.ts +2 -10
  779. package/src/Graph.ts +24 -11
  780. package/src/HashMap.ts +15 -14
  781. package/src/Iterable.ts +104 -50
  782. package/src/JsonSchema.ts +383 -10
  783. package/src/Latch.ts +112 -0
  784. package/src/Layer.ts +245 -150
  785. package/src/LayerMap.ts +9 -9
  786. package/src/LogLevel.ts +37 -0
  787. package/src/Logger.ts +33 -100
  788. package/src/ManagedRuntime.ts +2 -2
  789. package/src/Metric.ts +6 -8
  790. package/src/Newtype.ts +308 -0
  791. package/src/Optic.ts +948 -19
  792. package/src/Option.ts +32 -24
  793. package/src/Pipeable.ts +32 -1
  794. package/src/PlatformError.ts +5 -5
  795. package/src/Pool.ts +13 -11
  796. package/src/PubSub.ts +10 -9
  797. package/src/Pull.ts +1 -1
  798. package/src/Queue.ts +0 -1
  799. package/src/Random.ts +51 -14
  800. package/src/RcMap.ts +5 -5
  801. package/src/RcRef.ts +1 -1
  802. package/src/Record.ts +42 -152
  803. package/src/Reducer.ts +166 -7
  804. package/src/References.ts +10 -5
  805. package/src/Request.ts +3 -2
  806. package/src/RequestResolver.ts +29 -49
  807. package/src/Result.ts +2 -4
  808. package/src/Runtime.ts +102 -6
  809. package/src/Schedule.ts +462 -242
  810. package/src/Scheduler.ts +12 -0
  811. package/src/Schema.ts +3116 -312
  812. package/src/SchemaAST.ts +166 -33
  813. package/src/SchemaGetter.ts +15 -17
  814. package/src/SchemaParser.ts +11 -0
  815. package/src/SchemaRepresentation.ts +51 -26
  816. package/src/SchemaTransformation.ts +189 -4
  817. package/src/ScopedCache.ts +3 -3
  818. package/src/Semaphore.ts +356 -0
  819. package/src/ServiceMap.ts +50 -40
  820. package/src/Sink.ts +78 -26
  821. package/src/Stdio.ts +27 -4
  822. package/src/Stream.ts +586 -608
  823. package/src/Struct.ts +26 -0
  824. package/src/SubscriptionRef.ts +3 -2
  825. package/src/SynchronizedRef.ts +3 -2
  826. package/src/Trie.ts +18 -17
  827. package/src/TxChunk.ts +72 -53
  828. package/src/TxDeferred.ts +394 -0
  829. package/src/TxHashMap.ts +332 -285
  830. package/src/TxHashSet.ts +111 -116
  831. package/src/TxPriorityQueue.ts +767 -0
  832. package/src/TxPubSub.ts +789 -0
  833. package/src/TxQueue.ts +241 -251
  834. package/src/TxReentrantLock.ts +753 -0
  835. package/src/TxRef.ts +50 -38
  836. package/src/TxSemaphore.ts +29 -32
  837. package/src/TxSubscriptionRef.ts +639 -0
  838. package/src/Types.ts +73 -19
  839. package/src/Utils.ts +137 -111
  840. package/src/index.ts +728 -24
  841. package/src/internal/core.ts +12 -5
  842. package/src/internal/dateTime.ts +69 -81
  843. package/src/internal/effect.ts +775 -302
  844. package/src/internal/hashMap.ts +8 -7
  845. package/src/internal/random.ts +20 -0
  846. package/src/internal/rcRef.ts +4 -3
  847. package/src/internal/request.ts +2 -2
  848. package/src/internal/schema/annotations.ts +2 -0
  849. package/src/internal/schema/representation.ts +45 -94
  850. package/src/internal/schema/schema.ts +1 -0
  851. package/src/internal/schema/to-codec.ts +7 -17
  852. package/src/internal/trie.ts +15 -9
  853. package/src/testing/TestClock.ts +13 -11
  854. package/src/testing/TestSchema.ts +332 -35
  855. package/src/testing/index.ts +64 -1
  856. package/src/unstable/ai/AiError.ts +105 -48
  857. package/src/unstable/ai/Chat.ts +58 -74
  858. package/src/unstable/ai/LanguageModel.ts +294 -158
  859. package/src/unstable/ai/McpSchema.ts +73 -13
  860. package/src/unstable/ai/McpServer.ts +271 -61
  861. package/src/unstable/ai/Model.ts +40 -9
  862. package/src/unstable/ai/Prompt.ts +37 -37
  863. package/src/unstable/ai/Response.ts +25 -25
  864. package/src/unstable/ai/Tool.ts +20 -14
  865. package/src/unstable/ai/Toolkit.ts +5 -14
  866. package/src/unstable/ai/index.ts +1 -1
  867. package/src/unstable/ai/internal/codec-transformer.ts +0 -7
  868. package/src/unstable/cli/CliError.ts +47 -59
  869. package/src/unstable/cli/CliOutput.ts +75 -6
  870. package/src/unstable/cli/Command.ts +796 -187
  871. package/src/unstable/cli/Completions.ts +36 -0
  872. package/src/unstable/cli/GlobalFlag.ts +242 -0
  873. package/src/unstable/cli/HelpDoc.ts +80 -2
  874. package/src/unstable/cli/Primitive.ts +1 -1
  875. package/src/unstable/cli/Prompt.ts +31 -9
  876. package/src/unstable/cli/index.ts +10 -0
  877. package/src/unstable/cli/internal/command.ts +109 -63
  878. package/src/unstable/cli/internal/completions/CommandDescriptor.ts +7 -2
  879. package/src/unstable/cli/internal/config.ts +49 -0
  880. package/src/unstable/cli/internal/help.ts +171 -0
  881. package/src/unstable/cli/internal/parser.ts +66 -61
  882. package/src/unstable/cluster/ClusterCron.ts +2 -2
  883. package/src/unstable/cluster/ClusterWorkflowEngine.ts +6 -5
  884. package/src/unstable/cluster/DeliverAt.ts +1 -1
  885. package/src/unstable/cluster/Entity.ts +11 -10
  886. package/src/unstable/cluster/EntityResource.ts +4 -4
  887. package/src/unstable/cluster/Envelope.ts +1 -1
  888. package/src/unstable/cluster/K8sHttpClient.ts +5 -5
  889. package/src/unstable/cluster/MessageStorage.ts +3 -5
  890. package/src/unstable/cluster/Runners.ts +6 -5
  891. package/src/unstable/cluster/Sharding.ts +12 -10
  892. package/src/unstable/cluster/ShardingConfig.ts +30 -31
  893. package/src/unstable/cluster/SqlRunnerStorage.ts +1 -1
  894. package/src/unstable/cluster/internal/entityManager.ts +9 -8
  895. package/src/unstable/cluster/internal/entityReaper.ts +2 -1
  896. package/src/unstable/cluster/internal/resourceRef.ts +2 -1
  897. package/src/unstable/encoding/Ndjson.ts +17 -17
  898. package/src/unstable/encoding/Sse.ts +3 -5
  899. package/src/unstable/eventlog/EventLog.ts +2 -1
  900. package/src/unstable/http/Cookies.ts +87 -3
  901. package/src/unstable/http/Headers.ts +62 -13
  902. package/src/unstable/http/HttpBody.ts +6 -6
  903. package/src/unstable/http/HttpClient.ts +374 -33
  904. package/src/unstable/http/HttpClientRequest.ts +38 -30
  905. package/src/unstable/http/HttpClientResponse.ts +9 -4
  906. package/src/unstable/http/HttpEffect.ts +54 -68
  907. package/src/unstable/http/HttpIncomingMessage.ts +1 -1
  908. package/src/unstable/http/HttpMethod.ts +16 -4
  909. package/src/unstable/http/HttpMiddleware.ts +9 -24
  910. package/src/unstable/http/HttpServerError.ts +42 -45
  911. package/src/unstable/http/HttpServerRequest.ts +391 -4
  912. package/src/unstable/http/HttpServerRespondable.ts +6 -6
  913. package/src/unstable/http/HttpServerResponse.ts +337 -4
  914. package/src/unstable/http/HttpStaticServer.ts +456 -0
  915. package/src/unstable/http/Multipart.ts +2 -2
  916. package/src/unstable/http/UrlParams.ts +20 -5
  917. package/src/unstable/http/index.ts +5 -0
  918. package/src/unstable/http/internal/preResponseHandler.ts +15 -0
  919. package/src/unstable/httpapi/HttpApi.ts +6 -6
  920. package/src/unstable/httpapi/HttpApiBuilder.ts +83 -30
  921. package/src/unstable/httpapi/HttpApiClient.ts +100 -11
  922. package/src/unstable/httpapi/HttpApiEndpoint.ts +71 -87
  923. package/src/unstable/httpapi/HttpApiError.ts +51 -28
  924. package/src/unstable/httpapi/HttpApiGroup.ts +7 -6
  925. package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -4
  926. package/src/unstable/httpapi/HttpApiScalar.ts +6 -0
  927. package/src/unstable/httpapi/HttpApiSecurity.ts +3 -3
  928. package/src/unstable/httpapi/OpenApi.ts +41 -23
  929. package/src/unstable/observability/Otlp.ts +12 -12
  930. package/src/unstable/observability/OtlpExporter.ts +3 -3
  931. package/src/unstable/observability/OtlpLogger.ts +13 -9
  932. package/src/unstable/observability/OtlpMetrics.ts +4 -4
  933. package/src/unstable/observability/OtlpTracer.ts +4 -4
  934. package/src/unstable/persistence/KeyValueStore.ts +6 -6
  935. package/src/unstable/persistence/Persistable.ts +3 -3
  936. package/src/unstable/persistence/PersistedCache.ts +20 -9
  937. package/src/unstable/persistence/PersistedQueue.ts +25 -24
  938. package/src/unstable/persistence/Persistence.ts +3 -3
  939. package/src/unstable/persistence/RateLimiter.ts +4 -4
  940. package/src/unstable/process/ChildProcess.ts +6 -208
  941. package/src/unstable/process/ChildProcessSpawner.ts +75 -14
  942. package/src/unstable/reactivity/Atom.ts +211 -50
  943. package/src/unstable/reactivity/AtomHttpApi.ts +66 -31
  944. package/src/unstable/reactivity/AtomRegistry.ts +61 -9
  945. package/src/unstable/reactivity/AtomRpc.ts +51 -20
  946. package/src/unstable/reactivity/Hydration.ts +112 -0
  947. package/src/unstable/reactivity/index.ts +5 -0
  948. package/src/unstable/rpc/Rpc.ts +7 -9
  949. package/src/unstable/rpc/RpcClient.ts +12 -54
  950. package/src/unstable/rpc/RpcGroup.ts +7 -7
  951. package/src/unstable/rpc/RpcMiddleware.ts +15 -9
  952. package/src/unstable/rpc/RpcSchema.ts +17 -0
  953. package/src/unstable/rpc/RpcSerialization.ts +44 -9
  954. package/src/unstable/rpc/RpcServer.ts +28 -32
  955. package/src/unstable/rpc/Utils.ts +3 -2
  956. package/src/unstable/schema/Model.ts +31 -0
  957. package/src/unstable/schema/VariantSchema.ts +9 -9
  958. package/src/unstable/socket/Socket.ts +16 -17
  959. package/src/unstable/sql/SqlClient.ts +1 -1
  960. package/src/unstable/sql/SqlError.ts +11 -9
  961. package/src/unstable/sql/SqlModel.ts +5 -5
  962. package/src/unstable/sql/SqlResolver.ts +17 -7
  963. package/src/unstable/sql/SqlSchema.ts +42 -26
  964. package/src/unstable/sql/Statement.ts +0 -1
  965. package/src/unstable/workers/Worker.ts +2 -1
  966. package/src/unstable/workflow/DurableClock.ts +8 -8
  967. package/src/unstable/workflow/DurableDeferred.ts +2 -2
  968. package/src/unstable/workflow/Workflow.ts +6 -2
  969. package/src/unstable/workflow/WorkflowEngine.ts +185 -2
  970. package/dist/PartitionedSemaphore.d.ts +0 -52
  971. package/dist/PartitionedSemaphore.d.ts.map +0 -1
  972. package/dist/PartitionedSemaphore.js.map +0 -1
  973. package/dist/encoding/Base64.d.ts +0 -67
  974. package/dist/encoding/Base64.d.ts.map +0 -1
  975. package/dist/encoding/Base64.js +0 -146
  976. package/dist/encoding/Base64.js.map +0 -1
  977. package/dist/encoding/Base64Url.d.ts +0 -60
  978. package/dist/encoding/Base64Url.d.ts.map +0 -1
  979. package/dist/encoding/Base64Url.js +0 -89
  980. package/dist/encoding/Base64Url.js.map +0 -1
  981. package/dist/encoding/EncodingError.d.ts +0 -31
  982. package/dist/encoding/EncodingError.d.ts.map +0 -1
  983. package/dist/encoding/EncodingError.js +0 -22
  984. package/dist/encoding/EncodingError.js.map +0 -1
  985. package/dist/encoding/Hex.d.ts +0 -61
  986. package/dist/encoding/Hex.d.ts.map +0 -1
  987. package/dist/encoding/Hex.js +0 -115
  988. package/dist/encoding/Hex.js.map +0 -1
  989. package/dist/encoding/index.d.ts +0 -26
  990. package/dist/encoding/index.d.ts.map +0 -1
  991. package/dist/encoding/index.js +0 -27
  992. package/dist/encoding/index.js.map +0 -1
  993. package/dist/unstable/cli/internal/builtInFlags.d.ts +0 -7
  994. package/dist/unstable/cli/internal/builtInFlags.d.ts.map +0 -1
  995. package/dist/unstable/cli/internal/builtInFlags.js +0 -44
  996. package/dist/unstable/cli/internal/builtInFlags.js.map +0 -1
  997. package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
  998. package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
  999. package/dist/unstable/cli/internal/completions/Completions.js +0 -23
  1000. package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
  1001. package/src/PartitionedSemaphore.ts +0 -182
  1002. package/src/encoding/Base64.ts +0 -366
  1003. package/src/encoding/Base64Url.ts +0 -104
  1004. package/src/encoding/EncodingError.ts +0 -35
  1005. package/src/encoding/Hex.ts +0 -390
  1006. package/src/encoding/index.ts +0 -31
  1007. package/src/unstable/cli/internal/builtInFlags.ts +0 -78
  1008. package/src/unstable/cli/internal/completions/Completions.ts +0 -31
package/dist/Schema.js CHANGED
@@ -1,18 +1,104 @@
1
1
  /**
2
+ * Define data shapes, validate unknown input, and transform values between formats.
3
+ *
4
+ * ## Mental model
5
+ *
6
+ * - **Schema** — a description of a data shape. Every schema carries a decoded
7
+ * *Type* (the value you work with) and an *Encoded* representation (the
8
+ * serialized form, e.g. JSON).
9
+ * - **Decoding** — turning unknown external data (API responses, form
10
+ * submissions, config files) into typed, validated values.
11
+ * - **Encoding** — turning typed values back into a serializable format.
12
+ * - **Codec** — a schema that tracks both Type and Encoded, so it can decode
13
+ * *and* encode. Most concrete schemas are Codecs.
14
+ * - **Check / Filter** — a constraint attached to a schema (e.g. `isMinLength`,
15
+ * `isGreaterThan`). Attach them with `.check(...)`.
16
+ * - **Transformation** — a pair of functions (decode + encode) that convert
17
+ * values between two schemas. Created with {@link decodeTo} / {@link encodeTo}.
18
+ * - **Annotation** — metadata attached to a schema (title, description, custom
19
+ * keys). Attach with `.annotate(...)`.
20
+ *
21
+ * ## Common tasks
22
+ *
23
+ * - Define a struct: {@link Struct}
24
+ * - Define a union: {@link Union}, {@link TaggedUnion}, {@link Literals}
25
+ * - Define an array: {@link Array}, {@link NonEmptyArray}
26
+ * - Define a record: {@link Record}
27
+ * - Define a tuple: {@link Tuple}, {@link TupleWithRest}
28
+ * - Validate unknown data synchronously: {@link decodeUnknownSync}
29
+ * - Validate unknown data (Effect): {@link decodeUnknownEffect}
30
+ * - Encode a value: {@link encodeUnknownSync}, {@link encodeUnknownEffect}
31
+ * - Type guard: {@link is}
32
+ * - Assertion: {@link asserts}
33
+ * - Add constraints: `.check(...)` with filters like {@link isMinLength},
34
+ * {@link isGreaterThan}, {@link isPattern}, {@link isUUID}
35
+ * - Transform between schemas: {@link decodeTo}, {@link encodeTo}
36
+ * - Add a default for missing keys: {@link withDecodingDefault}, {@link withDecodingDefaultKey}
37
+ * - Create branded types: {@link brand}
38
+ * - Define classes with validation: {@link Class}, {@link TaggedClass}
39
+ * - Define error classes: {@link ErrorClass}, {@link TaggedErrorClass}
40
+ * - Generate JSON Schema: {@link toJsonSchemaDocument}
41
+ * - Generate test data: {@link toArbitrary}
42
+ * - Derive equivalence: {@link toEquivalence}
43
+ *
44
+ * ## Gotchas
45
+ *
46
+ * - `Schema.optional` creates `T | undefined` (key can be missing *or*
47
+ * `undefined`). Use `Schema.optionalKey` for exact optional properties.
48
+ * - `decodeTo` is curried: use `from.pipe(Schema.decodeTo(to, ...))`.
49
+ * - `decodeUnknownSync` throws on failure. Use `decodeUnknownExit` or
50
+ * `decodeUnknownOption` for non-throwing alternatives.
51
+ * - Filters do not change the TypeScript type. Use {@link refine} or
52
+ * {@link brand} to narrow the type.
53
+ * - Recursive schemas require {@link suspend} to avoid infinite loops.
54
+ *
55
+ * ## Quickstart
56
+ *
57
+ * **Example** (Validate a user object)
58
+ *
59
+ * ```ts
60
+ * import { Schema } from "effect"
61
+ *
62
+ * const User = Schema.Struct({
63
+ * name: Schema.String.check(Schema.isMinLength(1)),
64
+ * age: Schema.Number.check(Schema.isGreaterThanOrEqualTo(0)),
65
+ * email: Schema.optionalKey(Schema.String)
66
+ * })
67
+ *
68
+ * // Decode unknown input — throws on failure
69
+ * const user = Schema.decodeUnknownSync(User)({
70
+ * name: "Alice",
71
+ * age: 30
72
+ * })
73
+ *
74
+ * console.log(user)
75
+ * // { name: "Alice", age: 30 }
76
+ * ```
77
+ *
78
+ * @see {@link Schema} — type-level view tracking only the decoded Type
79
+ * @see {@link Codec} — type-level view tracking both Type and Encoded
80
+ * @see {@link Struct} — define object shapes
81
+ * @see {@link decodeUnknownSync} — synchronous validation
82
+ * @see {@link decodeTo} — schema transformations
83
+ *
2
84
  * @since 4.0.0
3
85
  */
4
86
  import * as Arr from "./Array.js";
87
+ import * as BigDecimal_ from "./BigDecimal.js";
5
88
  import * as Cause_ from "./Cause.js";
89
+ import * as Chunk_ from "./Chunk.js";
6
90
  import * as Data from "./Data.js";
7
91
  import * as DateTime from "./DateTime.js";
8
92
  import * as Duration_ from "./Duration.js";
9
93
  import * as Effect from "./Effect.js";
10
- import * as Base64 from "./encoding/Base64.js";
94
+ import * as Encoding from "./Encoding.js";
11
95
  import * as Equal from "./Equal.js";
12
96
  import * as Equivalence from "./Equivalence.js";
13
97
  import * as Exit_ from "./Exit.js";
14
98
  import { format, formatDate, formatPropertyKey } from "./Formatter.js";
15
99
  import { identity } from "./Function.js";
100
+ import * as HashMap_ from "./HashMap.js";
101
+ import * as HashSet_ from "./HashSet.js";
16
102
  import * as core from "./internal/core.js";
17
103
  import * as InternalAnnotations from "./internal/schema/annotations.js";
18
104
  import * as InternalArbitrary from "./internal/schema/arbitrary.js";
@@ -41,9 +127,51 @@ import * as Struct_ from "./Struct.js";
41
127
  import * as FastCheck from "./testing/FastCheck.js";
42
128
  const TypeId = InternalSchema.TypeId;
43
129
  /**
44
- * An API for creating schemas for parametric types.
130
+ * Creates a schema for a **parametric** type (a generic container such as
131
+ * `Array<A>`, `Option<A>`, etc.) by accepting a list of type-parameter schemas
132
+ * and a decoder factory.
133
+ *
134
+ * The outer call `declareConstructor<T, E, Iso>()` fixes the decoded type `T`,
135
+ * the encoded type `E`, and the optional iso type. The inner call receives:
136
+ * - `typeParameters` — the concrete schemas for each type variable
137
+ * - `run` — a factory that, given resolved codecs for each type parameter,
138
+ * returns a parsing function `(u, ast, options) => Effect<T, Issue>`
139
+ * - `annotations` — optional metadata
140
+ *
141
+ * @see {@link declare} for creating schemas for non-parametric types.
142
+ *
143
+ * **Example** (Schema for a parametric `Box<A>` type)
144
+ *
145
+ * ```ts
146
+ * import { Effect, Schema } from "effect"
147
+ * import * as SchemaParser from "effect/SchemaParser"
148
+ * import * as Issue from "effect/SchemaIssue"
149
+ * import * as Option from "effect/Option"
45
150
  *
46
- * @see {@link declare} for creating schemas for non parametric types.
151
+ * interface Box<A> {
152
+ * readonly value: A
153
+ * }
154
+ *
155
+ * const isBox = (u: unknown): u is Box<unknown> =>
156
+ * typeof u === "object" && u !== null && "value" in u
157
+ *
158
+ * const Box = <A extends Schema.Top>(item: A) =>
159
+ * Schema.declareConstructor<Box<A["Type"]>, Box<A["Encoded"]>>()(
160
+ * [item],
161
+ * ([itemCodec]) =>
162
+ * (u, ast, options) => {
163
+ * if (!isBox(u)) {
164
+ * return Effect.fail(new Issue.InvalidType(ast, Option.some(u)))
165
+ * }
166
+ * return Effect.map(
167
+ * SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
168
+ * (value) => ({ value })
169
+ * )
170
+ * }
171
+ * )
172
+ *
173
+ * const schema = Box(Schema.Number)
174
+ * ```
47
175
  *
48
176
  * @category Constructors
49
177
  * @since 4.0.0
@@ -54,18 +182,60 @@ export function declareConstructor() {
54
182
  };
55
183
  }
56
184
  /**
57
- * An API for creating schemas for non parametric types.
185
+ * Creates a schema for a **non-parametric** opaque type using a type-guard
186
+ * function. The schema accepts any unknown value and succeeds when `is` returns
187
+ * `true`, failing with an `InvalidType` issue otherwise.
188
+ *
189
+ * Use this when the type has no type parameters. For parametric types such as
190
+ * `Option<A>` or `Array<A>`, use {@link declareConstructor} instead.
191
+ *
192
+ * **Example** (Schema for a custom `UserId` branded type)
193
+ *
194
+ * ```ts
195
+ * import { Schema } from "effect"
196
+ *
197
+ * type UserId = string & { readonly _tag: "UserId" }
198
+ *
199
+ * const isUserId = (u: unknown): u is UserId =>
200
+ * typeof u === "string" && u.startsWith("user_")
201
+ *
202
+ * const UserId = Schema.declare<UserId>(isUserId, {
203
+ * title: "UserId",
204
+ * description: "A user identifier starting with 'user_'"
205
+ * })
206
+ * ```
58
207
  *
59
208
  * @see {@link declareConstructor} for creating schemas for parametric types.
60
209
  *
210
+ * @category Constructors
61
211
  * @since 4.0.0
62
212
  */
63
213
  export function declare(is, annotations) {
64
214
  return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new Issue.InvalidType(ast, Option_.some(input))), annotations);
65
215
  }
66
216
  /**
67
- * Reveals the complete Bottom interface type of a schema, exposing all 14 type
68
- * parameters.
217
+ * Widens a schema's type to the fully-parameterized {@link Bottom} interface,
218
+ * making all 14 type parameters visible to TypeScript.
219
+ *
220
+ * Normally, concrete schema interfaces (e.g. `Schema<string>`) hide most type
221
+ * parameters. `revealBottom` is useful when writing generic utilities that need
222
+ * to inspect or propagate the complete set of type parameters.
223
+ *
224
+ * **Example** (Inspecting all type parameters of a schema)
225
+ *
226
+ * ```ts
227
+ * import { Schema } from "effect"
228
+ *
229
+ * const schema = Schema.String
230
+ *
231
+ * // Widen to Bottom to access all 14 type parameters
232
+ * const bottom = Schema.revealBottom(schema)
233
+ *
234
+ * // `bottom` now exposes Type, Encoded, DecodingServices, EncodingServices,
235
+ * // ast, ~rebuild.out, ~type.make.in, Iso, ~type.parameters, etc.
236
+ * type T = typeof bottom["Type"] // string
237
+ * type E = typeof bottom["Encoded"] // string
238
+ * ```
69
239
  *
70
240
  * @since 4.0.0
71
241
  */
@@ -74,8 +244,24 @@ export function revealBottom(bottom) {
74
244
  }
75
245
  /**
76
246
  * Adds metadata annotations to a schema without changing its runtime behavior.
77
- * Annotations are used to provide additional context for documentation,
78
- * JSON schema generation, error formatting, and other tooling.
247
+ * This is the pipeable (curried) counterpart of the `.annotate` method.
248
+ *
249
+ * Annotations provide extra context used by documentation generators, JSON
250
+ * Schema converters, error formatters, and other tooling. Common keys include
251
+ * `title`, `description`, `examples`, `message`, and `identifier`.
252
+ *
253
+ * **Example** (Adding a title and description)
254
+ *
255
+ * ```ts
256
+ * import { Schema } from "effect"
257
+ *
258
+ * const Age = Schema.Number.pipe(
259
+ * Schema.annotate({
260
+ * title: "Age",
261
+ * description: "A non-negative integer representing age in years"
262
+ * })
263
+ * )
264
+ * ```
79
265
  *
80
266
  * @category Annotations
81
267
  * @since 4.0.0
@@ -86,9 +272,29 @@ export function annotate(annotations) {
86
272
  };
87
273
  }
88
274
  /**
89
- * Adds key-specific annotations to a schema field. This is useful for providing
90
- * custom error messages and documentation for individual fields within
91
- * structures.
275
+ * Adds key-level annotations to a schema field. This is the pipeable
276
+ * (curried) counterpart of the `.annotateKey` method.
277
+ *
278
+ * Key annotations apply to a field's position inside a `Struct` or `Tuple`
279
+ * rather than to the field's value type. They can carry a
280
+ * `messageMissingKey` to customise the error shown when the field is absent,
281
+ * as well as standard documentation fields such as `title`, `description`,
282
+ * and `examples`.
283
+ *
284
+ * **Example** (Custom missing-key message for a required field)
285
+ *
286
+ * ```ts
287
+ * import { Schema } from "effect"
288
+ *
289
+ * const schema = Schema.Struct({
290
+ * username: Schema.String.pipe(
291
+ * Schema.annotateKey({
292
+ * description: "The username used to log in",
293
+ * messageMissingKey: "Username is required"
294
+ * })
295
+ * )
296
+ * })
297
+ * ```
92
298
  *
93
299
  * @category Annotations
94
300
  * @since 4.0.0
@@ -99,6 +305,25 @@ export function annotateKey(annotations) {
99
305
  };
100
306
  }
101
307
  /**
308
+ * Identity function that widens a value to the full {@link Codec} interface,
309
+ * prompting TypeScript to infer all four type parameters (`T`, `E`, `RD`, `RE`).
310
+ *
311
+ * When a schema is stored in a variable typed as `Schema<T>` or `Top`, the
312
+ * encoded type and service requirements are erased. Passing the value through
313
+ * `revealCodec` recovers those parameters without any runtime cost.
314
+ *
315
+ * **Example** (Recovering encoded type from a schema variable)
316
+ *
317
+ * ```ts
318
+ * import { Schema } from "effect"
319
+ *
320
+ * const schema: Schema.Schema<number> = Schema.NumberFromString
321
+ *
322
+ * // Without revealCodec, Encoded is unknown
323
+ * const codec = Schema.revealCodec(schema)
324
+ * type Enc = typeof codec["Encoded"] // string
325
+ * ```
326
+ *
102
327
  * @since 4.0.0
103
328
  */
104
329
  export function revealCodec(codec) {
@@ -106,12 +331,30 @@ export function revealCodec(codec) {
106
331
  }
107
332
  const SchemaErrorTypeId = "~effect/Schema/SchemaError";
108
333
  /**
109
- * A `SchemaError` is returned when schema decoding or encoding fails.
334
+ * Error thrown (or returned as the error channel value) when schema decoding
335
+ * or encoding fails.
110
336
  *
111
- * This error extends `Data.TaggedError` and contains detailed information about
112
- * what went wrong during schema processing. The error includes an `issue` field
113
- * that provides comprehensive details about the validation failure, including
114
- * the path to the problematic data, expected types, and actual values.
337
+ * The `issue` field contains a structured {@link Issue.Issue} tree describing
338
+ * every validation failure, including the path to the problematic value,
339
+ * expected types, and actual values received. `message` renders the issue tree
340
+ * as a human-readable string.
341
+ *
342
+ * Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
343
+ *
344
+ * **Example** (Catching a SchemaError)
345
+ *
346
+ * ```ts
347
+ * import { Schema } from "effect"
348
+ *
349
+ * try {
350
+ * Schema.decodeUnknownSync(Schema.Number)("not a number")
351
+ * } catch (err) {
352
+ * if (Schema.isSchemaError(err)) {
353
+ * console.log(err.message)
354
+ * // Expected number, actual "not a number"
355
+ * }
356
+ * }
357
+ * ```
115
358
  *
116
359
  * @since 4.0.0
117
360
  */
@@ -131,6 +374,22 @@ export class SchemaError {
131
374
  }
132
375
  }
133
376
  /**
377
+ * Returns `true` if `u` is a {@link SchemaError}.
378
+ *
379
+ * **Example** (Type guard in a catch block)
380
+ *
381
+ * ```ts
382
+ * import { Schema } from "effect"
383
+ *
384
+ * try {
385
+ * Schema.decodeUnknownSync(Schema.Number)("oops")
386
+ * } catch (err) {
387
+ * if (Schema.isSchemaError(err)) {
388
+ * console.log(err._tag) // "SchemaError"
389
+ * }
390
+ * }
391
+ * ```
392
+ *
134
393
  * @since 4.0.0
135
394
  */
136
395
  export function isSchemaError(u) {
@@ -370,6 +629,11 @@ export const is = Parser.is;
370
629
  */
371
630
  export const asserts = Parser.asserts;
372
631
  /**
632
+ * Decodes an `unknown` input against a schema, returning an `Effect` that
633
+ * succeeds with the decoded value or fails with a {@link SchemaError}. Use this
634
+ * when the input type is not statically known. Prefer {@link decodeEffect} when
635
+ * the input is already typed as the schema's `Encoded` type.
636
+ *
373
637
  * @category Decoding
374
638
  * @since 4.0.0
375
639
  */
@@ -380,11 +644,22 @@ export function decodeUnknownEffect(schema) {
380
644
  };
381
645
  }
382
646
  /**
647
+ * Decodes a typed input (the schema's `Encoded` type) against a schema,
648
+ * returning an `Effect` that succeeds with the decoded value or fails with a
649
+ * {@link SchemaError}. Use this when the input is already typed; for `unknown`
650
+ * input use {@link decodeUnknownEffect}.
651
+ *
383
652
  * @category Decoding
384
653
  * @since 4.0.0
385
654
  */
386
655
  export const decodeEffect = decodeUnknownEffect;
387
656
  /**
657
+ * Decodes an `unknown` input against a schema synchronously, returning an
658
+ * `Exit` that is either a `Success` with the decoded value or a `Failure` with
659
+ * a {@link SchemaError}. Only usable with schemas that have no
660
+ * `DecodingServices` requirement. Prefer {@link decodeExit} when the input is
661
+ * already typed as the schema's `Encoded` type.
662
+ *
388
663
  * @category Decoding
389
664
  * @since 4.0.0
390
665
  */
@@ -395,41 +670,110 @@ export function decodeUnknownExit(schema) {
395
670
  };
396
671
  }
397
672
  /**
673
+ * Decodes a typed input (the schema's `Encoded` type) against a schema
674
+ * synchronously, returning an `Exit` that is either a `Success` with the
675
+ * decoded value or a `Failure` with a {@link SchemaError}. Only usable with
676
+ * schemas that have no `DecodingServices` requirement. For `unknown` input use
677
+ * {@link decodeUnknownExit}.
678
+ *
398
679
  * @category Decoding
399
680
  * @since 4.0.0
400
681
  */
401
682
  export const decodeExit = decodeUnknownExit;
402
683
  /**
684
+ * Decodes an `unknown` input against a schema, returning an `Option` that is
685
+ * `Some` with the decoded value on success or `None` on failure. Prefer this
686
+ * over {@link decodeUnknownExit} or {@link decodeUnknownEffect} when you only
687
+ * need to know whether decoding succeeded and don't need error details. For
688
+ * typed input use {@link decodeOption}.
689
+ *
403
690
  * @category Decoding
404
691
  * @since 4.0.0
405
692
  */
406
693
  export const decodeUnknownOption = Parser.decodeUnknownOption;
407
694
  /**
695
+ * Decodes a typed input (the schema's `Encoded` type) against a schema,
696
+ * returning an `Option` that is `Some` with the decoded value on success or
697
+ * `None` on failure. For `unknown` input use {@link decodeUnknownOption}.
698
+ *
408
699
  * @category Decoding
409
700
  * @since 4.0.0
410
701
  */
411
702
  export const decodeOption = Parser.decodeOption;
412
703
  /**
704
+ * Decodes an `unknown` input against a schema, returning a `Promise` that
705
+ * resolves with the decoded value or rejects with a {@link SchemaError}. Useful
706
+ * for integrating with Promise-based APIs. For typed input use
707
+ * {@link decodePromise}.
708
+ *
413
709
  * @category Decoding
414
710
  * @since 4.0.0
415
711
  */
416
712
  export const decodeUnknownPromise = Parser.decodeUnknownPromise;
417
713
  /**
714
+ * Decodes a typed input (the schema's `Encoded` type) against a schema,
715
+ * returning a `Promise` that resolves with the decoded value or rejects with a
716
+ * {@link SchemaError}. For `unknown` input use {@link decodeUnknownPromise}.
717
+ *
418
718
  * @category Decoding
419
719
  * @since 4.0.0
420
720
  */
421
721
  export const decodePromise = Parser.decodePromise;
422
722
  /**
723
+ * Decodes an `unknown` input against a schema synchronously, throwing a
724
+ * {@link SchemaError} on failure. Use this when you want to validate data at a
725
+ * boundary and treat a schema mismatch as an unrecoverable error. For
726
+ * non-throwing alternatives see {@link decodeUnknownOption},
727
+ * {@link decodeUnknownExit}, or {@link decodeUnknownEffect}. For typed input
728
+ * use {@link decodeSync}.
729
+ *
730
+ * **Example** (Decoding with a transformation schema)
731
+ *
732
+ * ```ts
733
+ * import { Schema } from "effect"
734
+ *
735
+ * const NumberFromString = Schema.NumberFromString
736
+ *
737
+ * console.log(Schema.decodeUnknownSync(NumberFromString)("42"))
738
+ * // Output: 42
739
+ *
740
+ * Schema.decodeUnknownSync(NumberFromString)("not a number")
741
+ * // throws SchemaError: NumberFromString
742
+ * // └─ Encoded side transformation failure
743
+ * // └─ NumberFromString
744
+ * // └─ Expected a numeric string, actual "not a number"
745
+ * ```
746
+ *
423
747
  * @category Decoding
424
748
  * @since 4.0.0
425
749
  */
426
750
  export const decodeUnknownSync = Parser.decodeUnknownSync;
427
751
  /**
752
+ * Decodes a typed input (the schema's `Encoded` type) against a schema
753
+ * synchronously, throwing a {@link SchemaError} on failure. For `unknown` input
754
+ * use {@link decodeUnknownSync}.
755
+ *
428
756
  * @category Decoding
429
757
  * @since 4.0.0
430
758
  */
431
759
  export const decodeSync = Parser.decodeSync;
432
760
  /**
761
+ * Encodes an `unknown` input against a schema, returning an `Effect` that
762
+ * succeeds with the encoded value or fails with a {@link SchemaError}. Use this
763
+ * when the input type is not statically known. Prefer {@link encodeEffect} when
764
+ * the input is already typed as the schema's `Type`.
765
+ *
766
+ * **Example** (Encoding a value to a string)
767
+ *
768
+ * ```ts
769
+ * import { Effect, Schema } from "effect"
770
+ *
771
+ * const NumberFromString = Schema.NumberFromString
772
+ *
773
+ * Effect.runPromise(Schema.encodeUnknownEffect(NumberFromString)(42)).then(console.log)
774
+ * // Output: "42"
775
+ * ```
776
+ *
433
777
  * @category Encoding
434
778
  * @since 4.0.0
435
779
  */
@@ -440,11 +784,22 @@ export function encodeUnknownEffect(schema) {
440
784
  };
441
785
  }
442
786
  /**
787
+ * Encodes a typed input (the schema's `Type`) against a schema, returning an
788
+ * `Effect` that succeeds with the encoded value or fails with a
789
+ * {@link SchemaError}. Use this when the input is already typed; for `unknown`
790
+ * input use {@link encodeUnknownEffect}.
791
+ *
443
792
  * @category Encoding
444
793
  * @since 4.0.0
445
794
  */
446
795
  export const encodeEffect = encodeUnknownEffect;
447
796
  /**
797
+ * Encodes an `unknown` input against a schema synchronously, returning an
798
+ * `Exit` that is either a `Success` with the encoded value or a `Failure` with
799
+ * a {@link SchemaError}. Only usable with schemas that have no
800
+ * `EncodingServices` requirement. Prefer {@link encodeExit} when the input is
801
+ * already typed as the schema's `Type`.
802
+ *
448
803
  * @category Encoding
449
804
  * @since 4.0.0
450
805
  */
@@ -455,36 +810,72 @@ export function encodeUnknownExit(schema) {
455
810
  };
456
811
  }
457
812
  /**
813
+ * Encodes a typed input (the schema's `Type`) against a schema synchronously,
814
+ * returning an `Exit` that is either a `Success` with the encoded value or a
815
+ * `Failure` with a {@link SchemaError}. Only usable with schemas that have no
816
+ * `EncodingServices` requirement. For `unknown` input use
817
+ * {@link encodeUnknownExit}.
818
+ *
458
819
  * @category Encoding
459
820
  * @since 4.0.0
460
821
  */
461
822
  export const encodeExit = encodeUnknownExit;
462
823
  /**
824
+ * Encodes an `unknown` input against a schema, returning an `Option` that is
825
+ * `Some` with the encoded value on success or `None` on failure. Prefer this
826
+ * over {@link encodeUnknownExit} or {@link encodeUnknownEffect} when you only
827
+ * need to know whether encoding succeeded and don't need error details. For
828
+ * typed input use {@link encodeOption}.
829
+ *
463
830
  * @category Encoding
464
831
  * @since 4.0.0
465
832
  */
466
833
  export const encodeUnknownOption = Parser.encodeUnknownOption;
467
834
  /**
835
+ * Encodes a typed input (the schema's `Type`) against a schema, returning an
836
+ * `Option` that is `Some` with the encoded value on success or `None` on
837
+ * failure. For `unknown` input use {@link encodeUnknownOption}.
838
+ *
468
839
  * @category Encoding
469
840
  * @since 4.0.0
470
841
  */
471
842
  export const encodeOption = Parser.encodeOption;
472
843
  /**
844
+ * Encodes an `unknown` input against a schema, returning a `Promise` that
845
+ * resolves with the encoded value or rejects with a {@link SchemaError}. Useful
846
+ * for integrating with Promise-based APIs. For typed input use
847
+ * {@link encodePromise}.
848
+ *
473
849
  * @category Encoding
474
850
  * @since 4.0.0
475
851
  */
476
852
  export const encodeUnknownPromise = Parser.encodeUnknownPromise;
477
853
  /**
854
+ * Encodes a typed input (the schema's `Type`) against a schema, returning a
855
+ * `Promise` that resolves with the encoded value or rejects with a
856
+ * {@link SchemaError}. For `unknown` input use {@link encodeUnknownPromise}.
857
+ *
478
858
  * @category Encoding
479
859
  * @since 4.0.0
480
860
  */
481
861
  export const encodePromise = Parser.encodePromise;
482
862
  /**
863
+ * Encodes an `unknown` input against a schema synchronously, throwing a
864
+ * {@link SchemaError} on failure. Use this when you want to serialize data at a
865
+ * boundary and treat a schema mismatch as an unrecoverable error. For
866
+ * non-throwing alternatives see {@link encodeUnknownOption},
867
+ * {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For typed input
868
+ * use {@link encodeSync}.
869
+ *
483
870
  * @category Encoding
484
871
  * @since 4.0.0
485
872
  */
486
873
  export const encodeUnknownSync = Parser.encodeUnknownSync;
487
874
  /**
875
+ * Encodes a typed input (the schema's `Type`) against a schema synchronously,
876
+ * throwing a {@link SchemaError} on failure. For `unknown` input use
877
+ * {@link encodeUnknownSync}.
878
+ *
488
879
  * @category Encoding
489
880
  * @since 4.0.0
490
881
  */
@@ -539,57 +930,74 @@ export const optionalKey = /*#__PURE__*/Struct_.lambda(schema => make(AST.option
539
930
  schema
540
931
  }));
541
932
  /**
933
+ * Reverses {@link optionalKey}, returning the inner required schema. Only
934
+ * applicable to schemas already wrapped with `optionalKey`.
935
+ *
542
936
  * @since 4.0.0
543
937
  */
544
938
  export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
545
939
  /**
546
- * Creates an optional schema field that allows both the specified type and
940
+ * Marks a struct field as optional, allowing the key to be absent or
547
941
  * `undefined`.
548
942
  *
549
- * This is equivalent to `optionalKey(UndefinedOr(schema))`, creating a field
550
- * that:
551
- * - Can be omitted from the object entirely
552
- * - Can be explicitly set to `undefined`
553
- * - Can contain the specified schema type
943
+ * explicitly set to `undefined`. Equivalent to `optionalKey(UndefinedOr(S))`.
944
+ *
945
+ * Use {@link optionalKey} instead if you want exact optional semantics (absent
946
+ * only, not `undefined`).
554
947
  *
555
- * **Example** (Creating a struct with optional)
948
+ * **Example** (Optional field accepting undefined)
556
949
  *
557
950
  * ```ts
558
951
  * import { Schema } from "effect"
559
952
  *
560
953
  * const schema = Schema.Struct({
561
954
  * name: Schema.String,
562
- * age: Schema.optionalKey(Schema.Number)
955
+ * age: Schema.optional(Schema.Number)
563
956
  * })
564
957
  *
565
- * // Type: { readonly name: string; readonly age?: number | undefined }
566
- * type Person = typeof schema["Type"]
958
+ * // { readonly name: string; readonly age?: number | undefined }
959
+ * type Person = typeof schema.Type
567
960
  * ```
568
961
  *
569
962
  * @since 4.0.0
570
963
  */
571
964
  export const optional = /*#__PURE__*/Struct_.lambda(self => optionalKey(UndefinedOr(self)));
572
965
  /**
966
+ * Reverses {@link optional}, returning the inner schema (unwrapping `UndefinedOr`).
967
+ * Only applicable to schemas already wrapped with `optional`.
968
+ *
573
969
  * @since 4.0.0
574
970
  */
575
971
  export const required = /*#__PURE__*/Struct_.lambda(self => self.schema.members[0]);
576
972
  /**
973
+ * Makes a struct field mutable (removes the `readonly` modifier on the property).
974
+ * Use {@link readonlyKey} to reverse.
975
+ *
577
976
  * @since 4.0.0
578
977
  */
579
978
  export const mutableKey = /*#__PURE__*/Struct_.lambda(schema => make(AST.mutableKey(schema.ast), {
580
979
  schema
581
980
  }));
582
981
  /**
982
+ * Reverses {@link mutableKey}, returning the inner schema as readonly again.
983
+ * Only applicable to schemas already wrapped with `mutableKey`.
984
+ *
583
985
  * @since 4.0.0
584
986
  */
585
987
  export const readonlyKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
586
988
  /**
989
+ * Extracts the type-side schema: sets `Encoded` to equal the decoded `Type`,
990
+ * discarding the encoding transformation path.
991
+ *
587
992
  * @since 4.0.0
588
993
  */
589
994
  export const toType = /*#__PURE__*/Struct_.lambda(schema => make(AST.toType(schema.ast), {
590
995
  schema
591
996
  }));
592
997
  /**
998
+ * Extracts the encoded-side schema: sets `Type` to equal the `Encoded`,
999
+ * discarding the decoding transformation path.
1000
+ *
593
1001
  * @since 4.0.0
594
1002
  */
595
1003
  export const toEncoded = /*#__PURE__*/Struct_.lambda(schema => make(AST.toEncoded(schema.ast), {
@@ -609,6 +1017,16 @@ export function flip(schema) {
609
1017
  });
610
1018
  }
611
1019
  /**
1020
+ * Creates a schema for a single literal value (string, number, bigint, boolean, or null).
1021
+ *
1022
+ * **Example** (String literal)
1023
+ * ```ts
1024
+ * import { Schema } from "effect"
1025
+ *
1026
+ * const schema = Schema.Literal("hello")
1027
+ * // Type: Schema.Literal<"hello">
1028
+ * ```
1029
+ *
612
1030
  * @see {@link Literals} for a schema that represents a union of literals.
613
1031
  * @see {@link tag} for a schema that represents a literal value that can be
614
1032
  * used as a discriminator field in tagged unions and has a constructor default.
@@ -630,6 +1048,18 @@ function templateLiteralFromParts(parts) {
630
1048
  return new AST.TemplateLiteral(parts.map(part => isSchema(part) ? part.ast : new AST.Literal(part)));
631
1049
  }
632
1050
  /**
1051
+ * Creates a schema that validates strings matching a template literal pattern. Each part can be
1052
+ * a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
1053
+ *
1054
+ * **Example** (URL path pattern)
1055
+ * ```ts
1056
+ * import { Schema } from "effect"
1057
+ *
1058
+ * const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
1059
+ * // matches strings like "/user/123", "/user/42", etc.
1060
+ * ```
1061
+ *
1062
+ * @see {@link TemplateLiteralParser} for a schema that also parses matched parts into a tuple.
633
1063
  * @since 4.0.0
634
1064
  */
635
1065
  export function TemplateLiteral(parts) {
@@ -638,6 +1068,18 @@ export function TemplateLiteral(parts) {
638
1068
  });
639
1069
  }
640
1070
  /**
1071
+ * Like {@link TemplateLiteral} but decodes the matched string into a readonly tuple of typed values,
1072
+ * one element per schema part.
1073
+ *
1074
+ * **Example** (Parse path parameters)
1075
+ * ```ts
1076
+ * import { Schema } from "effect"
1077
+ *
1078
+ * const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
1079
+ * // decodes "/user/42" => readonly ["/user/", 42]
1080
+ * ```
1081
+ *
1082
+ * @see {@link TemplateLiteral} for a validation-only version that keeps the string encoded.
641
1083
  * @since 4.0.0
642
1084
  */
643
1085
  export function TemplateLiteralParser(parts) {
@@ -646,6 +1088,21 @@ export function TemplateLiteralParser(parts) {
646
1088
  });
647
1089
  }
648
1090
  /**
1091
+ * Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
1092
+ *
1093
+ * **Example** (Direction enum)
1094
+ * ```ts
1095
+ * import { Schema } from "effect"
1096
+ *
1097
+ * enum Direction {
1098
+ * Up = "Up",
1099
+ * Down = "Down"
1100
+ * }
1101
+ *
1102
+ * const schema = Schema.Enum(Direction)
1103
+ * // accepts "Up" or "Down"
1104
+ * ```
1105
+ *
649
1106
  * @since 4.0.0
650
1107
  */
651
1108
  export function Enum(enums) {
@@ -654,84 +1111,102 @@ export function Enum(enums) {
654
1111
  });
655
1112
  }
656
1113
  /**
1114
+ * Schema for the `never` type. Always fails validation — no value satisfies it.
1115
+ *
657
1116
  * @since 4.0.0
658
1117
  */
659
1118
  export const Never = /*#__PURE__*/make(AST.never);
660
1119
  /**
1120
+ * Schema for the `any` type. Accepts any value without validation.
1121
+ *
1122
+ * @see {@link Unknown} for a safer alternative that uses `unknown`.
661
1123
  * @since 4.0.0
662
1124
  */
663
1125
  export const Any = /*#__PURE__*/make(AST.any);
664
1126
  /**
1127
+ * Schema for the `unknown` type. Accepts any value without validation.
1128
+ *
1129
+ * @see {@link Any} for the `any` variant.
665
1130
  * @since 4.0.0
666
1131
  */
667
1132
  export const Unknown = /*#__PURE__*/make(AST.unknown);
668
1133
  /**
1134
+ * Schema for the `null` literal. Validates that the input is strictly `null`.
1135
+ *
1136
+ * @see {@link NullOr} for a union with another schema.
669
1137
  * @since 4.0.0
670
1138
  */
671
1139
  export const Null = /*#__PURE__*/make(AST.null);
672
1140
  /**
1141
+ * Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
1142
+ *
1143
+ * @see {@link UndefinedOr} for a union with another schema.
673
1144
  * @since 4.0.0
674
1145
  */
675
1146
  export const Undefined = /*#__PURE__*/make(AST.undefined);
676
1147
  /**
677
- * A schema for all strings.
1148
+ * Schema for `string` values. Validates that the input is `typeof` `"string"`.
678
1149
  *
679
1150
  * @since 4.0.0
680
1151
  */
681
1152
  export const String = /*#__PURE__*/make(AST.string);
682
1153
  /**
683
- * A schema for all numbers, including `NaN`, `Infinity`, and `-Infinity`.
1154
+ * Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
684
1155
  *
685
1156
  * **Default Json Serializer**
686
1157
  *
687
- * - If the number is finite, it is serialized as a number.
688
- * - Otherwise, it is serialized as a string ("NaN", "Infinity", or "-Infinity").
1158
+ * - Finite numbers are serialized as numbers.
1159
+ * - Non-finite values are serialized as strings (`"NaN"`, `"Infinity"`, `"-Infinity"`).
689
1160
  *
1161
+ * @see {@link Finite} for a schema that excludes non-finite values.
690
1162
  * @since 4.0.0
691
1163
  */
692
1164
  export const Number = /*#__PURE__*/make(AST.number);
693
1165
  /**
694
- * A schema for all booleans.
1166
+ * Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
695
1167
  *
696
1168
  * @category Boolean
697
1169
  * @since 4.0.0
698
1170
  */
699
1171
  export const Boolean = /*#__PURE__*/make(AST.boolean);
700
1172
  /**
701
- * A schema for all symbols.
1173
+ * Schema for `symbol` values. Validates that the input is `typeof` `"symbol"`.
702
1174
  *
1175
+ * @see {@link UniqueSymbol} for a schema that matches a specific symbol.
703
1176
  * @since 4.0.0
704
1177
  */
705
1178
  export const Symbol = /*#__PURE__*/make(AST.symbol);
706
1179
  /**
707
- * A schema for all bigints.
1180
+ * Schema for `bigint` values. Validates that the input is `typeof` `"bigint"`.
708
1181
  *
709
1182
  * @since 4.0.0
710
1183
  */
711
1184
  export const BigInt = /*#__PURE__*/make(AST.bigInt);
712
1185
  /**
713
- * A schema for the `void` type.
1186
+ * Schema for the `void` type. Accepts `undefined` as the encoded value.
714
1187
  *
715
1188
  * @since 4.0.0
716
1189
  */
717
1190
  export const Void = /*#__PURE__*/make(AST.void);
718
1191
  /**
719
- * A schema for the `object` type.
1192
+ * Schema for the `object` type. Validates that the input is a non-null object or function
1193
+ * (i.e. `typeof value === "object" && value !== null || typeof value === "function"`).
720
1194
  *
721
1195
  * @since 4.0.0
722
1196
  */
723
1197
  export const ObjectKeyword = /*#__PURE__*/make(AST.objectKeyword);
724
1198
  /**
725
- * A schema for unique symbols.
726
- *
727
- * **Example**
1199
+ * Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
728
1200
  *
1201
+ * **Example** (Specific symbol)
729
1202
  * ```ts
730
1203
  * import { Schema } from "effect"
731
1204
  *
732
- * const a = Symbol.for("a")
733
- * const schema = Schema.UniqueSymbol(a)
1205
+ * const mySymbol = Symbol.for("mySymbol")
1206
+ * const schema = Schema.UniqueSymbol(mySymbol)
734
1207
  * ```
1208
+ *
1209
+ * @see {@link Symbol} for a schema that accepts any symbol.
735
1210
  * @since 4.0.0
736
1211
  */
737
1212
  export function UniqueSymbol(symbol) {
@@ -747,6 +1222,34 @@ function makeStruct(ast, fields) {
747
1222
  });
748
1223
  }
749
1224
  /**
1225
+ * Defines a struct schema from a map of field schemas.
1226
+ *
1227
+ * Each field value is a schema. Use {@link optionalKey} or {@link optional} to
1228
+ * mark fields as optional, and {@link mutableKey} to mark them as mutable.
1229
+ *
1230
+ * The resulting schema's `Type` is a readonly object type with the fields'
1231
+ * decoded types. The `Encoded` form mirrors the field schemas' encoded types.
1232
+ *
1233
+ * **Example** (Basic struct)
1234
+ *
1235
+ * ```ts
1236
+ * import { Schema } from "effect"
1237
+ *
1238
+ * const Person = Schema.Struct({
1239
+ * name: Schema.String,
1240
+ * age: Schema.Number,
1241
+ * email: Schema.optionalKey(Schema.String)
1242
+ * })
1243
+ *
1244
+ * // { readonly name: string; readonly age: number; readonly email?: string }
1245
+ * type Person = typeof Person.Type
1246
+ *
1247
+ * const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
1248
+ * console.log(alice)
1249
+ * // { name: 'Alice', age: 30 }
1250
+ * ```
1251
+ *
1252
+ * @category Constructors
750
1253
  * @since 4.0.0
751
1254
  */
752
1255
  export function Struct(fields) {
@@ -774,6 +1277,26 @@ export function fieldsAssign(fields) {
774
1277
  return Struct_.lambda(struct => struct.mapFields(Struct_.assign(fields)));
775
1278
  }
776
1279
  /**
1280
+ * Renames struct keys in the encoded form without changing the decoded type.
1281
+ *
1282
+ * Takes a partial mapping `{ decodedKey: encodedKey }` and produces a
1283
+ * transformation schema that decodes from the renamed keys and encodes back to
1284
+ * the renamed keys. Keys not present in the mapping are left unchanged.
1285
+ *
1286
+ * **Example** (Rename `name` to `full_name` in the encoded form)
1287
+ *
1288
+ * ```ts
1289
+ * import { Schema } from "effect"
1290
+ *
1291
+ * const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
1292
+ * const Encoded = Person.pipe(Schema.encodeKeys({ name: "full_name" }))
1293
+ *
1294
+ * // Decodes { full_name: "Alice", age: 30 } → { name: "Alice", age: 30 }
1295
+ * const alice = Schema.decodeUnknownSync(Encoded)({ full_name: "Alice", age: 30 })
1296
+ * console.log(alice)
1297
+ * // { name: 'Alice', age: 30 }
1298
+ * ```
1299
+ *
777
1300
  * @category Struct transformations
778
1301
  * @since 4.0.0
779
1302
  */
@@ -782,11 +1305,12 @@ export function encodeKeys(mapping) {
782
1305
  const fields = {};
783
1306
  const reverseMapping = {};
784
1307
  for (const k in self.fields) {
1308
+ const encoded = toEncoded(self.fields[k]);
785
1309
  if (Object.hasOwn(mapping, k)) {
786
- fields[mapping[k]] = toEncoded(self.fields[k]);
1310
+ fields[mapping[k]] = encoded;
787
1311
  reverseMapping[mapping[k]] = k;
788
1312
  } else {
789
- fields[k] = self.fields[k];
1313
+ fields[k] = encoded;
790
1314
  }
791
1315
  }
792
1316
  return Struct(fields).pipe(decodeTo(self, Transformation.transform({
@@ -796,6 +1320,31 @@ export function encodeKeys(mapping) {
796
1320
  };
797
1321
  }
798
1322
  /**
1323
+ * Adds derived fields to a struct schema during decoding.
1324
+ *
1325
+ * Each new field is derived from the decoded struct value via a function that
1326
+ * returns `Option`. On encoding the derived fields are stripped. This allows
1327
+ * computed or enriched fields to live in the decoded type without appearing in
1328
+ * the encoded form.
1329
+ *
1330
+ * **Example** (Add a computed `fullName` field)
1331
+ *
1332
+ * ```ts
1333
+ * import { Option, Schema } from "effect"
1334
+ *
1335
+ * const Person = Schema.Struct({ first: Schema.String, last: Schema.String })
1336
+ * const Extended = Person.pipe(
1337
+ * Schema.extendTo(
1338
+ * { fullName: Schema.String },
1339
+ * { fullName: (p) => Option.some(`${p.first} ${p.last}`) }
1340
+ * )
1341
+ * )
1342
+ *
1343
+ * const alice = Schema.decodeUnknownSync(Extended)({ first: "Alice", last: "Smith" })
1344
+ * console.log(alice.fullName)
1345
+ * // Alice Smith
1346
+ * ```
1347
+ *
799
1348
  * @since 4.0.0
800
1349
  * @experimental
801
1350
  */
@@ -835,6 +1384,24 @@ derive) {
835
1384
  };
836
1385
  }
837
1386
  /**
1387
+ * Defines a record (dictionary) schema with typed keys and values.
1388
+ *
1389
+ * **Example** (String-keyed record of numbers)
1390
+ *
1391
+ * ```ts
1392
+ * import { Schema } from "effect"
1393
+ *
1394
+ * const schema = Schema.Record(Schema.String, Schema.Number)
1395
+ *
1396
+ * // { readonly [x: string]: number }
1397
+ * type R = typeof schema.Type
1398
+ *
1399
+ * const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
1400
+ * console.log(result)
1401
+ * // { a: 1, b: 2 }
1402
+ * ```
1403
+ *
1404
+ * @category Constructors
838
1405
  * @since 4.0.0
839
1406
  */
840
1407
  export function Record(key, value, options) {
@@ -845,6 +1412,24 @@ export function Record(key, value, options) {
845
1412
  });
846
1413
  }
847
1414
  /**
1415
+ * Extends a struct schema with one or more record (index-signature) schemas,
1416
+ * producing a schema whose decoded type intersects the struct and all records.
1417
+ *
1418
+ * **Example** (Struct with string-indexed extra keys)
1419
+ *
1420
+ * ```ts
1421
+ * import { Schema } from "effect"
1422
+ *
1423
+ * const schema = Schema.StructWithRest(
1424
+ * Schema.Struct({ id: Schema.Number }),
1425
+ * [Schema.Record(Schema.String, Schema.String)]
1426
+ * )
1427
+ *
1428
+ * // { readonly id: number } & { readonly [x: string]: string }
1429
+ * type T = typeof schema.Type
1430
+ * ```
1431
+ *
1432
+ * @category Constructors
848
1433
  * @since 4.0.0
849
1434
  */
850
1435
  export function StructWithRest(schema, records) {
@@ -863,6 +1448,20 @@ function makeTuple(ast, elements) {
863
1448
  });
864
1449
  }
865
1450
  /**
1451
+ * Defines a fixed-length tuple schema from an array of element schemas.
1452
+ *
1453
+ * **Example** (Pair of string and number)
1454
+ *
1455
+ * ```ts
1456
+ * import { Schema } from "effect"
1457
+ *
1458
+ * const schema = Schema.Tuple([Schema.String, Schema.Number])
1459
+ *
1460
+ * const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
1461
+ * console.log(pair)
1462
+ * // [ 'hello', 42 ]
1463
+ * ```
1464
+ *
866
1465
  * @category Constructors
867
1466
  * @since 4.0.0
868
1467
  */
@@ -870,6 +1469,26 @@ export function Tuple(elements) {
870
1469
  return makeTuple(AST.tuple(elements), elements);
871
1470
  }
872
1471
  /**
1472
+ * Extends a fixed-length tuple schema with rest elements, creating a variadic
1473
+ * tuple that starts with the fixed elements and ends with zero or more rest
1474
+ * elements.
1475
+ *
1476
+ * **Example** (Tuple with rest)
1477
+ *
1478
+ * ```ts
1479
+ * import { Schema } from "effect"
1480
+ *
1481
+ * // [string, number, ...boolean[]]
1482
+ * const schema = Schema.TupleWithRest(
1483
+ * Schema.Tuple([Schema.String, Schema.Number]),
1484
+ * [Schema.Boolean]
1485
+ * )
1486
+ *
1487
+ * const result = Schema.decodeUnknownSync(schema)(["hello", 1, true, false])
1488
+ * console.log(result)
1489
+ * // [ 'hello', 1, true, false ]
1490
+ * ```
1491
+ *
873
1492
  * @category Constructors
874
1493
  * @since 4.0.0
875
1494
  */
@@ -880,6 +1499,20 @@ export function TupleWithRest(schema, rest) {
880
1499
  });
881
1500
  }
882
1501
  /**
1502
+ * Defines a `ReadonlyArray` schema for a given element schema.
1503
+ *
1504
+ * **Example** (Array of strings)
1505
+ *
1506
+ * ```ts
1507
+ * import { Schema } from "effect"
1508
+ *
1509
+ * const schema = Schema.Array(Schema.String)
1510
+ *
1511
+ * const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
1512
+ * console.log(result)
1513
+ * // [ 'a', 'b', 'c' ]
1514
+ * ```
1515
+ *
883
1516
  * @category Constructors
884
1517
  * @since 4.0.0
885
1518
  */
@@ -887,6 +1520,20 @@ export const Array = /*#__PURE__*/Struct_.lambda(schema => make(new AST.Arrays(f
887
1520
  schema
888
1521
  }));
889
1522
  /**
1523
+ * Defines a non-empty `ReadonlyArray` schema — at least one element required.
1524
+ * Type is `readonly [T, ...T[]]`.
1525
+ *
1526
+ * **Example** (Non-empty array of numbers)
1527
+ *
1528
+ * ```ts
1529
+ * import { Schema } from "effect"
1530
+ *
1531
+ * const schema = Schema.NonEmptyArray(Schema.Number)
1532
+ *
1533
+ * Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
1534
+ * Schema.decodeUnknownSync(schema)([]) // throws
1535
+ * ```
1536
+ *
890
1537
  * @category Constructors
891
1538
  * @since 4.0.0
892
1539
  */
@@ -906,7 +1553,18 @@ export function UniqueArray(item) {
906
1553
  return Array(item).check(isUnique());
907
1554
  }
908
1555
  /**
909
- * Makes arrays or tuples mutable.
1556
+ * Makes an array or tuple schema mutable, removing the `readonly` modifier.
1557
+ *
1558
+ * **Example** (Mutable array)
1559
+ *
1560
+ * ```ts
1561
+ * import { Schema } from "effect"
1562
+ *
1563
+ * const schema = Schema.mutable(Schema.Array(Schema.Number))
1564
+ *
1565
+ * // number[] (mutable)
1566
+ * type T = typeof schema.Type
1567
+ * ```
910
1568
  *
911
1569
  * @since 4.0.0
912
1570
  */
@@ -925,12 +1583,23 @@ function makeUnion(ast, members) {
925
1583
  });
926
1584
  }
927
1585
  /**
928
- * Creates a schema that represents a union of multiple schemas. Members are checked in order, and the first match is returned.
1586
+ * Creates a union schema from an array of member schemas. Members are tested in
1587
+ * order; the first match is returned.
1588
+ *
1589
+ * Optionally, specify `mode`:
1590
+ * - `"anyOf"` (default) — matches if any member matches.
1591
+ * - `"oneOf"` — matches if exactly one member matches.
1592
+ *
1593
+ * **Example** (String or number union)
1594
+ *
1595
+ * ```ts
1596
+ * import { Schema } from "effect"
929
1597
  *
930
- * Optionally, you can specify the `mode` to be `"anyOf"` or `"oneOf"`.
1598
+ * const schema = Schema.Union([Schema.String, Schema.Number])
931
1599
  *
932
- * - `"anyOf"` - The union matches if any member matches.
933
- * - `"oneOf"` - The union matches if exactly one member matches.
1600
+ * Schema.decodeUnknownSync(schema)("hello") // "hello"
1601
+ * Schema.decodeUnknownSync(schema)(42) // 42
1602
+ * ```
934
1603
  *
935
1604
  * @category Constructors
936
1605
  * @since 4.0.0
@@ -939,6 +1608,16 @@ export function Union(members, options) {
939
1608
  return makeUnion(AST.union(members, options?.mode ?? "anyOf", undefined), members);
940
1609
  }
941
1610
  /**
1611
+ * Creates a union schema from an array of literal values.
1612
+ *
1613
+ * **Example** (Status codes)
1614
+ * ```ts
1615
+ * import { Schema } from "effect"
1616
+ *
1617
+ * const schema = Schema.Literals(["active", "inactive", "pending"])
1618
+ * // accepts "active", "inactive", or "pending"
1619
+ * ```
1620
+ *
942
1621
  * @see {@link Literal} for a schema that represents a single literal.
943
1622
  * @category Constructors
944
1623
  * @since 4.0.0
@@ -960,16 +1639,21 @@ export function Literals(literals) {
960
1639
  });
961
1640
  }
962
1641
  /**
1642
+ * Creates a union schema of `S | null`.
1643
+ *
963
1644
  * @category Constructors
964
1645
  * @since 4.0.0
965
1646
  */
966
1647
  export const NullOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null]));
967
1648
  /**
1649
+ * Creates a union schema of `S | undefined`.
1650
+ *
968
1651
  * @category Constructors
969
1652
  * @since 4.0.0
970
1653
  */
971
1654
  export const UndefinedOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Undefined]));
972
1655
  /**
1656
+ * Creates a union schema of `S | null | undefined`.
973
1657
  * @category Constructors
974
1658
  * @since 4.0.0
975
1659
  */
@@ -979,6 +1663,21 @@ export const NullishOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null,
979
1663
  * essential for creating recursive schemas where a schema references itself,
980
1664
  * preventing infinite recursion during schema definition.
981
1665
  *
1666
+ * **Example** (Recursive tree schema)
1667
+ * ```ts
1668
+ * import { Schema } from "effect"
1669
+ *
1670
+ * interface Tree {
1671
+ * readonly value: number
1672
+ * readonly children: ReadonlyArray<Tree>
1673
+ * }
1674
+ *
1675
+ * const Tree = Schema.Struct({
1676
+ * value: Schema.Number,
1677
+ * children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
1678
+ * })
1679
+ * ```
1680
+ *
982
1681
  * @category Constructors
983
1682
  * @since 4.0.0
984
1683
  */
@@ -986,6 +1685,18 @@ export function suspend(f) {
986
1685
  return make(new AST.Suspend(() => f().ast));
987
1686
  }
988
1687
  /**
1688
+ * Pipeable function that attaches one or more filter checks to a schema without
1689
+ * changing the TypeScript type.
1690
+ *
1691
+ * **Example** (Adding checks to a schema)
1692
+ * ```ts
1693
+ * import { Schema } from "effect"
1694
+ *
1695
+ * const AgeSchema = Schema.Number.pipe(
1696
+ * Schema.check(Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(120))
1697
+ * )
1698
+ * ```
1699
+ *
989
1700
  * @category Filtering
990
1701
  * @since 4.0.0
991
1702
  */
@@ -993,6 +1704,9 @@ export function check(...checks) {
993
1704
  return self => self.check(...checks);
994
1705
  }
995
1706
  /**
1707
+ * Narrows the TypeScript type of a schema's output via a type guard predicate,
1708
+ * attaching the guard as a runtime filter check.
1709
+ *
996
1710
  * @category Filtering
997
1711
  * @since 4.0.0
998
1712
  */
@@ -1002,7 +1716,8 @@ export function refine(refinement, annotations) {
1002
1716
  });
1003
1717
  }
1004
1718
  /**
1005
- * Adds a brand to a schema.
1719
+ * Adds a nominal brand to a schema, intersecting the output type with
1720
+ * `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
1006
1721
  *
1007
1722
  * @category Branding
1008
1723
  * @since 4.0.0
@@ -1014,7 +1729,10 @@ export function brand(identifier) {
1014
1729
  });
1015
1730
  }
1016
1731
  /**
1017
- * @category Constructors
1732
+ * Creates a branded schema from a {@link Brand.Constructor}, applying the
1733
+ * constructor's checks and brand tag to the underlying schema.
1734
+ *
1735
+ * @category Branding
1018
1736
  * @since 4.0.0
1019
1737
  */
1020
1738
  export function fromBrand(identifier, ctor) {
@@ -1023,6 +1741,25 @@ export function fromBrand(identifier, ctor) {
1023
1741
  };
1024
1742
  }
1025
1743
  /**
1744
+ * Intercepts the decoding pipeline of a schema.
1745
+ *
1746
+ * The provided function receives the current decoding `Effect` and `ParseOptions`,
1747
+ * and returns a new `Effect` — potentially adding service requirements (`RD`),
1748
+ * recovering from errors, or augmenting the result.
1749
+ *
1750
+ * **Example** (Logging decode failures)
1751
+ *
1752
+ * ```ts
1753
+ * import { Effect, Schema } from "effect"
1754
+ *
1755
+ * const Logged = Schema.String.pipe(
1756
+ * Schema.middlewareDecoding((effect) =>
1757
+ * Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
1758
+ * )
1759
+ * )
1760
+ * ```
1761
+ *
1762
+ * @see {@link catchDecoding} for a simpler error-recovery variant
1026
1763
  * @since 4.0.0
1027
1764
  */
1028
1765
  export function middlewareDecoding(decode) {
@@ -1031,6 +1768,25 @@ export function middlewareDecoding(decode) {
1031
1768
  });
1032
1769
  }
1033
1770
  /**
1771
+ * Intercepts the encoding pipeline of a schema.
1772
+ *
1773
+ * The provided function receives the current encoding `Effect` and `ParseOptions`,
1774
+ * and returns a new `Effect` — potentially adding service requirements (`RE`),
1775
+ * recovering from errors, or augmenting the result.
1776
+ *
1777
+ * **Example** (Logging encode failures)
1778
+ *
1779
+ * ```ts
1780
+ * import { Effect, Schema } from "effect"
1781
+ *
1782
+ * const Logged = Schema.String.pipe(
1783
+ * Schema.middlewareEncoding((effect) =>
1784
+ * Effect.tapError(effect, (issue) => Effect.log("encode failed", issue))
1785
+ * )
1786
+ * )
1787
+ * ```
1788
+ *
1789
+ * @see {@link catchEncoding} for a simpler error-recovery variant
1034
1790
  * @since 4.0.0
1035
1791
  */
1036
1792
  export function middlewareEncoding(encode) {
@@ -1039,24 +1795,50 @@ export function middlewareEncoding(encode) {
1039
1795
  });
1040
1796
  }
1041
1797
  /**
1798
+ * Recovers from a decoding error by providing a fallback value.
1799
+ *
1800
+ * The handler receives the `Issue` and returns an `Effect` that either
1801
+ * succeeds with a fallback value or re-fails with a (possibly different) issue.
1802
+ *
1803
+ * **Example** (Returning a default on decode failure)
1804
+ *
1805
+ * ```ts
1806
+ * import { Effect, Option, Schema } from "effect"
1807
+ *
1808
+ * const schema = Schema.Number.pipe(
1809
+ * Schema.catchDecoding((_issue) => Effect.succeed(Option.some(0)))
1810
+ * )
1811
+ * ```
1812
+ *
1813
+ * @see {@link catchDecodingWithContext} to add service requirements to the handler
1042
1814
  * @since 4.0.0
1043
1815
  */
1044
1816
  export function catchDecoding(f) {
1045
1817
  return catchDecodingWithContext(f);
1046
1818
  }
1047
1819
  /**
1820
+ * Like {@link catchDecoding}, but the handler may require Effect services (`R`).
1821
+ *
1048
1822
  * @since 4.0.0
1049
1823
  */
1050
1824
  export function catchDecodingWithContext(f) {
1051
1825
  return self => self.pipe(middlewareDecoding(Effect.catchEager(f)));
1052
1826
  }
1053
1827
  /**
1828
+ * Recovers from an encoding error by providing a fallback value.
1829
+ *
1830
+ * The handler receives the `Issue` and returns an `Effect` that either
1831
+ * succeeds with a fallback value or re-fails with a (possibly different) issue.
1832
+ *
1833
+ * @see {@link catchEncodingWithContext} to add service requirements to the handler
1054
1834
  * @since 4.0.0
1055
1835
  */
1056
1836
  export function catchEncoding(f) {
1057
1837
  return catchEncodingWithContext(f);
1058
1838
  }
1059
1839
  /**
1840
+ * Like {@link catchEncoding}, but the handler may require Effect services (`R`).
1841
+ *
1060
1842
  * @since 4.0.0
1061
1843
  */
1062
1844
  export function catchEncodingWithContext(f) {
@@ -1118,6 +1900,25 @@ export function encodeTo(to, transformation) {
1118
1900
  };
1119
1901
  }
1120
1902
  /**
1903
+ * Applies a transformation to a schema's encoded type, creating a new schema where encoding/decoding
1904
+ * operate on `S["Encoded"]` rather than `S["Type"]`.
1905
+ *
1906
+ * The `decode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during decoding),
1907
+ * and the `encode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during encoding).
1908
+ *
1909
+ * **Example** (Upper-casing encoded strings)
1910
+ *
1911
+ * ```ts
1912
+ * import { Schema, SchemaGetter } from "effect"
1913
+ *
1914
+ * const UpperFromLower = Schema.String.pipe(
1915
+ * Schema.encode({
1916
+ * decode: SchemaGetter.transform((s: string) => s.toLowerCase()),
1917
+ * encode: SchemaGetter.transform((s: string) => s.toUpperCase())
1918
+ * })
1919
+ * )
1920
+ * ```
1921
+ *
1121
1922
  * @since 4.0.0
1122
1923
  */
1123
1924
  export function encode(transformation) {
@@ -1126,6 +1927,32 @@ export function encode(transformation) {
1126
1927
  };
1127
1928
  }
1128
1929
  /**
1930
+ * Attaches a constructor default value to a schema field.
1931
+ *
1932
+ * The `defaultValue` function receives `Option.some(undefined)` when the field is
1933
+ * explicitly set to `undefined`, or `Option.none()` when the field is absent.
1934
+ * Return `Option.some(value)` to supply a default, or `Option.none()` to leave the
1935
+ * field required. An `Effect` may be returned for async or service-dependent defaults.
1936
+ *
1937
+ * Constructor defaults are applied only during `makeUnsafe` / `make`, not during
1938
+ * decoding or encoding.
1939
+ *
1940
+ * **Example** (Optional field with a static default)
1941
+ *
1942
+ * ```ts
1943
+ * import { Option, Schema } from "effect"
1944
+ *
1945
+ * const MySchema = Schema.Struct({
1946
+ * name: Schema.String.pipe(
1947
+ * Schema.optionalKey,
1948
+ * Schema.withConstructorDefault(() => Option.some("anonymous"))
1949
+ * )
1950
+ * })
1951
+ *
1952
+ * const value = MySchema.makeUnsafe({})
1953
+ * // value: { name: "anonymous" }
1954
+ * ```
1955
+ *
1129
1956
  * @since 4.0.0
1130
1957
  */
1131
1958
  export function withConstructorDefault(defaultValue) {
@@ -1142,6 +1969,27 @@ export function withConstructorDefault(defaultValue) {
1142
1969
  * - `passthrough`: (default) Pass the default value through to the output.
1143
1970
  * - `omit`: Omit the value from the output.
1144
1971
  *
1972
+ * Provides a default value for a missing key during decoding.
1973
+ *
1974
+ * When the key is absent from the input, `defaultValue()` is called to supply a value.
1975
+ * During encoding, the behavior is controlled by `options.encodingStrategy`:
1976
+ * - `"passthrough"` (default): include the value in the output
1977
+ * - `"omit"`: omit the key from the output
1978
+ *
1979
+ * **Example** (Default for a missing struct key)
1980
+ *
1981
+ * ```ts
1982
+ * import { Schema } from "effect"
1983
+ *
1984
+ * const MySchema = Schema.Struct({
1985
+ * name: Schema.String.pipe(Schema.withDecodingDefaultKey(() => "anonymous"))
1986
+ * })
1987
+ *
1988
+ * const result = Schema.decodeUnknownSync(MySchema)({})
1989
+ * // result: { name: "anonymous" }
1990
+ * ```
1991
+ *
1992
+ * @see {@link withDecodingDefault} for the `optional` (value-level) variant
1145
1993
  * @since 4.0.0
1146
1994
  */
1147
1995
  export function withDecodingDefaultKey(defaultValue, options) {
@@ -1160,6 +2008,30 @@ export function withDecodingDefaultKey(defaultValue, options) {
1160
2008
  * - `passthrough`: (default) Pass the default value through to the output.
1161
2009
  * - `omit`: Omit the value from the output.
1162
2010
  *
2011
+ * Provides a default value for an `optional` field during decoding.
2012
+ *
2013
+ * Similar to {@link withDecodingDefaultKey} but works on `optional` (value-level optional)
2014
+ * rather than `optionalKey` (key-level optional).
2015
+ *
2016
+ * When the value is `undefined` or absent, `defaultValue()` is called to supply a value.
2017
+ * During encoding, the behavior is controlled by `options.encodingStrategy`:
2018
+ * - `"passthrough"` (default): include the value in the output
2019
+ * - `"omit"`: omit the value from the output
2020
+ *
2021
+ * **Example** (Default for an optional field value)
2022
+ *
2023
+ * ```ts
2024
+ * import { Schema } from "effect"
2025
+ *
2026
+ * const MySchema = Schema.Struct({
2027
+ * name: Schema.String.pipe(Schema.optional, Schema.withDecodingDefault(() => "anonymous"))
2028
+ * })
2029
+ *
2030
+ * const result = Schema.decodeUnknownSync(MySchema)({ name: undefined })
2031
+ * // result: { name: "anonymous" }
2032
+ * ```
2033
+ *
2034
+ * @see {@link withDecodingDefaultKey} for the key-level variant
1163
2035
  * @since 4.0.0
1164
2036
  */
1165
2037
  export function withDecodingDefault(defaultValue, options) {
@@ -1172,23 +2044,50 @@ export function withDecodingDefault(defaultValue, options) {
1172
2044
  };
1173
2045
  }
1174
2046
  /**
1175
- * Creates a schema for a literal value and automatically provides itself as a
1176
- * default.
2047
+ * Combines a {@link Literal} schema with {@link withConstructorDefault}, making it ideal
2048
+ * for discriminator fields in tagged unions. When constructing via `makeUnsafe`, the
2049
+ * `_tag` field can be omitted and will be filled automatically.
1177
2050
  *
1178
- * The `tag` function combines a literal schema with a constructor default,
1179
- * making it perfect for discriminated unions and tagged data structures. The
1180
- * tag value is automatically provided when the field is missing during
1181
- * construction.
2051
+ * **Example** (Discriminated union tag)
1182
2052
  *
2053
+ * ```ts
2054
+ * import { Schema } from "effect"
2055
+ *
2056
+ * const A = Schema.Struct({ _tag: Schema.tag("A"), value: Schema.Number })
2057
+ *
2058
+ * // _tag is optional in makeUnsafe, auto-filled to "A"
2059
+ * const a = A.makeUnsafe({ value: 42 })
2060
+ * // a: { _tag: "A", value: 42 }
2061
+ * ```
2062
+ *
2063
+ * @see {@link tagDefaultOmit} to also omit the tag during encoding
2064
+ * @see {@link TaggedStruct} for a shorthand that adds `_tag` automatically
1183
2065
  * @since 4.0.0
1184
2066
  */
1185
2067
  export function tag(literal) {
1186
2068
  return Literal(literal).pipe(withConstructorDefault(() => Option_.some(literal)));
1187
2069
  }
1188
2070
  /**
1189
- * Similar to `tag`, but provides itself as a default when decoding and omits
1190
- * the value from the output when encoding.
2071
+ * Like {@link tag}, but additionally omits the tag field from the encoded output.
2072
+ * Useful when the encoded form (e.g. JSON) does not include the discriminator key,
2073
+ * but the decoded type and constructor still need it.
2074
+ *
2075
+ * **Example** (Tag omitted during encoding)
2076
+ *
2077
+ * ```ts
2078
+ * import { Schema } from "effect"
2079
+ *
2080
+ * const A = Schema.Struct({
2081
+ * _tag: Schema.tagDefaultOmit("A"),
2082
+ * value: Schema.Number
2083
+ * })
2084
+ *
2085
+ * // Encode strips the _tag field
2086
+ * const encoded = Schema.encodeUnknownSync(A)({ _tag: "A", value: 1 })
2087
+ * // encoded: { value: 1 }
2088
+ * ```
1191
2089
  *
2090
+ * @see {@link tag} for the variant that keeps the tag during encoding
1192
2091
  * @since 4.0.0
1193
2092
  */
1194
2093
  export function tagDefaultOmit(literal) {
@@ -1244,18 +2143,27 @@ export function TaggedStruct(value, fields) {
1244
2143
  ...fields
1245
2144
  });
1246
2145
  }
1247
- /** @internal */
1248
- export function _getTagValueIfPropertyKey(tag, ast) {
1249
- const ps = ast.propertySignatures.find(p => p.name === tag);
1250
- if (ps) {
1251
- if (AST.isLiteral(ps.type) && Predicate.isPropertyKey(ps.type.literal)) {
1252
- return ps.type.literal;
1253
- } else if (AST.isUniqueSymbol(ps.type)) {
1254
- return ps.type.symbol;
1255
- }
1256
- }
1257
- }
1258
2146
  /**
2147
+ * Augments an existing {@link Union} of tagged structs with utility methods keyed by the discriminant field.
2148
+ *
2149
+ * **Example** (Adding tagged-union utilities to an existing union)
2150
+ *
2151
+ * ```ts
2152
+ * import { Schema } from "effect"
2153
+ *
2154
+ * const A = Schema.TaggedStruct("A", { value: Schema.Number })
2155
+ * const B = Schema.TaggedStruct("B", { name: Schema.String })
2156
+ *
2157
+ * const MyUnion = Schema.Union([A, B]).pipe(Schema.toTaggedUnion("_tag"))
2158
+ *
2159
+ * // Pattern-match on the union
2160
+ * const result = MyUnion.match({ _tag: "A", value: 1 }, {
2161
+ * A: (a) => `number: ${a.value}`,
2162
+ * B: (b) => `name: ${b.name}`
2163
+ * })
2164
+ * ```
2165
+ *
2166
+ * @see {@link TaggedUnion} for a shorthand that builds the union from scratch
1259
2167
  * @since 4.0.0
1260
2168
  * @experimental
1261
2169
  */
@@ -1276,15 +2184,16 @@ export function toTaggedUnion(tag) {
1276
2184
  if (AST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) && schema.members.every(isSchema)) {
1277
2185
  return schema.members.forEach(walk);
1278
2186
  }
1279
- if (AST.isObjects(ast)) {
1280
- const key = _getTagValueIfPropertyKey(tag, ast);
1281
- if (key !== undefined) {
1282
- cases[key] = schema;
1283
- guards[key] = is(toType(schema));
2187
+ const sentinels = AST.collectSentinels(ast);
2188
+ if (sentinels.length > 0) {
2189
+ const literal = sentinels.find(s => s.key === tag)?.literal;
2190
+ if (Predicate.isPropertyKey(literal)) {
2191
+ cases[literal] = schema;
2192
+ guards[literal] = is(toType(schema));
1284
2193
  return;
1285
2194
  }
1286
2195
  }
1287
- throw new globalThis.Error("No literal found");
2196
+ throw new globalThis.Error("No literal or unique symbol found");
1288
2197
  }
1289
2198
  function match() {
1290
2199
  if (arguments.length === 1) {
@@ -1300,6 +2209,28 @@ export function toTaggedUnion(tag) {
1300
2209
  };
1301
2210
  }
1302
2211
  /**
2212
+ * Builds a discriminated union from a record of field sets, one per variant.
2213
+ * Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
2214
+ * The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
2215
+ *
2216
+ * **Example** (Discriminated union with pattern matching)
2217
+ *
2218
+ * ```ts
2219
+ * import { Schema } from "effect"
2220
+ *
2221
+ * const Shape = Schema.TaggedUnion({
2222
+ * Circle: { radius: Schema.Number },
2223
+ * Rectangle: { width: Schema.Number, height: Schema.Number }
2224
+ * })
2225
+ *
2226
+ * // Pattern-match on a decoded value
2227
+ * const area = Shape.match({ _tag: "Circle", radius: 5 }, {
2228
+ * Circle: (c) => Math.PI * c.radius ** 2,
2229
+ * Rectangle: (r) => r.width * r.height
2230
+ * })
2231
+ * ```
2232
+ *
2233
+ * @see {@link toTaggedUnion} to augment an existing union instead
1303
2234
  * @category Constructors
1304
2235
  * @since 4.0.0
1305
2236
  */
@@ -1323,6 +2254,23 @@ export function TaggedUnion(casesByTag) {
1323
2254
  });
1324
2255
  }
1325
2256
  /**
2257
+ * Wraps a schema so that its decoded `Type` becomes a nominally distinct type `Self`.
2258
+ * Useful for creating opaque types that are structurally identical to a base schema
2259
+ * but type-incompatible with it.
2260
+ *
2261
+ * **Example** (Opaque user ID)
2262
+ *
2263
+ * ```ts
2264
+ * import { Schema } from "effect"
2265
+ *
2266
+ * type UserId = string & { readonly _tag: "UserId" }
2267
+ * const UserId = Schema.Opaque<UserId>()(Schema.String)
2268
+ *
2269
+ * // Decoded value is UserId, not plain string
2270
+ * const id = Schema.decodeUnknownSync(UserId)("abc")
2271
+ * // id: UserId
2272
+ * ```
2273
+ *
1326
2274
  * @since 4.0.0
1327
2275
  */
1328
2276
  export function Opaque() {
@@ -1334,7 +2282,19 @@ export function Opaque() {
1334
2282
  };
1335
2283
  }
1336
2284
  /**
1337
- * Creates a schema that validates an instance of a specific class constructor.
2285
+ * Creates a schema that validates values using `instanceof`.
2286
+ * Decoding and encoding pass the value through unchanged.
2287
+ *
2288
+ * **Example** (Schema for a built-in class)
2289
+ *
2290
+ * ```ts
2291
+ * import { Schema } from "effect"
2292
+ *
2293
+ * const DateSchema = Schema.instanceOf(Date)
2294
+ *
2295
+ * const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
2296
+ * // decoded: Date
2297
+ * ```
1338
2298
  *
1339
2299
  * @category Constructors
1340
2300
  * @since 4.0.0
@@ -1343,6 +2303,9 @@ export function instanceOf(constructor, annotations) {
1343
2303
  return declare(u => u instanceof constructor, annotations);
1344
2304
  }
1345
2305
  /**
2306
+ * Constructs an `AST.Link` that describes how a value of type `T` encodes to and decodes from a `To` schema.
2307
+ * Used when building low-level AST transformations that bridge two schema types.
2308
+ *
1346
2309
  * @since 4.0.0
1347
2310
  * @experimental
1348
2311
  */
@@ -1355,11 +2318,30 @@ export function link() {
1355
2318
  // Checks
1356
2319
  // -----------------------------------------------------------------------------
1357
2320
  /**
2321
+ * Creates a custom filter check from a predicate function. The predicate
2322
+ * receives the input value, the schema's AST, and parse options, and returns
2323
+ * `true`/`undefined` on success or a failure description on error.
2324
+ *
2325
+ * **Example** (Custom filter check)
2326
+ * ```ts
2327
+ * import { Schema } from "effect"
2328
+ *
2329
+ * // Check that a number is even
2330
+ * const isEven = Schema.makeFilter(
2331
+ * (n: number) => n % 2 === 0 || "expected an even number"
2332
+ * )
2333
+ *
2334
+ * const EvenNumber = Schema.Number.check(isEven)
2335
+ * ```
2336
+ *
1358
2337
  * @category Checks Constructors
1359
2338
  * @since 4.0.0
1360
2339
  */
1361
2340
  export const makeFilter = AST.makeFilter;
1362
2341
  /**
2342
+ * Groups multiple checks into a single {@link AST.FilterGroup}, applying
2343
+ * optional shared annotations to the group as a whole.
2344
+ *
1363
2345
  * @category Checks Constructors
1364
2346
  * @since 4.0.0
1365
2347
  */
@@ -1847,6 +2829,9 @@ export function isFinite(annotations) {
1847
2829
  });
1848
2830
  }
1849
2831
  /**
2832
+ * Generic factory for creating a "greater than" (`>`) check for any ordered
2833
+ * type by supplying an {@link Order.Order} instance.
2834
+ *
1850
2835
  * @category Order checks
1851
2836
  * @since 4.0.0
1852
2837
  */
@@ -1862,6 +2847,9 @@ export function makeIsGreaterThan(options) {
1862
2847
  };
1863
2848
  }
1864
2849
  /**
2850
+ * Generic factory for creating a ">=" check for any ordered type by supplying
2851
+ * an {@link Order.Order} instance.
2852
+ *
1865
2853
  * @category Order checks
1866
2854
  * @since 4.0.0
1867
2855
  */
@@ -1877,6 +2865,9 @@ export function makeIsGreaterThanOrEqualTo(options) {
1877
2865
  };
1878
2866
  }
1879
2867
  /**
2868
+ * Generic factory for creating a "<" check for any ordered type by supplying
2869
+ * an {@link Order.Order} instance.
2870
+ *
1880
2871
  * @category Order checks
1881
2872
  * @since 4.0.0
1882
2873
  */
@@ -1892,6 +2883,9 @@ export function makeIsLessThan(options) {
1892
2883
  };
1893
2884
  }
1894
2885
  /**
2886
+ * Generic factory for creating a "<=" check for any ordered type by supplying
2887
+ * an {@link Order.Order} instance.
2888
+ *
1895
2889
  * @category Order checks
1896
2890
  * @since 4.0.0
1897
2891
  */
@@ -1907,6 +2901,9 @@ export function makeIsLessThanOrEqualTo(options) {
1907
2901
  };
1908
2902
  }
1909
2903
  /**
2904
+ * Generic factory for creating an inclusive/exclusive range check for any
2905
+ * ordered type by supplying an {@link Order.Order} instance.
2906
+ *
1910
2907
  * @category Order checks
1911
2908
  * @since 4.0.0
1912
2909
  */
@@ -1927,6 +2924,9 @@ export function makeIsBetween(deriveOptions) {
1927
2924
  };
1928
2925
  }
1929
2926
  /**
2927
+ * Generic factory for creating a divisibility check for any numeric type by
2928
+ * supplying a remainder function and a zero value.
2929
+ *
1930
2930
  * @category Numeric checks
1931
2931
  * @since 4.0.0
1932
2932
  */
@@ -2528,6 +3528,58 @@ export const isBetweenBigInt = /*#__PURE__*/makeIsBetween({
2528
3528
  }
2529
3529
  })
2530
3530
  });
3531
+ /**
3532
+ * Validates that a BigDecimal is greater than the specified value (exclusive).
3533
+ *
3534
+ * @category BigDecimal checks
3535
+ * @since 4.0.0
3536
+ */
3537
+ export const isGreaterThanBigDecimal = /*#__PURE__*/makeIsGreaterThan({
3538
+ order: BigDecimal_.Order,
3539
+ formatter: bd => BigDecimal_.format(bd)
3540
+ });
3541
+ /**
3542
+ * Validates that a BigDecimal is greater than or equal to the specified value
3543
+ * (inclusive).
3544
+ *
3545
+ * @category BigDecimal checks
3546
+ * @since 4.0.0
3547
+ */
3548
+ export const isGreaterThanOrEqualToBigDecimal = /*#__PURE__*/makeIsGreaterThanOrEqualTo({
3549
+ order: BigDecimal_.Order,
3550
+ formatter: bd => BigDecimal_.format(bd)
3551
+ });
3552
+ /**
3553
+ * Validates that a BigDecimal is less than the specified value (exclusive).
3554
+ *
3555
+ * @category BigDecimal checks
3556
+ * @since 4.0.0
3557
+ */
3558
+ export const isLessThanBigDecimal = /*#__PURE__*/makeIsLessThan({
3559
+ order: BigDecimal_.Order,
3560
+ formatter: bd => BigDecimal_.format(bd)
3561
+ });
3562
+ /**
3563
+ * Validates that a BigDecimal is less than or equal to the specified value
3564
+ * (inclusive).
3565
+ *
3566
+ * @category BigDecimal checks
3567
+ * @since 4.0.0
3568
+ */
3569
+ export const isLessThanOrEqualToBigDecimal = /*#__PURE__*/makeIsLessThanOrEqualTo({
3570
+ order: BigDecimal_.Order,
3571
+ formatter: bd => BigDecimal_.format(bd)
3572
+ });
3573
+ /**
3574
+ * Validates that a BigDecimal is within a specified range.
3575
+ *
3576
+ * @category BigDecimal checks
3577
+ * @since 4.0.0
3578
+ */
3579
+ export const isBetweenBigDecimal = /*#__PURE__*/makeIsBetween({
3580
+ order: BigDecimal_.Order,
3581
+ formatter: bd => BigDecimal_.format(bd)
3582
+ });
2531
3583
  /**
2532
3584
  * Validates that a value has at least the specified length. Works with strings
2533
3585
  * and arrays.
@@ -2543,6 +3595,14 @@ export const isBetweenBigInt = /*#__PURE__*/makeIsBetween({
2543
3595
  * constraint to ensure generated strings or arrays have at least the required
2544
3596
  * length.
2545
3597
  *
3598
+ * **Example** (Minimum length check)
3599
+ * ```ts
3600
+ * import { Schema } from "effect"
3601
+ *
3602
+ * const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1))
3603
+ * const NonEmptyArraySchema = Schema.Array(Schema.Number).check(Schema.isMinLength(1))
3604
+ * ```
3605
+ *
2546
3606
  * @category Length checks
2547
3607
  * @since 4.0.0
2548
3608
  */
@@ -2935,6 +3995,7 @@ export function isPropertyNames(keySchema, annotations) {
2935
3995
  * constraint using the provided equivalence function to ensure generated arrays
2936
3996
  * contain only unique items.
2937
3997
  *
3998
+ * @category Array checks
2938
3999
  * @since 4.0.0
2939
4000
  */
2940
4001
  export function isUnique(annotations) {
@@ -2969,6 +4030,8 @@ export const NonEmptyString = /*#__PURE__*/String.check(/*#__PURE__*/isNonEmpty(
2969
4030
  */
2970
4031
  export const Char = /*#__PURE__*/String.check(/*#__PURE__*/isLengthBetween(1, 1));
2971
4032
  /**
4033
+ * Creates a schema for `Option<A>`. See {@link Option} for details.
4034
+ *
2972
4035
  * @category Option
2973
4036
  * @since 4.0.0
2974
4037
  */
@@ -3041,6 +4104,40 @@ export function Option(value) {
3041
4104
  export function OptionFromNullOr(schema) {
3042
4105
  return NullOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullOr()));
3043
4106
  }
4107
+ /**
4108
+ * Decodes an undefined-or value `T` to a required `Option<T>` value.
4109
+ *
4110
+ * Decoding:
4111
+ * - `undefined` is decoded as `None`
4112
+ * - other values are decoded as `Some`
4113
+ *
4114
+ * Encoding:
4115
+ * - `None` is encoded as `undefined`
4116
+ * - `Some` is encoded as the value
4117
+ *
4118
+ * @category Option
4119
+ * @since 4.0.0
4120
+ */
4121
+ export function OptionFromUndefinedOr(schema) {
4122
+ return UndefinedOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromUndefinedOr()));
4123
+ }
4124
+ /**
4125
+ * Decodes a nullish value `T` to a required `Option<T>` value.
4126
+ *
4127
+ * Decoding:
4128
+ * - `null` and `undefined` are decoded as `None`
4129
+ * - other values are decoded as `Some`
4130
+ *
4131
+ * Encoding:
4132
+ * - `None` is encoded as `null` or `undefined` depending on the provided `options.onNoneEncoding` (defaults to `undefined`)
4133
+ * - `Some` is encoded as the value
4134
+ *
4135
+ * @category Option
4136
+ * @since 4.0.0
4137
+ */
4138
+ export function OptionFromNullishOr(schema, options) {
4139
+ return NullishOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullishOr(options)));
4140
+ }
3044
4141
  /**
3045
4142
  * Decodes an optional value `A` to a required `Option<A>` value.
3046
4143
  *
@@ -3078,6 +4175,8 @@ export function OptionFromOptional(schema) {
3078
4175
  return optional(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromOptional()));
3079
4176
  }
3080
4177
  /**
4178
+ * Creates a schema for `Result<A, E>`. See {@link Result} for details.
4179
+ *
3081
4180
  * @category Result
3082
4181
  * @since 4.0.0
3083
4182
  */
@@ -3206,6 +4305,9 @@ export function Redacted(value, options) {
3206
4305
  });
3207
4306
  }
3208
4307
  /**
4308
+ * Middleware that wraps decoded errors in `Redacted`, preventing sensitive
4309
+ * schema details from leaking in error messages.
4310
+ *
3209
4311
  * @category Redacted
3210
4312
  * @since 4.0.0
3211
4313
  */
@@ -3213,6 +4315,10 @@ export function redact(schema) {
3213
4315
  return schema.pipe(middlewareDecoding(Effect.mapErrorEager(Issue.redact)));
3214
4316
  }
3215
4317
  /**
4318
+ * Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
4319
+ * expects the input to already be a `Redacted` instance, this schema decodes
4320
+ * the raw value and wraps it.
4321
+ *
3216
4322
  * @category Redacted
3217
4323
  * @since 4.0.0
3218
4324
  */
@@ -3225,10 +4331,12 @@ export function RedactedFromValue(value, options) {
3225
4331
  }));
3226
4332
  }
3227
4333
  /**
3228
- * @category CauseFailure
4334
+ * Creates a schema for `Cause.Reason<E>`. See {@link CauseReason} for details.
4335
+ *
4336
+ * @category CauseReason
3229
4337
  * @since 4.0.0
3230
4338
  */
3231
- export function CauseFailure(error, defect) {
4339
+ export function CauseReason(error, defect) {
3232
4340
  const schema = declareConstructor()([error, defect], ([error, defect]) => (input, ast, options) => {
3233
4341
  if (!Cause_.isReason(input)) {
3234
4342
  return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
@@ -3252,7 +4360,7 @@ export function CauseFailure(error, defect) {
3252
4360
  _tag: "effect/Cause/Failure"
3253
4361
  },
3254
4362
  generation: {
3255
- runtime: `Schema.CauseFailure(?, ?)`,
4363
+ runtime: `Schema.CauseReason(?, ?)`,
3256
4364
  Type: `Cause.Failure<?, ?>`,
3257
4365
  importDeclaration: `import * as Cause from "effect/Cause"`
3258
4366
  },
@@ -3279,16 +4387,16 @@ export function CauseFailure(error, defect) {
3279
4387
  },
3280
4388
  encode: identity
3281
4389
  })),
3282
- toArbitrary: ([error, defect]) => causeFailureToArbitrary(error, defect),
3283
- toEquivalence: ([error, defect]) => causeFailureToEquivalence(error, defect),
3284
- toFormatter: ([error, defect]) => causeFailureToFormatter(error, defect)
4390
+ toArbitrary: ([error, defect]) => causeReasonToArbitrary(error, defect),
4391
+ toEquivalence: ([error, defect]) => causeReasonToEquivalence(error, defect),
4392
+ toFormatter: ([error, defect]) => causeReasonToFormatter(error, defect)
3285
4393
  });
3286
4394
  return make(schema.ast, {
3287
4395
  error,
3288
4396
  defect
3289
4397
  });
3290
4398
  }
3291
- function causeFailureToArbitrary(error, defect) {
4399
+ function causeReasonToArbitrary(error, defect) {
3292
4400
  return (fc, ctx) => {
3293
4401
  return fc.oneof(ctx?.isSuspend ? {
3294
4402
  maxDepth: 2,
@@ -3298,7 +4406,7 @@ function causeFailureToArbitrary(error, defect) {
3298
4406
  }).map(Cause_.makeInterruptReason), error.map(e => Cause_.makeFailReason(e)), defect.map(d => Cause_.makeDieReason(d)));
3299
4407
  };
3300
4408
  }
3301
- function causeFailureToEquivalence(error, defect) {
4409
+ function causeReasonToEquivalence(error, defect) {
3302
4410
  return (a, b) => {
3303
4411
  if (a._tag !== b._tag) return false;
3304
4412
  switch (a._tag) {
@@ -3311,7 +4419,7 @@ function causeFailureToEquivalence(error, defect) {
3311
4419
  }
3312
4420
  };
3313
4421
  }
3314
- function causeFailureToFormatter(error, defect) {
4422
+ function causeReasonToFormatter(error, defect) {
3315
4423
  return t => {
3316
4424
  switch (t._tag) {
3317
4425
  case "Fail":
@@ -3324,19 +4432,23 @@ function causeFailureToFormatter(error, defect) {
3324
4432
  };
3325
4433
  }
3326
4434
  /**
4435
+ * Creates a schema for `Cause<E>`. See {@link Cause} for details.
4436
+ *
3327
4437
  * @category Cause
3328
4438
  * @since 4.0.0
3329
4439
  */
3330
4440
  export function Cause(error, defect) {
3331
- const schema = declareConstructor()([error, defect], ([error, defect]) => (input, ast, options) => {
3332
- if (!Cause_.isCause(input)) {
3333
- return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
3334
- }
3335
- const failures = Array(CauseFailure(error, defect));
3336
- return Effect.mapBothEager(Parser.decodeUnknownEffect(failures)(input.reasons, options), {
3337
- onSuccess: Cause_.fromReasons,
3338
- onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["failures"], issue)])
3339
- });
4441
+ const schema = declareConstructor()([error, defect], ([error, defect]) => {
4442
+ const failures = Array(CauseReason(error, defect));
4443
+ return (input, ast, options) => {
4444
+ if (!Cause_.isCause(input)) {
4445
+ return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4446
+ }
4447
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(failures)(input.reasons, options), {
4448
+ onSuccess: Cause_.fromReasons,
4449
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["failures"], issue)])
4450
+ });
4451
+ };
3340
4452
  }, {
3341
4453
  typeConstructor: {
3342
4454
  _tag: "effect/Cause"
@@ -3347,7 +4459,7 @@ export function Cause(error, defect) {
3347
4459
  importDeclaration: `import * as Cause from "effect/Cause"`
3348
4460
  },
3349
4461
  expected: "Cause",
3350
- toCodec: ([error, defect]) => link()(Array(CauseFailure(error, defect)), Transformation.transform({
4462
+ toCodec: ([error, defect]) => link()(Array(CauseReason(error, defect)), Transformation.transform({
3351
4463
  decode: Cause_.fromReasons,
3352
4464
  encode: ({
3353
4465
  reasons: failures
@@ -3364,16 +4476,16 @@ export function Cause(error, defect) {
3364
4476
  }
3365
4477
  function causeToArbitrary(error, defect) {
3366
4478
  return (fc, ctx) => {
3367
- return fc.array(causeFailureToArbitrary(error, defect)(fc, ctx)).map(Cause_.fromReasons);
4479
+ return fc.array(causeReasonToArbitrary(error, defect)(fc, ctx)).map(Cause_.fromReasons);
3368
4480
  };
3369
4481
  }
3370
4482
  function causeToEquivalence(error, defect) {
3371
- const failures = Equivalence.Array(causeFailureToEquivalence(error, defect));
4483
+ const failures = Equivalence.Array(causeReasonToEquivalence(error, defect));
3372
4484
  return (a, b) => failures(a.reasons, b.reasons);
3373
4485
  }
3374
4486
  function causeToFormatter(error, defect) {
3375
- const causeFailure = causeFailureToFormatter(error, defect);
3376
- return t => `Cause([${t.reasons.map(causeFailure).join(", ")}])`;
4487
+ const causeReason = causeReasonToFormatter(error, defect);
4488
+ return t => `Cause([${t.reasons.map(causeReason).join(", ")}])`;
3377
4489
  }
3378
4490
  const ErrorJsonEncoded = /*#__PURE__*/Struct({
3379
4491
  message: String,
@@ -3455,27 +4567,31 @@ export const DefectWithStack = /*#__PURE__*/Union([/*#__PURE__*/ErrorJsonEncoded
3455
4567
  toArbitrary: () => fc => fc.json()
3456
4568
  }), defectTransformation))]);
3457
4569
  /**
4570
+ * Creates a schema for `Exit<A, E>`. See {@link Exit} for details.
4571
+ *
3458
4572
  * @category Exit
3459
4573
  * @since 4.0.0
3460
4574
  */
3461
4575
  export function Exit(value, error, defect) {
3462
- const schema = declareConstructor()([value, error, defect], ([value, error, defect]) => (input, ast, options) => {
3463
- if (!Exit_.isExit(input)) {
3464
- return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
3465
- }
4576
+ const schema = declareConstructor()([value, error, defect], ([value, error, defect]) => {
3466
4577
  const cause = Cause(error, defect);
3467
- switch (input._tag) {
3468
- case "Success":
3469
- return Effect.mapBothEager(Parser.decodeUnknownEffect(value)(input.value, options), {
3470
- onSuccess: Exit_.succeed,
3471
- onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["value"], issue)])
3472
- });
3473
- case "Failure":
3474
- return Effect.mapBothEager(Parser.decodeUnknownEffect(cause)(input.cause, options), {
3475
- onSuccess: Exit_.failCause,
3476
- onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["cause"], issue)])
3477
- });
3478
- }
4578
+ return (input, ast, options) => {
4579
+ if (!Exit_.isExit(input)) {
4580
+ return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4581
+ }
4582
+ switch (input._tag) {
4583
+ case "Success":
4584
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(value)(input.value, options), {
4585
+ onSuccess: Exit_.succeed,
4586
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["value"], issue)])
4587
+ });
4588
+ case "Failure":
4589
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(cause)(input.cause, options), {
4590
+ onSuccess: Exit_.failCause,
4591
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["cause"], issue)])
4592
+ });
4593
+ }
4594
+ };
3479
4595
  }, {
3480
4596
  typeConstructor: {
3481
4597
  _tag: "effect/Exit"
@@ -3543,91 +4659,253 @@ export function Exit(value, error, defect) {
3543
4659
  * @category ReadonlyMap
3544
4660
  * @since 4.0.0
3545
4661
  */
3546
- export function ReadonlyMap(key, value) {
3547
- const schema = declareConstructor()([key, value], ([key, value]) => (input, ast, options) => {
3548
- if (input instanceof globalThis.Map) {
3549
- const array = Array(Tuple([key, value]));
3550
- return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
3551
- onSuccess: array => new globalThis.Map(array),
3552
- onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["entries"], issue)])
3553
- });
3554
- }
3555
- return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4662
+ export function ReadonlyMap(key, value) {
4663
+ const schema = declareConstructor()([key, value], ([key, value]) => {
4664
+ const array = Array(Tuple([key, value]));
4665
+ return (input, ast, options) => {
4666
+ if (input instanceof globalThis.Map) {
4667
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
4668
+ onSuccess: array => new globalThis.Map(array),
4669
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["entries"], issue)])
4670
+ });
4671
+ }
4672
+ return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4673
+ };
4674
+ }, {
4675
+ typeConstructor: {
4676
+ _tag: "ReadonlyMap"
4677
+ },
4678
+ generation: {
4679
+ runtime: `Schema.ReadonlyMap(?, ?)`,
4680
+ Type: `globalThis.ReadonlyMap<?, ?>`
4681
+ },
4682
+ expected: "ReadonlyMap",
4683
+ toCodec: ([key, value]) => link()(Array(Tuple([key, value])), Transformation.transform({
4684
+ decode: e => new globalThis.Map(e),
4685
+ encode: map => [...map.entries()]
4686
+ })),
4687
+ toArbitrary: ([key, value]) => (fc, ctx) => {
4688
+ return fc.oneof(ctx?.isSuspend ? {
4689
+ maxDepth: 2,
4690
+ depthIdentifier: "ReadonlyMap"
4691
+ } : {}, fc.constant([]), fc.array(fc.tuple(key, value), ctx?.constraints?.array)).map(as => new globalThis.Map(as));
4692
+ },
4693
+ toEquivalence: ([key, value]) => Equal.makeCompareMap(key, value),
4694
+ toFormatter: ([key, value]) => t => {
4695
+ const size = t.size;
4696
+ if (size === 0) {
4697
+ return "ReadonlyMap(0) {}";
4698
+ }
4699
+ const entries = globalThis.Array.from(t.entries()).sort().map(([k, v]) => `${key(k)} => ${value(v)}`);
4700
+ return `ReadonlyMap(${size}) { ${entries.join(", ")} }`;
4701
+ }
4702
+ });
4703
+ return make(schema.ast, {
4704
+ key,
4705
+ value
4706
+ });
4707
+ }
4708
+ /**
4709
+ * Creates a schema that validates a `HashMap` where keys and values must
4710
+ * conform to the provided schemas.
4711
+ *
4712
+ * @category HashMap
4713
+ * @since 4.0.0
4714
+ */
4715
+ export function HashMap(key, value) {
4716
+ const schema = declareConstructor()([key, value], ([key, value]) => {
4717
+ const entries = Array(Tuple([key, value]));
4718
+ return (input, ast, options) => {
4719
+ if (HashMap_.isHashMap(input)) {
4720
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options), {
4721
+ onSuccess: HashMap_.fromIterable,
4722
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["entries"], issue)])
4723
+ });
4724
+ }
4725
+ return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4726
+ };
4727
+ }, {
4728
+ typeConstructor: {
4729
+ _tag: "effect/HashMap"
4730
+ },
4731
+ generation: {
4732
+ runtime: `Schema.HashMap(?, ?)`,
4733
+ Type: `HashMap.HashMap<?, ?>`,
4734
+ importDeclaration: `import * as HashMap from "effect/HashMap"`
4735
+ },
4736
+ expected: "HashMap",
4737
+ toCodec: ([key, value]) => link()(Array(Tuple([key, value])), Transformation.transform({
4738
+ decode: HashMap_.fromIterable,
4739
+ encode: HashMap_.toEntries
4740
+ })),
4741
+ toArbitrary: ([key, value]) => (fc, ctx) => {
4742
+ return fc.oneof(ctx?.isSuspend ? {
4743
+ maxDepth: 2,
4744
+ depthIdentifier: "HashMap"
4745
+ } : {}, fc.constant([]), fc.array(fc.tuple(key, value), ctx?.constraints?.array)).map(HashMap_.fromIterable);
4746
+ },
4747
+ toEquivalence: ([key, value]) => Equal.makeCompareMap(key, value),
4748
+ toFormatter: ([key, value]) => t => {
4749
+ const size = HashMap_.size(t);
4750
+ if (size === 0) {
4751
+ return "HashMap(0) {}";
4752
+ }
4753
+ const entries = HashMap_.toEntries(t).sort().map(([k, v]) => `${key(k)} => ${value(v)}`);
4754
+ return `HashMap(${size}) { ${entries.join(", ")} }`;
4755
+ }
4756
+ });
4757
+ return make(schema.ast, {
4758
+ key,
4759
+ value
4760
+ });
4761
+ }
4762
+ /**
4763
+ * @category ReadonlySet
4764
+ * @since 4.0.0
4765
+ */
4766
+ export function ReadonlySet(value) {
4767
+ const schema = declareConstructor()([value], ([value]) => {
4768
+ const array = Array(value);
4769
+ return (input, ast, options) => {
4770
+ if (input instanceof globalThis.Set) {
4771
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
4772
+ onSuccess: array => new globalThis.Set(array),
4773
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
4774
+ });
4775
+ }
4776
+ return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4777
+ };
4778
+ }, {
4779
+ typeConstructor: {
4780
+ _tag: "ReadonlySet"
4781
+ },
4782
+ generation: {
4783
+ runtime: `Schema.ReadonlySet(?)`,
4784
+ Type: `globalThis.ReadonlySet<?>`
4785
+ },
4786
+ expected: "ReadonlySet",
4787
+ toCodec: ([value]) => link()(Array(value), Transformation.transform({
4788
+ decode: e => new globalThis.Set(e),
4789
+ encode: set => [...set.values()]
4790
+ })),
4791
+ toArbitrary: ([value]) => (fc, ctx) => {
4792
+ return fc.oneof(ctx?.isSuspend ? {
4793
+ maxDepth: 2,
4794
+ depthIdentifier: "ReadonlySet"
4795
+ } : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(as => new globalThis.Set(as));
4796
+ },
4797
+ toEquivalence: ([value]) => Equal.makeCompareSet(value),
4798
+ toFormatter: ([value]) => t => {
4799
+ const size = t.size;
4800
+ if (size === 0) {
4801
+ return "ReadonlySet(0) {}";
4802
+ }
4803
+ const values = globalThis.Array.from(t.values()).sort().map(v => `${value(v)}`);
4804
+ return `ReadonlySet(${size}) { ${values.join(", ")} }`;
4805
+ }
4806
+ });
4807
+ return make(schema.ast, {
4808
+ value
4809
+ });
4810
+ }
4811
+ /**
4812
+ * Creates a schema that validates a `HashSet` where values must conform to the
4813
+ * provided schema.
4814
+ *
4815
+ * @category HashSet
4816
+ * @since 4.0.0
4817
+ */
4818
+ export function HashSet(value) {
4819
+ const schema = declareConstructor()([value], ([value]) => {
4820
+ const values = Array(value);
4821
+ return (input, ast, options) => {
4822
+ if (HashSet_.isHashSet(input)) {
4823
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
4824
+ onSuccess: HashSet_.fromIterable,
4825
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
4826
+ });
4827
+ }
4828
+ return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4829
+ };
3556
4830
  }, {
3557
4831
  typeConstructor: {
3558
- _tag: "ReadonlyMap"
4832
+ _tag: "effect/HashSet"
3559
4833
  },
3560
4834
  generation: {
3561
- runtime: `Schema.ReadonlyMap(?, ?)`,
3562
- Type: `globalThis.ReadonlyMap<?, ?>`
4835
+ runtime: `Schema.HashSet(?)`,
4836
+ Type: `HashSet.HashSet<?>`
3563
4837
  },
3564
- expected: "ReadonlyMap",
3565
- toCodec: ([key, value]) => link()(Array(Tuple([key, value])), Transformation.transform({
3566
- decode: e => new globalThis.Map(e),
3567
- encode: map => [...map.entries()]
4838
+ expected: "HashSet",
4839
+ toCodec: ([value]) => link()(Array(value), Transformation.transform({
4840
+ decode: HashSet_.fromIterable,
4841
+ encode: Arr.fromIterable
3568
4842
  })),
3569
- toArbitrary: ([key, value]) => (fc, ctx) => {
4843
+ toArbitrary: ([value]) => (fc, ctx) => {
3570
4844
  return fc.oneof(ctx?.isSuspend ? {
3571
4845
  maxDepth: 2,
3572
- depthIdentifier: "ReadonlyMap"
3573
- } : {}, fc.constant([]), fc.array(fc.tuple(key, value), ctx?.constraints?.array)).map(as => new globalThis.Map(as));
4846
+ depthIdentifier: "HashSet"
4847
+ } : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(HashSet_.fromIterable);
3574
4848
  },
3575
- toEquivalence: ([key, value]) => Equal.makeCompareMap(key, value),
3576
- toFormatter: ([key, value]) => t => {
3577
- const size = t.size;
4849
+ toEquivalence: ([value]) => Equal.makeCompareSet(value),
4850
+ toFormatter: ([value]) => t => {
4851
+ const size = HashSet_.size(t);
3578
4852
  if (size === 0) {
3579
- return "ReadonlyMap(0) {}";
4853
+ return "HashSet(0) {}";
3580
4854
  }
3581
- const entries = globalThis.Array.from(t.entries()).sort().map(([k, v]) => `${key(k)} => ${value(v)}`);
3582
- return `ReadonlyMap(${size}) { ${entries.join(", ")} }`;
4855
+ const values = globalThis.Array.from(t).sort().map(v => `${value(v)}`);
4856
+ return `HashSet(${size}) { ${values.join(", ")} }`;
3583
4857
  }
3584
4858
  });
3585
4859
  return make(schema.ast, {
3586
- key,
3587
4860
  value
3588
4861
  });
3589
4862
  }
3590
4863
  /**
3591
- * @category ReadonlySet
4864
+ * Creates a schema that validates a `Chunk` where values must conform to the
4865
+ * provided schema.
4866
+ *
4867
+ * @category Chunk
3592
4868
  * @since 4.0.0
3593
4869
  */
3594
- export function ReadonlySet(value) {
3595
- const schema = declareConstructor()([value], ([value]) => (input, ast, options) => {
3596
- if (input instanceof globalThis.Set) {
3597
- const array = Array(value);
3598
- return Effect.mapBothEager(Parser.decodeUnknownEffect(array)([...input], options), {
3599
- onSuccess: array => new globalThis.Set(array),
3600
- onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
3601
- });
3602
- }
3603
- return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4870
+ export function Chunk(value) {
4871
+ const schema = declareConstructor()([value], ([value]) => {
4872
+ const values = Array(value);
4873
+ return (input, ast, options) => {
4874
+ if (Chunk_.isChunk(input)) {
4875
+ return Effect.mapBothEager(Parser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
4876
+ onSuccess: Chunk_.fromIterable,
4877
+ onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
4878
+ });
4879
+ }
4880
+ return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
4881
+ };
3604
4882
  }, {
3605
4883
  typeConstructor: {
3606
- _tag: "ReadonlySet"
4884
+ _tag: "effect/Chunk"
3607
4885
  },
3608
4886
  generation: {
3609
- runtime: `Schema.ReadonlySet(?)`,
3610
- Type: `globalThis.ReadonlySet<?>`
4887
+ runtime: `Schema.Chunk(?)`,
4888
+ Type: `Chunk.Chunk<?>`
3611
4889
  },
3612
- expected: "ReadonlySet",
4890
+ expected: "Chunk",
3613
4891
  toCodec: ([value]) => link()(Array(value), Transformation.transform({
3614
- decode: e => new globalThis.Set(e),
3615
- encode: set => [...set.values()]
4892
+ decode: Chunk_.fromIterable,
4893
+ encode: Arr.fromIterable
3616
4894
  })),
3617
4895
  toArbitrary: ([value]) => (fc, ctx) => {
3618
4896
  return fc.oneof(ctx?.isSuspend ? {
3619
4897
  maxDepth: 2,
3620
- depthIdentifier: "ReadonlySet"
3621
- } : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(as => new globalThis.Set(as));
4898
+ depthIdentifier: "Chunk"
4899
+ } : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(Chunk_.fromIterable);
3622
4900
  },
3623
- toEquivalence: ([value]) => Equal.makeCompareSet(value),
4901
+ toEquivalence: ([value]) => Chunk_.makeEquivalence(value),
3624
4902
  toFormatter: ([value]) => t => {
3625
- const size = t.size;
4903
+ const size = Chunk_.size(t);
3626
4904
  if (size === 0) {
3627
- return "ReadonlySet(0) {}";
4905
+ return "Chunk(0) {}";
3628
4906
  }
3629
- const values = globalThis.Array.from(t.values()).sort().map(v => `${value(v)}`);
3630
- return `ReadonlySet(${size}) { ${values.join(", ")} }`;
4907
+ const values = globalThis.Array.from(t).sort().map(v => `${value(v)}`);
4908
+ return `Chunk(${size}) { ${values.join(", ")} }`;
3631
4909
  }
3632
4910
  });
3633
4911
  return make(schema.ast, {
@@ -3635,6 +4913,11 @@ export function ReadonlySet(value) {
3635
4913
  });
3636
4914
  }
3637
4915
  /**
4916
+ * Schema for JavaScript `RegExp` objects.
4917
+ *
4918
+ * The default JSON serializer encodes a `RegExp` as `{ source, flags }`.
4919
+ *
4920
+ * @category Schemas
3638
4921
  * @since 4.0.0
3639
4922
  */
3640
4923
  export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
@@ -3712,8 +4995,19 @@ export const URLFromString = /*#__PURE__*/String.annotate({
3712
4995
  * A schema for JavaScript `Date` objects.
3713
4996
  *
3714
4997
  * This schema accepts any `Date` instance, including invalid dates (e.g., `new
3715
- * Date("invalid")`). For validating only valid dates, use `ValidDate` instead.
4998
+ * Date("invalid")`). For validating only valid dates, use {@link DateValid}
4999
+ * instead. The default JSON serializer encodes `Date` as an ISO 8601 string.
3716
5000
  *
5001
+ * **Example** (Date schema)
5002
+ *
5003
+ * ```ts
5004
+ * import { Schema } from "effect"
5005
+ *
5006
+ * Schema.decodeUnknownSync(Schema.Date)(new Date("2024-01-01"))
5007
+ * // => Date { 2024-01-01T00:00:00.000Z }
5008
+ * ```
5009
+ *
5010
+ * @category Schemas
3717
5011
  * @since 4.0.0
3718
5012
  */
3719
5013
  export const Date = /*#__PURE__*/instanceOf(globalThis.Date, {
@@ -3745,9 +5039,20 @@ export const DateValid = /*#__PURE__*/Date.check(/*#__PURE__*/isDateValid());
3745
5039
  /**
3746
5040
  * A schema for `Duration` values.
3747
5041
  *
3748
- * **Default JSON serializer**
5042
+ * The default JSON serializer encodes `Duration` as a tagged object with the
5043
+ * duration type and value.
3749
5044
  *
3750
- * - encodes `Duration` as a `string`
5045
+ * **Example** (Duration schema)
5046
+ *
5047
+ * ```ts
5048
+ * import { Schema } from "effect"
5049
+ * import { Duration } from "effect"
5050
+ *
5051
+ * Schema.decodeUnknownSync(Schema.Duration)(Duration.seconds(5))
5052
+ * // => Duration(5s)
5053
+ * ```
5054
+ *
5055
+ * @category Duration
3751
5056
  *
3752
5057
  * @since 4.0.0
3753
5058
  */
@@ -3842,6 +5147,35 @@ export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualT
3842
5147
  * @since 4.0.0
3843
5148
  */
3844
5149
  export const DurationFromMillis = /*#__PURE__*/Number.check(isGreaterThanOrEqualTo(0)).pipe(/*#__PURE__*/decodeTo(Duration, Transformation.durationFromMillis));
5150
+ /**
5151
+ * A schema for `BigDecimal` values.
5152
+ *
5153
+ * **Default JSON serializer**
5154
+ *
5155
+ * - encodes `BigDecimal` as a `string`
5156
+ *
5157
+ * @since 4.0.0
5158
+ */
5159
+ export const BigDecimal = /*#__PURE__*/declare(BigDecimal_.isBigDecimal, {
5160
+ typeConstructor: {
5161
+ _tag: "effect/BigDecimal"
5162
+ },
5163
+ generation: {
5164
+ runtime: `Schema.BigDecimal`,
5165
+ Type: `BigDecimal.BigDecimal`,
5166
+ importDeclaration: `import * as BigDecimal from "effect/BigDecimal"`
5167
+ },
5168
+ expected: "BigDecimal",
5169
+ toCodecJson: () => link()(String.annotate({
5170
+ expected: "a string that will be decoded as a BigDecimal"
5171
+ }), Transformation.bigDecimalFromString),
5172
+ toArbitrary: () => fc => fc.tuple(fc.bigInt(), fc.integer({
5173
+ min: 0,
5174
+ max: 20
5175
+ })).map(([value, scale]) => BigDecimal_.make(value, scale)),
5176
+ toFormatter: () => bd => BigDecimal_.format(bd),
5177
+ toEquivalence: () => BigDecimal_.Equivalence
5178
+ });
3845
5179
  /**
3846
5180
  * A transformation schema that decodes a JSON-encoded string into an `unknown` value.
3847
5181
  *
@@ -3936,6 +5270,12 @@ export function fromJsonString(schema) {
3936
5270
  }).pipe(decodeTo(schema, Transformation.fromJsonString));
3937
5271
  }
3938
5272
  /**
5273
+ * Schema for JavaScript `File` objects.
5274
+ *
5275
+ * The default JSON serializer encodes a `File` as `{ data, type, name, lastModified }`
5276
+ * where `data` is base64-encoded.
5277
+ *
5278
+ * @category Schemas
3939
5279
  * @since 4.0.0
3940
5280
  */
3941
5281
  export const File = /*#__PURE__*/instanceOf(globalThis.File, {
@@ -3953,7 +5293,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
3953
5293
  name: String,
3954
5294
  lastModified: Number
3955
5295
  }), Transformation.transformOrFail({
3956
- decode: e => Result_.match(Base64.decode(e.data), {
5296
+ decode: e => Result_.match(Encoding.decodeBase64(e.data), {
3957
5297
  onFailure: error => Effect.fail(new Issue.InvalidValue(Option_.some(e.data), {
3958
5298
  message: error.message
3959
5299
  })),
@@ -3969,7 +5309,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
3969
5309
  try: async () => {
3970
5310
  const bytes = new globalThis.Uint8Array(await file.arrayBuffer());
3971
5311
  return {
3972
- data: Base64.encode(bytes),
5312
+ data: Encoding.encodeBase64(bytes),
3973
5313
  type: file.type,
3974
5314
  name: file.name,
3975
5315
  lastModified: file.lastModified
@@ -3982,6 +5322,12 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
3982
5322
  }))
3983
5323
  });
3984
5324
  /**
5325
+ * Schema for JavaScript `FormData` objects.
5326
+ *
5327
+ * The default JSON serializer encodes a `FormData` as an array of `[key, entry]`
5328
+ * pairs where each entry is tagged as `"String"` or `"File"`.
5329
+ *
5330
+ * @category Schemas
3985
5331
  * @since 4.0.0
3986
5332
  */
3987
5333
  export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
@@ -4111,6 +5457,11 @@ export function fromFormData(schema) {
4111
5457
  return FormData.pipe(decodeTo(schema, Transformation.fromFormData));
4112
5458
  }
4113
5459
  /**
5460
+ * Schema for JavaScript `URLSearchParams` objects.
5461
+ *
5462
+ * The default JSON serializer encodes a `URLSearchParams` as a query string.
5463
+ *
5464
+ * @category Schemas
4114
5465
  * @since 4.0.0
4115
5466
  */
4116
5467
  export const URLSearchParams = /*#__PURE__*/instanceOf(globalThis.URLSearchParams, {
@@ -4268,6 +5619,9 @@ export const Trim = /*#__PURE__*/String.annotate({
4268
5619
  expected: "a string that will be decoded as a trimmed string"
4269
5620
  }).pipe(/*#__PURE__*/decodeTo(Trimmed, /*#__PURE__*/Transformation.trim()));
4270
5621
  /**
5622
+ * A union schema for JavaScript property keys: `number | symbol | string`.
5623
+ *
5624
+ * @category Schemas
4271
5625
  * @since 4.0.0
4272
5626
  */
4273
5627
  export const PropertyKey = /*#__PURE__*/Union([Finite, Symbol, String]);
@@ -4383,7 +5737,7 @@ export const Uint8ArrayFromHex = /*#__PURE__*/String.annotate({
4383
5737
  */
4384
5738
  export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && DateTime.isUtc(u), {
4385
5739
  typeConstructor: {
4386
- _tag: "DateTime.Utc"
5740
+ _tag: "effect/DateTime.Utc"
4387
5741
  },
4388
5742
  generation: {
4389
5743
  runtime: `Schema.DateTimeUtc`,
@@ -4391,10 +5745,7 @@ export const DateTimeUtc = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && D
4391
5745
  importDeclaration: `import * as DateTime from "effect/DateTime"`
4392
5746
  },
4393
5747
  expected: "DateTime.Utc",
4394
- toCodecJson: () => link()(String, {
4395
- decode: Getter.dateTimeUtcFromInput(),
4396
- encode: Getter.transform(DateTime.formatIso)
4397
- }),
5748
+ toCodecJson: () => link()(String, Transformation.dateTimeUtcFromString),
4398
5749
  toArbitrary: () => (fc, ctx) => fc.date({
4399
5750
  noInvalidDate: true,
4400
5751
  ...ctx?.constraints?.date
@@ -4434,10 +5785,7 @@ export const DateTimeUtcFromDate = /*#__PURE__*/DateValid.pipe(/*#__PURE__*/deco
4434
5785
  */
4435
5786
  export const DateTimeUtcFromString = /*#__PURE__*/String.annotate({
4436
5787
  expected: "a string that will be decoded as a DateTime.Utc"
4437
- }).pipe(/*#__PURE__*/decodeTo(DateTimeUtc, /*#__PURE__*/Transformation.transform({
4438
- decode: DateTime.makeUnsafe,
4439
- encode: DateTime.formatIso
4440
- })));
5788
+ }).pipe(/*#__PURE__*/decodeTo(DateTimeUtc, Transformation.dateTimeUtcFromString));
4441
5789
  /**
4442
5790
  * A transformation schema that decodes a number into a `DateTime.Utc`.
4443
5791
  *
@@ -4454,18 +5802,140 @@ export const DateTimeUtcFromMillis = /*#__PURE__*/Number.pipe(/*#__PURE__*/decod
4454
5802
  decode: /*#__PURE__*/Getter.dateTimeUtcFromInput(),
4455
5803
  encode: /*#__PURE__*/Getter.transform(DateTime.toEpochMillis)
4456
5804
  }));
5805
+ /**
5806
+ * A schema for `DateTime.TimeZone.Offset` values.
5807
+ *
5808
+ * **Default JSON serializer**
5809
+ *
5810
+ * - encodes `DateTime.TimeZone.Offset` as a number (offset in milliseconds)
5811
+ *
5812
+ * @category DateTime
5813
+ * @since 4.0.0
5814
+ */
5815
+ export const TimeZoneOffset = /*#__PURE__*/declare(DateTime.isTimeZoneOffset, {
5816
+ typeConstructor: {
5817
+ _tag: "effect/DateTime.TimeZone.Offset"
5818
+ },
5819
+ generation: {
5820
+ runtime: `Schema.TimeZoneOffset`,
5821
+ Type: `DateTime.TimeZone.Offset`,
5822
+ importDeclaration: `import * as DateTime from "effect/DateTime"`
5823
+ },
5824
+ expected: "DateTime.TimeZone.Offset",
5825
+ toCodecJson: () => link()(Number, Transformation.timeZoneOffsetFromNumber),
5826
+ toArbitrary: () => fc => fc.integer({
5827
+ min: -12 * 60 * 60 * 1000,
5828
+ max: 14 * 60 * 60 * 1000
5829
+ }).map(n => DateTime.zoneMakeOffset(n)),
5830
+ toFormatter: () => tz => DateTime.zoneToString(tz),
5831
+ toEquivalence: () => (a, b) => a.offset === b.offset
5832
+ });
5833
+ /**
5834
+ * A schema for `DateTime.TimeZone.Named` values.
5835
+ *
5836
+ * **Default JSON serializer**
5837
+ *
5838
+ * - encodes `DateTime.TimeZone.Named` as a string (IANA time zone identifier)
5839
+ *
5840
+ * @category DateTime
5841
+ * @since 4.0.0
5842
+ */
5843
+ export const TimeZoneNamed = /*#__PURE__*/declare(DateTime.isTimeZoneNamed, {
5844
+ typeConstructor: {
5845
+ _tag: "effect/DateTime.TimeZone.Named"
5846
+ },
5847
+ generation: {
5848
+ runtime: `Schema.TimeZoneNamed`,
5849
+ Type: `DateTime.TimeZone.Named`,
5850
+ importDeclaration: `import * as DateTime from "effect/DateTime"`
5851
+ },
5852
+ expected: "DateTime.TimeZone.Named",
5853
+ toCodecJson: () => link()(String.annotate({
5854
+ expected: "an IANA time zone identifier"
5855
+ }), Transformation.timeZoneNamedFromString),
5856
+ toArbitrary: () => fc => fc.constantFrom(...["UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney"].map(DateTime.zoneMakeNamedUnsafe)),
5857
+ toFormatter: () => tz => DateTime.zoneToString(tz),
5858
+ toEquivalence: () => (a, b) => a.id === b.id
5859
+ });
5860
+ /**
5861
+ * A schema for `DateTime.TimeZone` values.
5862
+ *
5863
+ * **Default JSON serializer**
5864
+ *
5865
+ * - encodes `DateTime.TimeZone` as a string (IANA identifier or offset like
5866
+ * `+03:00`)
5867
+ *
5868
+ * @category DateTime
5869
+ * @since 4.0.0
5870
+ */
5871
+ export const TimeZone = /*#__PURE__*/declare(DateTime.isTimeZone, {
5872
+ typeConstructor: {
5873
+ _tag: "effect/DateTime.TimeZone"
5874
+ },
5875
+ generation: {
5876
+ runtime: `Schema.TimeZone`,
5877
+ Type: `DateTime.TimeZone`,
5878
+ importDeclaration: `import * as DateTime from "effect/DateTime"`
5879
+ },
5880
+ expected: "DateTime.TimeZone",
5881
+ toCodecJson: () => link()(String.annotate({
5882
+ expected: "a time zone string (IANA identifier or offset like +03:00)"
5883
+ }), Transformation.timeZoneFromString),
5884
+ toArbitrary: () => fc => fc.oneof(fc.integer({
5885
+ min: -12 * 60 * 60 * 1000,
5886
+ max: 14 * 60 * 60 * 1000
5887
+ }).map(n => DateTime.zoneMakeOffset(n)), fc.constantFrom(...["UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney"].map(DateTime.zoneMakeNamedUnsafe))),
5888
+ toFormatter: () => tz => DateTime.zoneToString(tz),
5889
+ toEquivalence: () => (a, b) => DateTime.zoneToString(a) === DateTime.zoneToString(b)
5890
+ });
5891
+ /**
5892
+ * A schema for `DateTime.Zoned` values.
5893
+ *
5894
+ * **Default JSON serializer**
5895
+ *
5896
+ * - encodes `DateTime.Zoned` as a string in the format
5897
+ * `YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]`
5898
+ *
5899
+ * @category DateTime
5900
+ * @since 4.0.0
5901
+ */
5902
+ export const DateTimeZoned = /*#__PURE__*/declare(u => DateTime.isDateTime(u) && DateTime.isZoned(u), {
5903
+ typeConstructor: {
5904
+ _tag: "effect/DateTime.Zoned"
5905
+ },
5906
+ generation: {
5907
+ runtime: `Schema.DateTimeZoned`,
5908
+ Type: `DateTime.Zoned`,
5909
+ importDeclaration: `import * as DateTime from "effect/DateTime"`
5910
+ },
5911
+ expected: "DateTime.Zoned",
5912
+ toCodecJson: () => link()(String.annotate({
5913
+ expected: "a zoned DateTime string (e.g. 2024-01-01T00:00:00.000+00:00[Europe/London])"
5914
+ }), Transformation.dateTimeZonedFromString),
5915
+ toArbitrary: () => (fc, ctx) => fc.tuple(fc.date({
5916
+ noInvalidDate: true,
5917
+ min: new globalThis.Date(-8640000000000000 + 14 * 60 * 60 * 1000),
5918
+ max: new globalThis.Date(8640000000000000 - 14 * 60 * 60 * 1000),
5919
+ ...ctx?.constraints?.date
5920
+ }), fc.constantFrom("UTC", "Europe/London", "America/New_York", "Asia/Tokyo", "Australia/Sydney")).map(([date, zone]) => DateTime.makeZonedUnsafe(date, {
5921
+ timeZone: zone
5922
+ })),
5923
+ toFormatter: () => zoned => DateTime.formatIsoZoned(zoned),
5924
+ toEquivalence: () => DateTime.Equivalence
5925
+ });
4457
5926
  const immerable = /*#__PURE__*/globalThis.Symbol.for("immer-draftable");
4458
5927
  function makeClass(Inherited, identifier, struct, annotations) {
4459
5928
  const getClassSchema = getClassSchemaFactory(struct, identifier, annotations);
4460
5929
  const ClassTypeId = getClassTypeId(identifier); // HMR support
4461
5930
  return class extends Inherited {
4462
5931
  constructor(...[input, options]) {
5932
+ const props = input ?? {};
4463
5933
  if (options?.disableValidation) {
4464
- super(input, options);
5934
+ super(props, options);
4465
5935
  } else {
4466
- const validated = struct.makeUnsafe(input, options);
5936
+ const validated = struct.makeUnsafe(props, options);
4467
5937
  super({
4468
- ...input,
5938
+ ...props,
4469
5939
  ...validated
4470
5940
  }, {
4471
5941
  ...options,
@@ -4497,6 +5967,9 @@ function makeClass(Inherited, identifier, struct, annotations) {
4497
5967
  static makeUnsafe(input, options) {
4498
5968
  return new this(input, options);
4499
5969
  }
5970
+ static makeOption(input, options) {
5971
+ return Parser.makeOption(getClassSchema(this))(input, options);
5972
+ }
4500
5973
  static annotate(annotations) {
4501
5974
  return this.rebuild(AST.annotate(this.ast, annotations));
4502
5975
  }
@@ -4541,6 +6014,7 @@ function getClassSchemaFactory(from, identifier, annotations) {
4541
6014
  toCodec: ([from]) => new AST.Link(from.ast, transformation),
4542
6015
  toArbitrary: ([from]) => () => from.map(args => new self(args)),
4543
6016
  toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
6017
+ "~sentinels": AST.collectSentinels(from.ast),
4544
6018
  ...annotations
4545
6019
  }));
4546
6020
  memo = from.pipe(decodeTo(to, transformation));
@@ -4552,6 +6026,46 @@ function isStruct(schema) {
4552
6026
  return isSchema(schema);
4553
6027
  }
4554
6028
  /**
6029
+ * Creates a schema-backed class whose constructor validates input against a
6030
+ * {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
6031
+ * input (unless `disableValidation` is set in the options).
6032
+ *
6033
+ * Pass the desired class type as the first type parameter. The second optional
6034
+ * type parameter can be used to add nominal brands.
6035
+ *
6036
+ * **Example** (Basic class)
6037
+ *
6038
+ * ```ts
6039
+ * import { Schema } from "effect"
6040
+ *
6041
+ * class Person extends Schema.Class<Person>("Person")({
6042
+ * name: Schema.String,
6043
+ * age: Schema.Number
6044
+ * }) {}
6045
+ *
6046
+ * const alice = new Person({ name: "Alice", age: 30 })
6047
+ * console.log(alice.name) // "Alice"
6048
+ * console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
6049
+ * ```
6050
+ *
6051
+ * **Example** (Extending a class)
6052
+ *
6053
+ * ```ts
6054
+ * import { Schema } from "effect"
6055
+ *
6056
+ * class Animal extends Schema.Class<Animal>("Animal")({
6057
+ * name: Schema.String
6058
+ * }) {}
6059
+ *
6060
+ * class Dog extends Animal.extend<Dog>("Dog")({
6061
+ * breed: Schema.String
6062
+ * }) {}
6063
+ *
6064
+ * const dog = new Dog({ name: "Rex", breed: "Labrador" })
6065
+ * console.log(dog.name) // "Rex"
6066
+ * console.log(dog.breed) // "Labrador"
6067
+ * ```
6068
+ *
4555
6069
  * @category Constructors
4556
6070
  * @since 4.0.0
4557
6071
  */
@@ -4560,6 +6074,27 @@ export const Class = identifier => (schema, annotations) => {
4560
6074
  return makeClass(Data.Class, identifier, struct, annotations);
4561
6075
  };
4562
6076
  /**
6077
+ * Like {@link Class} but automatically adds a `_tag` literal field set to the
6078
+ * given `tag` value. This makes instances compatible with tagged union
6079
+ * discrimination patterns.
6080
+ *
6081
+ * The optional `identifier` parameter overrides the schema identifier;
6082
+ * it defaults to the `tag` value.
6083
+ *
6084
+ * **Example** (Tagged class)
6085
+ *
6086
+ * ```ts
6087
+ * import { Schema } from "effect"
6088
+ *
6089
+ * class Circle extends Schema.TaggedClass<Circle>()("Circle", {
6090
+ * radius: Schema.Number
6091
+ * }) {}
6092
+ *
6093
+ * const c = new Circle({ radius: 5 })
6094
+ * console.log(c._tag) // "Circle"
6095
+ * console.log(c.radius) // 5
6096
+ * ```
6097
+ *
4563
6098
  * @category Constructors
4564
6099
  * @since 4.0.0
4565
6100
  */
@@ -4574,14 +6109,53 @@ export const TaggedClass = identifier => {
4574
6109
  };
4575
6110
  };
4576
6111
  /**
6112
+ * Creates a schema-backed error class that can be used as a typed,
6113
+ * yieldable error in Effect programs. Combines {@link Class} validation with
6114
+ * the `YieldableError` interface so instances can be yielded directly inside
6115
+ * `Effect.gen`.
6116
+ *
6117
+ * **Example** (Schema-backed error)
6118
+ *
6119
+ * ```ts
6120
+ * import { Effect, Schema } from "effect"
6121
+ *
6122
+ * class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
6123
+ * id: Schema.Number
6124
+ * }) {}
6125
+ *
6126
+ * const program = Effect.gen(function*() {
6127
+ * yield* new NotFound({ id: 1 })
6128
+ * })
6129
+ * ```
6130
+ *
4577
6131
  * @category Constructors
4578
6132
  * @since 4.0.0
4579
6133
  */
4580
6134
  export const ErrorClass = identifier => (schema, annotations) => {
4581
6135
  const struct = isStruct(schema) ? schema : Struct(schema);
4582
- return makeClass(core.Error, identifier, struct, annotations);
6136
+ const self = makeClass(core.Error, identifier, struct, annotations);
6137
+ self.prototype.name = identifier;
6138
+ return self;
4583
6139
  };
4584
6140
  /**
6141
+ * Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
6142
+ * resulting class is both a schema-validated, yieldable error and a tagged
6143
+ * union member.
6144
+ *
6145
+ * **Example** (Tagged error class)
6146
+ *
6147
+ * ```ts
6148
+ * import { Effect, Schema } from "effect"
6149
+ *
6150
+ * class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
6151
+ * id: Schema.Number
6152
+ * }) {}
6153
+ *
6154
+ * const program = Effect.gen(function*() {
6155
+ * yield* new NotFound({ id: 42 })
6156
+ * })
6157
+ * ```
6158
+ *
4585
6159
  * @category Constructors
4586
6160
  * @since 4.0.0
4587
6161
  */
@@ -4596,6 +6170,11 @@ export const TaggedErrorClass = identifier => {
4596
6170
  };
4597
6171
  };
4598
6172
  /**
6173
+ * Derives a {@link LazyArbitrary} from a schema. The result is memoized so
6174
+ * repeated calls with the same schema are cheap.
6175
+ *
6176
+ * Prefer {@link toArbitrary} when you just need the arbitrary directly.
6177
+ *
4599
6178
  * @category Arbitrary
4600
6179
  * @since 4.0.0
4601
6180
  */
@@ -4604,6 +6183,24 @@ export function toArbitraryLazy(schema) {
4604
6183
  return fc => lawc(fc, {});
4605
6184
  }
4606
6185
  /**
6186
+ * Derives a `fast-check` `Arbitrary` from a schema for property-based
6187
+ * testing. The derived arbitrary generates values that satisfy the schema.
6188
+ *
6189
+ * **Example** (Generating arbitrary values)
6190
+ *
6191
+ * ```ts
6192
+ * import { Schema } from "effect"
6193
+ * import * as FastCheck from "fast-check"
6194
+ *
6195
+ * const PersonArb = Schema.toArbitrary(
6196
+ * Schema.Struct({ name: Schema.String, age: Schema.Number })
6197
+ * )
6198
+ *
6199
+ * // Sample a random value
6200
+ * const sample = FastCheck.sample(PersonArb, 1)[0]
6201
+ * console.log(typeof sample.name) // "string"
6202
+ * ```
6203
+ *
4607
6204
  * @category Arbitrary
4608
6205
  * @since 4.0.0
4609
6206
  */
@@ -4630,6 +6227,13 @@ export function overrideToFormatter(toFormatter) {
4630
6227
  };
4631
6228
  }
4632
6229
  /**
6230
+ * Derives a string formatter function from a schema. The formatter converts
6231
+ * a value to its human-readable string representation, recursing into structs,
6232
+ * arrays, and unions.
6233
+ *
6234
+ * The optional `onBefore` hook lets you intercept specific AST nodes before
6235
+ * the default formatting logic runs.
6236
+ *
4633
6237
  * @category Formatter
4634
6238
  * @since 4.0.0
4635
6239
  */
@@ -4768,10 +6372,9 @@ export function toFormatter(schema, options) {
4768
6372
  // Equivalence
4769
6373
  // -----------------------------------------------------------------------------
4770
6374
  /**
4771
- * **Technical Note**
4772
- *
4773
- * This annotation cannot be added to `Annotations.Bottom` because it would make
4774
- * the schema invariant.
6375
+ * Overrides the equivalence derivation for a schema by supplying a custom
6376
+ * `Equivalence`. Use this when the default structural equivalence derived by
6377
+ * {@link toEquivalence} is not appropriate for a type.
4775
6378
  *
4776
6379
  * @category Equivalence
4777
6380
  * @since 4.0.0
@@ -4782,6 +6385,21 @@ export function overrideToEquivalence(toEquivalence) {
4782
6385
  });
4783
6386
  }
4784
6387
  /**
6388
+ * Derives an `Equivalence` from a schema. Two values are considered equal when
6389
+ * every field (and nested field) compares equal according to the schema
6390
+ * structure.
6391
+ *
6392
+ * **Example** (Struct equivalence)
6393
+ *
6394
+ * ```ts
6395
+ * import { Schema } from "effect"
6396
+ *
6397
+ * const eq = Schema.toEquivalence(Schema.Struct({ id: Schema.Number, name: Schema.String }))
6398
+ *
6399
+ * console.log(eq({ id: 1, name: "Alice" }, { id: 1, name: "Alice" })) // true
6400
+ * console.log(eq({ id: 1, name: "Alice" }, { id: 2, name: "Alice" })) // false
6401
+ * ```
6402
+ *
4785
6403
  * @category Equivalence
4786
6404
  * @since 4.0.0
4787
6405
  */
@@ -4792,6 +6410,10 @@ export function toEquivalence(schema) {
4792
6410
  // Representation
4793
6411
  // -----------------------------------------------------------------------------
4794
6412
  /**
6413
+ * Derives an intermediate `SchemaRepresentation.Document` from a schema. This
6414
+ * document is used internally by {@link toJsonSchemaDocument} and related
6415
+ * functions to produce JSON Schema output.
6416
+ *
4795
6417
  * @category Representation
4796
6418
  * @since 4.0.0
4797
6419
  */
@@ -4816,17 +6438,23 @@ export function toJsonSchemaDocument(schema, options) {
4816
6438
  };
4817
6439
  }
4818
6440
  // -----------------------------------------------------------------------------
4819
- // Serializer
6441
+ // Canonical Codecs
4820
6442
  // -----------------------------------------------------------------------------
4821
6443
  /**
4822
- * @category Serializer
6444
+ * Derives a canonical JSON codec from a schema. The encoded form is `unknown`
6445
+ * (any JSON-compatible value), decoded to the schema's `Type`.
6446
+ *
6447
+ * @category Canonical Codecs
4823
6448
  * @since 4.0.0
4824
6449
  */
4825
6450
  export function toCodecJson(schema) {
4826
6451
  return make(InternalToCodec.toCodecJson(schema.ast));
4827
6452
  }
4828
6453
  /**
4829
- * @category Serializer
6454
+ * Derives an isomorphism codec from a schema. The encoded form is the
6455
+ * schema's `Iso` type — the intermediate representation used for round-tripping.
6456
+ *
6457
+ * @category Canonical Codecs
4830
6458
  * @since 4.0.0
4831
6459
  */
4832
6460
  export function toCodecIso(schema) {
@@ -4840,7 +6468,11 @@ export function toCodecStringTree(schema, options) {
4840
6468
  }
4841
6469
  }
4842
6470
  /**
4843
- * @category Serializer
6471
+ * Derives an XML encoder from a codec. Encodes a value to an XML string by
6472
+ * first converting it through {@link toCodecStringTree}, then serializing the
6473
+ * resulting tree to XML.
6474
+ *
6475
+ * @category Canonical Codecs
4844
6476
  * @since 4.0.0
4845
6477
  */
4846
6478
  export function toEncoderXml(codec, options) {
@@ -4956,8 +6588,6 @@ function getStringTreePriority(ast) {
4956
6588
  const treeReorder = /*#__PURE__*/InternalToCodec.makeReorder(getStringTreePriority);
4957
6589
  function serializerTree(ast, recur, onMissingAnnotation) {
4958
6590
  switch (ast._tag) {
4959
- case "Unknown":
4960
- case "ObjectKeyword":
4961
6591
  case "Declaration":
4962
6592
  {
4963
6593
  const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
@@ -4973,6 +6603,9 @@ function serializerTree(ast, recur, onMissingAnnotation) {
4973
6603
  return AST.replaceEncoding(ast, [nullToString]);
4974
6604
  case "Boolean":
4975
6605
  return AST.replaceEncoding(ast, [booleanToString]);
6606
+ case "Unknown":
6607
+ case "ObjectKeyword":
6608
+ return AST.replaceEncoding(ast, [AST.unknownToStringTree]);
4976
6609
  case "Enum":
4977
6610
  case "Number":
4978
6611
  case "Literal":
@@ -5051,6 +6684,9 @@ function onSerializerEnsureArray(ast) {
5051
6684
  // Optic APIs
5052
6685
  // -----------------------------------------------------------------------------
5053
6686
  /**
6687
+ * Derives an `Iso` optic from a schema that isomorphically converts between
6688
+ * the schema's `Type` and its `Iso` (intermediate / serialized form).
6689
+ *
5054
6690
  * @category Optic
5055
6691
  * @since 4.0.0
5056
6692
  */
@@ -5059,6 +6695,8 @@ export function toIso(schema) {
5059
6695
  return Optic_.makeIso(Parser.encodeSync(serializer), Parser.decodeSync(serializer));
5060
6696
  }
5061
6697
  /**
6698
+ * Returns an identity `Iso` over the schema's source (`Type`) side.
6699
+ *
5062
6700
  * @category Optic
5063
6701
  * @since 4.0.0
5064
6702
  */
@@ -5066,6 +6704,8 @@ export function toIsoSource(_) {
5066
6704
  return Optic_.id();
5067
6705
  }
5068
6706
  /**
6707
+ * Returns an identity `Iso` over the schema's focus (`Iso`) side.
6708
+ *
5069
6709
  * @category Optic
5070
6710
  * @since 4.0.0
5071
6711
  */
@@ -5073,10 +6713,11 @@ export function toIsoFocus(_) {
5073
6713
  return Optic_.id();
5074
6714
  }
5075
6715
  /**
5076
- * **Technical Note**
5077
- *
5078
- * This annotation cannot be added to `Annotations.Bottom` because it changes
5079
- * the schema type.
6716
+ * Overrides the ISO codec derivation for a schema by providing a target codec
6717
+ * and explicit `decode`/`encode` getters. The resulting schema carries a
6718
+ * custom `Iso` type, which changes the schema's type parameter — use
6719
+ * {@link overrideToCodecIso} when the default ISO transformation is not
6720
+ * appropriate.
5080
6721
  *
5081
6722
  * @category Optic
5082
6723
  * @since 4.0.0
@@ -5094,11 +6735,15 @@ export function overrideToCodecIso(to, transformation) {
5094
6735
  // Differ APIs
5095
6736
  // -----------------------------------------------------------------------------
5096
6737
  /**
6738
+ * Derives a JSON Patch differ from a codec. Serializes values to JSON (via
6739
+ * {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
6740
+ * and new values, and can apply patches back to the typed value.
6741
+ *
5097
6742
  * @category JsonPatch
5098
6743
  * @since 4.0.0
5099
6744
  */
5100
6745
  export function toDifferJsonPatch(schema) {
5101
- const serializer = toCodecJson(schema); // TODO: remove this cast
6746
+ const serializer = toCodecJson(schema);
5102
6747
  const get = Parser.encodeSync(serializer);
5103
6748
  const set = Parser.decodeSync(serializer);
5104
6749
  return {
@@ -5113,6 +6758,10 @@ export function toDifferJsonPatch(schema) {
5113
6758
  };
5114
6759
  }
5115
6760
  /**
6761
+ * Creates a recursive schema for a {@link Tree} of values described by `node`.
6762
+ * The resulting schema accepts a single node value, an array of trees, or an
6763
+ * object whose values are trees.
6764
+ *
5116
6765
  * @category Tree
5117
6766
  * @since 4.0.0
5118
6767
  */
@@ -5122,24 +6771,29 @@ export function Tree(node) {
5122
6771
  return Tree;
5123
6772
  }
5124
6773
  /**
5125
- * @category Tree
5126
- * @since 4.0.0
5127
- */
5128
- export function MutableTree(node) {
5129
- const MutableTree$ref = suspend(() => MutableTree);
5130
- const MutableTree = Union([node, mutable(Array(MutableTree$ref)), Record(String, mutableKey(MutableTree$ref))]);
5131
- return MutableTree;
5132
- }
5133
- /**
6774
+ * Schema that accepts and validates any immutable JSON-compatible value.
6775
+ *
6776
+ * **Example** (Validating a JSON value)
6777
+ *
6778
+ * ```ts
6779
+ * import { Schema } from "effect"
6780
+ *
6781
+ * const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
6782
+ * console.log(result._tag) // "Some"
6783
+ * ```
6784
+ *
5134
6785
  * @category JSON
5135
6786
  * @since 4.0.0
5136
6787
  */
5137
- export const Json = /*#__PURE__*/Tree(/*#__PURE__*/Union([Null, Number, Boolean, String]));
6788
+ export const Json = /*#__PURE__*/make(AST.Json);
5138
6789
  /**
6790
+ * Schema that accepts any mutable JSON-compatible value. See {@link Json} for
6791
+ * the immutable variant.
6792
+ *
5139
6793
  * @category JSON
5140
6794
  * @since 4.0.0
5141
6795
  */
5142
- export const MutableJson = /*#__PURE__*/MutableTree(/*#__PURE__*/Union([Null, Number, Boolean, String]));
6796
+ export const MutableJson = /*#__PURE__*/make(AST.MutableJson);
5143
6797
  // -----------------------------------------------------------------------------
5144
6798
  // Annotations
5145
6799
  // -----------------------------------------------------------------------------