effect 4.1.1 → 4.1.3

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 (548) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/ai-docs/tsconfig.json +2 -1
  3. package/dist/ByteSize.d.ts.map +1 -1
  4. package/dist/ByteSize.js +27 -14
  5. package/dist/ByteSize.js.map +1 -1
  6. package/dist/DateTime.d.ts +33 -2
  7. package/dist/DateTime.d.ts.map +1 -1
  8. package/dist/DateTime.js +16 -0
  9. package/dist/DateTime.js.map +1 -1
  10. package/dist/Iterable.d.ts.map +1 -1
  11. package/dist/Iterable.js +27 -24
  12. package/dist/Iterable.js.map +1 -1
  13. package/dist/JsonSchema.d.ts.map +1 -1
  14. package/dist/JsonSchema.js +27 -6
  15. package/dist/JsonSchema.js.map +1 -1
  16. package/dist/Match.d.ts +6 -6
  17. package/dist/Match.d.ts.map +1 -1
  18. package/dist/Match.js.map +1 -1
  19. package/dist/MutableRef.d.ts.map +1 -1
  20. package/dist/MutableRef.js +0 -7
  21. package/dist/MutableRef.js.map +1 -1
  22. package/dist/Queue.d.ts +2 -1
  23. package/dist/Queue.d.ts.map +1 -1
  24. package/dist/Queue.js +16 -9
  25. package/dist/Queue.js.map +1 -1
  26. package/dist/Rational.d.ts +1214 -0
  27. package/dist/Rational.d.ts.map +1 -0
  28. package/dist/Rational.js +880 -0
  29. package/dist/Rational.js.map +1 -0
  30. package/dist/RcMap.d.ts +3 -0
  31. package/dist/RcMap.d.ts.map +1 -1
  32. package/dist/RcMap.js +13 -14
  33. package/dist/RcMap.js.map +1 -1
  34. package/dist/Ref.d.ts.map +1 -1
  35. package/dist/Ref.js +0 -8
  36. package/dist/Ref.js.map +1 -1
  37. package/dist/Runtime.d.ts +75 -3
  38. package/dist/Runtime.d.ts.map +1 -1
  39. package/dist/Runtime.js +81 -4
  40. package/dist/Runtime.js.map +1 -1
  41. package/dist/Schedule.d.ts.map +1 -1
  42. package/dist/Schedule.js +8 -3
  43. package/dist/Schedule.js.map +1 -1
  44. package/dist/Schema.d.ts +131 -29
  45. package/dist/Schema.d.ts.map +1 -1
  46. package/dist/Schema.js +128 -22
  47. package/dist/Schema.js.map +1 -1
  48. package/dist/SchemaAST.d.ts.map +1 -1
  49. package/dist/SchemaAST.js +24 -12
  50. package/dist/SchemaAST.js.map +1 -1
  51. package/dist/SchemaParser.js +2 -2
  52. package/dist/SchemaParser.js.map +1 -1
  53. package/dist/SchemaRepresentation.d.ts +9 -0
  54. package/dist/SchemaRepresentation.d.ts.map +1 -1
  55. package/dist/SchemaRepresentation.js +9 -0
  56. package/dist/SchemaRepresentation.js.map +1 -1
  57. package/dist/ScopedCache.d.ts +7 -0
  58. package/dist/ScopedCache.d.ts.map +1 -1
  59. package/dist/ScopedCache.js +18 -1
  60. package/dist/ScopedCache.js.map +1 -1
  61. package/dist/Stream.d.ts.map +1 -1
  62. package/dist/Stream.js +6 -5
  63. package/dist/Stream.js.map +1 -1
  64. package/dist/ai/AgUi.d.ts +109 -0
  65. package/dist/ai/AgUi.d.ts.map +1 -0
  66. package/dist/ai/AgUi.js +543 -0
  67. package/dist/ai/AgUi.js.map +1 -0
  68. package/dist/ai/AgUiSchema.d.ts +6965 -0
  69. package/dist/ai/AgUiSchema.d.ts.map +1 -0
  70. package/dist/ai/AgUiSchema.js +974 -0
  71. package/dist/ai/AgUiSchema.js.map +1 -0
  72. package/dist/ai/AgUiServer.d.ts +6400 -0
  73. package/dist/ai/AgUiServer.d.ts.map +1 -0
  74. package/dist/ai/AgUiServer.js +309 -0
  75. package/dist/ai/AgUiServer.js.map +1 -0
  76. package/dist/ai/Chat.d.ts +30 -4
  77. package/dist/ai/Chat.d.ts.map +1 -1
  78. package/dist/ai/Chat.js +34 -4
  79. package/dist/ai/Chat.js.map +1 -1
  80. package/dist/ai/LanguageModel.d.ts +1 -1
  81. package/dist/ai/LanguageModel.d.ts.map +1 -1
  82. package/dist/ai/LanguageModel.js +18 -8
  83. package/dist/ai/LanguageModel.js.map +1 -1
  84. package/dist/ai/McpClient.d.ts +5 -0
  85. package/dist/ai/McpClient.d.ts.map +1 -1
  86. package/dist/ai/McpClient.js +11 -1
  87. package/dist/ai/McpClient.js.map +1 -1
  88. package/dist/ai/McpServer.d.ts +18 -1
  89. package/dist/ai/McpServer.d.ts.map +1 -1
  90. package/dist/ai/McpServer.js +251 -43
  91. package/dist/ai/McpServer.js.map +1 -1
  92. package/dist/ai/Prompt.d.ts +6 -2
  93. package/dist/ai/Prompt.d.ts.map +1 -1
  94. package/dist/ai/Prompt.js.map +1 -1
  95. package/dist/ai/Response.d.ts +5 -2
  96. package/dist/ai/Response.d.ts.map +1 -1
  97. package/dist/ai/Response.js +5 -1
  98. package/dist/ai/Response.js.map +1 -1
  99. package/dist/ai/Tool.d.ts +265 -69
  100. package/dist/ai/Tool.d.ts.map +1 -1
  101. package/dist/ai/Tool.js +19 -2
  102. package/dist/ai/Tool.js.map +1 -1
  103. package/dist/ai/Toolkit.d.ts +32 -2
  104. package/dist/ai/Toolkit.d.ts.map +1 -1
  105. package/dist/ai/Toolkit.js +61 -8
  106. package/dist/ai/Toolkit.js.map +1 -1
  107. package/dist/ai/index.d.ts +15 -0
  108. package/dist/ai/index.d.ts.map +1 -1
  109. package/dist/ai/index.js +15 -0
  110. package/dist/ai/index.js.map +1 -1
  111. package/dist/ai/internal/mcpCore.d.ts +0 -2
  112. package/dist/ai/internal/mcpCore.d.ts.map +1 -1
  113. package/dist/ai/internal/mcpCore.js +2 -8
  114. package/dist/ai/internal/mcpCore.js.map +1 -1
  115. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +6 -11
  116. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  117. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +6 -11
  118. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  119. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +6 -8
  120. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  121. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +6 -8
  122. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  123. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +64 -54
  124. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  125. package/dist/ai/internal/mcpProtocol.js +11 -1
  126. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  127. package/dist/ai/internal/mcpProtocolRegistry.js +4 -0
  128. package/dist/ai/internal/mcpProtocolRegistry.js.map +1 -1
  129. package/dist/ai/internal/mcpRuntime.js +6 -2
  130. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  131. package/dist/ai/internal/mcpSchema/v2024_11_05.js +0 -2
  132. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  133. package/dist/ai/internal/mcpSchema/v2025_03_26.d.ts.map +1 -1
  134. package/dist/ai/internal/mcpSchema/v2025_03_26.js +0 -2
  135. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  136. package/dist/ai/internal/mcpSchema/v2025_06_18.d.ts.map +1 -1
  137. package/dist/ai/internal/mcpSchema/v2025_06_18.js +0 -2
  138. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  139. package/dist/ai/internal/mcpSchema/v2025_11_25.d.ts.map +1 -1
  140. package/dist/ai/internal/mcpSchema/v2025_11_25.js +0 -2
  141. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  142. package/dist/ai/internal/mcpSchema/v2026_07_28.d.ts.map +1 -1
  143. package/dist/ai/internal/mcpSchema/v2026_07_28.js +0 -2
  144. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  145. package/dist/ai/internal/mcpSkills.js +3 -93
  146. package/dist/ai/internal/mcpSkills.js.map +1 -1
  147. package/dist/ai/internal/mcpStatefulRuntime.js +0 -2
  148. package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
  149. package/dist/ai/internal/structured-output.js +12 -3
  150. package/dist/ai/internal/structured-output.js.map +1 -1
  151. package/dist/cli/Argument.d.ts +81 -0
  152. package/dist/cli/Argument.d.ts.map +1 -1
  153. package/dist/cli/Argument.js +26 -0
  154. package/dist/cli/Argument.js.map +1 -1
  155. package/dist/cli/CliError.d.ts +7 -4
  156. package/dist/cli/CliError.d.ts.map +1 -1
  157. package/dist/cli/CliError.js +7 -4
  158. package/dist/cli/CliError.js.map +1 -1
  159. package/dist/cli/Command.d.ts +241 -22
  160. package/dist/cli/Command.d.ts.map +1 -1
  161. package/dist/cli/Command.js +85 -9
  162. package/dist/cli/Command.js.map +1 -1
  163. package/dist/cli/CommandSpec.d.ts +287 -0
  164. package/dist/cli/CommandSpec.d.ts.map +1 -0
  165. package/dist/cli/CommandSpec.js +277 -0
  166. package/dist/cli/CommandSpec.js.map +1 -0
  167. package/dist/cli/Completions.d.ts +5 -0
  168. package/dist/cli/Completions.d.ts.map +1 -1
  169. package/dist/cli/Completions.js.map +1 -1
  170. package/dist/cli/Flag.d.ts +102 -0
  171. package/dist/cli/Flag.d.ts.map +1 -1
  172. package/dist/cli/Flag.js +47 -0
  173. package/dist/cli/Flag.js.map +1 -1
  174. package/dist/cli/Param.d.ts +154 -1
  175. package/dist/cli/Param.d.ts.map +1 -1
  176. package/dist/cli/Param.js +87 -29
  177. package/dist/cli/Param.js.map +1 -1
  178. package/dist/cli/index.d.ts +5 -0
  179. package/dist/cli/index.d.ts.map +1 -1
  180. package/dist/cli/index.js +5 -0
  181. package/dist/cli/index.js.map +1 -1
  182. package/dist/cli/internal/command.d.ts +2 -2
  183. package/dist/cli/internal/command.d.ts.map +1 -1
  184. package/dist/cli/internal/command.js +1 -1
  185. package/dist/cli/internal/command.js.map +1 -1
  186. package/dist/cli/internal/completions/bash.js +6 -7
  187. package/dist/cli/internal/completions/bash.js.map +1 -1
  188. package/dist/cli/internal/completions/descriptor.js +21 -7
  189. package/dist/cli/internal/completions/descriptor.js.map +1 -1
  190. package/dist/cli/internal/completions/fish.js +3 -3
  191. package/dist/cli/internal/completions/fish.js.map +1 -1
  192. package/dist/cli/internal/completions/powershell.js +2 -2
  193. package/dist/cli/internal/completions/powershell.js.map +1 -1
  194. package/dist/cli/internal/completions/zsh.js +2 -2
  195. package/dist/cli/internal/completions/zsh.js.map +1 -1
  196. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  197. package/dist/cluster/ClusterWorkflowEngine.js +31 -20
  198. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  199. package/dist/cluster/Entity.d.ts +43 -0
  200. package/dist/cluster/Entity.d.ts.map +1 -1
  201. package/dist/cluster/Entity.js +20 -0
  202. package/dist/cluster/Entity.js.map +1 -1
  203. package/dist/cluster/MessageRetention.d.ts +71 -0
  204. package/dist/cluster/MessageRetention.d.ts.map +1 -0
  205. package/dist/cluster/MessageRetention.js +100 -0
  206. package/dist/cluster/MessageRetention.js.map +1 -0
  207. package/dist/cluster/MessageStorage.d.ts +87 -6
  208. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  209. package/dist/cluster/MessageStorage.js +35 -5
  210. package/dist/cluster/MessageStorage.js.map +1 -1
  211. package/dist/cluster/Runners.d.ts.map +1 -1
  212. package/dist/cluster/Runners.js +13 -2
  213. package/dist/cluster/Runners.js.map +1 -1
  214. package/dist/cluster/Sharding.d.ts +13 -0
  215. package/dist/cluster/Sharding.d.ts.map +1 -1
  216. package/dist/cluster/Sharding.js.map +1 -1
  217. package/dist/cluster/ShardingConfig.d.ts +24 -2
  218. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  219. package/dist/cluster/ShardingConfig.js.map +1 -1
  220. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  221. package/dist/cluster/SqlMessageStorage.js +187 -29
  222. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  223. package/dist/cluster/index.d.ts +5 -0
  224. package/dist/cluster/index.d.ts.map +1 -1
  225. package/dist/cluster/index.js +5 -0
  226. package/dist/cluster/index.js.map +1 -1
  227. package/dist/cluster/internal/clusterAbandon.d.ts.map +1 -1
  228. package/dist/cluster/internal/clusterAbandon.js +6 -4
  229. package/dist/cluster/internal/clusterAbandon.js.map +1 -1
  230. package/dist/cluster/internal/entityManager.js +48 -4
  231. package/dist/cluster/internal/entityManager.js.map +1 -1
  232. package/dist/cluster/internal/transactionNotifications.d.ts +5 -0
  233. package/dist/cluster/internal/transactionNotifications.d.ts.map +1 -0
  234. package/dist/cluster/internal/transactionNotifications.js +5 -0
  235. package/dist/cluster/internal/transactionNotifications.js.map +1 -0
  236. package/dist/encoding/Base64.d.ts +0 -6
  237. package/dist/encoding/Base64.d.ts.map +1 -1
  238. package/dist/encoding/Base64.js +25 -5
  239. package/dist/encoding/Base64.js.map +1 -1
  240. package/dist/encoding/Base64Url.d.ts +0 -6
  241. package/dist/encoding/Base64Url.d.ts.map +1 -1
  242. package/dist/encoding/Base64Url.js +91 -8
  243. package/dist/encoding/Base64Url.js.map +1 -1
  244. package/dist/encoding/Csv.d.ts.map +1 -1
  245. package/dist/encoding/Csv.js +11 -5
  246. package/dist/encoding/Csv.js.map +1 -1
  247. package/dist/encoding/Hex.d.ts.map +1 -1
  248. package/dist/encoding/Hex.js +51 -34
  249. package/dist/encoding/Hex.js.map +1 -1
  250. package/dist/encoding/Json5.d.ts +44 -0
  251. package/dist/encoding/Json5.d.ts.map +1 -0
  252. package/dist/encoding/Json5.js +56 -0
  253. package/dist/encoding/Json5.js.map +1 -0
  254. package/dist/encoding/Jsonc.d.ts +47 -0
  255. package/dist/encoding/Jsonc.d.ts.map +1 -0
  256. package/dist/encoding/Jsonc.js +120 -0
  257. package/dist/encoding/Jsonc.js.map +1 -0
  258. package/dist/encoding/SchemaBinary.d.ts +108 -2
  259. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  260. package/dist/encoding/SchemaBinary.js +297 -11
  261. package/dist/encoding/SchemaBinary.js.map +1 -1
  262. package/dist/encoding/Xml.d.ts +25 -0
  263. package/dist/encoding/Xml.d.ts.map +1 -1
  264. package/dist/encoding/Xml.js +44 -19
  265. package/dist/encoding/Xml.js.map +1 -1
  266. package/dist/encoding/index.d.ts +10 -0
  267. package/dist/encoding/index.d.ts.map +1 -1
  268. package/dist/encoding/index.js +10 -0
  269. package/dist/encoding/index.js.map +1 -1
  270. package/dist/eventlog/EventLogServer.d.ts.map +1 -1
  271. package/dist/eventlog/EventLogServer.js +28 -12
  272. package/dist/eventlog/EventLogServer.js.map +1 -1
  273. package/dist/graphql/GraphQL.d.ts.map +1 -1
  274. package/dist/graphql/GraphQL.js +4 -1
  275. package/dist/graphql/GraphQL.js.map +1 -1
  276. package/dist/http/Headers.d.ts +5 -1
  277. package/dist/http/Headers.d.ts.map +1 -1
  278. package/dist/http/Headers.js +7 -2
  279. package/dist/http/Headers.js.map +1 -1
  280. package/dist/http/HttpClient.d.ts +72 -21
  281. package/dist/http/HttpClient.d.ts.map +1 -1
  282. package/dist/http/HttpClient.js +105 -60
  283. package/dist/http/HttpClient.js.map +1 -1
  284. package/dist/http/HttpClientError.d.ts +22 -8
  285. package/dist/http/HttpClientError.d.ts.map +1 -1
  286. package/dist/http/HttpClientError.js +68 -14
  287. package/dist/http/HttpClientError.js.map +1 -1
  288. package/dist/http/HttpEffect.d.ts +63 -4
  289. package/dist/http/HttpEffect.d.ts.map +1 -1
  290. package/dist/http/HttpEffect.js +89 -9
  291. package/dist/http/HttpEffect.js.map +1 -1
  292. package/dist/http/HttpMiddleware.js +1 -1
  293. package/dist/http/HttpMiddleware.js.map +1 -1
  294. package/dist/http/HttpServer.d.ts +80 -0
  295. package/dist/http/HttpServer.d.ts.map +1 -1
  296. package/dist/http/HttpServer.js +16 -0
  297. package/dist/http/HttpServer.js.map +1 -1
  298. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  299. package/dist/http/HttpServerRequest.js +1 -14
  300. package/dist/http/HttpServerRequest.js.map +1 -1
  301. package/dist/http/HttpStaticServer.js +10 -16
  302. package/dist/http/HttpStaticServer.js.map +1 -1
  303. package/dist/http-api/HttpApiBuilder.js +9 -1
  304. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  305. package/dist/http-api/HttpApiSchema.d.ts +19 -0
  306. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  307. package/dist/http-api/HttpApiSchema.js +8 -1
  308. package/dist/http-api/HttpApiSchema.js.map +1 -1
  309. package/dist/index.d.ts +5 -0
  310. package/dist/index.d.ts.map +1 -1
  311. package/dist/index.js +5 -0
  312. package/dist/index.js.map +1 -1
  313. package/dist/internal/base64.d.ts +2 -0
  314. package/dist/internal/base64.d.ts.map +1 -0
  315. package/dist/internal/base64.js +30 -0
  316. package/dist/internal/base64.js.map +1 -0
  317. package/dist/internal/core.js +3 -4
  318. package/dist/internal/core.js.map +1 -1
  319. package/dist/internal/dateTime.js +35 -13
  320. package/dist/internal/dateTime.js.map +1 -1
  321. package/dist/internal/effect.js +41 -17
  322. package/dist/internal/effect.js.map +1 -1
  323. package/dist/internal/equal.js +7 -0
  324. package/dist/internal/equal.js.map +1 -1
  325. package/dist/internal/jsonParser.d.ts +5 -0
  326. package/dist/internal/jsonParser.d.ts.map +1 -0
  327. package/dist/internal/jsonParser.js +280 -0
  328. package/dist/internal/jsonParser.js.map +1 -0
  329. package/dist/internal/matcher.js +1 -1
  330. package/dist/internal/matcher.js.map +1 -1
  331. package/dist/internal/persistence.js +8 -1
  332. package/dist/internal/persistence.js.map +1 -1
  333. package/dist/internal/schema/codegen.js +7 -7
  334. package/dist/internal/schema/codegen.js.map +1 -1
  335. package/dist/internal/schema/fromJsonSchemaDocument.js +20 -1
  336. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  337. package/dist/internal/schema/interpreter.js +10 -10
  338. package/dist/internal/schema/interpreter.js.map +1 -1
  339. package/dist/internal/schema/parser.js +9 -4
  340. package/dist/internal/schema/parser.js.map +1 -1
  341. package/dist/internal/schema/toEquivalence.js +6 -5
  342. package/dist/internal/schema/toEquivalence.js.map +1 -1
  343. package/dist/internal/schema/toFormatter.js +3 -2
  344. package/dist/internal/schema/toFormatter.js.map +1 -1
  345. package/dist/internal/sql.js +16 -0
  346. package/dist/internal/sql.js.map +1 -1
  347. package/dist/internal/version.js +1 -1
  348. package/dist/observability/OtlpExporter.d.ts +4 -0
  349. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  350. package/dist/observability/OtlpExporter.js +40 -12
  351. package/dist/observability/OtlpExporter.js.map +1 -1
  352. package/dist/observability/OtlpMetrics.js +1 -1
  353. package/dist/observability/OtlpMetrics.js.map +1 -1
  354. package/dist/observability/OtlpTracer.js +2 -2
  355. package/dist/observability/OtlpTracer.js.map +1 -1
  356. package/dist/persistence/PersistedQueue.d.ts +72 -3
  357. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  358. package/dist/persistence/PersistedQueue.js +142 -29
  359. package/dist/persistence/PersistedQueue.js.map +1 -1
  360. package/dist/persistence/RateLimiter.d.ts +19 -2
  361. package/dist/persistence/RateLimiter.d.ts.map +1 -1
  362. package/dist/persistence/RateLimiter.js +24 -8
  363. package/dist/persistence/RateLimiter.js.map +1 -1
  364. package/dist/process/CommandLine.d.ts +9 -9
  365. package/dist/process/CommandLine.js +6 -6
  366. package/dist/process/index.d.ts +1 -1
  367. package/dist/process/index.js +1 -1
  368. package/dist/reactivity/Atom.d.ts.map +1 -1
  369. package/dist/reactivity/Atom.js +24 -3
  370. package/dist/reactivity/Atom.js.map +1 -1
  371. package/dist/reactivity/AtomRpc.d.ts +24 -6
  372. package/dist/reactivity/AtomRpc.d.ts.map +1 -1
  373. package/dist/reactivity/AtomRpc.js.map +1 -1
  374. package/dist/rpc/OpenRpc.d.ts +384 -0
  375. package/dist/rpc/OpenRpc.d.ts.map +1 -0
  376. package/dist/rpc/OpenRpc.js +490 -0
  377. package/dist/rpc/OpenRpc.js.map +1 -0
  378. package/dist/rpc/Rpc.d.ts +22 -3
  379. package/dist/rpc/Rpc.d.ts.map +1 -1
  380. package/dist/rpc/Rpc.js.map +1 -1
  381. package/dist/rpc/RpcClient.d.ts +20 -21
  382. package/dist/rpc/RpcClient.d.ts.map +1 -1
  383. package/dist/rpc/RpcClient.js.map +1 -1
  384. package/dist/rpc/RpcServer.d.ts +23 -2
  385. package/dist/rpc/RpcServer.d.ts.map +1 -1
  386. package/dist/rpc/RpcServer.js +77 -26
  387. package/dist/rpc/RpcServer.js.map +1 -1
  388. package/dist/rpc/index.d.ts +5 -0
  389. package/dist/rpc/index.d.ts.map +1 -1
  390. package/dist/rpc/index.js +5 -0
  391. package/dist/rpc/index.js.map +1 -1
  392. package/dist/schema/SchemaCompiler/runtime.js +3 -2
  393. package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
  394. package/dist/sql/SqlClient.d.ts +67 -6
  395. package/dist/sql/SqlClient.d.ts.map +1 -1
  396. package/dist/sql/SqlClient.js +98 -27
  397. package/dist/sql/SqlClient.js.map +1 -1
  398. package/dist/sql/Statement.d.ts +6 -1
  399. package/dist/sql/Statement.d.ts.map +1 -1
  400. package/dist/sql/Statement.js +17 -22
  401. package/dist/sql/Statement.js.map +1 -1
  402. package/dist/testing/TestClock.d.ts +2 -12
  403. package/dist/testing/TestClock.d.ts.map +1 -1
  404. package/dist/testing/TestClock.js +177 -169
  405. package/dist/testing/TestClock.js.map +1 -1
  406. package/dist/workflow/DurableClock.d.ts +27 -0
  407. package/dist/workflow/DurableClock.d.ts.map +1 -1
  408. package/dist/workflow/DurableClock.js +18 -2
  409. package/dist/workflow/DurableClock.js.map +1 -1
  410. package/dist/workflow/Workflow.d.ts.map +1 -1
  411. package/dist/workflow/Workflow.js +5 -4
  412. package/dist/workflow/Workflow.js.map +1 -1
  413. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  414. package/dist/workflow/WorkflowEngine.js +14 -3
  415. package/dist/workflow/WorkflowEngine.js.map +1 -1
  416. package/package.json +5 -5
  417. package/src/ByteSize.ts +29 -14
  418. package/src/DateTime.ts +35 -2
  419. package/src/Iterable.ts +20 -14
  420. package/src/JsonSchema.ts +45 -7
  421. package/src/Match.ts +10 -8
  422. package/src/MutableRef.ts +1 -8
  423. package/src/Queue.ts +16 -11
  424. package/src/Rational.ts +1549 -0
  425. package/src/RcMap.ts +16 -14
  426. package/src/Ref.ts +0 -8
  427. package/src/Runtime.ts +84 -4
  428. package/src/Schedule.ts +8 -6
  429. package/src/Schema.ts +188 -29
  430. package/src/SchemaAST.ts +29 -13
  431. package/src/SchemaParser.ts +2 -2
  432. package/src/SchemaRepresentation.ts +13 -0
  433. package/src/ScopedCache.ts +18 -1
  434. package/src/Stream.ts +6 -5
  435. package/src/ai/AgUi.ts +485 -0
  436. package/src/ai/AgUiSchema.ts +1666 -0
  437. package/src/ai/AgUiServer.ts +451 -0
  438. package/src/ai/Chat.ts +78 -16
  439. package/src/ai/LanguageModel.ts +27 -9
  440. package/src/ai/McpClient.ts +11 -1
  441. package/src/ai/McpServer.ts +287 -67
  442. package/src/ai/Prompt.ts +6 -2
  443. package/src/ai/Response.ts +19 -3
  444. package/src/ai/Tool.ts +426 -110
  445. package/src/ai/Toolkit.ts +71 -10
  446. package/src/ai/index.ts +18 -0
  447. package/src/ai/internal/mcpCore.ts +11 -15
  448. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +9 -14
  449. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +9 -14
  450. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +9 -11
  451. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +9 -11
  452. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +80 -60
  453. package/src/ai/internal/mcpProtocol.ts +22 -3
  454. package/src/ai/internal/mcpProtocolRegistry.ts +5 -0
  455. package/src/ai/internal/mcpRuntime.ts +10 -4
  456. package/src/ai/internal/mcpSchema/v2024_11_05.ts +0 -2
  457. package/src/ai/internal/mcpSchema/v2025_03_26.ts +0 -2
  458. package/src/ai/internal/mcpSchema/v2025_06_18.ts +0 -2
  459. package/src/ai/internal/mcpSchema/v2025_11_25.ts +0 -2
  460. package/src/ai/internal/mcpSchema/v2026_07_28.ts +0 -2
  461. package/src/ai/internal/mcpSkills.ts +3 -86
  462. package/src/ai/internal/mcpStatefulRuntime.ts +0 -2
  463. package/src/ai/internal/structured-output.ts +11 -5
  464. package/src/cli/Argument.ts +86 -0
  465. package/src/cli/CliError.ts +7 -4
  466. package/src/cli/Command.ts +261 -35
  467. package/src/cli/CommandSpec.ts +508 -0
  468. package/src/cli/Completions.ts +5 -0
  469. package/src/cli/Flag.ts +106 -0
  470. package/src/cli/Param.ts +225 -23
  471. package/src/cli/index.ts +6 -0
  472. package/src/cli/internal/command.ts +3 -4
  473. package/src/cli/internal/completions/bash.ts +9 -7
  474. package/src/cli/internal/completions/descriptor.ts +37 -5
  475. package/src/cli/internal/completions/fish.ts +9 -3
  476. package/src/cli/internal/completions/powershell.ts +2 -1
  477. package/src/cli/internal/completions/zsh.ts +2 -2
  478. package/src/cluster/ClusterWorkflowEngine.ts +41 -41
  479. package/src/cluster/Entity.ts +76 -0
  480. package/src/cluster/MessageRetention.ts +111 -0
  481. package/src/cluster/MessageStorage.ts +76 -8
  482. package/src/cluster/Runners.ts +16 -2
  483. package/src/cluster/Sharding.ts +13 -0
  484. package/src/cluster/ShardingConfig.ts +12 -1
  485. package/src/cluster/SqlMessageStorage.ts +271 -41
  486. package/src/cluster/index.ts +6 -0
  487. package/src/cluster/internal/clusterAbandon.ts +7 -7
  488. package/src/cluster/internal/entityManager.ts +65 -5
  489. package/src/cluster/internal/transactionNotifications.ts +7 -0
  490. package/src/encoding/Base64.ts +26 -5
  491. package/src/encoding/Base64Url.ts +93 -10
  492. package/src/encoding/Csv.ts +11 -5
  493. package/src/encoding/Hex.ts +56 -42
  494. package/src/encoding/Json5.ts +59 -0
  495. package/src/encoding/Jsonc.ts +126 -0
  496. package/src/encoding/SchemaBinary.ts +304 -12
  497. package/src/encoding/Xml.ts +65 -16
  498. package/src/encoding/index.ts +12 -0
  499. package/src/eventlog/EventLogServer.ts +36 -12
  500. package/src/graphql/GraphQL.ts +7 -4
  501. package/src/http/Headers.ts +7 -2
  502. package/src/http/HttpClient.ts +147 -85
  503. package/src/http/HttpClientError.ts +82 -15
  504. package/src/http/HttpEffect.ts +101 -10
  505. package/src/http/HttpMiddleware.ts +2 -2
  506. package/src/http/HttpServer.ts +80 -0
  507. package/src/http/HttpServerRequest.ts +1 -19
  508. package/src/http/HttpStaticServer.ts +10 -16
  509. package/src/http-api/HttpApiBuilder.ts +11 -1
  510. package/src/http-api/HttpApiSchema.ts +22 -1
  511. package/src/index.ts +6 -0
  512. package/src/internal/base64.ts +42 -0
  513. package/src/internal/core.ts +3 -4
  514. package/src/internal/dateTime.ts +53 -16
  515. package/src/internal/effect.ts +45 -18
  516. package/src/internal/equal.ts +8 -0
  517. package/src/internal/jsonParser.ts +307 -0
  518. package/src/internal/matcher.ts +7 -3
  519. package/src/internal/persistence.ts +9 -1
  520. package/src/internal/schema/codegen.ts +8 -7
  521. package/src/internal/schema/fromJsonSchemaDocument.ts +21 -1
  522. package/src/internal/schema/interpreter.ts +10 -10
  523. package/src/internal/schema/parser.ts +8 -4
  524. package/src/internal/schema/toEquivalence.ts +7 -5
  525. package/src/internal/schema/toFormatter.ts +3 -2
  526. package/src/internal/sql.ts +25 -0
  527. package/src/internal/version.ts +1 -1
  528. package/src/observability/OtlpExporter.ts +42 -18
  529. package/src/observability/OtlpMetrics.ts +1 -1
  530. package/src/observability/OtlpTracer.ts +2 -2
  531. package/src/persistence/PersistedQueue.ts +199 -41
  532. package/src/persistence/RateLimiter.ts +30 -9
  533. package/src/process/CommandLine.ts +10 -10
  534. package/src/process/index.ts +1 -1
  535. package/src/reactivity/Atom.ts +25 -3
  536. package/src/reactivity/AtomRpc.ts +61 -45
  537. package/src/rpc/OpenRpc.ts +747 -0
  538. package/src/rpc/Rpc.ts +38 -6
  539. package/src/rpc/RpcClient.ts +45 -82
  540. package/src/rpc/RpcServer.ts +89 -29
  541. package/src/rpc/index.ts +6 -0
  542. package/src/schema/SchemaCompiler/runtime.ts +8 -3
  543. package/src/sql/SqlClient.ts +156 -36
  544. package/src/sql/Statement.ts +27 -36
  545. package/src/testing/TestClock.ts +204 -189
  546. package/src/workflow/DurableClock.ts +20 -3
  547. package/src/workflow/Workflow.ts +5 -3
  548. package/src/workflow/WorkflowEngine.ts +20 -5
@@ -75,10 +75,12 @@ const ProtoTimeZoneNamed = {
75
75
  ...ProtoTimeZone,
76
76
  _tag: "Named",
77
77
  [Hash.symbol](this: DateTime.TimeZone.Named) {
78
- return Hash.string(`Named:${this.id}`)
78
+ return Hash.string(`Named:${this.resolvedId}`)
79
79
  },
80
80
  [Equal.symbol](this: DateTime.TimeZone.Named, that: unknown) {
81
- return isTimeZone(that) && that._tag === "Named" && this.id === that.id
81
+ // Zones from older copies of effect have no `resolvedId`; their `id` is the resolved one
82
+ return isTimeZone(that) && that._tag === "Named" &&
83
+ this.resolvedId === (that.resolvedId ?? that.id)
82
84
  },
83
85
  toString(this: DateTime.TimeZone.Named) {
84
86
  return `TimeZone.Named(${this.id})`
@@ -405,16 +407,20 @@ const formatOptions: Intl.DateTimeFormatOptions = {
405
407
  hourCycle: "h23"
406
408
  }
407
409
 
408
- const zoneMakeIntl = (format: Intl.DateTimeFormat): DateTime.TimeZone.Named => {
409
- const zoneId = format.resolvedOptions().timeZone
410
- const cached = validZoneCache.get(zoneId)
410
+ const zoneMakeIntl = (
411
+ format: Intl.DateTimeFormat,
412
+ resolvedId: string,
413
+ id: string = resolvedId
414
+ ): DateTime.TimeZone.Named => {
415
+ const cached = validZoneCache.get(id)
411
416
  if (cached !== undefined) {
412
417
  return cached
413
418
  }
414
419
  const zone = Object.create(ProtoTimeZoneNamed)
415
- zone.id = zoneId
420
+ zone.id = id
421
+ zone.resolvedId = resolvedId
416
422
  zone.format = format
417
- validZoneCache.set(zoneId, zone)
423
+ validZoneCache.set(id, zone)
418
424
  return zone
419
425
  }
420
426
 
@@ -425,11 +431,17 @@ export const zoneMakeNamedUnsafe = (zoneId: string): DateTime.TimeZone.Named =>
425
431
  return cached
426
432
  }
427
433
  try {
434
+ const format = new Intl.DateTimeFormat("en-US", {
435
+ ...formatOptions,
436
+ timeZone: zoneId
437
+ })
438
+ // Intl may resolve a zone to an older alias ("Asia/Kolkata" to "Asia/Calcutta"),
439
+ // so keep the supplied name and take only its casing from Intl
440
+ const resolvedId = format.resolvedOptions().timeZone
428
441
  const zone = zoneMakeIntl(
429
- new Intl.DateTimeFormat("en-US", {
430
- ...formatOptions,
431
- timeZone: zoneId
432
- })
442
+ format,
443
+ resolvedId,
444
+ resolvedId.toLowerCase() === zoneId.toLowerCase() ? resolvedId : zoneId
433
445
  )
434
446
  validZoneCache.set(zoneId, zone)
435
447
  return zone
@@ -458,8 +470,10 @@ export const zoneMakeNamedEffect = (zoneId: string): Effect.Effect<DateTime.Time
458
470
  })
459
471
 
460
472
  /** @internal */
461
- export const zoneMakeLocal = (): DateTime.TimeZone.Named =>
462
- zoneMakeIntl(new Intl.DateTimeFormat("en-US", formatOptions))
473
+ export const zoneMakeLocal = (): DateTime.TimeZone.Named => {
474
+ const format = new Intl.DateTimeFormat("en-US", formatOptions)
475
+ return zoneMakeIntl(format, format.resolvedOptions().timeZone)
476
+ }
463
477
 
464
478
  const offsetZoneRegExp = /^(?:GMT)?[+-]/
465
479
 
@@ -1054,6 +1068,29 @@ export const subtract: {
1054
1068
  return add(self, newParts)
1055
1069
  })
1056
1070
 
1071
+ const mutateRounding = (
1072
+ self: DateTime.DateTime,
1073
+ part: DateTime.DateTime.UnitSingular,
1074
+ f: (date: Date) => void,
1075
+ disambiguation: DateTime.Disambiguation = "compatible"
1076
+ ): DateTime.DateTime => {
1077
+ if (
1078
+ self._tag === "Utc" || self.zone._tag === "Offset" ||
1079
+ part === "day" || part === "week" || part === "month" || part === "year"
1080
+ ) {
1081
+ return mutate(self, f, { disambiguation })
1082
+ }
1083
+ // keep the input's offset so rounding stays in the same occurrence of a repeated hour
1084
+ const date = toDate(self)
1085
+ const offset = date.getTime() - Math.trunc(self.epochMilliseconds)
1086
+ f(date)
1087
+ const adjustedMillis = date.getTime()
1088
+ const result = makeZonedProto(adjustedMillis - offset, self.zone)
1089
+ return zonedOffset(result) === offset
1090
+ ? result
1091
+ : makeZonedFromAdjusted(adjustedMillis, self.zone, disambiguation)
1092
+ }
1093
+
1057
1094
  const startOfDate = (date: Date, part: DateTime.DateTime.UnitSingular, options?: {
1058
1095
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
1059
1096
  }) => {
@@ -1105,7 +1142,7 @@ export const startOf: {
1105
1142
  }): A
1106
1143
  } = dual(isDateTimeArgs, (self: DateTime.DateTime, part: DateTime.DateTime.UnitSingular, options?: {
1107
1144
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
1108
- }): DateTime.DateTime => mutate(self, (date) => startOfDate(date, part, options)))
1145
+ }): DateTime.DateTime => mutateRounding(self, part, (date) => startOfDate(date, part, options)))
1109
1146
 
1110
1147
  const endOfDate = (date: Date, part: DateTime.DateTime.UnitSingular, options?: {
1111
1148
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
@@ -1158,7 +1195,7 @@ export const endOf: {
1158
1195
  }): A
1159
1196
  } = dual(isDateTimeArgs, (self: DateTime.DateTime, part: DateTime.DateTime.UnitSingular, options?: {
1160
1197
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
1161
- }): DateTime.DateTime => mutate(self, (date) => endOfDate(date, part, options)))
1198
+ }): DateTime.DateTime => mutateRounding(self, part, (date) => endOfDate(date, part, options), "later"))
1162
1199
 
1163
1200
  /** @internal */
1164
1201
  export const nearest: {
@@ -1171,7 +1208,7 @@ export const nearest: {
1171
1208
  } = dual(isDateTimeArgs, (self: DateTime.DateTime, part: DateTime.DateTime.UnitSingular, options?: {
1172
1209
  readonly weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
1173
1210
  }): DateTime.DateTime =>
1174
- mutate(self, (date) => {
1211
+ mutateRounding(self, part, (date) => {
1175
1212
  if (part === "millisecond") return
1176
1213
  const millis = date.getTime()
1177
1214
  const start = new Date(millis)
@@ -533,6 +533,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
533
533
  this._children = undefined
534
534
  this._interruptedCause = undefined
535
535
  this._yielded = undefined
536
+ this._autoYielded = false
536
537
  this._running = false
537
538
  this._deferredInterrupt = false
538
539
  this._parent = undefined
@@ -553,6 +554,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
553
554
  declare _children: Set<FiberImpl<any, any>> | undefined
554
555
  declare _interruptedCause: Cause.Cause<never> | undefined
555
556
  declare _yielded: Exit.Exit<any, any> | (() => void) | undefined
557
+ declare _autoYielded: boolean
556
558
  declare _running: boolean
557
559
  declare _deferredInterrupt: boolean
558
560
  declare _parent: FiberImpl<any, any> | undefined
@@ -674,8 +676,11 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
674
676
  const prevRunning = this._running
675
677
  this._running = true
676
678
  let yielding = false
679
+ let resuming = this._autoYielded
680
+ this._autoYielded = false
677
681
  let current: Primitive | Yield = effect
678
- this.currentOpCount = 0
682
+ // Count the resumption as the exitVoid instruction it replaces.
683
+ this.currentOpCount = resuming ? 1 : 0
679
684
  try {
680
685
  while (true) {
681
686
  try {
@@ -686,18 +691,23 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
686
691
  this.currentOpCount++
687
692
  // Refresh the cache because a primitive can replace the fiber context.
688
693
  const cache = this.cache
694
+ // Only automatic resumptions must run their saved instruction before
695
+ // checking the budget; other slices retain their existing yield points.
689
696
  if (
697
+ !resuming &&
690
698
  !yielding &&
691
699
  !cache.preventYield &&
692
700
  cache.scheduler.shouldYield(this as any)
693
701
  ) {
702
+ // If dispatch throws, evaluate its defect instead of retrying the yield.
694
703
  yielding = true
695
- const prev = current
696
- current = flatMap(yieldNow, () => prev as any) as any
704
+ current = this.yieldNow(current as Primitive, 0, true)
705
+ } else {
706
+ resuming = false
707
+ current = cache.tracerContext
708
+ ? cache.tracerContext(current as any, this)
709
+ : (current as any)[evaluate](this)
697
710
  }
698
- current = cache.tracerContext
699
- ? cache.tracerContext(current as any, this)
700
- : (current as any)[evaluate](this)
701
711
  if (current === Yield) {
702
712
  const yielded = this._yielded!
703
713
  if (ExitTypeId in yielded) {
@@ -760,6 +770,17 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
760
770
  this._yielded = value
761
771
  return Yield
762
772
  }
773
+ yieldNow(effect: Primitive, priority = 0, automatic = false): Yield {
774
+ let resumed = false
775
+ this.currentDispatcher.scheduleTask(() => {
776
+ if (resumed) return
777
+ this._autoYielded = automatic
778
+ this.evaluate(effect)
779
+ }, priority)
780
+ return this.yieldWith(() => {
781
+ resumed = true
782
+ })
783
+ }
763
784
  children(): Set<Fiber.Fiber<any, any>> {
764
785
  return (this._children ??= new Set())
765
786
  }
@@ -1070,14 +1091,7 @@ export const fromNullishOr = <A>(value: A): Effect.Effect<NonNullable<A>, Cause.
1070
1091
  export const yieldNowWith: (priority?: number) => Effect.Effect<void> = makePrimitive({
1071
1092
  op: "Yield",
1072
1093
  [evaluate](fiber) {
1073
- let resumed = false
1074
- fiber.currentDispatcher.scheduleTask(() => {
1075
- if (resumed) return
1076
- fiber.evaluate(exitVoid as any)
1077
- }, this[args] ?? 0)
1078
- return fiber.yieldWith(() => {
1079
- resumed = true
1080
- })
1094
+ return fiber.yieldNow(exitVoid as any, this[args] ?? 0)
1081
1095
  }
1082
1096
  })
1083
1097
 
@@ -1707,8 +1721,9 @@ export const raceAll = <Eff extends Effect.Effect<any, any, any>>(
1707
1721
  const isWinner = !done
1708
1722
  done = true
1709
1723
  resume(exit)
1710
- if (isWinner && options?.onWinner) {
1711
- options.onWinner({ fiber, index: i, parentFiber: parent })
1724
+ if (isWinner) {
1725
+ interruptRaceLosers(fibers, parent)
1726
+ options?.onWinner?.({ fiber, index: i, parentFiber: parent })
1712
1727
  }
1713
1728
  }
1714
1729
 
@@ -1755,14 +1770,26 @@ export const raceAllFirst = <Eff extends Effect.Effect<any, any, any>>(
1755
1770
  const isWinner = !done
1756
1771
  done = true
1757
1772
  resume(exit)
1758
- if (isWinner && options?.onWinner) {
1759
- options.onWinner({ fiber, index, parentFiber: parent })
1773
+ if (isWinner) {
1774
+ interruptRaceLosers(fibers, parent)
1775
+ options?.onWinner?.({ fiber, index, parentFiber: parent })
1760
1776
  }
1761
1777
  })
1762
1778
  }
1763
1779
  })
1764
1780
  })
1765
1781
 
1782
+ // Interrupt the losers as soon as the race settles. Waiting for the parent to
1783
+ // resume leaves a gap, for example a scheduler yield, where a loser can
1784
+ // complete and have its result discarded. The parent still awaits the losers
1785
+ // on exit. Runs after `resume`, so a loser's interrupt cannot settle the race.
1786
+ const interruptRaceLosers = (fibers: Set<Fiber.Fiber<any, any>>, parent: Fiber.Fiber<any, any>) => {
1787
+ const annotations = fiberStackAnnotations(parent)
1788
+ for (const fiber of fibers) {
1789
+ fiber.interruptUnsafe(parent.id, annotations)
1790
+ }
1791
+ }
1792
+
1766
1793
  /** @internal */
1767
1794
  export const race: {
1768
1795
  <A2, E2, R2>(
@@ -1,3 +1,8 @@
1
+ // JavaScriptCore (Bun, Safari) stamps the construction site onto every Error as
2
+ // non-enumerable own properties. Like `stack`, they describe where the error was
3
+ // created, not what it is.
4
+ const errorSiteKeys = ["line", "column", "sourceURL", "originalLine", "originalColumn"]
5
+
1
6
  /** @internal */
2
7
  export const getAllObjectKeys = (obj: object): Set<PropertyKey> => {
3
8
  const keys = new Set<PropertyKey>(Reflect.ownKeys(obj))
@@ -5,6 +10,9 @@ export const getAllObjectKeys = (obj: object): Set<PropertyKey> => {
5
10
 
6
11
  if (obj instanceof Error) {
7
12
  keys.delete("stack")
13
+ for (const key of errorSiteKeys) {
14
+ if (!Object.prototype.propertyIsEnumerable.call(obj, key)) keys.delete(key)
15
+ }
8
16
  }
9
17
 
10
18
  const proto = Object.getPrototypeOf(obj)
@@ -0,0 +1,307 @@
1
+ const json5Space = /(?:[\t\n\v\f\r \u00A0\u2028\u2029\uFEFF\p{Zs}]|\/\/[^\n\r\u2028\u2029]*|\/\*[^]*?\*\/)*/uy
2
+ const idStart = /[$_\p{ID_Start}]/u
3
+ const idPart = /[$\u200C\u200D\p{ID_Continue}]/u
4
+ const idName = /[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*/uy
5
+ const hexDigits = /[\da-fA-F]*/y
6
+ const isDigit = (code: number) => code >= 0x30 && code <= 0x39
7
+ const isAsciiIdPart = (code: number) =>
8
+ (code >= 0x61 && code <= 0x7a) || (code >= 0x41 && code <= 0x5a) || isDigit(code) || code === 0x5f || code === 0x24
9
+
10
+ const jsoncSpace = /(?:[ \t\r\n]|\/\/[^\r\n]*|\/\*[^]*?\*\/)*/uy
11
+ const jsonNumber = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/y
12
+
13
+ // The escapes JSON and JSON5 share, indexed by the character after the backslash.
14
+ // A null prototype keeps absent entries from resolving to inherited properties.
15
+ const escapes: Record<number, string | undefined> = Object.create(null)
16
+ for (const [escape, value] of ["\"\"", "\\\\", "//", "b\b", "f\f", "n\n", "r\r", "t\t"]) {
17
+ escapes[escape.charCodeAt(0)] = value
18
+ }
19
+
20
+ // Runs of string content that need no further inspection.
21
+ const json5Double = /[^"\\\n\r]*/y
22
+ const json5Single = /[^'\\\n\r]*/y
23
+ // JSON forbids unescaped U+0000 through U+001F.
24
+ // oxlint-disable-next-line no-control-regex
25
+ const jsonDouble = /[^"\\\x00-\x1f]*/y
26
+
27
+ type Format = "JSON5" | "JSONC"
28
+
29
+ export const syntaxError = (text: string, at: number, format: Format): SyntaxError => {
30
+ const json5 = format === "JSON5"
31
+ const lines = text.slice(0, at).split(json5 ? /\r\n|[\n\r\u2028\u2029]/ : /\r\n|[\n\r]/)
32
+ return new SyntaxError(
33
+ `Invalid ${json5 ? "JSON5" : "JSONC"} at line ${lines.length}, column ${lines[lines.length - 1].length + 1}`
34
+ )
35
+ }
36
+
37
+ type Frame =
38
+ | { readonly object: true; readonly value: Record<string, unknown>; key: string; first: boolean }
39
+ | { readonly object: false; readonly value: Array<unknown>; first: boolean }
40
+
41
+ const set = (object: Record<string, unknown>, key: string, value: unknown): void => {
42
+ // Members are own data properties, as with JSON.parse. Assignment creates one unless
43
+ // the key is inherited (`__proto__`, `constructor`, added accessors, ...), where it
44
+ // could run a setter or throw, so inherited keys are defined directly.
45
+ if (key in Object.prototype) {
46
+ Object.defineProperty(object, key, { value, writable: true, enumerable: true, configurable: true })
47
+ } else object[key] = value
48
+ }
49
+
50
+ // JSONC only uses the strict mode to locate errors after JSON.parse fails.
51
+ export const parse = (text: string, format: Format): unknown => {
52
+ const json5 = format === "JSON5"
53
+ const space = json5 ? json5Space : jsoncSpace
54
+ // JSON strings forbid raw characters below U+0020; JSON5 strings only forbid line breaks.
55
+ const plainFloor = json5 ? 0 : 0x20
56
+ let i = 0
57
+
58
+ const fail = (at: number): never => {
59
+ throw syntaxError(text, at, format)
60
+ }
61
+
62
+ /** Skips whitespace and comments, rejecting a `/` that starts neither. */
63
+ const skip = () => {
64
+ // ASCII whitespace dominates formatted documents; the pattern handles the rest.
65
+ let code = text.charCodeAt(i)
66
+ while (code === 0x20 || code === 0x0a || code === 0x0d || code === 0x09) code = text.charCodeAt(++i)
67
+ if (code > 0x20 && code !== 0x2f && code < 0xa0) return
68
+ space.lastIndex = i
69
+ space.test(text)
70
+ i = space.lastIndex
71
+ if (text.charCodeAt(i) === 0x2f) {
72
+ fail(text.charAt(i + 1) === "*" ? text.length : i + 1)
73
+ }
74
+ }
75
+
76
+ /** Advances past a sticky pattern at `i`, returning the matched length. */
77
+ const run = (pattern: RegExp) => {
78
+ pattern.lastIndex = i
79
+ const length = pattern.test(text) ? pattern.lastIndex - i : 0
80
+ i += length
81
+ return length
82
+ }
83
+
84
+ const word = <A>(literal: string, result: A): A => {
85
+ if (!text.startsWith(literal, i)) {
86
+ let at = i
87
+ while (text.charAt(at) === literal[at - i]) at++
88
+ fail(at)
89
+ }
90
+ i += literal.length
91
+ return result
92
+ }
93
+
94
+ const hex = (count: number) => {
95
+ let value = 0
96
+ for (const end = i + count; i < end; i++) {
97
+ const code = text.charCodeAt(i)
98
+ const lower = code | 0x20
99
+ if (isDigit(code)) value = value * 16 + code - 0x30
100
+ else if (lower >= 0x61 && lower <= 0x66) value = value * 16 + lower - 0x57
101
+ else fail(i)
102
+ }
103
+ return String.fromCharCode(value)
104
+ }
105
+
106
+ const number = () => {
107
+ if (!json5) {
108
+ const start = i
109
+ if (run(jsonNumber) === 0) fail(i)
110
+ return Number(text.slice(start, i))
111
+ }
112
+ let code = text.charCodeAt(i)
113
+ let sign = 1
114
+ if (code === 0x2b || code === 0x2d) {
115
+ if (code === 0x2d) sign = -1
116
+ code = text.charCodeAt(++i)
117
+ }
118
+ const start = i
119
+ if (code === 0x49) return word("Infinity", sign * Infinity)
120
+ if (code === 0x4e) return word("NaN", NaN)
121
+ if (code === 0x30 && (text.charCodeAt(i + 1) | 0x20) === 0x78) {
122
+ i += 2
123
+ if (run(hexDigits) === 0) fail(i)
124
+ return sign * Number(text.slice(start, i))
125
+ }
126
+ // Integers below 2^53 are accumulated directly; anything else goes through Number.
127
+ let integer = 0
128
+ if (code === 0x30) code = text.charCodeAt(++i)
129
+ else if (isDigit(code)) {
130
+ do {
131
+ integer = integer * 10 + code - 0x30
132
+ code = text.charCodeAt(++i)
133
+ } while (isDigit(code))
134
+ } else if (code !== 0x2e) fail(i)
135
+ if (code !== 0x2e && code !== 0x65 && code !== 0x45 && i - start < 16) return sign * integer
136
+ if (code === 0x2e) {
137
+ const fraction = ++i
138
+ while (isDigit(text.charCodeAt(i))) i++
139
+ // A leading decimal point needs digits after it; a trailing one does not.
140
+ if (i === fraction && fraction === start + 1) fail(i)
141
+ code = text.charCodeAt(i)
142
+ }
143
+ if (code === 0x65 || code === 0x45) {
144
+ code = text.charCodeAt(++i)
145
+ if (code === 0x2b || code === 0x2d) i++
146
+ const exponent = i
147
+ while (isDigit(text.charCodeAt(i))) i++
148
+ if (i === exponent) fail(i)
149
+ }
150
+ return sign * Number(text.slice(start, i))
151
+ }
152
+
153
+ const string = (quote: number) => {
154
+ const plain = quote === 0x27 ? json5Single : json5 ? json5Double : jsonDouble
155
+ let result = ""
156
+ for (i++;;) {
157
+ // Plain content runs until the quote, an escape, a line break, a control character
158
+ // JSON forbids, or the end of input, where `code` is NaN and fails the last test.
159
+ const start = i
160
+ let code = text.charCodeAt(i)
161
+ // Short runs are cheaper to scan by hand; long runs are handed to the pattern.
162
+ const handoff = i + 24
163
+ while (code !== quote && code !== 0x5c && code !== 0x0a && code !== 0x0d && code >= plainFloor) {
164
+ if (++i === handoff) {
165
+ run(plain)
166
+ code = text.charCodeAt(i)
167
+ break
168
+ }
169
+ code = text.charCodeAt(i)
170
+ }
171
+ result += text.slice(start, i)
172
+ i++
173
+ if (code === quote) return result
174
+ // Anything else that stops a plain run is an escape or a forbidden character.
175
+ if (code !== 0x5c) fail(i - 1)
176
+ const escape = text.charCodeAt(i++)
177
+ const simple = escapes[escape]
178
+ if (simple !== undefined) result += simple
179
+ else if (escape === 0x75) result += hex(4)
180
+ else if (!json5 || i > text.length || (escape >= 0x31 && escape <= 0x39)) fail(i - 1)
181
+ else if (escape === 0x76) result += "\v"
182
+ else if (escape === 0x78) result += hex(2)
183
+ else if (escape === 0x30) {
184
+ if (isDigit(text.charCodeAt(i))) fail(i)
185
+ result += "\0"
186
+ } else if (escape === 0x0d) {
187
+ // A CR LF line continuation contributes nothing, like a single line terminator.
188
+ if (text.charCodeAt(i) === 0x0a) i++
189
+ } else if (escape !== 0x0a && escape !== 0x2028 && escape !== 0x2029) result += text[i - 1]
190
+ }
191
+ }
192
+
193
+ const identifier = () => {
194
+ const start = i
195
+ let code = text.charCodeAt(i)
196
+ if (isAsciiIdPart(code) && !isDigit(code)) {
197
+ do code = text.charCodeAt(++i)
198
+ while (isAsciiIdPart(code))
199
+ // Past an ASCII name, only an escape or a non-ASCII character can continue it.
200
+ if (code !== 0x5c && !(code >= 0x80)) return text.slice(start, i)
201
+ i = start
202
+ }
203
+ run(idName)
204
+ let name = text.slice(start, i)
205
+ if (name !== "" && text.charAt(i) !== "\\") return name
206
+ // Escapes are validated one code point at a time.
207
+ for (;;) {
208
+ const at = i
209
+ const valid = name === "" ? idStart : idPart
210
+ let c = String.fromCodePoint(text.codePointAt(i) ?? 0)
211
+ if (c === "\\") {
212
+ if (text.charAt(i + 1) !== "u") fail(i + 1)
213
+ i += 2
214
+ c = hex(4)
215
+ if (!valid.test(c)) fail(at)
216
+ } else if (i < text.length && valid.test(c)) i += c.length
217
+ else if (name === "") fail(i)
218
+ else return name
219
+ name += c
220
+ }
221
+ }
222
+
223
+ const stack: Array<Frame> = []
224
+
225
+ /**
226
+ * Reads a value at `i`, which must already be past any whitespace. Opening a
227
+ * collection returns `undefined`; the collection is completed later.
228
+ */
229
+ const value = (): unknown => {
230
+ const code = text.charCodeAt(i)
231
+ switch (code) {
232
+ case 0x7b:
233
+ stack.push({ object: true, value: {}, key: "", first: true })
234
+ i++
235
+ return undefined
236
+ case 0x5b:
237
+ stack.push({ object: false, value: [], first: true })
238
+ i++
239
+ return undefined
240
+ case 0x22:
241
+ return string(0x22)
242
+ case 0x27:
243
+ return json5 ? string(0x27) : fail(i)
244
+ case 0x6e:
245
+ return word("null", null)
246
+ case 0x74:
247
+ return word("true", true)
248
+ case 0x66:
249
+ return word("false", false)
250
+ case 0x2b:
251
+ case 0x2d:
252
+ case 0x2e:
253
+ case 0x49:
254
+ case 0x4e:
255
+ return number()
256
+ }
257
+ return isDigit(code) ? number() : fail(i)
258
+ }
259
+
260
+ /** After a member: consumes a comma unless the collection ends. */
261
+ const separated = (close: number) => {
262
+ skip()
263
+ const code = text.charCodeAt(i)
264
+ if (code === close) return
265
+ if (code !== 0x2c) fail(i)
266
+ i++
267
+ skip()
268
+ if (!json5 && text.charCodeAt(i) === close) fail(i)
269
+ }
270
+
271
+ skip()
272
+ let result = value()
273
+ // An explicit stack keeps deep nesting off the call stack.
274
+ while (stack.length > 0) {
275
+ const frame = stack[stack.length - 1]
276
+ const close = frame.object ? 0x7d : 0x5d
277
+ if (frame.first) skip()
278
+ else separated(close)
279
+ if (text.charCodeAt(i) === close) {
280
+ stack.pop()
281
+ i++
282
+ const parent = stack[stack.length - 1]
283
+ if (parent === undefined) result = frame.value
284
+ else if (parent.object) set(parent.value, parent.key, frame.value)
285
+ else parent.value.push(frame.value)
286
+ continue
287
+ }
288
+ frame.first = false
289
+ if (!frame.object) {
290
+ const item = value()
291
+ if (item !== undefined) frame.value.push(item)
292
+ } else {
293
+ const quote = text.charCodeAt(i)
294
+ if (!json5 && quote !== 0x22) fail(i)
295
+ const key = quote === 0x22 || quote === 0x27 ? string(quote) : identifier()
296
+ skip()
297
+ if (text.charCodeAt(i++) !== 0x3a) fail(i - 1)
298
+ skip()
299
+ const item = value()
300
+ if (item === undefined) frame.key = key
301
+ else set(frame.value, key, item)
302
+ }
303
+ }
304
+ skip()
305
+ if (i < text.length) fail(i)
306
+ return result
307
+ }
@@ -34,6 +34,10 @@ type ValueTagHandlers<I> = {
34
34
  readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, { readonly _tag: Tag }>) => any
35
35
  }
36
36
 
37
+ type HandledKeys<P, Keys extends keyof P = keyof P> = {
38
+ readonly [K in Keys]-?: undefined extends P[K] ? never : K
39
+ }[Keys]
40
+
37
41
  const TypeMatcherProto: Omit<TypeMatcher<any, any, any, any, any, any>, "cases" | "select"> = {
38
42
  [TypeId]: {
39
43
  _input: identity,
@@ -442,7 +446,7 @@ export const discriminators = <D extends string>(field: D) =>
442
446
  fields: Contextual<P, PartialTagHandlers<D, R, Ret>>
443
447
  ) => {
444
448
  const predicate = makeWhen(
445
- (arg: any) => arg != null && Object.hasOwn(fields, arg[field]),
449
+ (arg: any) => arg != null && Object.hasOwn(fields, arg[field]) && (fields as any)[arg[field]] !== undefined,
446
450
  (data: any) => (fields as any)[data[field]](data)
447
451
  )
448
452
 
@@ -450,8 +454,8 @@ export const discriminators = <D extends string>(field: D) =>
450
454
  self: Matcher<I, F, R, A, Pr, Ret>
451
455
  ): Matcher<
452
456
  I,
453
- Types.AddWithout<F, Extract<R, Record<D, keyof P>>>,
454
- Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, keyof P>>>>,
457
+ Types.AddWithout<F, Extract<R, Record<D, HandledKeys<P>>>>,
458
+ Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, HandledKeys<P>>>>>,
455
459
  A | ReturnType<P[keyof P] & {}>,
456
460
  Pr,
457
461
  Ret
@@ -1,13 +1,21 @@
1
1
  /** @internal */
2
2
  export const sqlCleanupBatchSize = 1000
3
3
 
4
+ /**
5
+ * Percent-encodes `%` and `:` so the result contains no `:` and distinct inputs
6
+ * stay distinct.
7
+ *
8
+ * @internal
9
+ */
10
+ export const escapeKeySegment = (segment: string): string => segment.replace(/%/g, "%25").replace(/:/g, "%3A")
11
+
4
12
  /**
5
13
  * Key prefix for a persistence store. The store id is escaped so the namespace
6
14
  * always ends at its first `:`, and distinct store / key pairs never collide.
7
15
  *
8
16
  * @internal
9
17
  */
10
- export const storeNamespace = (storeId: string): string => `${storeId.replace(/%/g, "%25").replace(/:/g, "%3A")}:`
18
+ export const storeNamespace = (storeId: string): string => `${escapeKeySegment(storeId)}:`
11
19
 
12
20
  /** @internal */
13
21
  export const escapeRedisGlob = (pattern: string): string => pattern.replace(/[\\*?[\]]/g, "\\$&")