effect 4.0.0-beta.100 → 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 (502) 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/MutableList.d.ts.map +1 -1
  43. package/dist/MutableList.js +4 -0
  44. package/dist/MutableList.js.map +1 -1
  45. package/dist/Optic.d.ts.map +1 -1
  46. package/dist/Optic.js +5 -4
  47. package/dist/Optic.js.map +1 -1
  48. package/dist/Option.d.ts.map +1 -1
  49. package/dist/Option.js +2 -1
  50. package/dist/Option.js.map +1 -1
  51. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  52. package/dist/PartitionedSemaphore.js +1 -4
  53. package/dist/PartitionedSemaphore.js.map +1 -1
  54. package/dist/Record.d.ts +93 -1
  55. package/dist/Record.d.ts.map +1 -1
  56. package/dist/Record.js +57 -19
  57. package/dist/Record.js.map +1 -1
  58. package/dist/References.d.ts +0 -45
  59. package/dist/References.d.ts.map +1 -1
  60. package/dist/References.js +0 -45
  61. package/dist/References.js.map +1 -1
  62. package/dist/Request.d.ts.map +1 -1
  63. package/dist/Request.js +9 -6
  64. package/dist/Request.js.map +1 -1
  65. package/dist/Result.d.ts.map +1 -1
  66. package/dist/Result.js +2 -1
  67. package/dist/Result.js.map +1 -1
  68. package/dist/Schema.d.ts +1269 -496
  69. package/dist/Schema.d.ts.map +1 -1
  70. package/dist/Schema.js +2308 -614
  71. package/dist/Schema.js.map +1 -1
  72. package/dist/SchemaAST.d.ts +2 -2
  73. package/dist/SchemaAST.d.ts.map +1 -1
  74. package/dist/SchemaAST.js +189 -130
  75. package/dist/SchemaAST.js.map +1 -1
  76. package/dist/SchemaError.js +1 -1
  77. package/dist/SchemaError.js.map +1 -1
  78. package/dist/SchemaGetter.d.ts +13 -11
  79. package/dist/SchemaGetter.d.ts.map +1 -1
  80. package/dist/SchemaGetter.js +34 -24
  81. package/dist/SchemaGetter.js.map +1 -1
  82. package/dist/SchemaIssue.js +1 -1
  83. package/dist/SchemaIssue.js.map +1 -1
  84. package/dist/SchemaParser.d.ts.map +1 -1
  85. package/dist/SchemaParser.js +1 -12
  86. package/dist/SchemaParser.js.map +1 -1
  87. package/dist/SchemaRepresentation.d.ts +403 -1504
  88. package/dist/SchemaRepresentation.d.ts.map +1 -1
  89. package/dist/SchemaRepresentation.js +294 -2852
  90. package/dist/SchemaRepresentation.js.map +1 -1
  91. package/dist/SchemaTransformation.d.ts +2 -2
  92. package/dist/SchemaTransformation.js +3 -3
  93. package/dist/SchemaTransformation.js.map +1 -1
  94. package/dist/Semaphore.d.ts +5 -3
  95. package/dist/Semaphore.d.ts.map +1 -1
  96. package/dist/Semaphore.js.map +1 -1
  97. package/dist/Stream.d.ts +15 -9
  98. package/dist/Stream.d.ts.map +1 -1
  99. package/dist/Stream.js +46 -16
  100. package/dist/Stream.js.map +1 -1
  101. package/dist/Struct.d.ts.map +1 -1
  102. package/dist/Struct.js +5 -4
  103. package/dist/Struct.js.map +1 -1
  104. package/dist/Types.d.ts +1 -3
  105. package/dist/Types.d.ts.map +1 -1
  106. package/dist/index.d.ts +0 -4
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +0 -4
  109. package/dist/index.js.map +1 -1
  110. package/dist/internal/core.js +3 -2
  111. package/dist/internal/core.js.map +1 -1
  112. package/dist/internal/effect.js +119 -53
  113. package/dist/internal/effect.js.map +1 -1
  114. package/dist/internal/matcher.js +1 -1
  115. package/dist/internal/matcher.js.map +1 -1
  116. package/dist/internal/record.d.ts +0 -3
  117. package/dist/internal/record.d.ts.map +1 -1
  118. package/dist/internal/record.js +10 -5
  119. package/dist/internal/record.js.map +1 -1
  120. package/dist/internal/references.js +0 -4
  121. package/dist/internal/references.js.map +1 -1
  122. package/dist/internal/schema/annotations.js +12 -0
  123. package/dist/internal/schema/annotations.js.map +1 -1
  124. package/dist/internal/schema/fromJsonSchemaDocument.d.ts +2 -0
  125. package/dist/internal/schema/fromJsonSchemaDocument.d.ts.map +1 -0
  126. package/dist/internal/schema/fromJsonSchemaDocument.js +743 -0
  127. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -0
  128. package/dist/internal/schema/fromRepresentation.d.ts +2 -0
  129. package/dist/internal/schema/fromRepresentation.d.ts.map +1 -0
  130. package/dist/internal/schema/fromRepresentation.js +252 -0
  131. package/dist/internal/schema/fromRepresentation.js.map +1 -0
  132. package/dist/internal/schema/schema.js +28 -40
  133. package/dist/internal/schema/schema.js.map +1 -1
  134. package/dist/internal/schema/{arbitrary.d.ts → toArbitrary.d.ts} +1 -1
  135. package/dist/internal/schema/toArbitrary.d.ts.map +1 -0
  136. package/dist/internal/schema/{arbitrary.js → toArbitrary.js} +8 -9
  137. package/dist/internal/schema/toArbitrary.js.map +1 -0
  138. package/dist/internal/schema/toCodeDocument.d.ts +2 -0
  139. package/dist/internal/schema/toCodeDocument.d.ts.map +1 -0
  140. package/dist/internal/schema/toCodeDocument.js +438 -0
  141. package/dist/internal/schema/toCodeDocument.js.map +1 -0
  142. package/dist/internal/schema/toEquivalence.d.ts +2 -0
  143. package/dist/internal/schema/toEquivalence.d.ts.map +1 -0
  144. package/dist/internal/schema/{equivalence.js → toEquivalence.js} +15 -13
  145. package/dist/internal/schema/toEquivalence.js.map +1 -0
  146. package/dist/internal/schema/toJsonSchemaDocument.d.ts +2 -0
  147. package/dist/internal/schema/toJsonSchemaDocument.d.ts.map +1 -0
  148. package/dist/internal/schema/toJsonSchemaDocument.js +466 -0
  149. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -0
  150. package/dist/internal/schema/toRepresentation.d.ts +2 -0
  151. package/dist/internal/schema/toRepresentation.d.ts.map +1 -0
  152. package/dist/internal/schema/toRepresentation.js +369 -0
  153. package/dist/internal/schema/toRepresentation.js.map +1 -0
  154. package/dist/internal/stackTraceLimit.js +3 -6
  155. package/dist/internal/stackTraceLimit.js.map +1 -1
  156. package/dist/testing/TestClock.js +4 -1
  157. package/dist/testing/TestClock.js.map +1 -1
  158. package/dist/unstable/ai/AiError.d.ts +26 -26
  159. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  160. package/dist/unstable/ai/AiError.js +5 -4
  161. package/dist/unstable/ai/AiError.js.map +1 -1
  162. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +21 -6
  163. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  164. package/dist/unstable/ai/AnthropicStructuredOutput.js +86 -316
  165. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  166. package/dist/unstable/ai/EmbeddingModel.d.ts +1 -1
  167. package/dist/unstable/ai/EmbeddingModel.js +1 -1
  168. package/dist/unstable/ai/EmbeddingModel.js.map +1 -1
  169. package/dist/unstable/ai/LanguageModel.d.ts +4 -1
  170. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  171. package/dist/unstable/ai/LanguageModel.js +19 -17
  172. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  173. package/dist/unstable/ai/McpSchema.d.ts +197 -197
  174. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  175. package/dist/unstable/ai/McpSchema.js +13 -13
  176. package/dist/unstable/ai/McpSchema.js.map +1 -1
  177. package/dist/unstable/ai/McpServer.d.ts +4 -4
  178. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  179. package/dist/unstable/ai/McpServer.js +116 -49
  180. package/dist/unstable/ai/McpServer.js.map +1 -1
  181. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +32 -10
  182. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  183. package/dist/unstable/ai/OpenAiStructuredOutput.js +193 -377
  184. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  185. package/dist/unstable/ai/Response.d.ts +19 -19
  186. package/dist/unstable/ai/Response.d.ts.map +1 -1
  187. package/dist/unstable/ai/Response.js +14 -14
  188. package/dist/unstable/ai/Response.js.map +1 -1
  189. package/dist/unstable/ai/Tool.d.ts +4 -0
  190. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  191. package/dist/unstable/ai/Tool.js +11 -3
  192. package/dist/unstable/ai/Tool.js.map +1 -1
  193. package/dist/unstable/ai/Toolkit.d.ts +9 -1
  194. package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
  195. package/dist/unstable/ai/Toolkit.js +14 -10
  196. package/dist/unstable/ai/Toolkit.js.map +1 -1
  197. package/dist/unstable/ai/internal/codec-transformer.js +15 -12
  198. package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
  199. package/dist/unstable/ai/internal/structured-output.d.ts +2 -0
  200. package/dist/unstable/ai/internal/structured-output.d.ts.map +1 -0
  201. package/dist/unstable/ai/internal/structured-output.js +316 -0
  202. package/dist/unstable/ai/internal/structured-output.js.map +1 -0
  203. package/dist/unstable/cli/CliError.d.ts +40 -2
  204. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  205. package/dist/unstable/cli/CliError.js +45 -6
  206. package/dist/unstable/cli/CliError.js.map +1 -1
  207. package/dist/unstable/cli/Command.js +14 -5
  208. package/dist/unstable/cli/Command.js.map +1 -1
  209. package/dist/unstable/cli/Param.js +3 -3
  210. package/dist/unstable/cli/Param.js.map +1 -1
  211. package/dist/unstable/cli/Primitive.js +1 -1
  212. package/dist/unstable/cli/Primitive.js.map +1 -1
  213. package/dist/unstable/cli/internal/command.d.ts +3 -1
  214. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  215. package/dist/unstable/cli/internal/command.js +11 -4
  216. package/dist/unstable/cli/internal/command.js.map +1 -1
  217. package/dist/unstable/cli/internal/config.d.ts +0 -48
  218. package/dist/unstable/cli/internal/config.d.ts.map +1 -1
  219. package/dist/unstable/cli/internal/config.js +8 -10
  220. package/dist/unstable/cli/internal/config.js.map +1 -1
  221. package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
  222. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  223. package/dist/unstable/cluster/Entity.js +1 -1
  224. package/dist/unstable/cluster/Entity.js.map +1 -1
  225. package/dist/unstable/cluster/Envelope.d.ts.map +1 -1
  226. package/dist/unstable/cluster/Envelope.js +2 -1
  227. package/dist/unstable/cluster/Envelope.js.map +1 -1
  228. package/dist/unstable/cluster/Reply.js +1 -1
  229. package/dist/unstable/cluster/Reply.js.map +1 -1
  230. package/dist/unstable/cluster/Runner.d.ts +1 -1
  231. package/dist/unstable/cluster/Runner.js +1 -1
  232. package/dist/unstable/cluster/Runner.js.map +1 -1
  233. package/dist/unstable/cluster/RunnerAddress.d.ts +1 -1
  234. package/dist/unstable/cluster/RunnerAddress.js +1 -1
  235. package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
  236. package/dist/unstable/cluster/ShardId.js +1 -1
  237. package/dist/unstable/cluster/ShardId.js.map +1 -1
  238. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  239. package/dist/unstable/cluster/Sharding.js +125 -24
  240. package/dist/unstable/cluster/Sharding.js.map +1 -1
  241. package/dist/unstable/cluster/ShardingConfig.d.ts +10 -2
  242. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  243. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  244. package/dist/unstable/cluster/SingleRunner.d.ts +4 -2
  245. package/dist/unstable/cluster/SingleRunner.d.ts.map +1 -1
  246. package/dist/unstable/cluster/SingleRunner.js +2 -1
  247. package/dist/unstable/cluster/SingleRunner.js.map +1 -1
  248. package/dist/unstable/cluster/SqlMessageStorage.d.ts +7 -4
  249. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  250. package/dist/unstable/cluster/SqlMessageStorage.js +55 -24
  251. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  252. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  253. package/dist/unstable/cluster/SqlRunnerStorage.js +109 -62
  254. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  255. package/dist/unstable/cluster/internal/entityManager.js +19 -7
  256. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  257. package/dist/unstable/cluster/internal/shardLock.d.ts +2 -0
  258. package/dist/unstable/cluster/internal/shardLock.d.ts.map +1 -0
  259. package/dist/unstable/cluster/internal/shardLock.js +4 -0
  260. package/dist/unstable/cluster/internal/shardLock.js.map +1 -0
  261. package/dist/unstable/devtools/DevToolsSchema.d.ts +20 -20
  262. package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
  263. package/dist/unstable/devtools/DevToolsSchema.js +8 -5
  264. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  265. package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
  266. package/dist/unstable/eventlog/EventJournal.js +1 -1
  267. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  268. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  269. package/dist/unstable/eventlog/EventLog.js +15 -11
  270. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  271. package/dist/unstable/eventlog/EventLogEncryption.d.ts +1 -1
  272. package/dist/unstable/eventlog/EventLogEncryption.js +1 -1
  273. package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
  274. package/dist/unstable/eventlog/EventLogMessage.d.ts +26 -26
  275. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  276. package/dist/unstable/eventlog/EventLogMessage.js +8 -3
  277. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  278. package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
  279. package/dist/unstable/eventlog/SqlEventJournal.js +2 -2
  280. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  281. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +1 -1
  282. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  283. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +3 -3
  284. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  285. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  286. package/dist/unstable/http/Cookies.js +24 -22
  287. package/dist/unstable/http/Cookies.js.map +1 -1
  288. package/dist/unstable/http/Headers.js +8 -8
  289. package/dist/unstable/http/Headers.js.map +1 -1
  290. package/dist/unstable/http/HttpClientRequest.d.ts +44 -0
  291. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  292. package/dist/unstable/http/HttpClientRequest.js +14 -0
  293. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  294. package/dist/unstable/http/HttpRouter.d.ts +2 -2
  295. package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
  296. package/dist/unstable/http/HttpRouter.js.map +1 -1
  297. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  298. package/dist/unstable/http/HttpServerRequest.js +5 -4
  299. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  300. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  301. package/dist/unstable/http/Multipart.js +17 -15
  302. package/dist/unstable/http/Multipart.js.map +1 -1
  303. package/dist/unstable/http/Template.js +1 -1
  304. package/dist/unstable/http/Template.js.map +1 -1
  305. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  306. package/dist/unstable/http/UrlParams.js +17 -14
  307. package/dist/unstable/http/UrlParams.js.map +1 -1
  308. package/dist/unstable/httpapi/HttpApi.js +3 -3
  309. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  310. package/dist/unstable/httpapi/HttpApiClient.js +5 -5
  311. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  312. package/dist/unstable/httpapi/HttpApiGroup.js +1 -1
  313. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  314. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  315. package/dist/unstable/httpapi/OpenApi.js +37 -24
  316. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  317. package/dist/unstable/observability/OtlpExporter.d.ts +72 -1
  318. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  319. package/dist/unstable/observability/OtlpExporter.js +69 -4
  320. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  321. package/dist/unstable/observability/OtlpLogger.d.ts +4 -3
  322. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  323. package/dist/unstable/observability/OtlpLogger.js +2 -2
  324. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  325. package/dist/unstable/observability/OtlpMetrics.d.ts +7 -3
  326. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  327. package/dist/unstable/observability/OtlpMetrics.js +5 -2
  328. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  329. package/dist/unstable/observability/OtlpTracer.d.ts +4 -3
  330. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  331. package/dist/unstable/observability/OtlpTracer.js +2 -2
  332. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  333. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  334. package/dist/unstable/persistence/Persistable.js +2 -1
  335. package/dist/unstable/persistence/Persistable.js.map +1 -1
  336. package/dist/unstable/persistence/RateLimiter.d.ts +2 -2
  337. package/dist/unstable/persistence/RateLimiter.js +2 -2
  338. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  339. package/dist/unstable/persistence/Redis.d.ts.map +1 -1
  340. package/dist/unstable/persistence/Redis.js +2 -2
  341. package/dist/unstable/persistence/Redis.js.map +1 -1
  342. package/dist/unstable/process/ChildProcessSpawner.js +3 -1
  343. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  344. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  345. package/dist/unstable/reactivity/AsyncResult.js +4 -3
  346. package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
  347. package/dist/unstable/reactivity/Atom.d.ts +83 -0
  348. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  349. package/dist/unstable/reactivity/Atom.js +31 -0
  350. package/dist/unstable/reactivity/Atom.js.map +1 -1
  351. package/dist/unstable/reactivity/AtomRegistry.js +1 -1
  352. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  353. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  354. package/dist/unstable/rpc/RpcClient.js +2 -1
  355. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  356. package/dist/unstable/schema/VariantSchema.d.ts +1 -2
  357. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  358. package/dist/unstable/schema/VariantSchema.js +13 -10
  359. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  360. package/dist/unstable/socket/Socket.d.ts +1 -1
  361. package/dist/unstable/socket/Socket.js +1 -1
  362. package/dist/unstable/socket/Socket.js.map +1 -1
  363. package/dist/unstable/sql/SqlError.d.ts +2 -2
  364. package/dist/unstable/sql/SqlError.js +2 -2
  365. package/dist/unstable/sql/SqlError.js.map +1 -1
  366. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  367. package/dist/unstable/sql/Statement.js +7 -6
  368. package/dist/unstable/sql/Statement.js.map +1 -1
  369. package/package.json +1 -1
  370. package/src/Array.ts +86 -25
  371. package/src/Channel.ts +32 -14
  372. package/src/Config.ts +6 -5
  373. package/src/ConfigProvider.ts +7 -7
  374. package/src/Data.ts +3 -2
  375. package/src/Effect.ts +70 -116
  376. package/src/FiberHandle.ts +3 -2
  377. package/src/Iterable.ts +2 -1
  378. package/src/JsonPatch.ts +4 -3
  379. package/src/JsonSchema.ts +9 -11
  380. package/src/Logger.ts +3 -2
  381. package/src/ManagedRuntime.ts +13 -0
  382. package/src/Metric.ts +4 -3
  383. package/src/MutableList.ts +4 -0
  384. package/src/Optic.ts +5 -4
  385. package/src/Option.ts +2 -1
  386. package/src/PartitionedSemaphore.ts +1 -4
  387. package/src/Record.ts +119 -22
  388. package/src/References.ts +0 -46
  389. package/src/Request.ts +5 -7
  390. package/src/Result.ts +2 -1
  391. package/src/Schema.ts +2538 -987
  392. package/src/SchemaAST.ts +228 -149
  393. package/src/SchemaError.ts +1 -1
  394. package/src/SchemaGetter.ts +36 -29
  395. package/src/SchemaIssue.ts +1 -1
  396. package/src/SchemaParser.ts +1 -25
  397. package/src/SchemaRepresentation.ts +697 -3398
  398. package/src/SchemaTransformation.ts +3 -3
  399. package/src/Semaphore.ts +5 -3
  400. package/src/Stream.ts +63 -19
  401. package/src/Struct.ts +5 -4
  402. package/src/Types.ts +1 -3
  403. package/src/index.ts +0 -5
  404. package/src/internal/core.ts +4 -3
  405. package/src/internal/effect.ts +132 -70
  406. package/src/internal/matcher.ts +1 -1
  407. package/src/internal/record.ts +11 -7
  408. package/src/internal/references.ts +0 -5
  409. package/src/internal/schema/annotations.ts +44 -0
  410. package/src/internal/schema/fromJsonSchemaDocument.ts +957 -0
  411. package/src/internal/schema/fromRepresentation.ts +345 -0
  412. package/src/internal/schema/schema.ts +45 -46
  413. package/src/internal/schema/{arbitrary.ts → toArbitrary.ts} +8 -10
  414. package/src/internal/schema/toCodeDocument.ts +572 -0
  415. package/src/internal/schema/{equivalence.ts → toEquivalence.ts} +12 -7
  416. package/src/internal/schema/toJsonSchemaDocument.ts +475 -0
  417. package/src/internal/schema/toRepresentation.ts +401 -0
  418. package/src/internal/stackTraceLimit.ts +3 -7
  419. package/src/testing/TestClock.ts +1 -1
  420. package/src/unstable/ai/AiError.ts +5 -4
  421. package/src/unstable/ai/AnthropicStructuredOutput.ts +102 -333
  422. package/src/unstable/ai/EmbeddingModel.ts +1 -1
  423. package/src/unstable/ai/LanguageModel.ts +30 -28
  424. package/src/unstable/ai/McpSchema.ts +15 -15
  425. package/src/unstable/ai/McpServer.ts +172 -56
  426. package/src/unstable/ai/OpenAiStructuredOutput.ts +230 -395
  427. package/src/unstable/ai/Response.ts +24 -24
  428. package/src/unstable/ai/Tool.ts +22 -4
  429. package/src/unstable/ai/Toolkit.ts +19 -7
  430. package/src/unstable/ai/internal/codec-transformer.ts +13 -7
  431. package/src/unstable/ai/internal/structured-output.ts +458 -0
  432. package/src/unstable/cli/CliError.ts +51 -5
  433. package/src/unstable/cli/Command.ts +4 -4
  434. package/src/unstable/cli/Param.ts +3 -3
  435. package/src/unstable/cli/Primitive.ts +1 -1
  436. package/src/unstable/cli/internal/command.ts +13 -5
  437. package/src/unstable/cli/internal/config.ts +8 -10
  438. package/src/unstable/cluster/ClusterWorkflowEngine.ts +3 -3
  439. package/src/unstable/cluster/Entity.ts +1 -1
  440. package/src/unstable/cluster/Envelope.ts +2 -1
  441. package/src/unstable/cluster/Reply.ts +1 -1
  442. package/src/unstable/cluster/Runner.ts +1 -1
  443. package/src/unstable/cluster/RunnerAddress.ts +1 -1
  444. package/src/unstable/cluster/ShardId.ts +1 -1
  445. package/src/unstable/cluster/Sharding.ts +161 -34
  446. package/src/unstable/cluster/ShardingConfig.ts +5 -1
  447. package/src/unstable/cluster/SingleRunner.ts +4 -2
  448. package/src/unstable/cluster/SqlMessageStorage.ts +83 -35
  449. package/src/unstable/cluster/SqlRunnerStorage.ts +186 -116
  450. package/src/unstable/cluster/internal/entityManager.ts +31 -10
  451. package/src/unstable/cluster/internal/shardLock.ts +9 -0
  452. package/src/unstable/devtools/DevToolsSchema.ts +10 -5
  453. package/src/unstable/eventlog/EventJournal.ts +1 -1
  454. package/src/unstable/eventlog/EventLog.ts +21 -11
  455. package/src/unstable/eventlog/EventLogEncryption.ts +1 -1
  456. package/src/unstable/eventlog/EventLogMessage.ts +10 -3
  457. package/src/unstable/eventlog/SqlEventJournal.ts +2 -2
  458. package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +1 -1
  459. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +6 -3
  460. package/src/unstable/http/Cookies.ts +29 -24
  461. package/src/unstable/http/Headers.ts +8 -8
  462. package/src/unstable/http/HttpClientRequest.ts +57 -0
  463. package/src/unstable/http/HttpRouter.ts +6 -3
  464. package/src/unstable/http/HttpServerRequest.ts +5 -4
  465. package/src/unstable/http/Multipart.ts +16 -13
  466. package/src/unstable/http/Template.ts +1 -1
  467. package/src/unstable/http/UrlParams.ts +17 -14
  468. package/src/unstable/httpapi/HttpApi.ts +3 -3
  469. package/src/unstable/httpapi/HttpApiClient.ts +5 -5
  470. package/src/unstable/httpapi/HttpApiGroup.ts +1 -1
  471. package/src/unstable/httpapi/OpenApi.ts +52 -28
  472. package/src/unstable/observability/OtlpExporter.ts +109 -5
  473. package/src/unstable/observability/OtlpLogger.ts +5 -5
  474. package/src/unstable/observability/OtlpMetrics.ts +8 -4
  475. package/src/unstable/observability/OtlpTracer.ts +8 -4
  476. package/src/unstable/persistence/Persistable.ts +3 -2
  477. package/src/unstable/persistence/RateLimiter.ts +2 -2
  478. package/src/unstable/persistence/Redis.ts +2 -2
  479. package/src/unstable/process/ChildProcessSpawner.ts +1 -1
  480. package/src/unstable/reactivity/AsyncResult.ts +4 -3
  481. package/src/unstable/reactivity/Atom.ts +92 -0
  482. package/src/unstable/reactivity/AtomRegistry.ts +1 -1
  483. package/src/unstable/rpc/RpcClient.ts +2 -1
  484. package/src/unstable/schema/VariantSchema.ts +14 -24
  485. package/src/unstable/socket/Socket.ts +1 -1
  486. package/src/unstable/sql/SqlError.ts +2 -2
  487. package/src/unstable/sql/Statement.ts +7 -6
  488. package/dist/SchemaUtils.d.ts +0 -28
  489. package/dist/SchemaUtils.d.ts.map +0 -1
  490. package/dist/SchemaUtils.js +0 -45
  491. package/dist/SchemaUtils.js.map +0 -1
  492. package/dist/internal/schema/arbitrary.d.ts.map +0 -1
  493. package/dist/internal/schema/arbitrary.js.map +0 -1
  494. package/dist/internal/schema/equivalence.d.ts +0 -2
  495. package/dist/internal/schema/equivalence.d.ts.map +0 -1
  496. package/dist/internal/schema/equivalence.js.map +0 -1
  497. package/dist/internal/schema/representation.d.ts +0 -2
  498. package/dist/internal/schema/representation.d.ts.map +0 -1
  499. package/dist/internal/schema/representation.js +0 -865
  500. package/dist/internal/schema/representation.js.map +0 -1
  501. package/src/SchemaUtils.ts +0 -51
  502. package/src/internal/schema/representation.ts +0 -795
@@ -0,0 +1,475 @@
1
+ import * as Arr from "../../Array.ts"
2
+ import { escapeToken } from "../../JsonPointer.ts"
3
+ import type * as JsonSchema from "../../JsonSchema.ts"
4
+ import * as RegEx from "../../RegExp.ts"
5
+ import type * as Schema from "../../Schema.ts"
6
+ import * as SchemaAST from "../../SchemaAST.ts"
7
+ import type * as SchemaRepresentation from "../../SchemaRepresentation.ts"
8
+ import { errorWithPath } from "../errors.ts"
9
+ import * as InternalRecord from "../record.ts"
10
+ import * as InternalAnnotations from "./annotations.ts"
11
+
12
+ type Path = ReadonlyArray<string | number>
13
+ type CheckRepresentationAnnotation = SchemaRepresentation.CheckRepresentationAnnotation<
14
+ SchemaRepresentation.Representation
15
+ >
16
+
17
+ const jsonSchemaAnnotationExcludedKeys = new Set([
18
+ ...InternalAnnotations.annotationExcludedKeys,
19
+ InternalAnnotations.IDENTIFIER_FALLBACK_KEY,
20
+ ...InternalAnnotations.jsonSchemaAnnotationKeys
21
+ ])
22
+
23
+ function collectJsonSchemaAnnotations(
24
+ annotations: Schema.Annotations.Annotations | undefined,
25
+ options: Schema.ToJsonSchemaOptions | undefined
26
+ ): JsonSchema.JsonSchema | undefined {
27
+ if (annotations === undefined) return undefined
28
+
29
+ const out: JsonSchema.JsonSchema = {}
30
+ const title = annotations.title
31
+ if (typeof title === "string") out.title = title
32
+ const description = annotations.description
33
+ const expected = annotations.expected
34
+ if (typeof description === "string") out.description = description
35
+ else if (options?.generateDescriptions === true && typeof expected === "string") out.description = expected
36
+
37
+ const defaultValue = annotations.default
38
+ if (SchemaAST.isJson(defaultValue)) out.default = defaultValue
39
+ const examples = annotations.examples
40
+ if (Array.isArray(examples) && SchemaAST.isJson(examples)) out.examples = examples
41
+ const readOnly = annotations.readOnly
42
+ if (typeof readOnly === "boolean") out.readOnly = readOnly
43
+ const writeOnly = annotations.writeOnly
44
+ if (typeof writeOnly === "boolean") out.writeOnly = writeOnly
45
+ const format = annotations.format
46
+ if (typeof format === "string") out.format = format
47
+ const contentEncoding = annotations.contentEncoding
48
+ if (typeof contentEncoding === "string") out.contentEncoding = contentEncoding
49
+ const contentMediaType = annotations.contentMediaType
50
+ if (typeof contentMediaType === "string") out.contentMediaType = contentMediaType
51
+ const contentSchema = annotations.contentSchema
52
+ if (SchemaAST.isJson(contentSchema)) out.contentSchema = contentSchema
53
+
54
+ if (options?.includeAnnotationKey !== undefined) {
55
+ for (const [key, value] of Object.entries(annotations)) {
56
+ if (
57
+ jsonSchemaAnnotationExcludedKeys.has(key) ||
58
+ !options.includeAnnotationKey(key)
59
+ ) {
60
+ continue
61
+ }
62
+ if (SchemaAST.isJson(value)) InternalRecord.assignProperty(out, key, value)
63
+ }
64
+ }
65
+
66
+ return Object.keys(out).length === 0 ? undefined : out
67
+ }
68
+
69
+ type JsonSchemaNumberType = "number" | "integer"
70
+
71
+ function extractJsonSchemaNumberType(schema: JsonSchema.JsonSchema): {
72
+ readonly type: JsonSchemaNumberType | undefined
73
+ readonly schema: JsonSchema.JsonSchema
74
+ } {
75
+ let type: JsonSchemaNumberType | undefined = schema.type === "number" || schema.type === "integer"
76
+ ? schema.type
77
+ : undefined
78
+ let out = schema
79
+ if (type !== undefined) {
80
+ out = { ...schema }
81
+ delete out.type
82
+ }
83
+ if (Array.isArray(out.allOf)) {
84
+ const members: Array<JsonSchema.JsonSchema> = []
85
+ let changed = false
86
+ for (const member of out.allOf) {
87
+ const extracted = extractJsonSchemaNumberType(member)
88
+ if (extracted.type !== undefined) {
89
+ changed = true
90
+ if (type === undefined || extracted.type === "integer") type = extracted.type
91
+ }
92
+ if (Object.keys(extracted.schema).length > 0) members.push(extracted.schema)
93
+ }
94
+ if (changed) {
95
+ const { allOf: _, ...rest } = out
96
+ out = members.length === 0 ? rest : { ...rest, allOf: members }
97
+ }
98
+ }
99
+ return { type, schema: out }
100
+ }
101
+
102
+ function isJsonSchemaNumberEncoding(schema: JsonSchema.JsonSchema): boolean {
103
+ return Array.isArray(schema.anyOf) && schema.anyOf.length === 4 && schema.anyOf[0]?.type === "number" &&
104
+ schema.anyOf.slice(1).every((member) => member.type === "string")
105
+ }
106
+
107
+ function appendJsonSchema(
108
+ left: JsonSchema.JsonSchema,
109
+ right: JsonSchema.JsonSchema
110
+ ): JsonSchema.JsonSchema {
111
+ if (Object.keys(left).length === 0) return right
112
+ const rightKeys = Object.keys(right)
113
+ if (rightKeys.length === 0) return left
114
+ const leftType = left.type === "number" || left.type === "integer" ? left.type : undefined
115
+ const isNumberEncoding = isJsonSchemaNumberEncoding(left)
116
+ if (leftType !== undefined || isNumberEncoding) {
117
+ const extracted = extractJsonSchemaNumberType(right)
118
+ if (extracted.type !== undefined) {
119
+ const type = leftType === "integer" || extracted.type === "integer" ? "integer" : "number"
120
+ const base: JsonSchema.JsonSchema = { ...left, type }
121
+ if (isNumberEncoding) delete base.anyOf
122
+ return Object.keys(extracted.schema).length === 0 ? base : appendJsonSchema(base, extracted.schema)
123
+ }
124
+ }
125
+ const members = Array.isArray(right.allOf) && rightKeys.length === 1 ? right.allOf : [right]
126
+ if (Array.isArray(left.allOf)) {
127
+ return { ...left, allOf: [...left.allOf, ...members] }
128
+ }
129
+ if (typeof left.$ref === "string") {
130
+ return { allOf: [left, ...members] }
131
+ }
132
+ return { ...left, allOf: members }
133
+ }
134
+
135
+ function compileJsonSchema(
136
+ representations: readonly [
137
+ SchemaRepresentation.Representation,
138
+ ...Array<SchemaRepresentation.Representation>
139
+ ],
140
+ rootPaths: ReadonlyArray<Path>,
141
+ references: SchemaRepresentation.References,
142
+ options: Schema.ToJsonSchemaOptions | undefined
143
+ ): JsonSchema.MultiDocument<"draft-2020-12"> {
144
+ const definitions: Record<string, JsonSchema.JsonSchema> = {}
145
+ for (const key of Object.keys(references)) {
146
+ InternalRecord.assignProperty(definitions, key, recur(references[key], ["references", key]))
147
+ }
148
+ const schemas = Arr.map(representations, (representation, index) => recur(representation, rootPaths[index]))
149
+ return { dialect: "draft-2020-12", schemas, definitions }
150
+
151
+ function annotationSchemas(
152
+ representation: CheckRepresentationAnnotation | undefined,
153
+ path: Path
154
+ ): ReadonlyArray<JsonSchema.JsonSchema> {
155
+ return representation?.schemas?.map((schema, index) => recur(schema, [...path, "schemas", index])) ?? []
156
+ }
157
+
158
+ function compileCheck(
159
+ check: SchemaRepresentation.Check,
160
+ type: JsonSchema.Type | undefined,
161
+ path: Path
162
+ ): JsonSchema.JsonSchema | undefined {
163
+ const annotations = check.annotations
164
+ const callback = annotations?.toJsonSchema
165
+ if (callback !== undefined) {
166
+ const schemas = annotationSchemas(check.representation, [...path, "representation"])
167
+ const fragment = (callback as SchemaRepresentation.ToJsonSchema.Check)({ type, schemas })
168
+ const ordinary = collectJsonSchemaAnnotations(annotations, options)
169
+ return ordinary === undefined ? fragment : { ...fragment, ...ordinary }
170
+ }
171
+ if (check._tag === "Filter") return undefined
172
+
173
+ const children = check.checks
174
+ .map((child, index) => compileCheck(child, type, [...path, "checks", index]))
175
+ .filter((child): child is JsonSchema.JsonSchema => child !== undefined)
176
+ if (children.length === 0) return undefined
177
+ const ordinary = collectJsonSchemaAnnotations(annotations, options)
178
+ return ordinary === undefined ? { allOf: children } : { allOf: children, ...ordinary }
179
+ }
180
+
181
+ function recur(
182
+ representation: SchemaRepresentation.Representation,
183
+ path: Path
184
+ ): JsonSchema.JsonSchema {
185
+ if (representation._tag === "Reference") {
186
+ if (!Object.hasOwn(references, representation.$ref)) {
187
+ throw errorWithPath(`Invalid reference ${representation.$ref}`, [...path, "$ref"])
188
+ }
189
+ return { $ref: `#/$defs/${escapeToken(representation.$ref)}` }
190
+ }
191
+
192
+ let output = on(representation, path)
193
+ const ordinary = collectJsonSchemaAnnotations(representation.annotations, options)
194
+ if (ordinary !== undefined) {
195
+ output = { ...output, ...ordinary }
196
+ }
197
+ for (let index = 0; index < representation.checks.length; index++) {
198
+ const type = typeof output.type === "string" && isJsonSchemaType(output.type) ? output.type : undefined
199
+ const check = compileCheck(representation.checks[index], type, [...path, "checks", index])
200
+ if (check !== undefined) {
201
+ output = appendJsonSchema(output, check)
202
+ }
203
+ }
204
+ return output
205
+ }
206
+
207
+ function on(
208
+ representation: Exclude<SchemaRepresentation.Representation, SchemaRepresentation.Reference>,
209
+ path: Path
210
+ ): JsonSchema.JsonSchema {
211
+ switch (representation._tag) {
212
+ case "Any":
213
+ case "Unknown":
214
+ return {}
215
+ case "ObjectKeyword":
216
+ return { anyOf: [{ type: "object" }, { type: "array" }] }
217
+ case "Void":
218
+ case "Undefined":
219
+ case "Null":
220
+ return { type: "null" }
221
+ case "BigInt":
222
+ return { type: "string", allOf: [{ pattern: "^-?\\d+$" }] }
223
+ case "Symbol":
224
+ case "UniqueSymbol":
225
+ return { type: "string", allOf: [{ pattern: "^Symbol\\((.*)\\)$" }] }
226
+ case "Declaration": {
227
+ return {}
228
+ }
229
+ case "Suspend":
230
+ return recur(representation.thunk, [...path, "thunk"])
231
+ case "Never":
232
+ return { not: {} }
233
+ case "String":
234
+ return { type: "string" }
235
+ case "Number":
236
+ return {
237
+ anyOf: [
238
+ { type: "number" },
239
+ { type: "string", enum: ["NaN"] },
240
+ { type: "string", enum: ["Infinity"] },
241
+ { type: "string", enum: ["-Infinity"] }
242
+ ]
243
+ }
244
+ case "Boolean":
245
+ return { type: "boolean" }
246
+ case "Literal": {
247
+ const literal = representation.literal
248
+ return typeof literal === "bigint"
249
+ ? { type: "string", enum: [globalThis.String(literal)] }
250
+ : { type: typeof literal, enum: [literal] }
251
+ }
252
+ case "Enum": {
253
+ const types = representation.enums.map(([title, literal]) =>
254
+ typeof literal === "number" && !globalThis.Number.isFinite(literal)
255
+ ? { type: "string", enum: [globalThis.String(literal)], title }
256
+ : { type: typeof literal, enum: [literal], title }
257
+ )
258
+ return types.length === 0 ? { not: {} } : { anyOf: types }
259
+ }
260
+ case "TemplateLiteral":
261
+ return { type: "string", pattern: `^${representation.parts.map(getPartPattern).join("")}$` }
262
+ case "Arrays": {
263
+ if (representation.rest.length > 1) {
264
+ throw errorWithPath("Invalid schema representation document", [...path, "rest"])
265
+ }
266
+ const out: JsonSchema.JsonSchema = { type: "array" }
267
+ let minItems = representation.elements.length
268
+ const prefixItems = representation.elements.map((element, index) => {
269
+ if (element.isOptional) minItems--
270
+ const compiled = recur(element.type, [...path, "elements", index, "type"])
271
+ const annotations = collectJsonSchemaAnnotations(element.annotations, options)
272
+ return annotations === undefined ? compiled : appendJsonSchema(compiled, annotations)
273
+ })
274
+ if (prefixItems.length > 0) {
275
+ out.prefixItems = prefixItems
276
+ out.maxItems = representation.elements.length
277
+ if (minItems > 0) out.minItems = minItems
278
+ } else {
279
+ out.items = false
280
+ }
281
+ if (representation.rest.length === 1) {
282
+ delete out.maxItems
283
+ const rest = recur(representation.rest[0], [...path, "rest", 0])
284
+ if (Object.keys(rest).length > 0) out.items = rest
285
+ else delete out.items
286
+ }
287
+ return out
288
+ }
289
+ case "Objects": {
290
+ if (representation.propertySignatures.length === 0 && representation.indexSignatures.length === 0) {
291
+ return { anyOf: [{ type: "object" }, { type: "array" }] }
292
+ }
293
+ const out: JsonSchema.JsonSchema = { type: "object" }
294
+ const properties: Record<string, JsonSchema.JsonSchema> = {}
295
+ const required: Array<string> = []
296
+ for (let index = 0; index < representation.propertySignatures.length; index++) {
297
+ const property = representation.propertySignatures[index]
298
+ if (typeof property.name !== "string") {
299
+ throw errorWithPath("Invalid schema representation document", [
300
+ ...path,
301
+ "propertySignatures",
302
+ index,
303
+ "name"
304
+ ])
305
+ }
306
+ const name = property.name
307
+ const compiled = recur(property.type, [...path, "propertySignatures", index, "type"])
308
+ const annotations = collectJsonSchemaAnnotations(property.annotations, options)
309
+ InternalRecord.assignProperty(
310
+ properties,
311
+ name,
312
+ annotations === undefined ? compiled : appendJsonSchema(compiled, annotations)
313
+ )
314
+ if (!property.isOptional) required.push(name)
315
+ }
316
+ if (representation.propertySignatures.length > 0) out.properties = properties
317
+ if (required.length > 0) out.required = required
318
+ out.additionalProperties = options?.additionalProperties ?? false
319
+ const patternProperties: Record<string, JsonSchema.JsonSchema | false> = {}
320
+ for (let index = 0; index < representation.indexSignatures.length; index++) {
321
+ const signature = representation.indexSignatures[index]
322
+ let type: JsonSchema.JsonSchema | false = recur(
323
+ signature.type,
324
+ [...path, "indexSignatures", index, "type"]
325
+ )
326
+ if (Object.keys(type).length === 1 && "not" in type) type = false
327
+ const patterns = getParameterPatterns(
328
+ signature.parameter,
329
+ [...path, "indexSignatures", index, "parameter"],
330
+ new Set()
331
+ )
332
+ if (patterns.length === 0) {
333
+ out.additionalProperties = type
334
+ } else {
335
+ for (const pattern of patterns) InternalRecord.assignProperty(patternProperties, pattern, type)
336
+ }
337
+ }
338
+ if (Object.keys(patternProperties).length > 0) {
339
+ out.patternProperties = patternProperties
340
+ delete out.additionalProperties
341
+ }
342
+ if (
343
+ typeof out.additionalProperties === "object" &&
344
+ out.additionalProperties !== null &&
345
+ Object.keys(out.additionalProperties).length === 0
346
+ ) {
347
+ delete out.additionalProperties
348
+ }
349
+ return out
350
+ }
351
+ case "Union": {
352
+ const types = representation.types.map((type, index) => recur(type, [...path, "types", index]))
353
+ if (types.length === 0) return { not: {} }
354
+ if (types.length > 1) {
355
+ const compacted = compactEnums(types)
356
+ if (compacted !== undefined) return compacted
357
+ }
358
+ return representation.mode === "anyOf" ? { anyOf: types } : { oneOf: types }
359
+ }
360
+ }
361
+ }
362
+
363
+ function getParameterPatterns(
364
+ parameter: SchemaRepresentation.Representation,
365
+ path: Path,
366
+ seenReferences: ReadonlySet<string>
367
+ ): ReadonlyArray<string> {
368
+ switch (parameter._tag) {
369
+ case "Reference": {
370
+ if (!Object.hasOwn(references, parameter.$ref)) {
371
+ throw errorWithPath(`Invalid reference ${parameter.$ref}`, [...path, "$ref"])
372
+ }
373
+ if (seenReferences.has(parameter.$ref)) return []
374
+ const next = new Set(seenReferences).add(parameter.$ref)
375
+ return getParameterPatterns(references[parameter.$ref], ["references", parameter.$ref], next)
376
+ }
377
+ case "String":
378
+ return collectPatterns(recur(parameter, path))
379
+ case "TemplateLiteral":
380
+ return [`^${parameter.parts.map(getPartPattern).join("")}$`]
381
+ case "Union":
382
+ return parameter.types.flatMap((type, index) =>
383
+ getParameterPatterns(type, [...path, "types", index], seenReferences)
384
+ )
385
+ default:
386
+ throw errorWithPath("Invalid schema representation document", path)
387
+ }
388
+ }
389
+ }
390
+
391
+ function isJsonSchemaType(input: string): input is JsonSchema.Type {
392
+ return input === "string" || input === "number" || input === "boolean" || input === "array" ||
393
+ input === "object" || input === "null" || input === "integer"
394
+ }
395
+
396
+ function compactEnums(
397
+ schemas: ReadonlyArray<JsonSchema.JsonSchema>
398
+ ): JsonSchema.JsonSchema | undefined {
399
+ let sharedType: unknown = undefined
400
+ const values: Array<unknown> = []
401
+ for (const schema of schemas) {
402
+ const keys = Object.keys(schema)
403
+ if (keys.length !== 2 || schema.type === undefined || !Array.isArray(schema.enum) || schema.enum.length === 0) {
404
+ return undefined
405
+ }
406
+ if (sharedType === undefined) sharedType = schema.type
407
+ else if (schema.type !== sharedType) return undefined
408
+ values.push(...schema.enum)
409
+ }
410
+ return { type: sharedType, enum: values }
411
+ }
412
+
413
+ function collectPatterns(schema: JsonSchema.JsonSchema): ReadonlyArray<string> {
414
+ const patterns: Array<string> = []
415
+ if (typeof schema.pattern === "string") patterns.push(schema.pattern)
416
+ for (const key of ["allOf", "anyOf", "oneOf"] as const) {
417
+ const members = schema[key]
418
+ if (Array.isArray(members)) {
419
+ for (const member of members) {
420
+ if (typeof member === "object" && member !== null && !Array.isArray(member)) {
421
+ patterns.push(...collectPatterns(member))
422
+ }
423
+ }
424
+ }
425
+ }
426
+ return patterns
427
+ }
428
+
429
+ function getPartPattern(part: SchemaRepresentation.Representation): string {
430
+ switch (part._tag) {
431
+ case "Literal":
432
+ return RegEx.escape(globalThis.String(part.literal))
433
+ case "String":
434
+ return SchemaAST.STRING_PATTERN
435
+ case "Number":
436
+ return SchemaAST.FINITE_PATTERN
437
+ case "TemplateLiteral":
438
+ return part.parts.map(getPartPattern).join("")
439
+ case "Union":
440
+ return part.types.map(getPartPattern).join("|")
441
+ default:
442
+ throw errorWithPath("Invalid schema representation document", [])
443
+ }
444
+ }
445
+
446
+ /** @internal */
447
+ export function toJsonSchemaDocument(
448
+ document: SchemaRepresentation.Document,
449
+ options?: Schema.ToJsonSchemaOptions
450
+ ): JsonSchema.Document<"draft-2020-12"> {
451
+ const output = compileJsonSchema(
452
+ [document.representation],
453
+ [["representation"]],
454
+ document.references,
455
+ options
456
+ )
457
+ return {
458
+ dialect: output.dialect,
459
+ schema: output.schemas[0],
460
+ definitions: output.definitions
461
+ }
462
+ }
463
+
464
+ /** @internal */
465
+ export function toJsonSchemaMultiDocument(
466
+ document: SchemaRepresentation.MultiDocument,
467
+ options?: Schema.ToJsonSchemaOptions
468
+ ): JsonSchema.MultiDocument<"draft-2020-12"> {
469
+ return compileJsonSchema(
470
+ document.representations,
471
+ document.representations.map((_, index) => ["representations", index]),
472
+ document.references,
473
+ options
474
+ )
475
+ }