effect 4.0.6 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (480) hide show
  1. package/dist/Arbitrary.d.ts +10 -2
  2. package/dist/Arbitrary.d.ts.map +1 -1
  3. package/dist/Arbitrary.js +2 -1
  4. package/dist/Arbitrary.js.map +1 -1
  5. package/dist/Channel.d.ts.map +1 -1
  6. package/dist/Channel.js +21 -6
  7. package/dist/Channel.js.map +1 -1
  8. package/dist/Data.d.ts +54 -235
  9. package/dist/Data.d.ts.map +1 -1
  10. package/dist/Data.js.map +1 -1
  11. package/dist/Effect.d.ts +1 -1
  12. package/dist/Effect.js +1 -1
  13. package/dist/Equal.d.ts.map +1 -1
  14. package/dist/Equal.js +8 -1
  15. package/dist/Equal.js.map +1 -1
  16. package/dist/Exit.d.ts +3 -3
  17. package/dist/Exit.d.ts.map +1 -1
  18. package/dist/Exit.js.map +1 -1
  19. package/dist/Formatter.d.ts.map +1 -1
  20. package/dist/Formatter.js +27 -13
  21. package/dist/Formatter.js.map +1 -1
  22. package/dist/Hash.d.ts.map +1 -1
  23. package/dist/Hash.js +4 -1
  24. package/dist/Hash.js.map +1 -1
  25. package/dist/JsonPatch.js +4 -0
  26. package/dist/JsonPatch.js.map +1 -1
  27. package/dist/JsonSchema.d.ts.map +1 -1
  28. package/dist/JsonSchema.js +13 -40
  29. package/dist/JsonSchema.js.map +1 -1
  30. package/dist/Metric.d.ts +3 -3
  31. package/dist/MutableList.d.ts +5 -2
  32. package/dist/MutableList.d.ts.map +1 -1
  33. package/dist/MutableList.js +7 -5
  34. package/dist/MutableList.js.map +1 -1
  35. package/dist/MutableRef.d.ts.map +1 -1
  36. package/dist/MutableRef.js +7 -0
  37. package/dist/MutableRef.js.map +1 -1
  38. package/dist/PartitionedSemaphore.d.ts +2 -1
  39. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  40. package/dist/PartitionedSemaphore.js +22 -12
  41. package/dist/PartitionedSemaphore.js.map +1 -1
  42. package/dist/Pool.d.ts.map +1 -1
  43. package/dist/Pool.js +77 -27
  44. package/dist/Pool.js.map +1 -1
  45. package/dist/PubSub.d.ts.map +1 -1
  46. package/dist/PubSub.js +5 -6
  47. package/dist/PubSub.js.map +1 -1
  48. package/dist/Ref.d.ts.map +1 -1
  49. package/dist/Ref.js +8 -0
  50. package/dist/Ref.js.map +1 -1
  51. package/dist/Schedule.js +1 -1
  52. package/dist/Schedule.js.map +1 -1
  53. package/dist/Schema.d.ts +24 -8
  54. package/dist/Schema.d.ts.map +1 -1
  55. package/dist/Schema.js +37 -28
  56. package/dist/Schema.js.map +1 -1
  57. package/dist/SchemaAST.d.ts +4 -2
  58. package/dist/SchemaAST.d.ts.map +1 -1
  59. package/dist/SchemaAST.js +14 -17
  60. package/dist/SchemaAST.js.map +1 -1
  61. package/dist/SchemaParser.d.ts.map +1 -1
  62. package/dist/SchemaParser.js +48 -22
  63. package/dist/SchemaParser.js.map +1 -1
  64. package/dist/SchemaRepresentation.d.ts +19 -10
  65. package/dist/SchemaRepresentation.d.ts.map +1 -1
  66. package/dist/SchemaRepresentation.js +23 -13
  67. package/dist/SchemaRepresentation.js.map +1 -1
  68. package/dist/SchemaTransformation.d.ts +4 -1
  69. package/dist/SchemaTransformation.d.ts.map +1 -1
  70. package/dist/SchemaTransformation.js +9 -2
  71. package/dist/SchemaTransformation.js.map +1 -1
  72. package/dist/Semaphore.d.ts.map +1 -1
  73. package/dist/Semaphore.js +54 -35
  74. package/dist/Semaphore.js.map +1 -1
  75. package/dist/Sink.d.ts.map +1 -1
  76. package/dist/Sink.js +7 -2
  77. package/dist/Sink.js.map +1 -1
  78. package/dist/Stream.d.ts.map +1 -1
  79. package/dist/Stream.js +22 -10
  80. package/dist/Stream.js.map +1 -1
  81. package/dist/String.d.ts +3 -0
  82. package/dist/String.d.ts.map +1 -1
  83. package/dist/String.js +3 -0
  84. package/dist/String.js.map +1 -1
  85. package/dist/Tracer.d.ts +11 -1
  86. package/dist/Tracer.d.ts.map +1 -1
  87. package/dist/Tracer.js +6 -1
  88. package/dist/Tracer.js.map +1 -1
  89. package/dist/ai/LanguageModel.d.ts.map +1 -1
  90. package/dist/ai/LanguageModel.js +9 -0
  91. package/dist/ai/LanguageModel.js.map +1 -1
  92. package/dist/ai/McpSchema.d.ts +110 -110
  93. package/dist/ai/McpSchema.d.ts.map +1 -1
  94. package/dist/ai/McpServer.d.ts.map +1 -1
  95. package/dist/ai/McpServer.js +21 -15
  96. package/dist/ai/McpServer.js.map +1 -1
  97. package/dist/ai/Prompt.d.ts +52 -0
  98. package/dist/ai/Prompt.d.ts.map +1 -1
  99. package/dist/ai/Prompt.js +38 -0
  100. package/dist/ai/Prompt.js.map +1 -1
  101. package/dist/ai/Response.d.ts +16 -3
  102. package/dist/ai/Response.d.ts.map +1 -1
  103. package/dist/ai/Response.js +4 -0
  104. package/dist/ai/Response.js.map +1 -1
  105. package/dist/ai/Tool.d.ts +24 -0
  106. package/dist/ai/Tool.d.ts.map +1 -1
  107. package/dist/ai/Tool.js +5 -2
  108. package/dist/ai/Tool.js.map +1 -1
  109. package/dist/ai/Toolkit.d.ts.map +1 -1
  110. package/dist/ai/Toolkit.js +8 -1
  111. package/dist/ai/Toolkit.js.map +1 -1
  112. package/dist/cli/Argument.d.ts +15 -0
  113. package/dist/cli/Argument.d.ts.map +1 -1
  114. package/dist/cli/Argument.js +5 -0
  115. package/dist/cli/Argument.js.map +1 -1
  116. package/dist/cli/CliError.d.ts +78 -0
  117. package/dist/cli/CliError.d.ts.map +1 -1
  118. package/dist/cli/CliError.js +65 -3
  119. package/dist/cli/CliError.js.map +1 -1
  120. package/dist/cli/CliOutput.d.ts +155 -6
  121. package/dist/cli/CliOutput.d.ts.map +1 -1
  122. package/dist/cli/CliOutput.js +62 -6
  123. package/dist/cli/CliOutput.js.map +1 -1
  124. package/dist/cli/Command.d.ts +24 -16
  125. package/dist/cli/Command.d.ts.map +1 -1
  126. package/dist/cli/Command.js +59 -29
  127. package/dist/cli/Command.js.map +1 -1
  128. package/dist/cli/Completions.d.ts +58 -0
  129. package/dist/cli/Completions.d.ts.map +1 -1
  130. package/dist/cli/Completions.js +49 -9
  131. package/dist/cli/Completions.js.map +1 -1
  132. package/dist/cli/Flag.d.ts +15 -0
  133. package/dist/cli/Flag.d.ts.map +1 -1
  134. package/dist/cli/Flag.js +5 -0
  135. package/dist/cli/Flag.js.map +1 -1
  136. package/dist/cli/GlobalFlag.d.ts.map +1 -1
  137. package/dist/cli/GlobalFlag.js +15 -7
  138. package/dist/cli/GlobalFlag.js.map +1 -1
  139. package/dist/cli/Param.d.ts +9 -0
  140. package/dist/cli/Param.d.ts.map +1 -1
  141. package/dist/cli/Param.js +21 -2
  142. package/dist/cli/Param.js.map +1 -1
  143. package/dist/cli/TerminalCapabilities.d.ts +3 -2
  144. package/dist/cli/TerminalCapabilities.d.ts.map +1 -1
  145. package/dist/cli/TerminalCapabilities.js +3 -1
  146. package/dist/cli/TerminalCapabilities.js.map +1 -1
  147. package/dist/cli/internal/completions/bash.js +73 -27
  148. package/dist/cli/internal/completions/bash.js.map +1 -1
  149. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  150. package/dist/cluster/ClusterWorkflowEngine.js +45 -10
  151. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  152. package/dist/cluster/MessageStorage.d.ts +23 -45
  153. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  154. package/dist/cluster/MessageStorage.js +6 -7
  155. package/dist/cluster/MessageStorage.js.map +1 -1
  156. package/dist/cluster/Sharding.d.ts.map +1 -1
  157. package/dist/cluster/Sharding.js +61 -21
  158. package/dist/cluster/Sharding.js.map +1 -1
  159. package/dist/cluster/ShardingConfig.d.ts +10 -0
  160. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  161. package/dist/cluster/ShardingConfig.js.map +1 -1
  162. package/dist/cluster/Snowflake.d.ts.map +1 -1
  163. package/dist/cluster/Snowflake.js +3 -7
  164. package/dist/cluster/Snowflake.js.map +1 -1
  165. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  166. package/dist/cluster/SqlRunnerStorage.js +87 -39
  167. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  168. package/dist/cluster/internal/entityManager.js +54 -20
  169. package/dist/cluster/internal/entityManager.js.map +1 -1
  170. package/dist/devtools/DevToolsClient.d.ts.map +1 -1
  171. package/dist/devtools/DevToolsClient.js +2 -0
  172. package/dist/devtools/DevToolsClient.js.map +1 -1
  173. package/dist/encoding/Base64.js +36 -0
  174. package/dist/encoding/Base64.js.map +1 -1
  175. package/dist/encoding/Sse.d.ts.map +1 -1
  176. package/dist/encoding/Sse.js +3 -3
  177. package/dist/encoding/Sse.js.map +1 -1
  178. package/dist/encoding/Toml.d.ts.map +1 -1
  179. package/dist/encoding/Toml.js +21 -16
  180. package/dist/encoding/Toml.js.map +1 -1
  181. package/dist/eventlog/SqlEventJournal.d.ts.map +1 -1
  182. package/dist/eventlog/SqlEventJournal.js +47 -27
  183. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  184. package/dist/eventlog/internal/conflicts.d.ts +0 -1
  185. package/dist/eventlog/internal/conflicts.d.ts.map +1 -1
  186. package/dist/eventlog/internal/conflicts.js +0 -3
  187. package/dist/eventlog/internal/conflicts.js.map +1 -1
  188. package/dist/http/Cookies.d.ts.map +1 -1
  189. package/dist/http/Cookies.js +10 -9
  190. package/dist/http/Cookies.js.map +1 -1
  191. package/dist/http/HttpClient.d.ts +423 -0
  192. package/dist/http/HttpClient.d.ts.map +1 -1
  193. package/dist/http/HttpClient.js +231 -7
  194. package/dist/http/HttpClient.js.map +1 -1
  195. package/dist/http/HttpClientError.d.ts +8 -1
  196. package/dist/http/HttpClientError.d.ts.map +1 -1
  197. package/dist/http/HttpClientError.js +37 -1
  198. package/dist/http/HttpClientError.js.map +1 -1
  199. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  200. package/dist/http/HttpClientRequest.js +1 -1
  201. package/dist/http/HttpClientRequest.js.map +1 -1
  202. package/dist/http/HttpMiddleware.d.ts +1 -1
  203. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  204. package/dist/http/HttpMiddleware.js +14 -16
  205. package/dist/http/HttpMiddleware.js.map +1 -1
  206. package/dist/http/HttpRouter.d.ts.map +1 -1
  207. package/dist/http/HttpRouter.js +2 -1
  208. package/dist/http/HttpRouter.js.map +1 -1
  209. package/dist/http/HttpServerError.js +2 -2
  210. package/dist/http/HttpServerError.js.map +1 -1
  211. package/dist/http/HttpServerRequest.d.ts +6 -1
  212. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  213. package/dist/http/HttpServerRequest.js +73 -10
  214. package/dist/http/HttpServerRequest.js.map +1 -1
  215. package/dist/http/HttpStaticServer.d.ts.map +1 -1
  216. package/dist/http/HttpStaticServer.js +48 -21
  217. package/dist/http/HttpStaticServer.js.map +1 -1
  218. package/dist/http/MultipartParser/internal/contentType.js +3 -3
  219. package/dist/http/UrlParams.d.ts +3 -1
  220. package/dist/http/UrlParams.d.ts.map +1 -1
  221. package/dist/http/UrlParams.js +4 -2
  222. package/dist/http/UrlParams.js.map +1 -1
  223. package/dist/http/internal/compression.js +4 -5
  224. package/dist/http/internal/compression.js.map +1 -1
  225. package/dist/http/internal/decompression.js +3 -0
  226. package/dist/http/internal/decompression.js.map +1 -1
  227. package/dist/http/internal/httpBody.js +8 -1
  228. package/dist/http/internal/httpBody.js.map +1 -1
  229. package/dist/http/internal/urlParams.js +25 -0
  230. package/dist/http/internal/urlParams.js.map +1 -1
  231. package/dist/http-api/HttpApi.d.ts +3 -6
  232. package/dist/http-api/HttpApi.d.ts.map +1 -1
  233. package/dist/http-api/HttpApi.js +3 -6
  234. package/dist/http-api/HttpApi.js.map +1 -1
  235. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  236. package/dist/http-api/HttpApiBuilder.js +27 -11
  237. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  238. package/dist/http-api/HttpApiClient.d.ts +77 -7
  239. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  240. package/dist/http-api/HttpApiClient.js +142 -44
  241. package/dist/http-api/HttpApiClient.js.map +1 -1
  242. package/dist/http-api/HttpApiEndpoint.d.ts +24 -7
  243. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  244. package/dist/http-api/HttpApiEndpoint.js +109 -27
  245. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  246. package/dist/http-api/HttpApiSchema.d.ts +76 -29
  247. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  248. package/dist/http-api/HttpApiSchema.js +70 -59
  249. package/dist/http-api/HttpApiSchema.js.map +1 -1
  250. package/dist/http-api/HttpApiTest.d.ts.map +1 -1
  251. package/dist/http-api/HttpApiTest.js +3 -2
  252. package/dist/http-api/HttpApiTest.js.map +1 -1
  253. package/dist/http-api/OpenApi.d.ts.map +1 -1
  254. package/dist/http-api/OpenApi.js +25 -16
  255. package/dist/http-api/OpenApi.js.map +1 -1
  256. package/dist/http-api/internal/toCodecHttpProperties.d.ts +2 -0
  257. package/dist/http-api/internal/toCodecHttpProperties.d.ts.map +1 -0
  258. package/dist/http-api/internal/toCodecHttpProperties.js +38 -0
  259. package/dist/http-api/internal/toCodecHttpProperties.js.map +1 -0
  260. package/dist/internal/arbitrary/runner.d.ts.map +1 -1
  261. package/dist/internal/arbitrary/runner.js +120 -44
  262. package/dist/internal/arbitrary/runner.js.map +1 -1
  263. package/dist/internal/core.js +2 -0
  264. package/dist/internal/core.js.map +1 -1
  265. package/dist/internal/effect.js +21 -13
  266. package/dist/internal/effect.js.map +1 -1
  267. package/dist/internal/equal.js +14 -0
  268. package/dist/internal/equal.js.map +1 -1
  269. package/dist/internal/jsonSchema.d.ts +2 -0
  270. package/dist/internal/jsonSchema.d.ts.map +1 -0
  271. package/dist/internal/jsonSchema.js +28 -0
  272. package/dist/internal/jsonSchema.js.map +1 -0
  273. package/dist/internal/matcher.js +1 -1
  274. package/dist/internal/matcher.js.map +1 -1
  275. package/dist/internal/schema/compilerRegistry.js +4 -1
  276. package/dist/internal/schema/compilerRegistry.js.map +1 -1
  277. package/dist/internal/schema/content.d.ts +2 -0
  278. package/dist/internal/schema/content.d.ts.map +1 -0
  279. package/dist/internal/schema/content.js +13 -0
  280. package/dist/internal/schema/content.js.map +1 -0
  281. package/dist/internal/schema/fromJsonSchemaDocument.js +173 -185
  282. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  283. package/dist/internal/schema/fromRepresentation.js +2 -1
  284. package/dist/internal/schema/fromRepresentation.js.map +1 -1
  285. package/dist/internal/schema/standardSchema.js +8 -2
  286. package/dist/internal/schema/standardSchema.js.map +1 -1
  287. package/dist/internal/schema/toCodeDocument.js +3 -3
  288. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  289. package/dist/internal/schema/toCodec.js +21 -24
  290. package/dist/internal/schema/toCodec.js.map +1 -1
  291. package/dist/internal/schema/toJsonSchemaDocument.js +205 -140
  292. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  293. package/dist/internal/schema/toRepresentation.js +107 -129
  294. package/dist/internal/schema/toRepresentation.js.map +1 -1
  295. package/dist/internal/sql.d.ts +2 -0
  296. package/dist/internal/sql.d.ts.map +1 -0
  297. package/dist/internal/sql.js +13 -0
  298. package/dist/internal/sql.js.map +1 -0
  299. package/dist/internal/version.js +1 -1
  300. package/dist/observability/OtlpProxy.d.ts +154 -0
  301. package/dist/observability/OtlpProxy.d.ts.map +1 -0
  302. package/dist/observability/OtlpProxy.js +235 -0
  303. package/dist/observability/OtlpProxy.js.map +1 -0
  304. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  305. package/dist/observability/OtlpTracer.js +4 -0
  306. package/dist/observability/OtlpTracer.js.map +1 -1
  307. package/dist/observability/index.d.ts +5 -0
  308. package/dist/observability/index.d.ts.map +1 -1
  309. package/dist/observability/index.js +5 -0
  310. package/dist/observability/index.js.map +1 -1
  311. package/dist/persistence/CircuitBreaker.d.ts +897 -0
  312. package/dist/persistence/CircuitBreaker.d.ts.map +1 -0
  313. package/dist/persistence/CircuitBreaker.js +1165 -0
  314. package/dist/persistence/CircuitBreaker.js.map +1 -0
  315. package/dist/persistence/Redis.d.ts +78 -2
  316. package/dist/persistence/Redis.d.ts.map +1 -1
  317. package/dist/persistence/Redis.js +62 -7
  318. package/dist/persistence/Redis.js.map +1 -1
  319. package/dist/persistence/index.d.ts +5 -0
  320. package/dist/persistence/index.d.ts.map +1 -1
  321. package/dist/persistence/index.js +5 -0
  322. package/dist/persistence/index.js.map +1 -1
  323. package/dist/process/ChildProcess.d.ts +30 -4
  324. package/dist/process/ChildProcess.d.ts.map +1 -1
  325. package/dist/process/ChildProcess.js.map +1 -1
  326. package/dist/process/ChildProcessSpawner.d.ts +30 -0
  327. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  328. package/dist/process/ChildProcessSpawner.js +5 -2
  329. package/dist/process/ChildProcessSpawner.js.map +1 -1
  330. package/dist/reactivity/AsyncResult.d.ts +1 -1
  331. package/dist/reactivity/AsyncResult.d.ts.map +1 -1
  332. package/dist/rpc/RpcClient.d.ts.map +1 -1
  333. package/dist/rpc/RpcClient.js +9 -8
  334. package/dist/rpc/RpcClient.js.map +1 -1
  335. package/dist/rpc/RpcSerialization.d.ts +14 -0
  336. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  337. package/dist/rpc/RpcSerialization.js +20 -8
  338. package/dist/rpc/RpcSerialization.js.map +1 -1
  339. package/dist/rpc/RpcServer.d.ts.map +1 -1
  340. package/dist/rpc/RpcServer.js +11 -1
  341. package/dist/rpc/RpcServer.js.map +1 -1
  342. package/dist/rpc/RpcTest.d.ts +1 -0
  343. package/dist/rpc/RpcTest.d.ts.map +1 -1
  344. package/dist/rpc/RpcTest.js +1 -0
  345. package/dist/rpc/RpcTest.js.map +1 -1
  346. package/dist/sql/Migrator.d.ts +2 -1
  347. package/dist/sql/Migrator.d.ts.map +1 -1
  348. package/dist/sql/Migrator.js +11 -8
  349. package/dist/sql/Migrator.js.map +1 -1
  350. package/dist/sql/SqlClient.d.ts +9 -4
  351. package/dist/sql/SqlClient.d.ts.map +1 -1
  352. package/dist/sql/SqlClient.js +8 -1
  353. package/dist/sql/SqlClient.js.map +1 -1
  354. package/dist/sql/SqlResolver.d.ts +4 -0
  355. package/dist/sql/SqlResolver.d.ts.map +1 -1
  356. package/dist/sql/SqlResolver.js +18 -4
  357. package/dist/sql/SqlResolver.js.map +1 -1
  358. package/dist/sql/Statement.d.ts +7 -0
  359. package/dist/sql/Statement.d.ts.map +1 -1
  360. package/dist/sql/Statement.js +21 -2
  361. package/dist/sql/Statement.js.map +1 -1
  362. package/dist/workflow/DurableDeferred.d.ts.map +1 -1
  363. package/dist/workflow/DurableDeferred.js +21 -2
  364. package/dist/workflow/DurableDeferred.js.map +1 -1
  365. package/package.json +1 -1
  366. package/src/Arbitrary.ts +10 -2
  367. package/src/Channel.ts +47 -18
  368. package/src/Data.ts +60 -265
  369. package/src/Effect.ts +1 -1
  370. package/src/Equal.ts +8 -1
  371. package/src/Exit.ts +3 -3
  372. package/src/Formatter.ts +28 -13
  373. package/src/Hash.ts +4 -1
  374. package/src/JsonPatch.ts +4 -0
  375. package/src/JsonSchema.ts +12 -40
  376. package/src/Metric.ts +3 -3
  377. package/src/MutableList.ts +7 -5
  378. package/src/MutableRef.ts +8 -1
  379. package/src/PartitionedSemaphore.ts +24 -13
  380. package/src/Pool.ts +109 -37
  381. package/src/PubSub.ts +5 -6
  382. package/src/Ref.ts +8 -0
  383. package/src/Schedule.ts +1 -1
  384. package/src/Schema.ts +48 -25
  385. package/src/SchemaAST.ts +20 -20
  386. package/src/SchemaParser.ts +51 -18
  387. package/src/SchemaRepresentation.ts +31 -34
  388. package/src/SchemaTransformation.ts +9 -2
  389. package/src/Semaphore.ts +67 -40
  390. package/src/Sink.ts +15 -2
  391. package/src/Stream.ts +33 -16
  392. package/src/String.ts +3 -0
  393. package/src/Tracer.ts +15 -1
  394. package/src/ai/LanguageModel.ts +9 -0
  395. package/src/ai/McpServer.ts +14 -13
  396. package/src/ai/Prompt.ts +65 -0
  397. package/src/ai/Response.ts +34 -9
  398. package/src/ai/Tool.ts +38 -2
  399. package/src/ai/Toolkit.ts +4 -1
  400. package/src/cli/Argument.ts +15 -0
  401. package/src/cli/CliError.ts +90 -3
  402. package/src/cli/CliOutput.ts +183 -6
  403. package/src/cli/Command.ts +53 -41
  404. package/src/cli/Completions.ts +51 -0
  405. package/src/cli/Flag.ts +15 -0
  406. package/src/cli/GlobalFlag.ts +6 -7
  407. package/src/cli/Param.ts +29 -6
  408. package/src/cli/TerminalCapabilities.ts +6 -3
  409. package/src/cli/internal/completions/bash.ts +79 -29
  410. package/src/cluster/ClusterWorkflowEngine.ts +46 -16
  411. package/src/cluster/MessageStorage.ts +19 -14
  412. package/src/cluster/Sharding.ts +83 -21
  413. package/src/cluster/ShardingConfig.ts +5 -0
  414. package/src/cluster/Snowflake.ts +3 -7
  415. package/src/cluster/SqlRunnerStorage.ts +110 -47
  416. package/src/cluster/internal/entityManager.ts +75 -22
  417. package/src/devtools/DevToolsClient.ts +2 -0
  418. package/src/encoding/Base64.ts +38 -0
  419. package/src/encoding/Sse.ts +4 -3
  420. package/src/encoding/Toml.ts +33 -16
  421. package/src/eventlog/SqlEventJournal.ts +68 -45
  422. package/src/eventlog/internal/conflicts.ts +0 -4
  423. package/src/http/Cookies.ts +10 -11
  424. package/src/http/HttpClient.ts +547 -7
  425. package/src/http/HttpClientError.ts +35 -1
  426. package/src/http/HttpClientRequest.ts +9 -1
  427. package/src/http/HttpMiddleware.ts +15 -18
  428. package/src/http/HttpRouter.ts +2 -1
  429. package/src/http/HttpServerError.ts +2 -2
  430. package/src/http/HttpServerRequest.ts +102 -16
  431. package/src/http/HttpStaticServer.ts +51 -22
  432. package/src/http/MultipartParser/internal/contentType.ts +3 -3
  433. package/src/http/UrlParams.ts +6 -1
  434. package/src/http/internal/compression.ts +4 -5
  435. package/src/http/internal/decompression.ts +6 -0
  436. package/src/http/internal/httpBody.ts +10 -2
  437. package/src/http/internal/urlParams.ts +29 -0
  438. package/src/http-api/HttpApi.ts +3 -6
  439. package/src/http-api/HttpApiBuilder.ts +45 -15
  440. package/src/http-api/HttpApiClient.ts +218 -72
  441. package/src/http-api/HttpApiEndpoint.ts +121 -30
  442. package/src/http-api/HttpApiSchema.ts +141 -48
  443. package/src/http-api/HttpApiTest.ts +3 -2
  444. package/src/http-api/OpenApi.ts +20 -17
  445. package/src/http-api/internal/toCodecHttpProperties.ts +56 -0
  446. package/src/internal/arbitrary/runner.ts +133 -36
  447. package/src/internal/core.ts +2 -0
  448. package/src/internal/effect.ts +24 -16
  449. package/src/internal/equal.ts +17 -0
  450. package/src/internal/jsonSchema.ts +27 -0
  451. package/src/internal/matcher.ts +1 -1
  452. package/src/internal/schema/compilerRegistry.ts +6 -1
  453. package/src/internal/schema/content.ts +18 -0
  454. package/src/internal/schema/fromJsonSchemaDocument.ts +228 -190
  455. package/src/internal/schema/fromRepresentation.ts +2 -1
  456. package/src/internal/schema/standardSchema.ts +2 -2
  457. package/src/internal/schema/toCodeDocument.ts +4 -4
  458. package/src/internal/schema/toCodec.ts +26 -22
  459. package/src/internal/schema/toJsonSchemaDocument.ts +189 -167
  460. package/src/internal/schema/toRepresentation.ts +122 -140
  461. package/src/internal/sql.ts +14 -0
  462. package/src/internal/version.ts +1 -1
  463. package/src/observability/OtlpProxy.ts +314 -0
  464. package/src/observability/OtlpTracer.ts +4 -0
  465. package/src/observability/index.ts +6 -0
  466. package/src/persistence/CircuitBreaker.ts +1678 -0
  467. package/src/persistence/Redis.ts +129 -8
  468. package/src/persistence/index.ts +6 -0
  469. package/src/process/ChildProcess.ts +30 -4
  470. package/src/process/ChildProcessSpawner.ts +41 -2
  471. package/src/reactivity/AsyncResult.ts +1 -1
  472. package/src/rpc/RpcClient.ts +13 -10
  473. package/src/rpc/RpcSerialization.ts +32 -9
  474. package/src/rpc/RpcServer.ts +16 -1
  475. package/src/rpc/RpcTest.ts +3 -0
  476. package/src/sql/Migrator.ts +12 -7
  477. package/src/sql/SqlClient.ts +11 -4
  478. package/src/sql/SqlResolver.ts +23 -9
  479. package/src/sql/Statement.ts +30 -2
  480. package/src/workflow/DurableDeferred.ts +23 -6
package/src/MutableRef.ts CHANGED
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import * as Equal from "./Equal.ts"
14
14
  import * as Dual from "./Function.ts"
15
+ import * as Hash from "./Hash.ts"
15
16
  import { type Inspectable, toJson } from "./Inspectable.ts"
16
17
  import { PipeInspectableProto } from "./internal/core.ts"
17
18
  import type { Pipeable } from "./Pipeable.ts"
@@ -74,9 +75,15 @@ export interface MutableRef<out T> extends Pipeable, Inspectable {
74
75
  current: T
75
76
  }
76
77
 
77
- const MutableRefProto: Omit<MutableRef<unknown>, "current"> = {
78
+ const MutableRefProto: Omit<MutableRef<unknown>, "current"> & Equal.Equal = {
78
79
  [TypeId]: TypeId,
79
80
  ...PipeInspectableProto,
81
+ [Equal.symbol](that: unknown): boolean {
82
+ return this === that
83
+ },
84
+ [Hash.symbol](): number {
85
+ return Hash.random(this)
86
+ },
80
87
  toJSON<A>(this: MutableRef<A>) {
81
88
  return {
82
89
  _id: "MutableRef",
@@ -59,7 +59,8 @@ export type PartitionedTypeId = "~effect/PartitionedSemaphore"
59
59
  *
60
60
  * **Details**
61
61
  *
62
- * Waiting permits are distributed across partitions in round-robin order.
62
+ * Waiters are served across partitions in round-robin order, completing each
63
+ * waiter's permit request before moving to the next partition.
63
64
  *
64
65
  * @stability unstable
65
66
  * @category models
@@ -150,6 +151,7 @@ export const makeUnsafe = <K = unknown>(options: {
150
151
  let iterator = partitions[Symbol.iterator]()
151
152
  let releasing = false
152
153
  let pendingPermits = 0
154
+ let partial: Waiter | undefined
153
155
 
154
156
  const releaseUnsafe = (permits: number): number => {
155
157
  if (permits > 0) {
@@ -162,26 +164,32 @@ export const makeUnsafe = <K = unknown>(options: {
162
164
  releasing = true
163
165
  try {
164
166
  while (pendingPermits > 0 && waitingPermits > 0) {
165
- let state = iterator.next()
166
- if (state.done) {
167
- iterator = partitions[Symbol.iterator]()
168
- state = iterator.next()
167
+ let waiter = partial
168
+ if (waiter === undefined) {
169
+ let state = iterator.next()
169
170
  if (state.done) {
170
- break
171
+ iterator = partitions[Symbol.iterator]()
172
+ state = iterator.next()
173
+ if (state.done) {
174
+ break
175
+ }
171
176
  }
172
- }
173
177
 
174
- const waiter = state.value[1].values().next().value
175
- if (waiter === undefined) {
176
- continue
178
+ waiter = state.value[1].values().next().value
179
+ if (waiter === undefined) {
180
+ continue
181
+ }
177
182
  }
178
183
 
179
- waiter.permits -= 1
180
- waitingPermits -= 1
181
- pendingPermits -= 1
184
+ const granted = Math.min(waiter.permits, pendingPermits)
185
+ waiter.permits -= granted
186
+ waitingPermits -= granted
187
+ pendingPermits -= granted
182
188
 
183
189
  if (waiter.permits === 0) {
184
190
  waiter.resume()
191
+ } else {
192
+ partial = waiter
185
193
  }
186
194
  }
187
195
  } finally {
@@ -249,6 +257,9 @@ export const makeUnsafe = <K = unknown>(options: {
249
257
  }
250
258
 
251
259
  const cleanup = () => {
260
+ if (partial === entry) {
261
+ partial = undefined
262
+ }
252
263
  if (waiters.delete(entry) && waiters.size === 0) {
253
264
  MutableHashMap.remove(partitions, key)
254
265
  }
package/src/Pool.ts CHANGED
@@ -463,7 +463,7 @@ export const get = <A, E>(self: Pool<A, E>): Effect.Effect<A, E, Scope.Scope> =>
463
463
  core.withFiber((fiber) => {
464
464
  const state = self.state
465
465
  if (state.isShuttingDown) return internal.interrupt
466
- if (state.availableHead?.exit._tag === "Success") {
466
+ if (state.waiters.size === 0 && state.availableHead?.exit._tag === "Success") {
467
467
  state.usage++
468
468
  if (self.config.isFixed || targetSize(self) <= activeSize(self)) {
469
469
  return leaseItem(self, state.availableHead, fiber)
@@ -570,7 +570,7 @@ export const use: {
570
570
  core.withFiber((fiber) => {
571
571
  const state = self.state
572
572
  if (state.isShuttingDown) return internal.interrupt
573
- if (state.availableHead?.exit._tag === "Success") {
573
+ if (state.waiters.size === 0 && state.availableHead?.exit._tag === "Success") {
574
574
  state.usage++
575
575
  if (self.config.isFixed || targetSize(self) <= activeSize(self)) {
576
576
  return useItem(self, state.availableHead, f, fiber)
@@ -611,12 +611,18 @@ const getSlowWith = <A, E, X, R>(
611
611
  internal.uninterruptibleMask((restore) => {
612
612
  const state = self.state
613
613
  state.usage++
614
+ const waiter = makeWaiter<A, E>()
614
615
  const wait: Effect.Effect<X, any, R> = internal.flatMap(
615
616
  internal.onError(
616
- restore(waitForItem(self)),
617
+ restore(waitForItem(self, waiter)),
617
618
  () =>
618
- internal.sync(() => {
619
+ core.withFiber((fiber) => {
619
620
  state.usage--
621
+ // Only a woken waiter is still registered here: one cancelled while
622
+ // asleep already left. It passes its wake on, so the capacity it was
623
+ // woken for is not stranded.
624
+ if (state.waiters.delete(waiter)) wakeWaiters(self, fiber, 1)
625
+ return internal.void
620
626
  })
621
627
  ),
622
628
  () => loop
@@ -626,6 +632,12 @@ const getSlowWith = <A, E, X, R>(
626
632
  state.usage--
627
633
  return internal.interrupt
628
634
  }
635
+ // A borrower that has not waited yet queues behind the borrowers already
636
+ // waiting. Waiters keep their place until they take an item, so this
637
+ // also holds while a woken waiter has yet to run.
638
+ if (state.waiters.size > 0 && !state.waiters.has(waiter)) {
639
+ return wait
640
+ }
629
641
  // Replace failed slots only when the pool cannot grow.
630
642
  const item = firstHealthyAvailable(self) ??
631
643
  (targetSize(self) <= activeSize(self) ? state.availableHead : undefined)
@@ -636,6 +648,7 @@ const getSlowWith = <A, E, X, R>(
636
648
  removeFailedItem(self, item)
637
649
  return loop
638
650
  }
651
+ state.waiters.delete(waiter)
639
652
  return lease(self, item, fiber, restore)
640
653
  })
641
654
  const loop: Effect.Effect<X, any, R> = internal.suspend(() => {
@@ -718,19 +731,49 @@ const firstHealthyAvailable = <A, E>(self: Pool<A, E>): PoolItem<A, E> | undefin
718
731
  return item
719
732
  }
720
733
 
721
- const waitForItem = <A, E>(self: Pool<A, E>): Effect.Effect<void, E> =>
734
+ /**
735
+ * A borrower's entry in `State.waiters`. It stays registered from the first
736
+ * wait until the borrower takes an item or leaves, so the borrower keeps its
737
+ * place in the queue across wakes.
738
+ *
739
+ * `resume` is set while the borrower is asleep. A registered waiter without
740
+ * one has been woken and has yet to take an item, wait again or leave.
741
+ */
742
+ interface Waiter<A, E> {
743
+ (failure?: Exit.Failure<A, E>): void
744
+ resume: ((effect: Effect.Effect<void, E>) => void) | undefined
745
+ }
746
+
747
+ const makeWaiter = <A, E>(): Waiter<A, E> => {
748
+ const waiter = ((failure?: Exit.Failure<A, E>) => {
749
+ const resume = waiter.resume
750
+ if (resume === undefined) return
751
+ waiter.resume = undefined
752
+ resume(failure ?? internal.void)
753
+ }) as Waiter<A, E>
754
+ waiter.resume = undefined
755
+ return waiter
756
+ }
757
+
758
+ const waitForItem = <A, E>(self: Pool<A, E>, waiter: Waiter<A, E>): Effect.Effect<void, E> =>
722
759
  internal.callback((resume) => {
723
760
  const state = self.state
724
- if (firstHealthyAvailable(self) !== undefined || state.isShuttingDown) {
761
+ if (
762
+ state.isShuttingDown ||
763
+ (state.waiters.size === 0 && firstHealthyAvailable(self) !== undefined)
764
+ ) {
725
765
  return resume(internal.void)
726
766
  }
727
- const observer = (failure?: Exit.Failure<A, E>) => {
728
- state.waiters.delete(observer)
729
- resume(failure ?? internal.void)
730
- }
731
- state.waiters.add(observer)
767
+ waiter.resume = resume
768
+ // Re-adding a registered waiter keeps its position.
769
+ state.waiters.add(waiter)
732
770
  return internal.sync(() => {
733
- state.waiters.delete(observer)
771
+ // Cancelled while asleep: leave at once, so no wake or failure is spent
772
+ // on it. Cancelled after a wake: stay until the wake is passed on.
773
+ if (waiter.resume !== undefined) {
774
+ waiter.resume = undefined
775
+ state.waiters.delete(waiter)
776
+ }
734
777
  })
735
778
  })
736
779
 
@@ -738,23 +781,36 @@ const wakeWaiters = <A, E>(self: Pool<A, E>, fiber: Fiber.Fiber<unknown, unknown
738
781
  const waiters = self.state.waiters
739
782
  if (waiters.size === 0) return
740
783
  fiber.currentDispatcher.scheduleTask(() => {
784
+ // Walk the live set, so a waiter that leaves during the walk does not use
785
+ // up a wake. Skip waiters already woken, and stop once nothing is left to
786
+ // take.
741
787
  let remaining = count
742
- const toWake: Array<(failure?: Exit.Failure<A, E>) => void> = []
743
788
  for (const notify of waiters) {
744
- if (remaining-- <= 0) break
745
- toWake.push(notify)
746
- }
747
- for (let i = 0; i < toWake.length; i++) {
748
- toWake[i]()
789
+ if (remaining <= 0 || self.state.availableHead === undefined) break
790
+ if ((notify as Waiter<A, E>).resume === undefined) continue
791
+ remaining--
792
+ notify()
749
793
  }
750
794
  }, 0)
751
795
  }
752
796
 
753
- const wakeAll = <A, E>(self: Pool<A, E>): Effect.Effect<void> =>
754
- core.withFiber((fiber) => {
755
- wakeWaiters(self, fiber, Number.POSITIVE_INFINITY)
756
- return internal.void
757
- })
797
+ const firstSleepingWaiter = <A, E>(self: Pool<A, E>) => {
798
+ for (const notify of self.state.waiters) {
799
+ if ((notify as Waiter<A, E>).resume !== undefined) return notify
800
+ }
801
+ return undefined
802
+ }
803
+
804
+ // Wakes every waiter so it can retry after a failed acquisition. A waiter that
805
+ // could not start a resize while another was running depends on this. Waking
806
+ // a waiter that is already awake is a no-op.
807
+ const wakeAll = <A, E>(self: Pool<A, E>, fiber: Fiber.Fiber<unknown, unknown>) => {
808
+ const waiters = self.state.waiters
809
+ if (waiters.size === 0) return
810
+ fiber.currentDispatcher.scheduleTask(() => {
811
+ for (const notify of Array.from(waiters)) notify()
812
+ }, 0)
813
+ }
758
814
 
759
815
  // Reservations prevent reuse without extending the lifetime of borrowed items.
760
816
  const reservations = new WeakMap<PoolItem<unknown, unknown>, number>()
@@ -1005,22 +1061,38 @@ const resizeLoop = <A, E>(self: Pool<A, E>): Effect.Effect<void> =>
1005
1061
  return Effect.void
1006
1062
  }
1007
1063
  const toAcquire = target - active
1008
- const acquireOne = self.config.strategy === strategyNoop
1009
- ? allocate(self)
1010
- : Effect.flatMap(
1011
- self.config.strategy.reclaim(self),
1012
- (item) => item ? Effect.succeed(item) : allocate(self)
1013
- )
1064
+ // Wake waiters as each item arrives. Waiting for the whole batch would
1065
+ // leave acquired items idle behind a slow acquisition, with every borrower
1066
+ // queued behind the waiters.
1067
+ const acquireOne = Effect.tap(
1068
+ self.config.strategy === strategyNoop
1069
+ ? allocate(self)
1070
+ : Effect.flatMap(
1071
+ self.config.strategy.reclaim(self),
1072
+ (item) =>
1073
+ item
1074
+ ? Effect.sync(() => {
1075
+ // A reclaimed item rejoins circulation like a released one.
1076
+ if (self.state.items.has(item) && !self.state.invalidated.has(item)) addAvailableFront(self, item)
1077
+ return item
1078
+ })
1079
+ : allocate(self)
1080
+ ),
1081
+ (item) =>
1082
+ core.withFiber((fiber) => {
1083
+ // A failed acquisition wakes everyone so they can retry it. A new
1084
+ // item can only serve as many waiters as it has slots.
1085
+ if (item.exit._tag === "Failure") wakeAll(self, fiber)
1086
+ else wakeWaiters(self, fiber, self.config.concurrency)
1087
+ return internal.void
1088
+ })
1089
+ )
1014
1090
  if (toAcquire === 1) {
1015
- const acquired = Effect.tap(acquireOne, wakeAll(self))
1016
1091
  return self.config.isFixed
1017
- ? Effect.asVoid(acquired)
1018
- : Effect.flatMap(acquired, (item) => item.exit._tag === "Failure" ? Effect.void : resizeLoop(self))
1092
+ ? Effect.asVoid(acquireOne)
1093
+ : Effect.flatMap(acquireOne, (item) => item.exit._tag === "Failure" ? Effect.void : resizeLoop(self))
1019
1094
  }
1020
- const acquired = acquireOne.pipe(
1021
- Effect.replicateEffect(toAcquire, { concurrency: toAcquire }),
1022
- Effect.tap(wakeAll(self))
1023
- )
1095
+ const acquired = Effect.replicateEffect(acquireOne, toAcquire, { concurrency: toAcquire })
1024
1096
  return self.config.isFixed
1025
1097
  ? Effect.asVoid(acquired)
1026
1098
  : Effect.flatMap(
@@ -1059,7 +1131,7 @@ const allocate = <A, E>(self: Pool<A, E>): Effect.Effect<PoolItem<A, E>> =>
1059
1131
  return self.config.strategy === strategyNoop ? Effect.succeed(item) : Effect.as(onAcquire, item)
1060
1132
  }
1061
1133
  // Deliver a waiting borrower its own failure; otherwise retain the slot.
1062
- const waiter = firstHealthyAvailable(self) === undefined ? self.state.waiters.values().next().value : undefined
1134
+ const waiter = firstHealthyAvailable(self) === undefined ? firstSleepingWaiter(self) : undefined
1063
1135
  if (waiter !== undefined) {
1064
1136
  waiter(exit)
1065
1137
  } else {
package/src/PubSub.ts CHANGED
@@ -3129,14 +3129,13 @@ export class BackPressureStrategy<in out A> implements PubSub.Strategy<A> {
3129
3129
  if (publisher === MutableList.Empty) {
3130
3130
  keepPolling = false
3131
3131
  } else {
3132
- const [value, deferred] = publisher
3132
+ const [value, deferred, last] = publisher
3133
3133
  const published = pubsub.publish(value)
3134
- if (published && publisher[2]) {
3135
- Deferred.doneUnsafe(deferred, Exit.succeed(true))
3136
- } else if (!published) {
3137
- MutableList.prepend(this.publishers, publisher)
3138
- }
3134
+ if (!published) MutableList.prepend(this.publishers, publisher)
3139
3135
  this.completeSubscribersUnsafe(pubsub, subscribers)
3136
+ // Resuming the publisher can synchronously end the PubSub, so notify
3137
+ // waiting subscribers first.
3138
+ if (published && last) Deferred.doneUnsafe(deferred, Exit.succeed(true))
3140
3139
  }
3141
3140
  }
3142
3141
  }
package/src/Ref.ts CHANGED
@@ -12,7 +12,9 @@
12
12
  * @since 2.0.0
13
13
  */
14
14
  import * as Effect from "./Effect.ts"
15
+ import * as Equal from "./Equal.ts"
15
16
  import { dual, identity } from "./Function.ts"
17
+ import * as Hash from "./Hash.ts"
16
18
  import { PipeInspectableProto } from "./internal/core.ts"
17
19
  import * as MutableRef from "./MutableRef.ts"
18
20
  import type * as Option from "./Option.ts"
@@ -110,6 +112,12 @@ const RefProto = {
110
112
  _A: identity
111
113
  },
112
114
  ...PipeInspectableProto,
115
+ [Equal.symbol](that: unknown): boolean {
116
+ return this === that
117
+ },
118
+ [Hash.symbol](): number {
119
+ return Hash.random(this)
120
+ },
113
121
  toJSON(this: Ref<any>) {
114
122
  return {
115
123
  _id: "Ref",
package/src/Schedule.ts CHANGED
@@ -1071,10 +1071,10 @@ export const fibonacci = (one: Duration.Input): Schedule<Duration.Duration> => {
1071
1071
  let a = 0
1072
1072
  let b = oneMillis
1073
1073
  return constant(effect.sync(() => {
1074
+ const duration = Duration.millis(b)
1074
1075
  const next = a + b
1075
1076
  a = b
1076
1077
  b = next
1077
- const duration = Duration.millis(next)
1078
1078
  return [duration, duration]
1079
1079
  }))
1080
1080
  }))
package/src/Schema.ts CHANGED
@@ -3983,11 +3983,18 @@ export interface $Record<Key extends Record.Key, Value extends Constraint> exten
3983
3983
  *
3984
3984
  * **Gotchas**
3985
3985
  *
3986
+ * Dynamic records reject value schemas wrapped with {@link optionalKey} or
3987
+ * {@link optional}. Index signatures already allow keys to be absent; use
3988
+ * {@link UndefinedOr} when existing entries may contain `undefined`. Optional
3989
+ * value schemas remain valid for finite literal keys, which become declared
3990
+ * properties.
3991
+ *
3986
3992
  * When decoded or encoded key transformations produce the same property key,
3987
3993
  * sequential parsing applies selected own properties in selection order, so
3988
3994
  * the later selected property overwrites the earlier value. Dynamic key
3989
- * selection always examines own properties. Finite literal keys are declared
3990
- * fields and may therefore be inherited. Output key order is not guaranteed.
3995
+ * selection always examines own properties. Finite literal and enum keys are
3996
+ * declared fields and may therefore be inherited. Output key order is not
3997
+ * guaranteed.
3991
3998
  *
3992
3999
  * **Example** (Defining a string-keyed record of numbers)
3993
4000
  *
@@ -6737,9 +6744,8 @@ export function link<T>() {
6737
6744
  * )
6738
6745
  *
6739
6746
  * const result = Schema.decodeUnknownResult(schema)({ password: "123456", confirmPassword: "1234567" })
6740
- * if (Result.isFailure(result) && result.failure.issue._tag === "Filter" && result.failure.issue.issue._tag === "Pointer") {
6741
- * result.failure.issue.issue.path // => ["password"]
6742
- * }
6747
+ * const message = Result.isFailure(result) ? result.failure.message : ""
6748
+ * message // => "password and confirmPassword must match\n at [\"password\"]"
6743
6749
  * ```
6744
6750
  *
6745
6751
  * **Example** (Reporting multiple failures at once)
@@ -6759,9 +6765,8 @@ export function link<T>() {
6759
6765
  * )
6760
6766
  *
6761
6767
  * const result = Schema.decodeUnknownResult(schema)({ a: 1, b: 0, c: 0 })
6762
- * if (Result.isFailure(result) && result.failure.issue._tag === "Filter" && result.failure.issue.issue._tag === "Composite") {
6763
- * result.failure.issue.issue.issues.map((issue) => issue._tag === "Pointer" ? issue.path : []) // => [["b"], ["c"]]
6764
- * }
6768
+ * const message = Result.isFailure(result) ? result.failure.message : ""
6769
+ * message // => "b must be greater than 0\n at [\"b\"]\nc must be greater than 0\n at [\"c\"]"
6765
6770
  * ```
6766
6771
  *
6767
6772
  * @stability stable
@@ -6904,8 +6909,8 @@ export function isPattern(
6904
6909
  const flags = regExp.flags
6905
6910
  const canExport = /^[dg]*uy?$/.test(flags)
6906
6911
  const runtimeRegExp = flags === ""
6907
- ? `new RegExp(${format(source)})`
6908
- : `new RegExp(${format(source)}, ${format(flags)})`
6912
+ ? `new globalThis.RegExp(${format(source)})`
6913
+ : `new globalThis.RegExp(${format(source)}, ${format(flags)})`
6909
6914
  return SchemaAST.isPattern(regExp, {
6910
6915
  toJsonSchema: () => canExport ? { pattern: flags.endsWith("y") ? `^(?:${source})` : source } : [{}, true],
6911
6916
  toCode: () => ({ runtime: `Schema.isPattern(${runtimeRegExp})` }),
@@ -7037,7 +7042,7 @@ export function isUUID(version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8, annotations?: An
7037
7042
  )
7038
7043
  }
7039
7044
 
7040
- const GUID_REGEXP = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/
7045
+ const GUID_REGEXP = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/u
7041
7046
  /**
7042
7047
  * Validates that a string has the GUID / UUID textual shape.
7043
7048
  *
@@ -7072,18 +7077,22 @@ export function isGUID(annotations?: Annotations.Filter) {
7072
7077
  id: "effect/schema/isGUID",
7073
7078
  payload: null
7074
7079
  },
7075
- toJsonSchema: () => ({ pattern: GUID_REGEXP.source }),
7076
7080
  toCode: () => ({ runtime: "Schema.isGUID()" }),
7077
7081
  ...annotations
7078
7082
  }
7079
7083
  )
7080
7084
  }
7085
+
7086
+ const ULID_REGEXP = /^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/u
7081
7087
  /**
7082
7088
  * Validates that a string is a valid ULID (Universally Unique Lexicographically
7083
7089
  * Sortable Identifier).
7084
7090
  *
7085
7091
  * **Details**
7086
7092
  *
7093
+ * Accepts uppercase and lowercase characters. The first character must be
7094
+ * between `0` and `7` so the value fits in 128 bits.
7095
+ *
7087
7096
  * JSON Schema:
7088
7097
  *
7089
7098
  * This check corresponds to a `pattern` constraint in JSON Schema that matches
@@ -7099,15 +7108,13 @@ export function isGUID(annotations?: Annotations.Filter) {
7099
7108
  * @since 4.0.0
7100
7109
  */
7101
7110
  export function isULID(annotations?: Annotations.Filter) {
7102
- const regExp = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/
7103
7111
  return isPattern(
7104
- regExp,
7112
+ ULID_REGEXP,
7105
7113
  {
7106
7114
  representation: {
7107
7115
  id: "effect/schema/isULID",
7108
7116
  payload: null
7109
7117
  },
7110
- toJsonSchema: () => ({ pattern: regExp.source }),
7111
7118
  toCode: () => ({ runtime: "Schema.isULID()" }),
7112
7119
  ...annotations
7113
7120
  }
@@ -7392,16 +7399,18 @@ const CAPITALIZED_PATTERN = "^(?:[^a-z][\\s\\S]*)?$"
7392
7399
  * @since 4.0.0
7393
7400
  */
7394
7401
  export function isCapitalized(annotations?: Annotations.Filter) {
7395
- const regExp = new globalThis.RegExp(CAPITALIZED_PATTERN)
7396
7402
  return makeFilter(
7397
- (s: string) => s.charAt(0).toUpperCase() === s.charAt(0),
7403
+ (s: string) => {
7404
+ const [first = ""] = s
7405
+ return first.toUpperCase() === first
7406
+ },
7398
7407
  {
7399
7408
  expected: "a string with the first character in uppercase",
7400
7409
  representation: {
7401
7410
  id: "effect/schema/isCapitalized",
7402
7411
  payload: null
7403
7412
  },
7404
- toJsonSchema: () => [{ pattern: regExp.source }, true],
7413
+ toJsonSchema: () => [{ pattern: CAPITALIZED_PATTERN }, true],
7405
7414
  toCode: () => ({ runtime: "Schema.isCapitalized()" }),
7406
7415
  arbitraryConstraint: {
7407
7416
  patterns: [{ source: CAPITALIZED_PATTERN, flags: "" }]
@@ -7426,16 +7435,18 @@ const UNCAPITALIZED_PATTERN = "^(?:[^A-Z][\\s\\S]*)?$"
7426
7435
  * @since 4.0.0
7427
7436
  */
7428
7437
  export function isUncapitalized(annotations?: Annotations.Filter) {
7429
- const regExp = new globalThis.RegExp(UNCAPITALIZED_PATTERN)
7430
7438
  return makeFilter(
7431
- (s: string) => s.charAt(0).toLowerCase() === s.charAt(0),
7439
+ (s: string) => {
7440
+ const [first = ""] = s
7441
+ return first.toLowerCase() === first
7442
+ },
7432
7443
  {
7433
7444
  expected: "a string with the first character in lowercase",
7434
7445
  representation: {
7435
7446
  id: "effect/schema/isUncapitalized",
7436
7447
  payload: null
7437
7448
  },
7438
- toJsonSchema: () => [{ pattern: regExp.source }, true],
7449
+ toJsonSchema: () => [{ pattern: UNCAPITALIZED_PATTERN }, true],
7439
7450
  toCode: () => ({ runtime: "Schema.isUncapitalized()" }),
7440
7451
  arbitraryConstraint: {
7441
7452
  patterns: [{ source: UNCAPITALIZED_PATTERN, flags: "" }]
@@ -8064,7 +8075,7 @@ function encodeDatePayload(date: globalThis.Date): string {
8064
8075
  }
8065
8076
 
8066
8077
  function formatDateRuntime(date: globalThis.Date): string {
8067
- return `new Date(${format(date.getTime())})`
8078
+ return `new globalThis.Date(${format(date.getTime())})`
8068
8079
  }
8069
8080
  /**
8070
8081
  * Validates that a Date is greater than the specified value (exclusive).
@@ -9799,8 +9810,7 @@ export interface fromJsonString<S extends Constraint> extends decodeTo<S, String
9799
9810
  }
9800
9811
 
9801
9812
  const JsonString = String.annotate({
9802
- expected: "a string that will be decoded as JSON",
9803
- contentMediaType: "application/json"
9813
+ expected: "a string that will be decoded as JSON"
9804
9814
  })
9805
9815
  /**
9806
9816
  * Returns a schema that decodes a JSON string and then decodes the parsed value
@@ -16268,7 +16278,12 @@ function makeClass<
16268
16278
  return getClassSchema(this).rebuild(ast)
16269
16279
  }
16270
16280
  static make(input: S["~type.make.in"], options?: MakeOptions): Self {
16271
- return SchemaParser.make(getClassSchema(this) as any)(input ?? {}, options) as Self
16281
+ return SchemaParser.makeClassSync(
16282
+ SchemaAST.toType(getClassSchema(this).ast),
16283
+ input ?? {},
16284
+ options,
16285
+ (fields) => makeClassTrusted(this, fields)
16286
+ )
16272
16287
  }
16273
16288
  static makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self> {
16274
16289
  return SchemaParser.makeOption(getClassSchema(this) as any)(input ?? {}, options) as any
@@ -16417,6 +16432,10 @@ function isStruct(schema: Struct.Fields | Struct<Struct.Fields>): schema is Stru
16417
16432
  *
16418
16433
  * **Gotchas**
16419
16434
  *
16435
+ * To subclass a `Schema.Class`, use `Base.extend<Self>(...)`, even when only
16436
+ * adding methods or getters. Pass `{}` for the fields when none are added.
16437
+ * Plain `class Child extends Base` is unsupported.
16438
+ *
16420
16439
  * Passing `disableChecks: true` skips filters and checks, not parsing of types
16421
16440
  * and structure. Wrong types and shapes are still rejected, and constructor
16422
16441
  * defaults still apply.
@@ -16490,6 +16509,10 @@ export const Class: {
16490
16509
  *
16491
16510
  * **Gotchas**
16492
16511
  *
16512
+ * To subclass a `Schema.Class`, use `Base.extend<Self>(...)`, even when only
16513
+ * adding methods or getters. Pass `{}` for the fields when none are added.
16514
+ * Plain `class Child extends Base` is unsupported.
16515
+ *
16493
16516
  * Passing `disableChecks: true` skips filters and checks, not parsing of types
16494
16517
  * and structure. Wrong types and shapes are still rejected, and constructor
16495
16518
  * defaults still apply.
package/src/SchemaAST.ts CHANGED
@@ -2739,8 +2739,10 @@ function isIndexSignatureParameter(ast: AST): ast is IndexSignatureParameter {
2739
2739
  *
2740
2740
  * **Gotchas**
2741
2741
  *
2742
- * Using `Schema.optionalKey` on the value type is not allowed for index
2743
- * signatures (throws at construction); use `Schema.optional` instead.
2742
+ * Using `Schema.optionalKey` or `Schema.optional` on the value type is not
2743
+ * allowed for index signatures (throws at construction). Index signatures
2744
+ * already allow keys to be absent; use `Schema.UndefinedOr` to allow
2745
+ * `undefined` values.
2744
2746
  *
2745
2747
  * @see {@link Objects}
2746
2748
  * @see {@link PropertySignature}
@@ -2773,8 +2775,10 @@ export const IndexSignature: new(parameter: AST, type: AST) => IndexSignature =
2773
2775
  }
2774
2776
  this.parameter = parameter
2775
2777
  this.type = type
2776
- if (isOptional(type) && !containsUndefined(type)) {
2777
- throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")
2778
+ if (isOptional(type) || (type.encoding !== undefined && isOptional(toEncoded(type)))) {
2779
+ throw new Error(
2780
+ "Cannot use `Schema.optionalKey` or `Schema.optional` with index signatures. Index signatures already allow keys to be absent; use `Schema.UndefinedOr` to allow `undefined` values."
2781
+ )
2778
2782
  }
2779
2783
  }
2780
2784
  }
@@ -4598,16 +4602,24 @@ function parseParameter(ast: AST): {
4598
4602
  } {
4599
4603
  const literals: Array<PropertyKey> = []
4600
4604
  const parameters: Array<AST> = []
4605
+ function addLiteral(literal: PropertyKey) {
4606
+ if (!literals.includes(literal)) {
4607
+ literals.push(literal)
4608
+ }
4609
+ }
4601
4610
  function go(ast: AST) {
4602
4611
  switch (ast._tag) {
4603
4612
  case "Literal":
4604
- if (Predicate.isPropertyKey(ast.literal) && !literals.includes(ast.literal)) {
4605
- literals.push(ast.literal)
4613
+ if (Predicate.isPropertyKey(ast.literal)) {
4614
+ addLiteral(ast.literal)
4606
4615
  }
4607
4616
  return
4608
4617
  case "UniqueSymbol":
4609
- if (!literals.includes(ast.symbol)) {
4610
- literals.push(ast.symbol)
4618
+ addLiteral(ast.symbol)
4619
+ return
4620
+ case "Enum":
4621
+ for (const [, value] of ast.enums) {
4622
+ addLiteral(value)
4611
4623
  }
4612
4624
  return
4613
4625
  case "Never":
@@ -4812,18 +4824,6 @@ export const flip = memoize((ast: AST): AST => {
4812
4824
  return "flip" in ast ? ast.flip(flip) : "recur" in ast ? ast.recur(flip) : ast
4813
4825
  })
4814
4826
 
4815
- /** @internal */
4816
- export function containsUndefined(ast: AST): boolean {
4817
- switch (ast._tag) {
4818
- case "Undefined":
4819
- return true
4820
- case "Union":
4821
- return ast.types.some(containsUndefined)
4822
- default:
4823
- return false
4824
- }
4825
- }
4826
-
4827
4827
  function fromConst<const T>(
4828
4828
  ast: AST,
4829
4829
  value: T