effect 4.0.0-beta.101 → 4.0.0-beta.102

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 (494) hide show
  1. package/dist/Array.d.ts.map +1 -1
  2. package/dist/Array.js +81 -5
  3. package/dist/Array.js.map +1 -1
  4. package/dist/Channel.d.ts.map +1 -1
  5. package/dist/Channel.js +27 -9
  6. package/dist/Channel.js.map +1 -1
  7. package/dist/Config.d.ts +1 -1
  8. package/dist/Config.d.ts.map +1 -1
  9. package/dist/Config.js +6 -5
  10. package/dist/Config.js.map +1 -1
  11. package/dist/ConfigProvider.js +7 -7
  12. package/dist/ConfigProvider.js.map +1 -1
  13. package/dist/Data.d.ts.map +1 -1
  14. package/dist/Data.js +2 -1
  15. package/dist/Data.js.map +1 -1
  16. package/dist/Effect.d.ts +61 -100
  17. package/dist/Effect.d.ts.map +1 -1
  18. package/dist/Effect.js +66 -39
  19. package/dist/Effect.js.map +1 -1
  20. package/dist/FiberHandle.d.ts.map +1 -1
  21. package/dist/FiberHandle.js +3 -2
  22. package/dist/FiberHandle.js.map +1 -1
  23. package/dist/Iterable.d.ts.map +1 -1
  24. package/dist/Iterable.js +2 -1
  25. package/dist/Iterable.js.map +1 -1
  26. package/dist/JsonPatch.d.ts.map +1 -1
  27. package/dist/JsonPatch.js +4 -3
  28. package/dist/JsonPatch.js.map +1 -1
  29. package/dist/JsonSchema.d.ts.map +1 -1
  30. package/dist/JsonSchema.js +9 -11
  31. package/dist/JsonSchema.js.map +1 -1
  32. package/dist/Logger.d.ts.map +1 -1
  33. package/dist/Logger.js +3 -2
  34. package/dist/Logger.js.map +1 -1
  35. package/dist/ManagedRuntime.d.ts +9 -0
  36. package/dist/ManagedRuntime.d.ts.map +1 -1
  37. package/dist/ManagedRuntime.js +3 -0
  38. package/dist/ManagedRuntime.js.map +1 -1
  39. package/dist/Metric.d.ts.map +1 -1
  40. package/dist/Metric.js +4 -3
  41. package/dist/Metric.js.map +1 -1
  42. package/dist/Optic.d.ts.map +1 -1
  43. package/dist/Optic.js +5 -4
  44. package/dist/Optic.js.map +1 -1
  45. package/dist/Option.d.ts.map +1 -1
  46. package/dist/Option.js +2 -1
  47. package/dist/Option.js.map +1 -1
  48. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  49. package/dist/PartitionedSemaphore.js +1 -4
  50. package/dist/PartitionedSemaphore.js.map +1 -1
  51. package/dist/Record.d.ts +93 -1
  52. package/dist/Record.d.ts.map +1 -1
  53. package/dist/Record.js +57 -19
  54. package/dist/Record.js.map +1 -1
  55. package/dist/References.d.ts +0 -45
  56. package/dist/References.d.ts.map +1 -1
  57. package/dist/References.js +0 -45
  58. package/dist/References.js.map +1 -1
  59. package/dist/Request.d.ts.map +1 -1
  60. package/dist/Request.js +9 -6
  61. package/dist/Request.js.map +1 -1
  62. package/dist/Result.d.ts.map +1 -1
  63. package/dist/Result.js +2 -1
  64. package/dist/Result.js.map +1 -1
  65. package/dist/Schema.d.ts +1268 -495
  66. package/dist/Schema.d.ts.map +1 -1
  67. package/dist/Schema.js +2308 -614
  68. package/dist/Schema.js.map +1 -1
  69. package/dist/SchemaAST.d.ts +2 -2
  70. package/dist/SchemaAST.d.ts.map +1 -1
  71. package/dist/SchemaAST.js +189 -130
  72. package/dist/SchemaAST.js.map +1 -1
  73. package/dist/SchemaError.js +1 -1
  74. package/dist/SchemaError.js.map +1 -1
  75. package/dist/SchemaGetter.d.ts +13 -11
  76. package/dist/SchemaGetter.d.ts.map +1 -1
  77. package/dist/SchemaGetter.js +34 -24
  78. package/dist/SchemaGetter.js.map +1 -1
  79. package/dist/SchemaIssue.js +1 -1
  80. package/dist/SchemaIssue.js.map +1 -1
  81. package/dist/SchemaParser.d.ts.map +1 -1
  82. package/dist/SchemaParser.js +1 -12
  83. package/dist/SchemaParser.js.map +1 -1
  84. package/dist/SchemaRepresentation.d.ts +403 -1504
  85. package/dist/SchemaRepresentation.d.ts.map +1 -1
  86. package/dist/SchemaRepresentation.js +294 -2852
  87. package/dist/SchemaRepresentation.js.map +1 -1
  88. package/dist/SchemaTransformation.d.ts +2 -2
  89. package/dist/SchemaTransformation.js +3 -3
  90. package/dist/SchemaTransformation.js.map +1 -1
  91. package/dist/Semaphore.d.ts +5 -3
  92. package/dist/Semaphore.d.ts.map +1 -1
  93. package/dist/Semaphore.js.map +1 -1
  94. package/dist/Stream.d.ts +15 -9
  95. package/dist/Stream.d.ts.map +1 -1
  96. package/dist/Stream.js +46 -16
  97. package/dist/Stream.js.map +1 -1
  98. package/dist/Struct.d.ts.map +1 -1
  99. package/dist/Struct.js +5 -4
  100. package/dist/Struct.js.map +1 -1
  101. package/dist/Types.d.ts +1 -3
  102. package/dist/Types.d.ts.map +1 -1
  103. package/dist/index.d.ts +0 -4
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +0 -4
  106. package/dist/index.js.map +1 -1
  107. package/dist/internal/core.js +2 -1
  108. package/dist/internal/core.js.map +1 -1
  109. package/dist/internal/effect.js +64 -21
  110. package/dist/internal/effect.js.map +1 -1
  111. package/dist/internal/matcher.js +1 -1
  112. package/dist/internal/matcher.js.map +1 -1
  113. package/dist/internal/record.d.ts +0 -3
  114. package/dist/internal/record.d.ts.map +1 -1
  115. package/dist/internal/record.js +10 -5
  116. package/dist/internal/record.js.map +1 -1
  117. package/dist/internal/references.js +0 -4
  118. package/dist/internal/references.js.map +1 -1
  119. package/dist/internal/schema/annotations.js +12 -0
  120. package/dist/internal/schema/annotations.js.map +1 -1
  121. package/dist/internal/schema/fromJsonSchemaDocument.d.ts +2 -0
  122. package/dist/internal/schema/fromJsonSchemaDocument.d.ts.map +1 -0
  123. package/dist/internal/schema/fromJsonSchemaDocument.js +743 -0
  124. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -0
  125. package/dist/internal/schema/fromRepresentation.d.ts +2 -0
  126. package/dist/internal/schema/fromRepresentation.d.ts.map +1 -0
  127. package/dist/internal/schema/fromRepresentation.js +252 -0
  128. package/dist/internal/schema/fromRepresentation.js.map +1 -0
  129. package/dist/internal/schema/schema.js +28 -40
  130. package/dist/internal/schema/schema.js.map +1 -1
  131. package/dist/internal/schema/{arbitrary.d.ts → toArbitrary.d.ts} +1 -1
  132. package/dist/internal/schema/toArbitrary.d.ts.map +1 -0
  133. package/dist/internal/schema/{arbitrary.js → toArbitrary.js} +8 -9
  134. package/dist/internal/schema/toArbitrary.js.map +1 -0
  135. package/dist/internal/schema/toCodeDocument.d.ts +2 -0
  136. package/dist/internal/schema/toCodeDocument.d.ts.map +1 -0
  137. package/dist/internal/schema/toCodeDocument.js +438 -0
  138. package/dist/internal/schema/toCodeDocument.js.map +1 -0
  139. package/dist/internal/schema/toEquivalence.d.ts +2 -0
  140. package/dist/internal/schema/toEquivalence.d.ts.map +1 -0
  141. package/dist/internal/schema/{equivalence.js → toEquivalence.js} +15 -13
  142. package/dist/internal/schema/toEquivalence.js.map +1 -0
  143. package/dist/internal/schema/toJsonSchemaDocument.d.ts +2 -0
  144. package/dist/internal/schema/toJsonSchemaDocument.d.ts.map +1 -0
  145. package/dist/internal/schema/toJsonSchemaDocument.js +466 -0
  146. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -0
  147. package/dist/internal/schema/toRepresentation.d.ts +2 -0
  148. package/dist/internal/schema/toRepresentation.d.ts.map +1 -0
  149. package/dist/internal/schema/toRepresentation.js +369 -0
  150. package/dist/internal/schema/toRepresentation.js.map +1 -0
  151. package/dist/internal/stackTraceLimit.js +3 -6
  152. package/dist/internal/stackTraceLimit.js.map +1 -1
  153. package/dist/testing/TestClock.js +4 -1
  154. package/dist/testing/TestClock.js.map +1 -1
  155. package/dist/unstable/ai/AiError.d.ts +26 -26
  156. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  157. package/dist/unstable/ai/AiError.js +5 -4
  158. package/dist/unstable/ai/AiError.js.map +1 -1
  159. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +21 -6
  160. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  161. package/dist/unstable/ai/AnthropicStructuredOutput.js +86 -316
  162. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  163. package/dist/unstable/ai/EmbeddingModel.d.ts +1 -1
  164. package/dist/unstable/ai/EmbeddingModel.js +1 -1
  165. package/dist/unstable/ai/EmbeddingModel.js.map +1 -1
  166. package/dist/unstable/ai/LanguageModel.d.ts +4 -1
  167. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  168. package/dist/unstable/ai/LanguageModel.js +19 -17
  169. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  170. package/dist/unstable/ai/McpSchema.d.ts +197 -197
  171. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  172. package/dist/unstable/ai/McpSchema.js +13 -13
  173. package/dist/unstable/ai/McpSchema.js.map +1 -1
  174. package/dist/unstable/ai/McpServer.d.ts +4 -4
  175. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  176. package/dist/unstable/ai/McpServer.js +116 -49
  177. package/dist/unstable/ai/McpServer.js.map +1 -1
  178. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +32 -10
  179. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  180. package/dist/unstable/ai/OpenAiStructuredOutput.js +193 -377
  181. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  182. package/dist/unstable/ai/Response.d.ts +19 -19
  183. package/dist/unstable/ai/Response.d.ts.map +1 -1
  184. package/dist/unstable/ai/Response.js +14 -14
  185. package/dist/unstable/ai/Response.js.map +1 -1
  186. package/dist/unstable/ai/Tool.d.ts +4 -0
  187. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  188. package/dist/unstable/ai/Tool.js +11 -3
  189. package/dist/unstable/ai/Tool.js.map +1 -1
  190. package/dist/unstable/ai/Toolkit.d.ts +9 -1
  191. package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
  192. package/dist/unstable/ai/Toolkit.js +14 -10
  193. package/dist/unstable/ai/Toolkit.js.map +1 -1
  194. package/dist/unstable/ai/internal/codec-transformer.js +15 -12
  195. package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
  196. package/dist/unstable/ai/internal/structured-output.d.ts +2 -0
  197. package/dist/unstable/ai/internal/structured-output.d.ts.map +1 -0
  198. package/dist/unstable/ai/internal/structured-output.js +316 -0
  199. package/dist/unstable/ai/internal/structured-output.js.map +1 -0
  200. package/dist/unstable/cli/CliError.d.ts +40 -2
  201. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  202. package/dist/unstable/cli/CliError.js +45 -6
  203. package/dist/unstable/cli/CliError.js.map +1 -1
  204. package/dist/unstable/cli/Command.js +14 -5
  205. package/dist/unstable/cli/Command.js.map +1 -1
  206. package/dist/unstable/cli/Param.js +3 -3
  207. package/dist/unstable/cli/Param.js.map +1 -1
  208. package/dist/unstable/cli/Primitive.js +1 -1
  209. package/dist/unstable/cli/Primitive.js.map +1 -1
  210. package/dist/unstable/cli/internal/command.d.ts +3 -1
  211. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  212. package/dist/unstable/cli/internal/command.js +11 -4
  213. package/dist/unstable/cli/internal/command.js.map +1 -1
  214. package/dist/unstable/cli/internal/config.d.ts +0 -48
  215. package/dist/unstable/cli/internal/config.d.ts.map +1 -1
  216. package/dist/unstable/cli/internal/config.js +8 -10
  217. package/dist/unstable/cli/internal/config.js.map +1 -1
  218. package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
  219. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  220. package/dist/unstable/cluster/Entity.js +1 -1
  221. package/dist/unstable/cluster/Entity.js.map +1 -1
  222. package/dist/unstable/cluster/Envelope.d.ts.map +1 -1
  223. package/dist/unstable/cluster/Envelope.js +2 -1
  224. package/dist/unstable/cluster/Envelope.js.map +1 -1
  225. package/dist/unstable/cluster/Reply.js +1 -1
  226. package/dist/unstable/cluster/Reply.js.map +1 -1
  227. package/dist/unstable/cluster/Runner.d.ts +1 -1
  228. package/dist/unstable/cluster/Runner.js +1 -1
  229. package/dist/unstable/cluster/Runner.js.map +1 -1
  230. package/dist/unstable/cluster/RunnerAddress.d.ts +1 -1
  231. package/dist/unstable/cluster/RunnerAddress.js +1 -1
  232. package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
  233. package/dist/unstable/cluster/ShardId.js +1 -1
  234. package/dist/unstable/cluster/ShardId.js.map +1 -1
  235. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  236. package/dist/unstable/cluster/Sharding.js +125 -24
  237. package/dist/unstable/cluster/Sharding.js.map +1 -1
  238. package/dist/unstable/cluster/ShardingConfig.d.ts +10 -2
  239. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  240. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  241. package/dist/unstable/cluster/SingleRunner.d.ts +4 -2
  242. package/dist/unstable/cluster/SingleRunner.d.ts.map +1 -1
  243. package/dist/unstable/cluster/SingleRunner.js +2 -1
  244. package/dist/unstable/cluster/SingleRunner.js.map +1 -1
  245. package/dist/unstable/cluster/SqlMessageStorage.d.ts +7 -4
  246. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  247. package/dist/unstable/cluster/SqlMessageStorage.js +55 -24
  248. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  249. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  250. package/dist/unstable/cluster/SqlRunnerStorage.js +109 -62
  251. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  252. package/dist/unstable/cluster/internal/entityManager.js +19 -7
  253. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  254. package/dist/unstable/cluster/internal/shardLock.d.ts +2 -0
  255. package/dist/unstable/cluster/internal/shardLock.d.ts.map +1 -0
  256. package/dist/unstable/cluster/internal/shardLock.js +4 -0
  257. package/dist/unstable/cluster/internal/shardLock.js.map +1 -0
  258. package/dist/unstable/devtools/DevToolsSchema.d.ts +20 -20
  259. package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
  260. package/dist/unstable/devtools/DevToolsSchema.js +8 -5
  261. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  262. package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
  263. package/dist/unstable/eventlog/EventJournal.js +1 -1
  264. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  265. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  266. package/dist/unstable/eventlog/EventLog.js +15 -11
  267. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  268. package/dist/unstable/eventlog/EventLogEncryption.d.ts +1 -1
  269. package/dist/unstable/eventlog/EventLogEncryption.js +1 -1
  270. package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
  271. package/dist/unstable/eventlog/EventLogMessage.d.ts +4 -4
  272. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  273. package/dist/unstable/eventlog/EventLogMessage.js +8 -3
  274. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  275. package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
  276. package/dist/unstable/eventlog/SqlEventJournal.js +2 -2
  277. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  278. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +1 -1
  279. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  280. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +3 -3
  281. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  282. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  283. package/dist/unstable/http/Cookies.js +24 -22
  284. package/dist/unstable/http/Cookies.js.map +1 -1
  285. package/dist/unstable/http/Headers.js +8 -8
  286. package/dist/unstable/http/Headers.js.map +1 -1
  287. package/dist/unstable/http/HttpClientRequest.d.ts +44 -0
  288. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  289. package/dist/unstable/http/HttpClientRequest.js +14 -0
  290. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  291. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  292. package/dist/unstable/http/HttpServerRequest.js +5 -4
  293. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  294. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  295. package/dist/unstable/http/Multipart.js +17 -15
  296. package/dist/unstable/http/Multipart.js.map +1 -1
  297. package/dist/unstable/http/Template.js +1 -1
  298. package/dist/unstable/http/Template.js.map +1 -1
  299. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  300. package/dist/unstable/http/UrlParams.js +17 -14
  301. package/dist/unstable/http/UrlParams.js.map +1 -1
  302. package/dist/unstable/httpapi/HttpApi.js +3 -3
  303. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  304. package/dist/unstable/httpapi/HttpApiClient.js +5 -5
  305. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  306. package/dist/unstable/httpapi/HttpApiGroup.js +1 -1
  307. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  308. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  309. package/dist/unstable/httpapi/OpenApi.js +37 -24
  310. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  311. package/dist/unstable/observability/OtlpExporter.d.ts +72 -1
  312. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  313. package/dist/unstable/observability/OtlpExporter.js +69 -4
  314. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  315. package/dist/unstable/observability/OtlpLogger.d.ts +4 -3
  316. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  317. package/dist/unstable/observability/OtlpLogger.js +2 -2
  318. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  319. package/dist/unstable/observability/OtlpMetrics.d.ts +7 -3
  320. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  321. package/dist/unstable/observability/OtlpMetrics.js +5 -2
  322. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  323. package/dist/unstable/observability/OtlpTracer.d.ts +4 -3
  324. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  325. package/dist/unstable/observability/OtlpTracer.js +2 -2
  326. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  327. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  328. package/dist/unstable/persistence/Persistable.js +2 -1
  329. package/dist/unstable/persistence/Persistable.js.map +1 -1
  330. package/dist/unstable/persistence/RateLimiter.d.ts +2 -2
  331. package/dist/unstable/persistence/RateLimiter.js +2 -2
  332. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  333. package/dist/unstable/persistence/Redis.d.ts.map +1 -1
  334. package/dist/unstable/persistence/Redis.js +2 -2
  335. package/dist/unstable/persistence/Redis.js.map +1 -1
  336. package/dist/unstable/process/ChildProcessSpawner.js +3 -1
  337. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  338. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  339. package/dist/unstable/reactivity/AsyncResult.js +4 -3
  340. package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
  341. package/dist/unstable/reactivity/Atom.d.ts +83 -0
  342. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  343. package/dist/unstable/reactivity/Atom.js +31 -0
  344. package/dist/unstable/reactivity/Atom.js.map +1 -1
  345. package/dist/unstable/reactivity/AtomRegistry.js +1 -1
  346. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  347. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  348. package/dist/unstable/rpc/RpcClient.js +2 -1
  349. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  350. package/dist/unstable/schema/VariantSchema.d.ts +1 -2
  351. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  352. package/dist/unstable/schema/VariantSchema.js +13 -10
  353. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  354. package/dist/unstable/socket/Socket.d.ts +1 -1
  355. package/dist/unstable/socket/Socket.js +1 -1
  356. package/dist/unstable/socket/Socket.js.map +1 -1
  357. package/dist/unstable/sql/SqlError.d.ts +2 -2
  358. package/dist/unstable/sql/SqlError.js +2 -2
  359. package/dist/unstable/sql/SqlError.js.map +1 -1
  360. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  361. package/dist/unstable/sql/Statement.js +7 -6
  362. package/dist/unstable/sql/Statement.js.map +1 -1
  363. package/package.json +1 -1
  364. package/src/Array.ts +86 -25
  365. package/src/Channel.ts +32 -14
  366. package/src/Config.ts +6 -5
  367. package/src/ConfigProvider.ts +7 -7
  368. package/src/Data.ts +3 -2
  369. package/src/Effect.ts +70 -116
  370. package/src/FiberHandle.ts +3 -2
  371. package/src/Iterable.ts +2 -1
  372. package/src/JsonPatch.ts +4 -3
  373. package/src/JsonSchema.ts +9 -11
  374. package/src/Logger.ts +3 -2
  375. package/src/ManagedRuntime.ts +13 -0
  376. package/src/Metric.ts +4 -3
  377. package/src/Optic.ts +5 -4
  378. package/src/Option.ts +2 -1
  379. package/src/PartitionedSemaphore.ts +1 -4
  380. package/src/Record.ts +119 -22
  381. package/src/References.ts +0 -46
  382. package/src/Request.ts +5 -7
  383. package/src/Result.ts +2 -1
  384. package/src/Schema.ts +2537 -986
  385. package/src/SchemaAST.ts +228 -149
  386. package/src/SchemaError.ts +1 -1
  387. package/src/SchemaGetter.ts +36 -29
  388. package/src/SchemaIssue.ts +1 -1
  389. package/src/SchemaParser.ts +1 -25
  390. package/src/SchemaRepresentation.ts +697 -3398
  391. package/src/SchemaTransformation.ts +3 -3
  392. package/src/Semaphore.ts +5 -3
  393. package/src/Stream.ts +63 -19
  394. package/src/Struct.ts +5 -4
  395. package/src/Types.ts +1 -3
  396. package/src/index.ts +0 -5
  397. package/src/internal/core.ts +3 -2
  398. package/src/internal/effect.ts +67 -31
  399. package/src/internal/matcher.ts +1 -1
  400. package/src/internal/record.ts +11 -7
  401. package/src/internal/references.ts +0 -5
  402. package/src/internal/schema/annotations.ts +44 -0
  403. package/src/internal/schema/fromJsonSchemaDocument.ts +957 -0
  404. package/src/internal/schema/fromRepresentation.ts +345 -0
  405. package/src/internal/schema/schema.ts +45 -46
  406. package/src/internal/schema/{arbitrary.ts → toArbitrary.ts} +8 -10
  407. package/src/internal/schema/toCodeDocument.ts +572 -0
  408. package/src/internal/schema/{equivalence.ts → toEquivalence.ts} +12 -7
  409. package/src/internal/schema/toJsonSchemaDocument.ts +475 -0
  410. package/src/internal/schema/toRepresentation.ts +401 -0
  411. package/src/internal/stackTraceLimit.ts +3 -7
  412. package/src/testing/TestClock.ts +1 -1
  413. package/src/unstable/ai/AiError.ts +5 -4
  414. package/src/unstable/ai/AnthropicStructuredOutput.ts +102 -333
  415. package/src/unstable/ai/EmbeddingModel.ts +1 -1
  416. package/src/unstable/ai/LanguageModel.ts +30 -28
  417. package/src/unstable/ai/McpSchema.ts +15 -15
  418. package/src/unstable/ai/McpServer.ts +172 -56
  419. package/src/unstable/ai/OpenAiStructuredOutput.ts +230 -395
  420. package/src/unstable/ai/Response.ts +24 -24
  421. package/src/unstable/ai/Tool.ts +22 -4
  422. package/src/unstable/ai/Toolkit.ts +19 -7
  423. package/src/unstable/ai/internal/codec-transformer.ts +13 -7
  424. package/src/unstable/ai/internal/structured-output.ts +458 -0
  425. package/src/unstable/cli/CliError.ts +51 -5
  426. package/src/unstable/cli/Command.ts +4 -4
  427. package/src/unstable/cli/Param.ts +3 -3
  428. package/src/unstable/cli/Primitive.ts +1 -1
  429. package/src/unstable/cli/internal/command.ts +13 -5
  430. package/src/unstable/cli/internal/config.ts +8 -10
  431. package/src/unstable/cluster/ClusterWorkflowEngine.ts +3 -3
  432. package/src/unstable/cluster/Entity.ts +1 -1
  433. package/src/unstable/cluster/Envelope.ts +2 -1
  434. package/src/unstable/cluster/Reply.ts +1 -1
  435. package/src/unstable/cluster/Runner.ts +1 -1
  436. package/src/unstable/cluster/RunnerAddress.ts +1 -1
  437. package/src/unstable/cluster/ShardId.ts +1 -1
  438. package/src/unstable/cluster/Sharding.ts +161 -34
  439. package/src/unstable/cluster/ShardingConfig.ts +5 -1
  440. package/src/unstable/cluster/SingleRunner.ts +4 -2
  441. package/src/unstable/cluster/SqlMessageStorage.ts +83 -35
  442. package/src/unstable/cluster/SqlRunnerStorage.ts +186 -116
  443. package/src/unstable/cluster/internal/entityManager.ts +31 -10
  444. package/src/unstable/cluster/internal/shardLock.ts +9 -0
  445. package/src/unstable/devtools/DevToolsSchema.ts +10 -5
  446. package/src/unstable/eventlog/EventJournal.ts +1 -1
  447. package/src/unstable/eventlog/EventLog.ts +21 -11
  448. package/src/unstable/eventlog/EventLogEncryption.ts +1 -1
  449. package/src/unstable/eventlog/EventLogMessage.ts +10 -3
  450. package/src/unstable/eventlog/SqlEventJournal.ts +2 -2
  451. package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +1 -1
  452. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +6 -3
  453. package/src/unstable/http/Cookies.ts +29 -24
  454. package/src/unstable/http/Headers.ts +8 -8
  455. package/src/unstable/http/HttpClientRequest.ts +57 -0
  456. package/src/unstable/http/HttpServerRequest.ts +5 -4
  457. package/src/unstable/http/Multipart.ts +16 -13
  458. package/src/unstable/http/Template.ts +1 -1
  459. package/src/unstable/http/UrlParams.ts +17 -14
  460. package/src/unstable/httpapi/HttpApi.ts +3 -3
  461. package/src/unstable/httpapi/HttpApiClient.ts +5 -5
  462. package/src/unstable/httpapi/HttpApiGroup.ts +1 -1
  463. package/src/unstable/httpapi/OpenApi.ts +52 -28
  464. package/src/unstable/observability/OtlpExporter.ts +109 -5
  465. package/src/unstable/observability/OtlpLogger.ts +5 -5
  466. package/src/unstable/observability/OtlpMetrics.ts +8 -4
  467. package/src/unstable/observability/OtlpTracer.ts +8 -4
  468. package/src/unstable/persistence/Persistable.ts +3 -2
  469. package/src/unstable/persistence/RateLimiter.ts +2 -2
  470. package/src/unstable/persistence/Redis.ts +2 -2
  471. package/src/unstable/process/ChildProcessSpawner.ts +1 -1
  472. package/src/unstable/reactivity/AsyncResult.ts +4 -3
  473. package/src/unstable/reactivity/Atom.ts +92 -0
  474. package/src/unstable/reactivity/AtomRegistry.ts +1 -1
  475. package/src/unstable/rpc/RpcClient.ts +2 -1
  476. package/src/unstable/schema/VariantSchema.ts +14 -24
  477. package/src/unstable/socket/Socket.ts +1 -1
  478. package/src/unstable/sql/SqlError.ts +2 -2
  479. package/src/unstable/sql/Statement.ts +7 -6
  480. package/dist/SchemaUtils.d.ts +0 -28
  481. package/dist/SchemaUtils.d.ts.map +0 -1
  482. package/dist/SchemaUtils.js +0 -45
  483. package/dist/SchemaUtils.js.map +0 -1
  484. package/dist/internal/schema/arbitrary.d.ts.map +0 -1
  485. package/dist/internal/schema/arbitrary.js.map +0 -1
  486. package/dist/internal/schema/equivalence.d.ts +0 -2
  487. package/dist/internal/schema/equivalence.d.ts.map +0 -1
  488. package/dist/internal/schema/equivalence.js.map +0 -1
  489. package/dist/internal/schema/representation.d.ts +0 -2
  490. package/dist/internal/schema/representation.d.ts.map +0 -1
  491. package/dist/internal/schema/representation.js +0 -865
  492. package/dist/internal/schema/representation.js.map +0 -1
  493. package/src/SchemaUtils.ts +0 -51
  494. package/src/internal/schema/representation.ts +0 -795
@@ -0,0 +1,957 @@
1
+ import { unescapeToken } from "../../JsonPointer.ts"
2
+ import type * as JsonSchema from "../../JsonSchema.ts"
3
+ import { remainder } from "../../Number.ts"
4
+ import * as Schema from "../../Schema.ts"
5
+ import * as SchemaAST from "../../SchemaAST.ts"
6
+ import type * as SchemaRepresentation from "../../SchemaRepresentation.ts"
7
+ import { errorWithPath } from "../errors.ts"
8
+ import * as InternalRecord from "../record.ts"
9
+ import * as InternalAnnotations from "./annotations.ts"
10
+ import { fromRepresentation, fromRepresentations } from "./fromRepresentation.ts"
11
+
12
+ type Path = ReadonlyArray<string | number>
13
+ type Representation = SchemaRepresentation.Representation
14
+ type Check = SchemaRepresentation.Check
15
+
16
+ type ImportedJsonSchemaRepresentation = Extract<Representation, {
17
+ readonly _tag:
18
+ | "Reference"
19
+ | "Suspend"
20
+ | "Never"
21
+ | "Unknown"
22
+ | "Null"
23
+ | "String"
24
+ | "Number"
25
+ | "Boolean"
26
+ | "Literal"
27
+ | "Arrays"
28
+ | "Objects"
29
+ | "Union"
30
+ }>
31
+
32
+ const never: ImportedJsonSchemaRepresentation = { _tag: "Never", checks: [] }
33
+ const unknown: ImportedJsonSchemaRepresentation = { _tag: "Unknown", checks: [] }
34
+ const string: ImportedJsonSchemaRepresentation = { _tag: "String", checks: [] }
35
+
36
+ function makeLiteral(literal: string | number | boolean): SchemaRepresentation.Literal {
37
+ return { _tag: "Literal", literal, checks: [] }
38
+ }
39
+
40
+ function annotate(
41
+ representation: ImportedJsonSchemaRepresentation,
42
+ annotations: Schema.Annotations.Annotations | undefined
43
+ ): ImportedJsonSchemaRepresentation {
44
+ if (annotations === undefined) return representation
45
+ if (representation._tag === "Reference") {
46
+ return {
47
+ _tag: "Suspend",
48
+ annotations,
49
+ checks: [],
50
+ thunk: representation
51
+ }
52
+ }
53
+ return {
54
+ ...representation,
55
+ annotations: {
56
+ ...representation.annotations,
57
+ ...annotations
58
+ }
59
+ }
60
+ }
61
+
62
+ const jsonSchemaTypes = new Set([
63
+ "null",
64
+ "string",
65
+ "number",
66
+ "integer",
67
+ "boolean",
68
+ "object",
69
+ "array"
70
+ ])
71
+
72
+ const jsonSchemaStringKeys = ["minLength", "maxLength", "pattern", "format", "contentMediaType", "contentSchema"]
73
+ const jsonSchemaNumberKeys = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"]
74
+ const jsonSchemaObjectKeys = [
75
+ "properties",
76
+ "required",
77
+ "additionalProperties",
78
+ "patternProperties",
79
+ "propertyNames",
80
+ "minProperties",
81
+ "maxProperties"
82
+ ]
83
+ const jsonSchemaArrayKeys = ["items", "prefixItems", "additionalItems", "minItems", "maxItems", "uniqueItems"]
84
+ function isImportedJsonSchemaType(input: unknown): input is JsonSchema.Type {
85
+ return typeof input === "string" && jsonSchemaTypes.has(input)
86
+ }
87
+
88
+ function inferJsonSchemaType(schema: JsonSchema.JsonSchema): JsonSchema.Type | undefined {
89
+ if (jsonSchemaStringKeys.some((key) => schema[key] !== undefined)) return "string"
90
+ if (jsonSchemaNumberKeys.some((key) => schema[key] !== undefined)) return "number"
91
+ if (jsonSchemaObjectKeys.some((key) => schema[key] !== undefined)) return "object"
92
+ if (jsonSchemaArrayKeys.some((key) => schema[key] !== undefined)) return "array"
93
+ }
94
+
95
+ function jsonSchemaReferenceKey($ref: string): string | undefined {
96
+ const token = $ref.slice($ref.lastIndexOf("/") + 1)
97
+ return token.length === 0 ? undefined : unescapeToken(token)
98
+ }
99
+
100
+ function jsonSchemaFilter(
101
+ id: string,
102
+ payload: Schema.Json,
103
+ schemas?: ReadonlyArray<Representation>
104
+ ): Check {
105
+ return {
106
+ _tag: "Filter",
107
+ aborted: false,
108
+ representation: {
109
+ id,
110
+ payload,
111
+ ...(schemas === undefined ? undefined : { schemas })
112
+ }
113
+ }
114
+ }
115
+
116
+ function addNumberCheck(
117
+ checks: Array<Check>,
118
+ value: unknown,
119
+ id: string,
120
+ key: string
121
+ ): void {
122
+ if (typeof value === "number") {
123
+ checks.push(jsonSchemaFilter(id, { [key]: value }))
124
+ }
125
+ }
126
+
127
+ function jsonSchemaAnnotations(
128
+ schema: JsonSchema.JsonSchema
129
+ ): Schema.Annotations.Annotations | undefined {
130
+ const annotations: Record<string, Schema.Json> = {}
131
+ if (typeof schema.title === "string") annotations.title = schema.title
132
+ if (typeof schema.description === "string") annotations.description = schema.description
133
+ if (Object.hasOwn(schema, "default")) annotations.default = schema.default as Schema.Json
134
+ if (Array.isArray(schema.examples)) annotations.examples = schema.examples as ReadonlyArray<Schema.Json>
135
+ if (typeof schema.readOnly === "boolean") annotations.readOnly = schema.readOnly
136
+ if (typeof schema.writeOnly === "boolean") annotations.writeOnly = schema.writeOnly
137
+ if (typeof schema.format === "string") annotations.format = schema.format
138
+ if (typeof schema.contentEncoding === "string") annotations.contentEncoding = schema.contentEncoding
139
+ if (typeof schema.contentMediaType === "string") annotations.contentMediaType = schema.contentMediaType
140
+ if (SchemaAST.isJson(schema.contentSchema)) annotations.contentSchema = schema.contentSchema
141
+ return Object.keys(annotations).length === 0 ? undefined : annotations
142
+ }
143
+
144
+ function jsonDeclaration(
145
+ annotations: Schema.Annotations.Annotations | undefined
146
+ ): Representation {
147
+ return {
148
+ _tag: "Declaration",
149
+ representation: {
150
+ id: "effect/schema/Json",
151
+ payload: null
152
+ },
153
+ annotations: {
154
+ ...annotations,
155
+ expected: "JSON value"
156
+ },
157
+ checks: [],
158
+ typeParameters: []
159
+ }
160
+ }
161
+
162
+ function unknownJsonSchemas(representation: Representation): Representation {
163
+ switch (representation._tag) {
164
+ case "Unknown":
165
+ return jsonDeclaration(representation.annotations)
166
+ case "Suspend":
167
+ return { ...representation, thunk: unknownJsonSchemas(representation.thunk) }
168
+ case "Arrays":
169
+ return {
170
+ ...representation,
171
+ elements: representation.elements.map((element) => ({
172
+ ...element,
173
+ type: unknownJsonSchemas(element.type)
174
+ })),
175
+ rest: representation.rest.map(unknownJsonSchemas)
176
+ }
177
+ case "Objects":
178
+ return {
179
+ ...representation,
180
+ propertySignatures: representation.propertySignatures.map((property) => ({
181
+ ...property,
182
+ type: unknownJsonSchemas(property.type)
183
+ })),
184
+ indexSignatures: representation.indexSignatures.map((indexSignature) => ({
185
+ parameter: unknownJsonSchemas(indexSignature.parameter),
186
+ type: unknownJsonSchemas(indexSignature.type)
187
+ })),
188
+ checks: representation.checks.map(unknownJsonSchemaCheck)
189
+ }
190
+ case "Union":
191
+ return { ...representation, types: representation.types.map(unknownJsonSchemas) }
192
+ default:
193
+ return representation
194
+ }
195
+ }
196
+
197
+ function unknownJsonSchemaCheck(check: Check): Check {
198
+ const representation = check.representation
199
+ const schemas = representation?.schemas
200
+ if (representation === undefined || schemas === undefined) {
201
+ return check
202
+ }
203
+ return {
204
+ ...check,
205
+ representation: {
206
+ ...representation,
207
+ schemas: schemas.map(unknownJsonSchemas)
208
+ }
209
+ }
210
+ }
211
+
212
+ function translateJsonSchemaMultiDocument(
213
+ document: JsonSchema.MultiDocument<"draft-2020-12">,
214
+ options?: SchemaRepresentation.FromJsonSchemaOptions,
215
+ singleRoot = false
216
+ ): SchemaRepresentation.MultiDocument {
217
+ const definitionCache = new Map<string, ImportedJsonSchemaRepresentation>()
218
+ const definitionsInProgress = new Set<string>()
219
+ const annotatedReferences: Array<{
220
+ readonly reference: SchemaRepresentation.Reference
221
+ readonly path: Path
222
+ }> = []
223
+
224
+ function translateDefinition(
225
+ key: string,
226
+ path: Path,
227
+ recursiveReferenceError?: string
228
+ ): ImportedJsonSchemaRepresentation {
229
+ const cached = definitionCache.get(key)
230
+ if (cached !== undefined) return cached
231
+ if (!Object.hasOwn(document.definitions, key)) {
232
+ throw errorWithPath(`Invalid reference ${key}`, [...path, "$ref"])
233
+ }
234
+ if (definitionsInProgress.has(key)) {
235
+ throw errorWithPath(recursiveReferenceError ?? `Invalid reference ${key}`, [...path, "$ref"])
236
+ }
237
+ definitionsInProgress.add(key)
238
+ const representation = recur(document.definitions[key], ["definitions", key])
239
+ definitionsInProgress.delete(key)
240
+ definitionCache.set(key, representation)
241
+ return representation
242
+ }
243
+
244
+ function resolveReference(
245
+ reference: SchemaRepresentation.Reference,
246
+ path: Path,
247
+ options?: { readonly recursiveReferenceError?: string },
248
+ seen: ReadonlySet<string> = new Set()
249
+ ): ImportedJsonSchemaRepresentation {
250
+ if (seen.has(reference.$ref)) {
251
+ throw errorWithPath(`Invalid reference ${reference.$ref}`, [...path, "$ref"])
252
+ }
253
+ const nextSeen = new Set(seen).add(reference.$ref)
254
+ const representation = translateDefinition(reference.$ref, path, options?.recursiveReferenceError)
255
+ if (representation._tag === "Reference") {
256
+ return resolveReference(representation, path, options, nextSeen)
257
+ }
258
+ if (representation._tag === "Suspend" && representation.thunk._tag === "Reference") {
259
+ return annotate(
260
+ resolveReference(representation.thunk, path, options, nextSeen),
261
+ representation.annotations
262
+ )
263
+ }
264
+ return representation
265
+ }
266
+
267
+ function annotationsOf(
268
+ representation: ImportedJsonSchemaRepresentation
269
+ ): Schema.Annotations.Annotations | undefined {
270
+ return representation._tag === "Reference" ? undefined : representation.annotations
271
+ }
272
+
273
+ function mergeAnnotations(
274
+ left: Schema.Annotations.Annotations | undefined,
275
+ right: Schema.Annotations.Annotations | undefined
276
+ ): Schema.Annotations.Annotations | undefined {
277
+ if (left === undefined) return right
278
+ if (right === undefined) return left
279
+ return { ...left, ...right }
280
+ }
281
+
282
+ function combinedAnnotations(
283
+ representation: ImportedJsonSchemaRepresentation,
284
+ left: ImportedJsonSchemaRepresentation,
285
+ right: ImportedJsonSchemaRepresentation
286
+ ): ImportedJsonSchemaRepresentation {
287
+ return annotate(
288
+ representation,
289
+ mergeAnnotations(annotationsOf(left), annotationsOf(right))
290
+ )
291
+ }
292
+
293
+ function asChecks(
294
+ checks: ReadonlyArray<Check>,
295
+ annotations: Schema.Annotations.Annotations | undefined
296
+ ): ReadonlyArray<Check> | undefined {
297
+ if (checks.length === 0) return undefined
298
+ if (annotations === undefined) return checks
299
+ if (checks.length === 1 && checks[0].annotations === undefined) {
300
+ return [{
301
+ ...checks[0],
302
+ annotations
303
+ }]
304
+ }
305
+ return [{
306
+ _tag: "FilterGroup",
307
+ checks: checks as [Check, ...Array<Check>],
308
+ annotations
309
+ }]
310
+ }
311
+
312
+ function combineChecks(
313
+ left: ReadonlyArray<Check>,
314
+ right: ReadonlyArray<Check>,
315
+ annotations: Schema.Annotations.Annotations | undefined,
316
+ deduplicate: ReadonlyArray<string> = []
317
+ ): ReadonlyArray<Check> | undefined {
318
+ for (const id of deduplicate) {
319
+ if (left.some((check) => checkId(check) === id)) {
320
+ right = right.filter((check) => checkId(check) !== id)
321
+ }
322
+ }
323
+ const checks = asChecks(right, annotations)
324
+ return checks === undefined ? undefined : [...left, ...checks]
325
+ }
326
+
327
+ function checkId(check: Check): string | undefined {
328
+ return check._tag === "Filter" ? check.representation?.id : undefined
329
+ }
330
+
331
+ function satisfiesPrimitiveCheck(check: Check, value: string | number): boolean | undefined {
332
+ if (check._tag === "FilterGroup") {
333
+ return check.checks.every((check) => satisfiesPrimitiveCheck(check, value))
334
+ }
335
+ const representation = check.representation!
336
+ const payload = representation.payload as Record<string, any>
337
+ switch (representation.id) {
338
+ case "effect/schema/isMinLength":
339
+ return (value as string).length >= payload.minLength
340
+ case "effect/schema/isMaxLength":
341
+ return (value as string).length <= payload.maxLength
342
+ case "effect/schema/isPattern":
343
+ return new RegExp(payload.source as string, payload.flags as string).test(value as string)
344
+ case "effect/schema/isFinite":
345
+ return globalThis.Number.isFinite(value as number)
346
+ case "effect/schema/isInt":
347
+ return globalThis.Number.isSafeInteger(value as number)
348
+ case "effect/schema/isMultipleOf":
349
+ return remainder(value as number, payload.divisor) === 0
350
+ case "effect/schema/isGreaterThan":
351
+ return (value as number) > payload.exclusiveMinimum
352
+ case "effect/schema/isGreaterThanOrEqualTo":
353
+ return (value as number) >= payload.minimum
354
+ case "effect/schema/isLessThan":
355
+ return (value as number) < payload.exclusiveMaximum
356
+ case "effect/schema/isLessThanOrEqualTo":
357
+ return (value as number) <= payload.maximum
358
+ }
359
+ }
360
+
361
+ function satisfiesLiteral(
362
+ representation:
363
+ | SchemaRepresentation.String
364
+ | SchemaRepresentation.Number,
365
+ literal: SchemaRepresentation.Literal
366
+ ): boolean {
367
+ const value = literal.literal
368
+ if (representation._tag === "String" ? typeof value !== "string" : typeof value !== "number") {
369
+ return false
370
+ }
371
+ return representation.checks.every((check) => satisfiesPrimitiveCheck(check, value as string | number))
372
+ }
373
+
374
+ function combinePrimitiveWithLiteral(
375
+ primitive:
376
+ | SchemaRepresentation.String
377
+ | SchemaRepresentation.Number
378
+ | SchemaRepresentation.Boolean,
379
+ literal: SchemaRepresentation.Literal
380
+ ): ImportedJsonSchemaRepresentation {
381
+ const satisfies = primitive._tag === "Boolean"
382
+ ? typeof literal.literal === "boolean"
383
+ : satisfiesLiteral(primitive, literal)
384
+ return satisfies ? combinedAnnotations(literal, primitive, literal) : never
385
+ }
386
+
387
+ function combineArrays(
388
+ left: SchemaRepresentation.Arrays,
389
+ right: SchemaRepresentation.Arrays,
390
+ path: Path
391
+ ): Pick<SchemaRepresentation.Arrays, "elements" | "rest"> | undefined {
392
+ const elements: Array<SchemaRepresentation.Element> = []
393
+ const length = Math.max(left.elements.length, right.elements.length)
394
+ for (let index = 0; index < length; index++) {
395
+ const leftElement = left.elements[index]
396
+ const rightElement = right.elements[index]
397
+ const isOptional = leftElement?.isOptional !== false && rightElement?.isOptional !== false
398
+ const leftType = leftElement?.type ?? left.rest[0]
399
+ const rightType = rightElement?.type ?? right.rest[0]
400
+ if (leftType === undefined || rightType === undefined) {
401
+ return isOptional ? { elements, rest: [] } : undefined
402
+ }
403
+ const type = combine(
404
+ leftType as ImportedJsonSchemaRepresentation,
405
+ rightType as ImportedJsonSchemaRepresentation,
406
+ [...path, "elements", index, "type"]
407
+ )
408
+ if (type._tag === "Never") {
409
+ return isOptional ? { elements, rest: [] } : undefined
410
+ }
411
+ elements.push({
412
+ isOptional,
413
+ type
414
+ })
415
+ }
416
+
417
+ const leftRest = left.rest[0]
418
+ const rightRest = right.rest[0]
419
+ if (leftRest === undefined || rightRest === undefined) {
420
+ return { elements, rest: [] }
421
+ }
422
+ const rest = combine(
423
+ leftRest as ImportedJsonSchemaRepresentation,
424
+ rightRest as ImportedJsonSchemaRepresentation,
425
+ [...path, "rest", 0]
426
+ )
427
+ return { elements, rest: rest._tag === "Never" ? [] : [rest] }
428
+ }
429
+
430
+ function combineProperties(
431
+ left: ReadonlyArray<SchemaRepresentation.PropertySignature>,
432
+ right: ReadonlyArray<SchemaRepresentation.PropertySignature>,
433
+ path: Path
434
+ ): Array<SchemaRepresentation.PropertySignature> {
435
+ const rightByName = new Map(right.map((property) => [property.name, property]))
436
+ const names = new Set<PropertyKey>()
437
+ const properties = left.map((property) => {
438
+ const name = property.name
439
+ names.add(name)
440
+ const other = rightByName.get(name)
441
+ if (other === undefined) return property
442
+ return {
443
+ name: property.name,
444
+ type: combine(
445
+ property.type as ImportedJsonSchemaRepresentation,
446
+ other.type as ImportedJsonSchemaRepresentation,
447
+ [...path, "properties", globalThis.String(name)]
448
+ ),
449
+ isOptional: property.isOptional && other.isOptional,
450
+ isMutable: false
451
+ }
452
+ })
453
+ for (const property of right) {
454
+ if (!names.has(property.name)) properties.push(property)
455
+ }
456
+ return properties
457
+ }
458
+
459
+ function isUnconstrainedString(representation: Representation): boolean {
460
+ return representation._tag === "String" && representation.checks.length === 0 &&
461
+ representation.annotations === undefined
462
+ }
463
+
464
+ function combineIndexSignatures(
465
+ left: ReadonlyArray<SchemaRepresentation.IndexSignature>,
466
+ right: ReadonlyArray<SchemaRepresentation.IndexSignature>,
467
+ path: Path
468
+ ): Array<SchemaRepresentation.IndexSignature> {
469
+ if (left.length === 0 || right.length === 0) return []
470
+ const signatures = [...left]
471
+ for (const signature of right) {
472
+ if (isUnconstrainedString(signature.parameter)) {
473
+ const index = signatures.findIndex((candidate) => isUnconstrainedString(candidate.parameter))
474
+ if (index !== -1) {
475
+ signatures[index] = {
476
+ parameter: signatures[index].parameter,
477
+ type: combine(
478
+ signatures[index].type as ImportedJsonSchemaRepresentation,
479
+ signature.type as ImportedJsonSchemaRepresentation,
480
+ [...path, "indexSignatures", index, "type"]
481
+ )
482
+ }
483
+ } else {
484
+ signatures.push(signature)
485
+ }
486
+ } else {
487
+ signatures.push(signature)
488
+ }
489
+ }
490
+ return signatures
491
+ }
492
+
493
+ function combine(
494
+ left: ImportedJsonSchemaRepresentation,
495
+ right: ImportedJsonSchemaRepresentation,
496
+ path: Path
497
+ ): ImportedJsonSchemaRepresentation {
498
+ if (left._tag === "Never") return left
499
+ if (right._tag === "Never") return right
500
+ if (left._tag === "Unknown") return combinedAnnotations(right, left, right)
501
+ if (right._tag === "Unknown") return combinedAnnotations(left, left, right)
502
+ if (left._tag === "Reference") return combine(resolveReference(left, path), right, path)
503
+ if (right._tag === "Reference") return combine(left, resolveReference(right, path), path)
504
+ if (left._tag === "Suspend") {
505
+ return annotate(
506
+ combine(left.thunk as ImportedJsonSchemaRepresentation, right, path),
507
+ left.annotations
508
+ )
509
+ }
510
+ if (right._tag === "Suspend") {
511
+ return annotate(
512
+ combine(left, right.thunk as ImportedJsonSchemaRepresentation, path),
513
+ right.annotations
514
+ )
515
+ }
516
+ if (left._tag === "Union") {
517
+ const types = left.types
518
+ .map((type, index) => combine(type as ImportedJsonSchemaRepresentation, right, [...path, "types", index]))
519
+ .filter((type) => type._tag !== "Never")
520
+ if (types.length === 0) return never
521
+ return annotate({
522
+ _tag: "Union",
523
+ types,
524
+ mode: left.mode,
525
+ checks: left.checks
526
+ }, left.annotations)
527
+ }
528
+ if (right._tag === "Union") return combine(right, left, path)
529
+
530
+ switch (left._tag) {
531
+ case "Null":
532
+ return right._tag === "Null"
533
+ ? combinedAnnotations({ _tag: "Null", checks: [...left.checks, ...right.checks] }, left, right)
534
+ : never
535
+ case "String":
536
+ if (right._tag === "Literal") {
537
+ return combinePrimitiveWithLiteral(left, right)
538
+ }
539
+ if (right._tag !== "String") return never
540
+ const stringChecks = combineChecks(left.checks, right.checks, right.annotations)
541
+ return annotate(
542
+ {
543
+ _tag: "String",
544
+ checks: stringChecks ?? left.checks
545
+ },
546
+ mergeAnnotations(left.annotations, stringChecks === undefined ? right.annotations : undefined)
547
+ )
548
+ case "Number":
549
+ if (right._tag === "Literal") {
550
+ return combinePrimitiveWithLiteral(left, right)
551
+ }
552
+ if (right._tag !== "Number") return never
553
+ const numberChecks = combineChecks(left.checks, right.checks, right.annotations, [
554
+ "effect/schema/isFinite",
555
+ "effect/schema/isInt"
556
+ ])
557
+ return annotate(
558
+ {
559
+ _tag: "Number",
560
+ checks: numberChecks ?? left.checks
561
+ },
562
+ mergeAnnotations(left.annotations, numberChecks === undefined ? right.annotations : undefined)
563
+ )
564
+ case "Boolean":
565
+ if (right._tag === "Literal") {
566
+ return combinePrimitiveWithLiteral(left, right)
567
+ }
568
+ return right._tag === "Boolean"
569
+ ? combinedAnnotations(
570
+ {
571
+ _tag: "Boolean",
572
+ checks: [...left.checks, ...right.checks]
573
+ },
574
+ left,
575
+ right
576
+ )
577
+ : never
578
+ case "Literal":
579
+ if (right._tag === "Literal") {
580
+ return left.literal === right.literal
581
+ ? combinedAnnotations(
582
+ {
583
+ ...left,
584
+ checks: [...left.checks, ...right.checks]
585
+ },
586
+ left,
587
+ right
588
+ )
589
+ : never
590
+ }
591
+ if (
592
+ (right._tag === "String" || right._tag === "Number") && satisfiesLiteral(right, left) ||
593
+ right._tag === "Boolean" && typeof left.literal === "boolean"
594
+ ) {
595
+ return combinedAnnotations(left, left, right)
596
+ }
597
+ return never
598
+ case "Arrays": {
599
+ if (right._tag !== "Arrays") return never
600
+ const arrays = combineArrays(left, right, path)
601
+ if (arrays === undefined) return never
602
+ const arrayChecks = combineChecks(left.checks, right.checks, right.annotations, ["effect/schema/isUnique"])
603
+ return annotate(
604
+ {
605
+ _tag: "Arrays",
606
+ elements: arrays.elements,
607
+ rest: arrays.rest,
608
+ checks: arrayChecks ?? left.checks
609
+ },
610
+ mergeAnnotations(left.annotations, arrayChecks === undefined ? right.annotations : undefined)
611
+ )
612
+ }
613
+ case "Objects": {
614
+ if (right._tag !== "Objects") return never
615
+ const objectChecks = combineChecks(left.checks, right.checks, right.annotations)
616
+ return annotate(
617
+ {
618
+ _tag: "Objects",
619
+ propertySignatures: combineProperties(left.propertySignatures, right.propertySignatures, path),
620
+ indexSignatures: combineIndexSignatures(left.indexSignatures, right.indexSignatures, path),
621
+ checks: objectChecks ?? left.checks
622
+ },
623
+ mergeAnnotations(left.annotations, objectChecks === undefined ? right.annotations : undefined)
624
+ )
625
+ }
626
+ }
627
+ }
628
+
629
+ function enter(input: unknown): JsonSchema.JsonSchema | undefined {
630
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
631
+ return undefined
632
+ }
633
+ const schema = input as JsonSchema.JsonSchema
634
+ return options?.onEnter === undefined ? schema : options.onEnter(schema)
635
+ }
636
+
637
+ function recur(input: unknown, path: Path): ImportedJsonSchemaRepresentation {
638
+ if (input === false) {
639
+ return never
640
+ }
641
+ const schema = enter(input)
642
+ if (schema === undefined) {
643
+ return unknown
644
+ }
645
+
646
+ let representation = on(schema, path)
647
+ if (representation._tag === "Reference") {
648
+ const siblingSchema: JsonSchema.JsonSchema = { ...schema, $ref: undefined }
649
+ for (const key of InternalAnnotations.jsonSchemaAnnotationKeys) {
650
+ delete siblingSchema[key]
651
+ }
652
+ const sibling = on(siblingSchema, path)
653
+ if (sibling._tag !== "Unknown") {
654
+ const reference = representation
655
+ representation = combine(
656
+ resolveReference(reference, path, {
657
+ recursiveReferenceError: `Unsupported assertion siblings on recursive reference ${reference.$ref}`
658
+ }),
659
+ sibling,
660
+ path
661
+ )
662
+ }
663
+ }
664
+ const annotations = jsonSchemaAnnotations(schema)
665
+ if (annotations !== undefined && representation._tag === "Reference") {
666
+ annotatedReferences.push({ reference: representation, path })
667
+ }
668
+ representation = annotate(representation, annotations)
669
+
670
+ if (Array.isArray(schema.allOf)) {
671
+ for (let index = 0; index < schema.allOf.length; index++) {
672
+ representation = combine(
673
+ representation,
674
+ recur(schema.allOf[index], [...path, "allOf", index]),
675
+ [...path, "allOf", index]
676
+ )
677
+ }
678
+ }
679
+
680
+ for (const mode of ["anyOf", "oneOf"] as const) {
681
+ const members = schema[mode]
682
+ if (Array.isArray(members)) {
683
+ const union: ImportedJsonSchemaRepresentation = {
684
+ _tag: "Union",
685
+ types: members.map((member, index) => recur(member, [...path, mode, index])),
686
+ mode,
687
+ checks: []
688
+ }
689
+ representation = combine(union, representation, [...path, mode])
690
+ }
691
+ }
692
+ return representation
693
+ }
694
+
695
+ function on(schema: JsonSchema.JsonSchema, path: Path): ImportedJsonSchemaRepresentation {
696
+ if (typeof schema.$ref === "string") {
697
+ const $ref = jsonSchemaReferenceKey(schema.$ref)
698
+ if ($ref !== undefined) {
699
+ return { _tag: "Reference", $ref }
700
+ }
701
+ }
702
+ if (Object.hasOwn(schema, "const")) {
703
+ if (schema.const === null) {
704
+ return { _tag: "Null", checks: [] }
705
+ }
706
+ if (typeof schema.const === "string" || typeof schema.const === "number" || typeof schema.const === "boolean") {
707
+ return makeLiteral(schema.const)
708
+ }
709
+ }
710
+ if (Array.isArray(schema.enum)) {
711
+ const types: Array<ImportedJsonSchemaRepresentation> = []
712
+ for (let index = 0; index < schema.enum.length; index++) {
713
+ const value = schema.enum[index]
714
+ if (value === null) {
715
+ types.push({ _tag: "Null", checks: [] })
716
+ } else if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
717
+ types.push(makeLiteral(value))
718
+ } else {
719
+ types.push(recur(value, [...path, "enum", index]))
720
+ }
721
+ }
722
+ if (types.length === 1) {
723
+ return types[0]
724
+ }
725
+ return { _tag: "Union", types, mode: "anyOf", checks: [] }
726
+ }
727
+
728
+ if (Array.isArray(schema.type) && schema.type.every(isImportedJsonSchemaType)) {
729
+ return {
730
+ _tag: "Union",
731
+ types: schema.type.map((type) => on({ ...schema, type }, path)),
732
+ mode: "anyOf",
733
+ checks: []
734
+ }
735
+ }
736
+
737
+ const type = isImportedJsonSchemaType(schema.type) ? schema.type : inferJsonSchemaType(schema)
738
+ switch (type) {
739
+ case "null":
740
+ return { _tag: "Null", checks: [] }
741
+ case "string":
742
+ return {
743
+ _tag: "String",
744
+ checks: collectStringChecks(schema)
745
+ }
746
+ case "number":
747
+ case "integer":
748
+ return {
749
+ _tag: "Number",
750
+ checks: [
751
+ jsonSchemaFilter(type === "number" ? "effect/schema/isFinite" : "effect/schema/isInt", null),
752
+ ...collectNumberChecks(schema)
753
+ ]
754
+ }
755
+ case "boolean":
756
+ return { _tag: "Boolean", checks: [] }
757
+ case "array": {
758
+ const minItems = typeof schema.minItems === "number" ? schema.minItems : 0
759
+ const elements = Array.isArray(schema.prefixItems)
760
+ ? schema.prefixItems.map((element, index) => ({
761
+ isOptional: index + 1 > minItems,
762
+ type: recur(element, [...path, "prefixItems", index])
763
+ }))
764
+ : []
765
+ const rest = schema.items !== undefined
766
+ ? [recur(schema.items, [...path, "items"])]
767
+ : schema.prefixItems !== undefined && typeof schema.maxItems === "number"
768
+ ? []
769
+ : [unknown]
770
+ return {
771
+ _tag: "Arrays",
772
+ elements,
773
+ rest,
774
+ checks: collectArrayChecks(schema)
775
+ }
776
+ }
777
+ case "object":
778
+ return {
779
+ _tag: "Objects",
780
+ propertySignatures: collectProperties(schema, path),
781
+ indexSignatures: collectIndexSignatures(schema, path),
782
+ checks: collectObjectChecks(schema, path)
783
+ }
784
+ default:
785
+ return unknown
786
+ }
787
+ }
788
+
789
+ function collectStringChecks(schema: JsonSchema.JsonSchema): Array<Check> {
790
+ const checks: Array<Check> = []
791
+ addNumberCheck(checks, schema.minLength, "effect/schema/isMinLength", "minLength")
792
+ addNumberCheck(checks, schema.maxLength, "effect/schema/isMaxLength", "maxLength")
793
+ if (typeof schema.pattern === "string") {
794
+ checks.push(jsonSchemaFilter("effect/schema/isPattern", { source: schema.pattern, flags: "" }))
795
+ }
796
+ return checks
797
+ }
798
+
799
+ function collectNumberChecks(schema: JsonSchema.JsonSchema): Array<Check> {
800
+ const checks: Array<Check> = []
801
+ addNumberCheck(checks, schema.minimum, "effect/schema/isGreaterThanOrEqualTo", "minimum")
802
+ addNumberCheck(checks, schema.maximum, "effect/schema/isLessThanOrEqualTo", "maximum")
803
+ addNumberCheck(checks, schema.exclusiveMinimum, "effect/schema/isGreaterThan", "exclusiveMinimum")
804
+ addNumberCheck(checks, schema.exclusiveMaximum, "effect/schema/isLessThan", "exclusiveMaximum")
805
+ addNumberCheck(checks, schema.multipleOf, "effect/schema/isMultipleOf", "divisor")
806
+ return checks
807
+ }
808
+
809
+ function collectArrayChecks(schema: JsonSchema.JsonSchema): Array<Check> {
810
+ const checks: Array<Check> = []
811
+ if (schema.prefixItems === undefined) {
812
+ addNumberCheck(checks, schema.minItems, "effect/schema/isMinLength", "minLength")
813
+ addNumberCheck(checks, schema.maxItems, "effect/schema/isMaxLength", "maxLength")
814
+ }
815
+ if (typeof schema.uniqueItems === "boolean") {
816
+ checks.push(jsonSchemaFilter("effect/schema/isUnique", null))
817
+ }
818
+ return checks
819
+ }
820
+
821
+ function collectProperties(
822
+ schema: JsonSchema.JsonSchema,
823
+ path: Path
824
+ ): Array<SchemaRepresentation.PropertySignature> {
825
+ const properties =
826
+ typeof schema.properties === "object" && schema.properties !== null && !Array.isArray(schema.properties)
827
+ ? schema.properties as Record<string, unknown>
828
+ : {}
829
+ const required = Array.isArray(schema.required)
830
+ ? schema.required.filter((key): key is string => typeof key === "string")
831
+ : []
832
+ const keys = new Set([...Object.keys(properties), ...required])
833
+ return Array.from(keys, (name) => ({
834
+ name,
835
+ type: recur(properties[name], [...path, "properties", name]),
836
+ isOptional: !required.includes(name),
837
+ isMutable: false
838
+ }))
839
+ }
840
+
841
+ function collectIndexSignatures(
842
+ schema: JsonSchema.JsonSchema,
843
+ path: Path
844
+ ): Array<SchemaRepresentation.IndexSignature> {
845
+ const signatures: Array<SchemaRepresentation.IndexSignature> = []
846
+ if (
847
+ typeof schema.patternProperties === "object" &&
848
+ schema.patternProperties !== null &&
849
+ !Array.isArray(schema.patternProperties)
850
+ ) {
851
+ for (const [pattern, value] of Object.entries(schema.patternProperties)) {
852
+ signatures.push({
853
+ parameter: {
854
+ _tag: "String",
855
+ checks: [jsonSchemaFilter("effect/schema/isPattern", { source: pattern, flags: "" })]
856
+ },
857
+ type: recur(value, [...path, "patternProperties", pattern])
858
+ })
859
+ }
860
+ }
861
+ if (schema.additionalProperties === undefined || schema.additionalProperties === true) {
862
+ signatures.push({
863
+ parameter: string,
864
+ type: unknown
865
+ })
866
+ } else if (typeof schema.additionalProperties === "object" && schema.additionalProperties !== null) {
867
+ signatures.push({
868
+ parameter: string,
869
+ type: recur(schema.additionalProperties, [...path, "additionalProperties"])
870
+ })
871
+ }
872
+ return signatures
873
+ }
874
+
875
+ function collectObjectChecks(
876
+ schema: JsonSchema.JsonSchema,
877
+ path: Path
878
+ ): Array<Check> {
879
+ const checks: Array<Check> = []
880
+ addNumberCheck(checks, schema.minProperties, "effect/schema/isMinProperties", "minProperties")
881
+ addNumberCheck(checks, schema.maxProperties, "effect/schema/isMaxProperties", "maxProperties")
882
+ if (schema.propertyNames !== undefined) {
883
+ checks.push(jsonSchemaFilter(
884
+ "effect/schema/isPropertyNames",
885
+ null,
886
+ [recur(schema.propertyNames, [...path, "propertyNames"])]
887
+ ))
888
+ }
889
+ return checks
890
+ }
891
+
892
+ const references: Record<string, Representation> = {}
893
+ for (const key of Object.keys(document.definitions)) {
894
+ InternalRecord.assignProperty(references, key, unknownJsonSchemas(translateDefinition(key, ["definitions", key])))
895
+ }
896
+ const representations = document.schemas.map((schema, index) =>
897
+ unknownJsonSchemas(recur(schema, singleRoot ? ["schema"] : ["schemas", index]))
898
+ ) as [Representation, ...Array<Representation>]
899
+ for (const { reference, path } of annotatedReferences) {
900
+ resolveReference(reference, path)
901
+ }
902
+ return { representations, references }
903
+ }
904
+
905
+ /** @internal */
906
+ function toRepresentation(
907
+ document: JsonSchema.Document<"draft-2020-12">,
908
+ options?: SchemaRepresentation.FromJsonSchemaOptions
909
+ ): SchemaRepresentation.Document {
910
+ const translated = translateJsonSchemaMultiDocument(
911
+ {
912
+ dialect: document.dialect,
913
+ schemas: [document.schema],
914
+ definitions: document.definitions
915
+ },
916
+ options,
917
+ true
918
+ )
919
+ return {
920
+ representation: translated.representations[0],
921
+ references: translated.references
922
+ }
923
+ }
924
+
925
+ const jsonSchemaRevivers: ReadonlyArray<SchemaRepresentation.AnyReviver> = [
926
+ Schema.JsonReviver,
927
+ Schema.isPatternReviver,
928
+ Schema.isFiniteReviver,
929
+ Schema.isGreaterThanReviver,
930
+ Schema.isGreaterThanOrEqualToReviver,
931
+ Schema.isLessThanReviver,
932
+ Schema.isLessThanOrEqualToReviver,
933
+ Schema.isMultipleOfReviver,
934
+ Schema.isIntReviver,
935
+ Schema.isMinLengthReviver,
936
+ Schema.isMaxLengthReviver,
937
+ Schema.isMinPropertiesReviver,
938
+ Schema.isMaxPropertiesReviver,
939
+ Schema.isPropertyNamesReviver,
940
+ Schema.isUniqueReviver
941
+ ]
942
+
943
+ /** @internal */
944
+ export function fromJsonSchemaDocument(
945
+ document: JsonSchema.Document<"draft-2020-12">,
946
+ options?: SchemaRepresentation.FromJsonSchemaOptions
947
+ ): Schema.Top {
948
+ return fromRepresentation(toRepresentation(document, options), jsonSchemaRevivers)
949
+ }
950
+
951
+ /** @internal */
952
+ export function fromJsonSchemaMultiDocument(
953
+ document: JsonSchema.MultiDocument<"draft-2020-12">,
954
+ options?: SchemaRepresentation.FromJsonSchemaOptions
955
+ ): SchemaRepresentation.SchemaMultiDocument {
956
+ return fromRepresentations(translateJsonSchemaMultiDocument(document, options), jsonSchemaRevivers)
957
+ }