effect 4.0.5 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1177) hide show
  1. package/ai-docs/package.json +1 -1
  2. package/ai-docs/src/06_schedule/10_schedules.ts +5 -4
  3. package/ai-docs/tsconfig.json +3 -1
  4. package/dist/Arbitrary.d.ts +10 -2
  5. package/dist/Arbitrary.d.ts.map +1 -1
  6. package/dist/Arbitrary.js +2 -1
  7. package/dist/Arbitrary.js.map +1 -1
  8. package/dist/Array.d.ts +117 -52
  9. package/dist/Array.d.ts.map +1 -1
  10. package/dist/Array.js +41 -20
  11. package/dist/Array.js.map +1 -1
  12. package/dist/Bytes.d.ts +79 -0
  13. package/dist/Bytes.d.ts.map +1 -0
  14. package/dist/Bytes.js +109 -0
  15. package/dist/Bytes.js.map +1 -0
  16. package/dist/Channel.d.ts +181 -13
  17. package/dist/Channel.d.ts.map +1 -1
  18. package/dist/Channel.js +144 -34
  19. package/dist/Channel.js.map +1 -1
  20. package/dist/ChannelSchema.d.ts.map +1 -1
  21. package/dist/ChannelSchema.js.map +1 -1
  22. package/dist/Chunk.d.ts +39 -21
  23. package/dist/Chunk.d.ts.map +1 -1
  24. package/dist/Chunk.js +26 -17
  25. package/dist/Chunk.js.map +1 -1
  26. package/dist/Config.d.ts.map +1 -1
  27. package/dist/Config.js +8 -3
  28. package/dist/Config.js.map +1 -1
  29. package/dist/ConfigProvider.d.ts.map +1 -1
  30. package/dist/ConfigProvider.js +2 -1
  31. package/dist/ConfigProvider.js.map +1 -1
  32. package/dist/Cron.d.ts +2 -2
  33. package/dist/Cron.d.ts.map +1 -1
  34. package/dist/Cron.js +6 -3
  35. package/dist/Cron.js.map +1 -1
  36. package/dist/Data.d.ts +54 -235
  37. package/dist/Data.d.ts.map +1 -1
  38. package/dist/Data.js.map +1 -1
  39. package/dist/Duration.d.ts.map +1 -1
  40. package/dist/Duration.js +56 -16
  41. package/dist/Duration.js.map +1 -1
  42. package/dist/Effect.d.ts +488 -164
  43. package/dist/Effect.d.ts.map +1 -1
  44. package/dist/Effect.js +204 -38
  45. package/dist/Effect.js.map +1 -1
  46. package/dist/Equal.d.ts.map +1 -1
  47. package/dist/Equal.js +8 -1
  48. package/dist/Equal.js.map +1 -1
  49. package/dist/Equivalence.d.ts +2 -1
  50. package/dist/Equivalence.d.ts.map +1 -1
  51. package/dist/Equivalence.js +12 -8
  52. package/dist/Equivalence.js.map +1 -1
  53. package/dist/Exit.d.ts +27 -12
  54. package/dist/Exit.d.ts.map +1 -1
  55. package/dist/Exit.js +8 -3
  56. package/dist/Exit.js.map +1 -1
  57. package/dist/FiberHandle.d.ts +2 -0
  58. package/dist/FiberHandle.d.ts.map +1 -1
  59. package/dist/FiberHandle.js +9 -4
  60. package/dist/FiberHandle.js.map +1 -1
  61. package/dist/FiberMap.d.ts +2 -0
  62. package/dist/FiberMap.d.ts.map +1 -1
  63. package/dist/FiberMap.js +5 -2
  64. package/dist/FiberMap.js.map +1 -1
  65. package/dist/FileSystem.d.ts +5 -0
  66. package/dist/FileSystem.d.ts.map +1 -1
  67. package/dist/FileSystem.js +3 -0
  68. package/dist/FileSystem.js.map +1 -1
  69. package/dist/Formatter.d.ts.map +1 -1
  70. package/dist/Formatter.js +27 -13
  71. package/dist/Formatter.js.map +1 -1
  72. package/dist/Graph.d.ts.map +1 -1
  73. package/dist/Graph.js.map +1 -1
  74. package/dist/Hash.d.ts.map +1 -1
  75. package/dist/Hash.js +4 -1
  76. package/dist/Hash.js.map +1 -1
  77. package/dist/HashSet.d.ts.map +1 -1
  78. package/dist/HashSet.js.map +1 -1
  79. package/dist/Iterable.d.ts.map +1 -1
  80. package/dist/Iterable.js +18 -17
  81. package/dist/Iterable.js.map +1 -1
  82. package/dist/JsonPatch.js +4 -0
  83. package/dist/JsonPatch.js.map +1 -1
  84. package/dist/JsonSchema.d.ts +9 -3
  85. package/dist/JsonSchema.d.ts.map +1 -1
  86. package/dist/JsonSchema.js +32 -43
  87. package/dist/JsonSchema.js.map +1 -1
  88. package/dist/Layer.d.ts.map +1 -1
  89. package/dist/Layer.js +2 -2
  90. package/dist/Layer.js.map +1 -1
  91. package/dist/ManagedRuntime.d.ts +19 -1
  92. package/dist/ManagedRuntime.d.ts.map +1 -1
  93. package/dist/ManagedRuntime.js +62 -6
  94. package/dist/ManagedRuntime.js.map +1 -1
  95. package/dist/Metric.d.ts +135 -3
  96. package/dist/Metric.d.ts.map +1 -1
  97. package/dist/Metric.js +197 -25
  98. package/dist/Metric.js.map +1 -1
  99. package/dist/MutableHashMap.d.ts.map +1 -1
  100. package/dist/MutableHashMap.js.map +1 -1
  101. package/dist/MutableList.d.ts +5 -2
  102. package/dist/MutableList.d.ts.map +1 -1
  103. package/dist/MutableList.js +7 -5
  104. package/dist/MutableList.js.map +1 -1
  105. package/dist/MutableRef.d.ts.map +1 -1
  106. package/dist/MutableRef.js +7 -0
  107. package/dist/MutableRef.js.map +1 -1
  108. package/dist/Number.js +2 -2
  109. package/dist/Number.js.map +1 -1
  110. package/dist/Optic.d.ts.map +1 -1
  111. package/dist/Optic.js.map +1 -1
  112. package/dist/PartitionedSemaphore.d.ts +2 -1
  113. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  114. package/dist/PartitionedSemaphore.js +22 -12
  115. package/dist/PartitionedSemaphore.js.map +1 -1
  116. package/dist/Path.d.ts.map +1 -1
  117. package/dist/Path.js +8 -1
  118. package/dist/Path.js.map +1 -1
  119. package/dist/Pool.d.ts.map +1 -1
  120. package/dist/Pool.js +77 -27
  121. package/dist/Pool.js.map +1 -1
  122. package/dist/PubSub.d.ts.map +1 -1
  123. package/dist/PubSub.js +17 -13
  124. package/dist/PubSub.js.map +1 -1
  125. package/dist/Queue.d.ts +4 -1
  126. package/dist/Queue.d.ts.map +1 -1
  127. package/dist/Queue.js +4 -1
  128. package/dist/Queue.js.map +1 -1
  129. package/dist/Random.d.ts.map +1 -1
  130. package/dist/Random.js +1 -1
  131. package/dist/Random.js.map +1 -1
  132. package/dist/RcMap.d.ts +12 -7
  133. package/dist/RcMap.d.ts.map +1 -1
  134. package/dist/RcMap.js +9 -6
  135. package/dist/RcMap.js.map +1 -1
  136. package/dist/Record.d.ts +51 -0
  137. package/dist/Record.d.ts.map +1 -1
  138. package/dist/Record.js +17 -0
  139. package/dist/Record.js.map +1 -1
  140. package/dist/Ref.d.ts.map +1 -1
  141. package/dist/Ref.js +8 -0
  142. package/dist/Ref.js.map +1 -1
  143. package/dist/References.d.ts +5 -4
  144. package/dist/References.d.ts.map +1 -1
  145. package/dist/References.js +5 -4
  146. package/dist/References.js.map +1 -1
  147. package/dist/RequestResolver.d.ts +31 -1
  148. package/dist/RequestResolver.d.ts.map +1 -1
  149. package/dist/RequestResolver.js +39 -4
  150. package/dist/RequestResolver.js.map +1 -1
  151. package/dist/Resource.js +1 -1
  152. package/dist/Resource.js.map +1 -1
  153. package/dist/Runtime.d.ts +3 -3
  154. package/dist/Runtime.d.ts.map +1 -1
  155. package/dist/Runtime.js +18 -15
  156. package/dist/Runtime.js.map +1 -1
  157. package/dist/Schedule.d.ts.map +1 -1
  158. package/dist/Schedule.js +1 -1
  159. package/dist/Schedule.js.map +1 -1
  160. package/dist/Schema.d.ts +408 -340
  161. package/dist/Schema.d.ts.map +1 -1
  162. package/dist/Schema.js +370 -47
  163. package/dist/Schema.js.map +1 -1
  164. package/dist/SchemaAST.d.ts +9 -7
  165. package/dist/SchemaAST.d.ts.map +1 -1
  166. package/dist/SchemaAST.js +38 -25
  167. package/dist/SchemaAST.js.map +1 -1
  168. package/dist/SchemaGetter.d.ts +8 -3
  169. package/dist/SchemaGetter.d.ts.map +1 -1
  170. package/dist/SchemaGetter.js +15 -5
  171. package/dist/SchemaGetter.js.map +1 -1
  172. package/dist/SchemaIssue.d.ts +4 -4
  173. package/dist/SchemaIssue.d.ts.map +1 -1
  174. package/dist/SchemaIssue.js +29 -51
  175. package/dist/SchemaIssue.js.map +1 -1
  176. package/dist/SchemaParser.d.ts.map +1 -1
  177. package/dist/SchemaParser.js +48 -22
  178. package/dist/SchemaParser.js.map +1 -1
  179. package/dist/SchemaRepresentation.d.ts +75 -11
  180. package/dist/SchemaRepresentation.d.ts.map +1 -1
  181. package/dist/SchemaRepresentation.js +41 -13
  182. package/dist/SchemaRepresentation.js.map +1 -1
  183. package/dist/SchemaTransformation.d.ts +5 -2
  184. package/dist/SchemaTransformation.d.ts.map +1 -1
  185. package/dist/SchemaTransformation.js +10 -3
  186. package/dist/SchemaTransformation.js.map +1 -1
  187. package/dist/Scope.d.ts +12 -2
  188. package/dist/Scope.d.ts.map +1 -1
  189. package/dist/Scope.js +5 -0
  190. package/dist/Scope.js.map +1 -1
  191. package/dist/ScopedCache.d.ts +10 -7
  192. package/dist/ScopedCache.d.ts.map +1 -1
  193. package/dist/ScopedCache.js +9 -5
  194. package/dist/ScopedCache.js.map +1 -1
  195. package/dist/SemVer.d.ts +1196 -0
  196. package/dist/SemVer.d.ts.map +1 -0
  197. package/dist/SemVer.js +756 -0
  198. package/dist/SemVer.js.map +1 -0
  199. package/dist/SemVerRange.d.ts +559 -0
  200. package/dist/SemVerRange.d.ts.map +1 -0
  201. package/dist/SemVerRange.js +551 -0
  202. package/dist/SemVerRange.js.map +1 -0
  203. package/dist/Semaphore.d.ts.map +1 -1
  204. package/dist/Semaphore.js +54 -35
  205. package/dist/Semaphore.js.map +1 -1
  206. package/dist/Sink.d.ts.map +1 -1
  207. package/dist/Sink.js +13 -4
  208. package/dist/Sink.js.map +1 -1
  209. package/dist/Stream.d.ts +235 -8
  210. package/dist/Stream.d.ts.map +1 -1
  211. package/dist/Stream.js +167 -70
  212. package/dist/Stream.js.map +1 -1
  213. package/dist/String.d.ts +7 -2
  214. package/dist/String.d.ts.map +1 -1
  215. package/dist/String.js +11 -6
  216. package/dist/String.js.map +1 -1
  217. package/dist/TextDiff.d.ts +399 -0
  218. package/dist/TextDiff.d.ts.map +1 -0
  219. package/dist/TextDiff.js +634 -0
  220. package/dist/TextDiff.js.map +1 -0
  221. package/dist/Tracer.d.ts +11 -1
  222. package/dist/Tracer.d.ts.map +1 -1
  223. package/dist/Tracer.js +6 -1
  224. package/dist/Tracer.js.map +1 -1
  225. package/dist/TxHashMap.d.ts.map +1 -1
  226. package/dist/TxHashMap.js.map +1 -1
  227. package/dist/TxHashSet.d.ts.map +1 -1
  228. package/dist/TxHashSet.js.map +1 -1
  229. package/dist/ai/AiError.d.ts +68 -4
  230. package/dist/ai/AiError.d.ts.map +1 -1
  231. package/dist/ai/AiError.js +50 -2
  232. package/dist/ai/AiError.js.map +1 -1
  233. package/dist/ai/Chat.d.ts +1 -2
  234. package/dist/ai/Chat.d.ts.map +1 -1
  235. package/dist/ai/Chat.js +6 -3
  236. package/dist/ai/Chat.js.map +1 -1
  237. package/dist/ai/Decision.d.ts +46 -1
  238. package/dist/ai/Decision.d.ts.map +1 -1
  239. package/dist/ai/Decision.js.map +1 -1
  240. package/dist/ai/DecisionModel.d.ts +129 -11
  241. package/dist/ai/DecisionModel.d.ts.map +1 -1
  242. package/dist/ai/DecisionModel.js +182 -94
  243. package/dist/ai/DecisionModel.js.map +1 -1
  244. package/dist/ai/EmbeddingModel.d.ts +10 -0
  245. package/dist/ai/EmbeddingModel.d.ts.map +1 -1
  246. package/dist/ai/EmbeddingModel.js +21 -7
  247. package/dist/ai/EmbeddingModel.js.map +1 -1
  248. package/dist/ai/LanguageModel.d.ts.map +1 -1
  249. package/dist/ai/LanguageModel.js +9 -0
  250. package/dist/ai/LanguageModel.js.map +1 -1
  251. package/dist/ai/McpClient.d.ts +289 -0
  252. package/dist/ai/McpClient.d.ts.map +1 -0
  253. package/dist/ai/McpClient.js +819 -0
  254. package/dist/ai/McpClient.js.map +1 -0
  255. package/dist/ai/McpClientError.d.ts +254 -0
  256. package/dist/ai/McpClientError.d.ts.map +1 -0
  257. package/dist/ai/McpClientError.js +260 -0
  258. package/dist/ai/McpClientError.js.map +1 -0
  259. package/dist/ai/McpProtocol.d.ts +2 -2
  260. package/dist/ai/McpProtocol.d.ts.map +1 -1
  261. package/dist/ai/McpSchema.d.ts +258 -125
  262. package/dist/ai/McpSchema.d.ts.map +1 -1
  263. package/dist/ai/McpSchema.js +94 -24
  264. package/dist/ai/McpSchema.js.map +1 -1
  265. package/dist/ai/McpServer.d.ts.map +1 -1
  266. package/dist/ai/McpServer.js +46 -37
  267. package/dist/ai/McpServer.js.map +1 -1
  268. package/dist/ai/Prompt.d.ts +74 -20
  269. package/dist/ai/Prompt.d.ts.map +1 -1
  270. package/dist/ai/Prompt.js +61 -1
  271. package/dist/ai/Prompt.js.map +1 -1
  272. package/dist/ai/Response.d.ts +160 -3
  273. package/dist/ai/Response.d.ts.map +1 -1
  274. package/dist/ai/Response.js +39 -37
  275. package/dist/ai/Response.js.map +1 -1
  276. package/dist/ai/Tool.d.ts +36 -4
  277. package/dist/ai/Tool.d.ts.map +1 -1
  278. package/dist/ai/Tool.js +5 -2
  279. package/dist/ai/Tool.js.map +1 -1
  280. package/dist/ai/Toolkit.d.ts +48 -1
  281. package/dist/ai/Toolkit.d.ts.map +1 -1
  282. package/dist/ai/Toolkit.js +73 -13
  283. package/dist/ai/Toolkit.js.map +1 -1
  284. package/dist/ai/index.d.ts +10 -0
  285. package/dist/ai/index.d.ts.map +1 -1
  286. package/dist/ai/index.js +10 -0
  287. package/dist/ai/index.js.map +1 -1
  288. package/dist/ai/internal/mcpCore.js.map +1 -1
  289. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +1 -1
  290. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  291. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +1 -1
  292. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  293. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +2 -2
  294. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  295. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +2 -2
  296. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  297. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +4 -7
  298. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  299. package/dist/ai/internal/mcpProtocol.js +16 -2
  300. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  301. package/dist/ai/internal/mcpRuntime.js +3 -4
  302. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  303. package/dist/ai/internal/mcpSchema/v2024_11_05.js +19 -13
  304. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  305. package/dist/ai/internal/mcpSchema/v2025_03_26.js +3 -2
  306. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  307. package/dist/ai/internal/mcpSchema/v2025_06_18.js +7 -7
  308. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  309. package/dist/ai/internal/mcpSchema/v2025_11_25.js +8 -8
  310. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  311. package/dist/ai/internal/mcpSchema/v2026_07_28.js +43 -42
  312. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  313. package/dist/cli/Argument.d.ts +15 -0
  314. package/dist/cli/Argument.d.ts.map +1 -1
  315. package/dist/cli/Argument.js +5 -0
  316. package/dist/cli/Argument.js.map +1 -1
  317. package/dist/cli/CliError.d.ts +120 -2
  318. package/dist/cli/CliError.d.ts.map +1 -1
  319. package/dist/cli/CliError.js +106 -5
  320. package/dist/cli/CliError.js.map +1 -1
  321. package/dist/cli/CliOutput.d.ts +155 -6
  322. package/dist/cli/CliOutput.d.ts.map +1 -1
  323. package/dist/cli/CliOutput.js +62 -6
  324. package/dist/cli/CliOutput.js.map +1 -1
  325. package/dist/cli/Command.d.ts +310 -18
  326. package/dist/cli/Command.d.ts.map +1 -1
  327. package/dist/cli/Command.js +164 -33
  328. package/dist/cli/Command.js.map +1 -1
  329. package/dist/cli/Completions.d.ts +63 -0
  330. package/dist/cli/Completions.d.ts.map +1 -1
  331. package/dist/cli/Completions.js +49 -9
  332. package/dist/cli/Completions.js.map +1 -1
  333. package/dist/cli/Flag.d.ts +130 -0
  334. package/dist/cli/Flag.d.ts.map +1 -1
  335. package/dist/cli/Flag.js +61 -0
  336. package/dist/cli/Flag.js.map +1 -1
  337. package/dist/cli/GlobalFlag.d.ts.map +1 -1
  338. package/dist/cli/GlobalFlag.js +14 -6
  339. package/dist/cli/GlobalFlag.js.map +1 -1
  340. package/dist/cli/Param.d.ts +116 -0
  341. package/dist/cli/Param.d.ts.map +1 -1
  342. package/dist/cli/Param.js +77 -2
  343. package/dist/cli/Param.js.map +1 -1
  344. package/dist/cli/TerminalCapabilities.d.ts +85 -0
  345. package/dist/cli/TerminalCapabilities.d.ts.map +1 -0
  346. package/dist/cli/TerminalCapabilities.js +124 -0
  347. package/dist/cli/TerminalCapabilities.js.map +1 -0
  348. package/dist/cli/index.d.ts +5 -0
  349. package/dist/cli/index.d.ts.map +1 -1
  350. package/dist/cli/index.js +5 -0
  351. package/dist/cli/index.js.map +1 -1
  352. package/dist/cli/internal/command.d.ts +2 -1
  353. package/dist/cli/internal/command.d.ts.map +1 -1
  354. package/dist/cli/internal/command.js +5 -2
  355. package/dist/cli/internal/command.js.map +1 -1
  356. package/dist/cli/internal/completions/bash.js +77 -30
  357. package/dist/cli/internal/completions/bash.js.map +1 -1
  358. package/dist/cli/internal/completions/descriptor.js +9 -1
  359. package/dist/cli/internal/completions/descriptor.js.map +1 -1
  360. package/dist/cli/internal/completions/fish.js +10 -8
  361. package/dist/cli/internal/completions/fish.js.map +1 -1
  362. package/dist/cli/internal/completions/powershell.js +18 -9
  363. package/dist/cli/internal/completions/powershell.js.map +1 -1
  364. package/dist/cli/internal/completions/zsh.js +8 -5
  365. package/dist/cli/internal/completions/zsh.js.map +1 -1
  366. package/dist/cli/internal/formatter.d.ts +2 -0
  367. package/dist/cli/internal/formatter.d.ts.map +1 -0
  368. package/dist/cli/internal/formatter.js +15 -0
  369. package/dist/cli/internal/formatter.js.map +1 -0
  370. package/dist/cli/internal/lexer.js +24 -10
  371. package/dist/cli/internal/lexer.js.map +1 -1
  372. package/dist/cli/internal/parser.js +24 -12
  373. package/dist/cli/internal/parser.js.map +1 -1
  374. package/dist/cluster/ClusterCron.d.ts +29 -1
  375. package/dist/cluster/ClusterCron.d.ts.map +1 -1
  376. package/dist/cluster/ClusterCron.js +64 -32
  377. package/dist/cluster/ClusterCron.js.map +1 -1
  378. package/dist/cluster/ClusterMetrics.d.ts +143 -7
  379. package/dist/cluster/ClusterMetrics.d.ts.map +1 -1
  380. package/dist/cluster/ClusterMetrics.js +151 -7
  381. package/dist/cluster/ClusterMetrics.js.map +1 -1
  382. package/dist/cluster/ClusterWorkflowEngine.d.ts +1 -1
  383. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  384. package/dist/cluster/ClusterWorkflowEngine.js +82 -21
  385. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  386. package/dist/cluster/Entity.d.ts +2 -0
  387. package/dist/cluster/Entity.d.ts.map +1 -1
  388. package/dist/cluster/Entity.js.map +1 -1
  389. package/dist/cluster/MessageStorage.d.ts +44 -45
  390. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  391. package/dist/cluster/MessageStorage.js +6 -7
  392. package/dist/cluster/MessageStorage.js.map +1 -1
  393. package/dist/cluster/Runners.d.ts.map +1 -1
  394. package/dist/cluster/Runners.js +54 -15
  395. package/dist/cluster/Runners.js.map +1 -1
  396. package/dist/cluster/Sharding.d.ts +1 -0
  397. package/dist/cluster/Sharding.d.ts.map +1 -1
  398. package/dist/cluster/Sharding.js +155 -52
  399. package/dist/cluster/Sharding.js.map +1 -1
  400. package/dist/cluster/ShardingConfig.d.ts +30 -0
  401. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  402. package/dist/cluster/ShardingConfig.js +4 -0
  403. package/dist/cluster/ShardingConfig.js.map +1 -1
  404. package/dist/cluster/Snowflake.d.ts.map +1 -1
  405. package/dist/cluster/Snowflake.js +3 -7
  406. package/dist/cluster/Snowflake.js.map +1 -1
  407. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  408. package/dist/cluster/SqlMessageStorage.js +40 -50
  409. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  410. package/dist/cluster/SqlRunnerStorage.d.ts +2 -2
  411. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  412. package/dist/cluster/SqlRunnerStorage.js +97 -43
  413. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  414. package/dist/cluster/internal/entityManager.js +119 -28
  415. package/dist/cluster/internal/entityManager.js.map +1 -1
  416. package/dist/devtools/DevTools.d.ts +3 -2
  417. package/dist/devtools/DevTools.d.ts.map +1 -1
  418. package/dist/devtools/DevTools.js +3 -2
  419. package/dist/devtools/DevTools.js.map +1 -1
  420. package/dist/devtools/DevToolsClient.d.ts +11 -0
  421. package/dist/devtools/DevToolsClient.d.ts.map +1 -1
  422. package/dist/devtools/DevToolsClient.js +33 -4
  423. package/dist/devtools/DevToolsClient.js.map +1 -1
  424. package/dist/encoding/Base64.js +36 -0
  425. package/dist/encoding/Base64.js.map +1 -1
  426. package/dist/encoding/Base64Url.d.ts +29 -0
  427. package/dist/encoding/Base64Url.d.ts.map +1 -1
  428. package/dist/encoding/Base64Url.js +29 -0
  429. package/dist/encoding/Base64Url.js.map +1 -1
  430. package/dist/encoding/Ini.d.ts.map +1 -1
  431. package/dist/encoding/Ini.js +3 -0
  432. package/dist/encoding/Ini.js.map +1 -1
  433. package/dist/encoding/JsonArray.d.ts +270 -0
  434. package/dist/encoding/JsonArray.d.ts.map +1 -0
  435. package/dist/encoding/JsonArray.js +691 -0
  436. package/dist/encoding/JsonArray.js.map +1 -0
  437. package/dist/encoding/Ndjson.d.ts +43 -4
  438. package/dist/encoding/Ndjson.d.ts.map +1 -1
  439. package/dist/encoding/Ndjson.js +169 -18
  440. package/dist/encoding/Ndjson.js.map +1 -1
  441. package/dist/encoding/SchemaBinary.d.ts +9 -1
  442. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  443. package/dist/encoding/SchemaBinary.js +12 -19
  444. package/dist/encoding/SchemaBinary.js.map +1 -1
  445. package/dist/encoding/Sse.d.ts.map +1 -1
  446. package/dist/encoding/Sse.js +3 -3
  447. package/dist/encoding/Sse.js.map +1 -1
  448. package/dist/encoding/Tar.d.ts +309 -0
  449. package/dist/encoding/Tar.d.ts.map +1 -0
  450. package/dist/encoding/Tar.js +1182 -0
  451. package/dist/encoding/Tar.js.map +1 -0
  452. package/dist/encoding/Toml.d.ts.map +1 -1
  453. package/dist/encoding/Toml.js +24 -19
  454. package/dist/encoding/Toml.js.map +1 -1
  455. package/dist/encoding/Xml.d.ts +464 -0
  456. package/dist/encoding/Xml.d.ts.map +1 -0
  457. package/dist/encoding/Xml.js +1619 -0
  458. package/dist/encoding/Xml.js.map +1 -0
  459. package/dist/encoding/Yaml.d.ts +6 -2
  460. package/dist/encoding/Yaml.d.ts.map +1 -1
  461. package/dist/encoding/Yaml.js +97 -34
  462. package/dist/encoding/Yaml.js.map +1 -1
  463. package/dist/encoding/Zip.d.ts +413 -0
  464. package/dist/encoding/Zip.d.ts.map +1 -0
  465. package/dist/encoding/Zip.js +1255 -0
  466. package/dist/encoding/Zip.js.map +1 -0
  467. package/dist/encoding/index.d.ts +20 -0
  468. package/dist/encoding/index.d.ts.map +1 -1
  469. package/dist/encoding/index.js +20 -0
  470. package/dist/encoding/index.js.map +1 -1
  471. package/dist/eventlog/EventJournal.d.ts +90 -5
  472. package/dist/eventlog/EventJournal.d.ts.map +1 -1
  473. package/dist/eventlog/EventJournal.js +488 -228
  474. package/dist/eventlog/EventJournal.js.map +1 -1
  475. package/dist/eventlog/EventLog.d.ts +180 -12
  476. package/dist/eventlog/EventLog.d.ts.map +1 -1
  477. package/dist/eventlog/EventLog.js +394 -146
  478. package/dist/eventlog/EventLog.js.map +1 -1
  479. package/dist/eventlog/EventLogEncryption.d.ts +36 -30
  480. package/dist/eventlog/EventLogEncryption.d.ts.map +1 -1
  481. package/dist/eventlog/EventLogEncryption.js +97 -38
  482. package/dist/eventlog/EventLogEncryption.js.map +1 -1
  483. package/dist/eventlog/EventLogMessage.d.ts +74 -34
  484. package/dist/eventlog/EventLogMessage.d.ts.map +1 -1
  485. package/dist/eventlog/EventLogMessage.js +45 -11
  486. package/dist/eventlog/EventLogMessage.js.map +1 -1
  487. package/dist/eventlog/EventLogRemote.d.ts +45 -8
  488. package/dist/eventlog/EventLogRemote.d.ts.map +1 -1
  489. package/dist/eventlog/EventLogRemote.js +51 -14
  490. package/dist/eventlog/EventLogRemote.js.map +1 -1
  491. package/dist/eventlog/EventLogServer.d.ts +46 -3
  492. package/dist/eventlog/EventLogServer.d.ts.map +1 -1
  493. package/dist/eventlog/EventLogServer.js +119 -19
  494. package/dist/eventlog/EventLogServer.js.map +1 -1
  495. package/dist/eventlog/EventLogServerEncrypted.d.ts +23 -33
  496. package/dist/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
  497. package/dist/eventlog/EventLogServerEncrypted.js +97 -70
  498. package/dist/eventlog/EventLogServerEncrypted.js.map +1 -1
  499. package/dist/eventlog/EventLogServerUnencrypted.d.ts +39 -5
  500. package/dist/eventlog/EventLogServerUnencrypted.d.ts.map +1 -1
  501. package/dist/eventlog/EventLogServerUnencrypted.js +151 -69
  502. package/dist/eventlog/EventLogServerUnencrypted.js.map +1 -1
  503. package/dist/eventlog/EventRow.d.ts +288 -0
  504. package/dist/eventlog/EventRow.d.ts.map +1 -0
  505. package/dist/eventlog/EventRow.js +435 -0
  506. package/dist/eventlog/EventRow.js.map +1 -0
  507. package/dist/eventlog/SqlEventJournal.d.ts +18 -18
  508. package/dist/eventlog/SqlEventJournal.d.ts.map +1 -1
  509. package/dist/eventlog/SqlEventJournal.js +417 -169
  510. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  511. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts +10 -18
  512. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
  513. package/dist/eventlog/SqlEventLogServerEncrypted.js +179 -69
  514. package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  515. package/dist/eventlog/SqlEventLogServerUnencrypted.d.ts +23 -3
  516. package/dist/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -1
  517. package/dist/eventlog/SqlEventLogServerUnencrypted.js +102 -51
  518. package/dist/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  519. package/dist/eventlog/index.d.ts +5 -0
  520. package/dist/eventlog/index.d.ts.map +1 -1
  521. package/dist/eventlog/index.js +5 -0
  522. package/dist/eventlog/index.js.map +1 -1
  523. package/dist/eventlog/internal/conflicts.d.ts +46 -0
  524. package/dist/eventlog/internal/conflicts.d.ts.map +1 -0
  525. package/dist/eventlog/internal/conflicts.js +89 -0
  526. package/dist/eventlog/internal/conflicts.js.map +1 -0
  527. package/dist/graphql/GraphQLClientError.d.ts +2 -2
  528. package/dist/graphql/GraphQLClientError.d.ts.map +1 -1
  529. package/dist/graphql/GraphQLClientError.js +4 -18
  530. package/dist/graphql/GraphQLClientError.js.map +1 -1
  531. package/dist/graphql/GraphQLProtocol.d.ts +12 -9
  532. package/dist/graphql/GraphQLProtocol.d.ts.map +1 -1
  533. package/dist/graphql/GraphQLProtocol.js +4 -3
  534. package/dist/graphql/GraphQLProtocol.js.map +1 -1
  535. package/dist/graphql/GraphQLResolver.d.ts +2 -0
  536. package/dist/graphql/GraphQLResolver.d.ts.map +1 -1
  537. package/dist/graphql/GraphQLResolver.js +74 -32
  538. package/dist/graphql/GraphQLResolver.js.map +1 -1
  539. package/dist/http/Cookies.d.ts.map +1 -1
  540. package/dist/http/Cookies.js +10 -9
  541. package/dist/http/Cookies.js.map +1 -1
  542. package/dist/http/FetchHttpClient.d.ts +8 -1
  543. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  544. package/dist/http/FetchHttpClient.js +51 -4
  545. package/dist/http/FetchHttpClient.js.map +1 -1
  546. package/dist/http/FindMyWay/internal/router.js +10 -0
  547. package/dist/http/FindMyWay/internal/router.js.map +1 -1
  548. package/dist/http/Headers.d.ts +227 -0
  549. package/dist/http/Headers.d.ts.map +1 -1
  550. package/dist/http/Headers.js +261 -0
  551. package/dist/http/Headers.js.map +1 -1
  552. package/dist/http/HttpClient.d.ts +516 -0
  553. package/dist/http/HttpClient.d.ts.map +1 -1
  554. package/dist/http/HttpClient.js +286 -23
  555. package/dist/http/HttpClient.js.map +1 -1
  556. package/dist/http/HttpClientError.d.ts +8 -1
  557. package/dist/http/HttpClientError.d.ts.map +1 -1
  558. package/dist/http/HttpClientError.js +37 -1
  559. package/dist/http/HttpClientError.js.map +1 -1
  560. package/dist/http/HttpClientRequest.d.ts +127 -3
  561. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  562. package/dist/http/HttpClientRequest.js +45 -3
  563. package/dist/http/HttpClientRequest.js.map +1 -1
  564. package/dist/http/HttpClientResponse.d.ts +53 -0
  565. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  566. package/dist/http/HttpClientResponse.js +47 -0
  567. package/dist/http/HttpClientResponse.js.map +1 -1
  568. package/dist/http/HttpEffect.d.ts +6 -2
  569. package/dist/http/HttpEffect.d.ts.map +1 -1
  570. package/dist/http/HttpEffect.js +21 -17
  571. package/dist/http/HttpEffect.js.map +1 -1
  572. package/dist/http/HttpIncomingMessage.d.ts +2 -1
  573. package/dist/http/HttpIncomingMessage.d.ts.map +1 -1
  574. package/dist/http/HttpIncomingMessage.js +3 -23
  575. package/dist/http/HttpIncomingMessage.js.map +1 -1
  576. package/dist/http/HttpMiddleware.d.ts +119 -2
  577. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  578. package/dist/http/HttpMiddleware.js +173 -29
  579. package/dist/http/HttpMiddleware.js.map +1 -1
  580. package/dist/http/HttpRouter.d.ts.map +1 -1
  581. package/dist/http/HttpRouter.js +9 -3
  582. package/dist/http/HttpRouter.js.map +1 -1
  583. package/dist/http/HttpServerError.d.ts +5 -2
  584. package/dist/http/HttpServerError.d.ts.map +1 -1
  585. package/dist/http/HttpServerError.js +7 -5
  586. package/dist/http/HttpServerError.js.map +1 -1
  587. package/dist/http/HttpServerRequest.d.ts +30 -5
  588. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  589. package/dist/http/HttpServerRequest.js +109 -20
  590. package/dist/http/HttpServerRequest.js.map +1 -1
  591. package/dist/http/HttpServerResponse.d.ts +17 -8
  592. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  593. package/dist/http/HttpServerResponse.js +37 -21
  594. package/dist/http/HttpServerResponse.js.map +1 -1
  595. package/dist/http/HttpStaticServer.d.ts +0 -12
  596. package/dist/http/HttpStaticServer.d.ts.map +1 -1
  597. package/dist/http/HttpStaticServer.js +65 -24
  598. package/dist/http/HttpStaticServer.js.map +1 -1
  599. package/dist/http/MultipartParser/internal/contentType.d.ts +15 -1
  600. package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
  601. package/dist/http/MultipartParser/internal/contentType.js +89 -7
  602. package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
  603. package/dist/http/MultipartParser/internal/headers.d.ts.map +1 -1
  604. package/dist/http/MultipartParser/internal/headers.js +4 -12
  605. package/dist/http/MultipartParser/internal/headers.js.map +1 -1
  606. package/dist/http/MultipartParser/internal/multipart.d.ts.map +1 -1
  607. package/dist/http/MultipartParser/internal/multipart.js +6 -27
  608. package/dist/http/MultipartParser/internal/multipart.js.map +1 -1
  609. package/dist/http/Url.d.ts.map +1 -1
  610. package/dist/http/Url.js +6 -1
  611. package/dist/http/Url.js.map +1 -1
  612. package/dist/http/UrlParams.d.ts +3 -1
  613. package/dist/http/UrlParams.d.ts.map +1 -1
  614. package/dist/http/UrlParams.js +4 -2
  615. package/dist/http/UrlParams.js.map +1 -1
  616. package/dist/http/internal/compression.js +4 -5
  617. package/dist/http/internal/compression.js.map +1 -1
  618. package/dist/http/internal/decompression.js +20 -11
  619. package/dist/http/internal/decompression.js.map +1 -1
  620. package/dist/http/internal/httpBody.js +8 -1
  621. package/dist/http/internal/httpBody.js.map +1 -1
  622. package/dist/http/internal/lazyStream.d.ts +2 -0
  623. package/dist/http/internal/lazyStream.d.ts.map +1 -0
  624. package/dist/http/internal/lazyStream.js +18 -0
  625. package/dist/http/internal/lazyStream.js.map +1 -0
  626. package/dist/http/internal/requestState.d.ts +2 -0
  627. package/dist/http/internal/requestState.d.ts.map +1 -0
  628. package/dist/http/internal/requestState.js +28 -0
  629. package/dist/http/internal/requestState.js.map +1 -0
  630. package/dist/http/internal/urlParams.js +25 -0
  631. package/dist/http/internal/urlParams.js.map +1 -1
  632. package/dist/http/internal/webResponse.d.ts +2 -0
  633. package/dist/http/internal/webResponse.d.ts.map +1 -0
  634. package/dist/http/internal/webResponse.js +12 -0
  635. package/dist/http/internal/webResponse.js.map +1 -0
  636. package/dist/http-api/HttpApi.d.ts +3 -6
  637. package/dist/http-api/HttpApi.d.ts.map +1 -1
  638. package/dist/http-api/HttpApi.js +4 -7
  639. package/dist/http-api/HttpApi.js.map +1 -1
  640. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  641. package/dist/http-api/HttpApiBuilder.js +142 -23
  642. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  643. package/dist/http-api/HttpApiClient.d.ts +99 -4
  644. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  645. package/dist/http-api/HttpApiClient.js +218 -60
  646. package/dist/http-api/HttpApiClient.js.map +1 -1
  647. package/dist/http-api/HttpApiEndpoint.d.ts +72 -29
  648. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  649. package/dist/http-api/HttpApiEndpoint.js +140 -14
  650. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  651. package/dist/http-api/HttpApiError.d.ts +58 -0
  652. package/dist/http-api/HttpApiError.d.ts.map +1 -1
  653. package/dist/http-api/HttpApiError.js +38 -12
  654. package/dist/http-api/HttpApiError.js.map +1 -1
  655. package/dist/http-api/HttpApiScalar.d.ts +2 -1
  656. package/dist/http-api/HttpApiScalar.d.ts.map +1 -1
  657. package/dist/http-api/HttpApiScalar.js +6 -3
  658. package/dist/http-api/HttpApiScalar.js.map +1 -1
  659. package/dist/http-api/HttpApiSchema.d.ts +242 -13
  660. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  661. package/dist/http-api/HttpApiSchema.js +149 -5
  662. package/dist/http-api/HttpApiSchema.js.map +1 -1
  663. package/dist/http-api/HttpApiSwagger.d.ts +5 -0
  664. package/dist/http-api/HttpApiSwagger.d.ts.map +1 -1
  665. package/dist/http-api/HttpApiSwagger.js +14 -4
  666. package/dist/http-api/HttpApiSwagger.js.map +1 -1
  667. package/dist/http-api/HttpApiTest.d.ts +13 -2
  668. package/dist/http-api/HttpApiTest.d.ts.map +1 -1
  669. package/dist/http-api/HttpApiTest.js +33 -11
  670. package/dist/http-api/HttpApiTest.js.map +1 -1
  671. package/dist/http-api/OpenApi.d.ts +17 -3
  672. package/dist/http-api/OpenApi.d.ts.map +1 -1
  673. package/dist/http-api/OpenApi.js +81 -47
  674. package/dist/http-api/OpenApi.js.map +1 -1
  675. package/dist/http-api/internal/path.js +35 -10
  676. package/dist/http-api/internal/path.js.map +1 -1
  677. package/dist/http-api/internal/toCodecHttpProperties.d.ts +2 -0
  678. package/dist/http-api/internal/toCodecHttpProperties.d.ts.map +1 -0
  679. package/dist/http-api/internal/toCodecHttpProperties.js +38 -0
  680. package/dist/http-api/internal/toCodecHttpProperties.js.map +1 -0
  681. package/dist/index.d.ts +20 -0
  682. package/dist/index.d.ts.map +1 -1
  683. package/dist/index.js +20 -0
  684. package/dist/index.js.map +1 -1
  685. package/dist/internal/arbitrary/runner.d.ts.map +1 -1
  686. package/dist/internal/arbitrary/runner.js +120 -44
  687. package/dist/internal/arbitrary/runner.js.map +1 -1
  688. package/dist/internal/core.js +3 -1
  689. package/dist/internal/core.js.map +1 -1
  690. package/dist/internal/dateTime.js +19 -7
  691. package/dist/internal/dateTime.js.map +1 -1
  692. package/dist/internal/effect.js +106 -87
  693. package/dist/internal/effect.js.map +1 -1
  694. package/dist/internal/equal.js +14 -0
  695. package/dist/internal/equal.js.map +1 -1
  696. package/dist/internal/hashMap.js +2 -2
  697. package/dist/internal/hashMap.js.map +1 -1
  698. package/dist/internal/hydration.d.ts +2 -0
  699. package/dist/internal/hydration.d.ts.map +1 -0
  700. package/dist/internal/hydration.js +15 -0
  701. package/dist/internal/hydration.js.map +1 -0
  702. package/dist/internal/inflate.d.ts +2 -0
  703. package/dist/internal/inflate.d.ts.map +1 -0
  704. package/dist/internal/inflate.js +680 -0
  705. package/dist/internal/inflate.js.map +1 -0
  706. package/dist/internal/jsonSchema.d.ts +2 -0
  707. package/dist/internal/jsonSchema.d.ts.map +1 -0
  708. package/dist/internal/jsonSchema.js +28 -0
  709. package/dist/internal/jsonSchema.js.map +1 -0
  710. package/dist/internal/matcher.js +1 -1
  711. package/dist/internal/matcher.js.map +1 -1
  712. package/dist/internal/record.js +6 -0
  713. package/dist/internal/record.js.map +1 -1
  714. package/dist/internal/request.js +20 -7
  715. package/dist/internal/request.js.map +1 -1
  716. package/dist/internal/schedule.js +17 -22
  717. package/dist/internal/schedule.js.map +1 -1
  718. package/dist/internal/schema/compilerRegistry.js +4 -1
  719. package/dist/internal/schema/compilerRegistry.js.map +1 -1
  720. package/dist/internal/schema/content.d.ts +2 -0
  721. package/dist/internal/schema/content.d.ts.map +1 -0
  722. package/dist/internal/schema/content.js +13 -0
  723. package/dist/internal/schema/content.js.map +1 -0
  724. package/dist/internal/schema/fromJsonSchemaDocument.js +253 -255
  725. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  726. package/dist/internal/schema/fromRepresentation.js +2 -1
  727. package/dist/internal/schema/fromRepresentation.js.map +1 -1
  728. package/dist/internal/schema/interpreter.js +51 -36
  729. package/dist/internal/schema/interpreter.js.map +1 -1
  730. package/dist/internal/schema/standardSchema.js +42 -35
  731. package/dist/internal/schema/standardSchema.js.map +1 -1
  732. package/dist/internal/schema/toCodeDocument.js +10 -5
  733. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  734. package/dist/internal/schema/toCodec.js +99 -17
  735. package/dist/internal/schema/toCodec.js.map +1 -1
  736. package/dist/internal/schema/toFormatter.js +5 -5
  737. package/dist/internal/schema/toFormatter.js.map +1 -1
  738. package/dist/internal/schema/toJsonSchemaDocument.js +257 -170
  739. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  740. package/dist/internal/schema/toRepresentation.js +107 -129
  741. package/dist/internal/schema/toRepresentation.js.map +1 -1
  742. package/dist/internal/sql.d.ts +2 -0
  743. package/dist/internal/sql.d.ts.map +1 -0
  744. package/dist/internal/sql.js +13 -0
  745. package/dist/internal/sql.js.map +1 -0
  746. package/dist/internal/trie.js +1 -3
  747. package/dist/internal/trie.js.map +1 -1
  748. package/dist/internal/uuid.js +7 -3
  749. package/dist/internal/uuid.js.map +1 -1
  750. package/dist/internal/version.js +1 -1
  751. package/dist/net/NetAddress.d.ts.map +1 -1
  752. package/dist/net/NetAddress.js +2 -8
  753. package/dist/net/NetAddress.js.map +1 -1
  754. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  755. package/dist/observability/OtlpExporter.js +5 -12
  756. package/dist/observability/OtlpExporter.js.map +1 -1
  757. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  758. package/dist/observability/OtlpMetrics.js +5 -3
  759. package/dist/observability/OtlpMetrics.js.map +1 -1
  760. package/dist/observability/OtlpProxy.d.ts +154 -0
  761. package/dist/observability/OtlpProxy.d.ts.map +1 -0
  762. package/dist/observability/OtlpProxy.js +235 -0
  763. package/dist/observability/OtlpProxy.js.map +1 -0
  764. package/dist/observability/OtlpResource.d.ts +3 -1
  765. package/dist/observability/OtlpResource.d.ts.map +1 -1
  766. package/dist/observability/OtlpResource.js +11 -4
  767. package/dist/observability/OtlpResource.js.map +1 -1
  768. package/dist/observability/OtlpSerialization.d.ts +5 -0
  769. package/dist/observability/OtlpSerialization.d.ts.map +1 -1
  770. package/dist/observability/OtlpSerialization.js +14 -3
  771. package/dist/observability/OtlpSerialization.js.map +1 -1
  772. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  773. package/dist/observability/OtlpTracer.js +4 -0
  774. package/dist/observability/OtlpTracer.js.map +1 -1
  775. package/dist/observability/index.d.ts +5 -0
  776. package/dist/observability/index.d.ts.map +1 -1
  777. package/dist/observability/index.js +5 -0
  778. package/dist/observability/index.js.map +1 -1
  779. package/dist/observability/internal/protobuf.d.ts +0 -9
  780. package/dist/observability/internal/protobuf.d.ts.map +1 -1
  781. package/dist/observability/internal/protobuf.js +2 -10
  782. package/dist/observability/internal/protobuf.js.map +1 -1
  783. package/dist/persistence/CircuitBreaker.d.ts +897 -0
  784. package/dist/persistence/CircuitBreaker.d.ts.map +1 -0
  785. package/dist/persistence/CircuitBreaker.js +1165 -0
  786. package/dist/persistence/CircuitBreaker.js.map +1 -0
  787. package/dist/persistence/PersistedCache.d.ts.map +1 -1
  788. package/dist/persistence/PersistedCache.js +1 -1
  789. package/dist/persistence/PersistedCache.js.map +1 -1
  790. package/dist/persistence/PersistedQueue.d.ts +6 -2
  791. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  792. package/dist/persistence/PersistedQueue.js +162 -84
  793. package/dist/persistence/PersistedQueue.js.map +1 -1
  794. package/dist/persistence/Persistence.d.ts +28 -0
  795. package/dist/persistence/Persistence.d.ts.map +1 -1
  796. package/dist/persistence/Persistence.js +36 -8
  797. package/dist/persistence/Persistence.js.map +1 -1
  798. package/dist/persistence/RateLimiter.d.ts.map +1 -1
  799. package/dist/persistence/RateLimiter.js +8 -12
  800. package/dist/persistence/RateLimiter.js.map +1 -1
  801. package/dist/persistence/Redis.d.ts +78 -2
  802. package/dist/persistence/Redis.d.ts.map +1 -1
  803. package/dist/persistence/Redis.js +62 -7
  804. package/dist/persistence/Redis.js.map +1 -1
  805. package/dist/persistence/UserDirectories.d.ts +129 -0
  806. package/dist/persistence/UserDirectories.d.ts.map +1 -0
  807. package/dist/persistence/UserDirectories.js +178 -0
  808. package/dist/persistence/UserDirectories.js.map +1 -0
  809. package/dist/persistence/index.d.ts +10 -0
  810. package/dist/persistence/index.d.ts.map +1 -1
  811. package/dist/persistence/index.js +10 -0
  812. package/dist/persistence/index.js.map +1 -1
  813. package/dist/process/ChildProcess.d.ts +32 -5
  814. package/dist/process/ChildProcess.d.ts.map +1 -1
  815. package/dist/process/ChildProcess.js.map +1 -1
  816. package/dist/process/ChildProcessSpawner.d.ts +30 -0
  817. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  818. package/dist/process/ChildProcessSpawner.js +5 -2
  819. package/dist/process/ChildProcessSpawner.js.map +1 -1
  820. package/dist/reactivity/AsyncResult.d.ts +1 -1
  821. package/dist/reactivity/AsyncResult.d.ts.map +1 -1
  822. package/dist/reactivity/AsyncResult.js +1 -1
  823. package/dist/reactivity/AsyncResult.js.map +1 -1
  824. package/dist/reactivity/Atom.d.ts +69 -30
  825. package/dist/reactivity/Atom.d.ts.map +1 -1
  826. package/dist/reactivity/Atom.js +40 -15
  827. package/dist/reactivity/Atom.js.map +1 -1
  828. package/dist/reactivity/AtomHttpApi.d.ts +5 -5
  829. package/dist/reactivity/AtomHttpApi.d.ts.map +1 -1
  830. package/dist/reactivity/AtomHttpApi.js +1 -1
  831. package/dist/reactivity/AtomHttpApi.js.map +1 -1
  832. package/dist/reactivity/AtomRegistry.d.ts +2 -2
  833. package/dist/reactivity/AtomRegistry.d.ts.map +1 -1
  834. package/dist/reactivity/AtomRegistry.js +44 -9
  835. package/dist/reactivity/AtomRegistry.js.map +1 -1
  836. package/dist/reactivity/AtomRpc.d.ts +3 -3
  837. package/dist/reactivity/AtomRpc.d.ts.map +1 -1
  838. package/dist/reactivity/AtomRpc.js +1 -1
  839. package/dist/reactivity/AtomRpc.js.map +1 -1
  840. package/dist/reactivity/Hydration.d.ts.map +1 -1
  841. package/dist/reactivity/Hydration.js +46 -12
  842. package/dist/reactivity/Hydration.js.map +1 -1
  843. package/dist/reactivity/Reactivity.d.ts +71 -7
  844. package/dist/reactivity/Reactivity.d.ts.map +1 -1
  845. package/dist/reactivity/Reactivity.js +21 -12
  846. package/dist/reactivity/Reactivity.js.map +1 -1
  847. package/dist/rpc/Rpc.d.ts +18 -0
  848. package/dist/rpc/Rpc.d.ts.map +1 -1
  849. package/dist/rpc/Rpc.js +20 -0
  850. package/dist/rpc/Rpc.js.map +1 -1
  851. package/dist/rpc/RpcClient.d.ts +26 -2
  852. package/dist/rpc/RpcClient.d.ts.map +1 -1
  853. package/dist/rpc/RpcClient.js +198 -61
  854. package/dist/rpc/RpcClient.js.map +1 -1
  855. package/dist/rpc/RpcSerialization.d.ts +29 -0
  856. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  857. package/dist/rpc/RpcSerialization.js +41 -13
  858. package/dist/rpc/RpcSerialization.js.map +1 -1
  859. package/dist/rpc/RpcServer.d.ts.map +1 -1
  860. package/dist/rpc/RpcServer.js +20 -19
  861. package/dist/rpc/RpcServer.js.map +1 -1
  862. package/dist/rpc/RpcTest.d.ts +1 -0
  863. package/dist/rpc/RpcTest.d.ts.map +1 -1
  864. package/dist/rpc/RpcTest.js +1 -0
  865. package/dist/rpc/RpcTest.js.map +1 -1
  866. package/dist/schema/Model.d.ts +1 -1
  867. package/dist/schema/VariantSchema.d.ts +22 -3
  868. package/dist/schema/VariantSchema.d.ts.map +1 -1
  869. package/dist/schema/VariantSchema.js +32 -18
  870. package/dist/schema/VariantSchema.js.map +1 -1
  871. package/dist/socket/Socket.d.ts +23 -1
  872. package/dist/socket/Socket.d.ts.map +1 -1
  873. package/dist/socket/Socket.js +36 -3
  874. package/dist/socket/Socket.js.map +1 -1
  875. package/dist/sql/Migrator.d.ts +2 -1
  876. package/dist/sql/Migrator.d.ts.map +1 -1
  877. package/dist/sql/Migrator.js +21 -6
  878. package/dist/sql/Migrator.js.map +1 -1
  879. package/dist/sql/SqlClient.d.ts +148 -5
  880. package/dist/sql/SqlClient.d.ts.map +1 -1
  881. package/dist/sql/SqlClient.js +155 -27
  882. package/dist/sql/SqlClient.js.map +1 -1
  883. package/dist/sql/SqlResolver.d.ts +13 -0
  884. package/dist/sql/SqlResolver.d.ts.map +1 -1
  885. package/dist/sql/SqlResolver.js +27 -4
  886. package/dist/sql/SqlResolver.js.map +1 -1
  887. package/dist/sql/Statement.d.ts +10 -1
  888. package/dist/sql/Statement.d.ts.map +1 -1
  889. package/dist/sql/Statement.js +45 -7
  890. package/dist/sql/Statement.js.map +1 -1
  891. package/dist/testing/TestClock.d.ts.map +1 -1
  892. package/dist/testing/TestClock.js +4 -2
  893. package/dist/testing/TestClock.js.map +1 -1
  894. package/dist/testing/TestSchema.d.ts +7 -1
  895. package/dist/testing/TestSchema.d.ts.map +1 -1
  896. package/dist/testing/TestSchema.js +9 -3
  897. package/dist/testing/TestSchema.js.map +1 -1
  898. package/dist/workflow/DurableDeferred.d.ts.map +1 -1
  899. package/dist/workflow/DurableDeferred.js +21 -2
  900. package/dist/workflow/DurableDeferred.js.map +1 -1
  901. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  902. package/dist/workflow/WorkflowEngine.js +18 -4
  903. package/dist/workflow/WorkflowEngine.js.map +1 -1
  904. package/package.json +13 -3
  905. package/src/Arbitrary.ts +10 -2
  906. package/src/Array.ts +128 -55
  907. package/src/Bytes.ts +111 -0
  908. package/src/Channel.ts +308 -452
  909. package/src/ChannelSchema.ts +1 -49
  910. package/src/Chunk.ts +55 -61
  911. package/src/Config.ts +12 -86
  912. package/src/ConfigProvider.ts +2 -1
  913. package/src/Cron.ts +6 -3
  914. package/src/Data.ts +60 -265
  915. package/src/Duration.ts +66 -16
  916. package/src/Effect.ts +503 -168
  917. package/src/Equal.ts +8 -1
  918. package/src/Equivalence.ts +7 -4
  919. package/src/Exit.ts +27 -12
  920. package/src/FiberHandle.ts +10 -9
  921. package/src/FiberMap.ts +13 -66
  922. package/src/FileSystem.ts +10 -0
  923. package/src/Formatter.ts +28 -13
  924. package/src/Graph.ts +171 -1263
  925. package/src/Hash.ts +4 -1
  926. package/src/HashSet.ts +0 -60
  927. package/src/Iterable.ts +15 -14
  928. package/src/JsonPatch.ts +4 -0
  929. package/src/JsonSchema.ts +40 -43
  930. package/src/Layer.ts +2 -2
  931. package/src/ManagedRuntime.ts +72 -6
  932. package/src/Metric.ts +252 -510
  933. package/src/MutableHashMap.ts +4 -473
  934. package/src/MutableList.ts +7 -5
  935. package/src/MutableRef.ts +8 -1
  936. package/src/Number.ts +2 -2
  937. package/src/Optic.ts +17 -332
  938. package/src/PartitionedSemaphore.ts +24 -13
  939. package/src/Path.ts +9 -1
  940. package/src/Pool.ts +109 -37
  941. package/src/PubSub.ts +17 -13
  942. package/src/Queue.ts +5 -37
  943. package/src/Random.ts +1 -1
  944. package/src/RcMap.ts +14 -8
  945. package/src/Record.ts +51 -0
  946. package/src/Ref.ts +15 -104
  947. package/src/References.ts +5 -4
  948. package/src/RequestResolver.ts +46 -87
  949. package/src/Resource.ts +1 -1
  950. package/src/Runtime.ts +19 -18
  951. package/src/Schedule.ts +3 -95
  952. package/src/Schema.ts +639 -381
  953. package/src/SchemaAST.ts +40 -29
  954. package/src/SchemaGetter.ts +22 -5
  955. package/src/SchemaIssue.ts +44 -53
  956. package/src/SchemaParser.ts +51 -18
  957. package/src/SchemaRepresentation.ts +95 -35
  958. package/src/SchemaTransformation.ts +10 -3
  959. package/src/Scope.ts +12 -2
  960. package/src/ScopedCache.ts +17 -142
  961. package/src/SemVer.ts +1528 -0
  962. package/src/SemVerRange.ts +883 -0
  963. package/src/Semaphore.ts +67 -40
  964. package/src/Sink.ts +21 -4
  965. package/src/Stream.ts +367 -1027
  966. package/src/String.ts +11 -8
  967. package/src/TextDiff.ts +766 -0
  968. package/src/Tracer.ts +15 -1
  969. package/src/TxHashMap.ts +1 -103
  970. package/src/TxHashSet.ts +48 -753
  971. package/src/ai/AiError.ts +66 -4
  972. package/src/ai/Chat.ts +10 -5
  973. package/src/ai/Decision.ts +49 -1
  974. package/src/ai/DecisionModel.ts +264 -108
  975. package/src/ai/EmbeddingModel.ts +25 -13
  976. package/src/ai/LanguageModel.ts +9 -0
  977. package/src/ai/McpClient.ts +1211 -0
  978. package/src/ai/McpClientError.ts +329 -0
  979. package/src/ai/McpProtocol.ts +2 -2
  980. package/src/ai/McpSchema.ts +153 -35
  981. package/src/ai/McpServer.ts +231 -233
  982. package/src/ai/Prompt.ts +114 -35
  983. package/src/ai/Response.ts +220 -65
  984. package/src/ai/Tool.ts +50 -6
  985. package/src/ai/Toolkit.ts +82 -11
  986. package/src/ai/index.ts +12 -0
  987. package/src/ai/internal/mcpCore.ts +13 -14
  988. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +1 -1
  989. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +1 -1
  990. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +3 -3
  991. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +3 -3
  992. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +12 -14
  993. package/src/ai/internal/mcpProtocol.ts +22 -2
  994. package/src/ai/internal/mcpRuntime.ts +3 -4
  995. package/src/ai/internal/mcpSchema/v2024_11_05.ts +20 -13
  996. package/src/ai/internal/mcpSchema/v2025_03_26.ts +4 -2
  997. package/src/ai/internal/mcpSchema/v2025_06_18.ts +7 -7
  998. package/src/ai/internal/mcpSchema/v2025_11_25.ts +8 -8
  999. package/src/ai/internal/mcpSchema/v2026_07_28.ts +44 -42
  1000. package/src/cli/Argument.ts +15 -0
  1001. package/src/cli/CliError.ts +136 -4
  1002. package/src/cli/CliOutput.ts +183 -6
  1003. package/src/cli/Command.ts +367 -48
  1004. package/src/cli/Completions.ts +56 -0
  1005. package/src/cli/Flag.ts +132 -0
  1006. package/src/cli/GlobalFlag.ts +5 -6
  1007. package/src/cli/Param.ts +151 -6
  1008. package/src/cli/TerminalCapabilities.ts +159 -0
  1009. package/src/cli/index.ts +6 -0
  1010. package/src/cli/internal/command.ts +8 -3
  1011. package/src/cli/internal/completions/bash.ts +83 -32
  1012. package/src/cli/internal/completions/descriptor.ts +11 -1
  1013. package/src/cli/internal/completions/fish.ts +10 -8
  1014. package/src/cli/internal/completions/powershell.ts +23 -14
  1015. package/src/cli/internal/completions/zsh.ts +8 -5
  1016. package/src/cli/internal/formatter.ts +18 -0
  1017. package/src/cli/internal/lexer.ts +12 -5
  1018. package/src/cli/internal/parser.ts +31 -11
  1019. package/src/cluster/ClusterCron.ts +94 -35
  1020. package/src/cluster/ClusterMetrics.ts +149 -7
  1021. package/src/cluster/ClusterWorkflowEngine.ts +130 -57
  1022. package/src/cluster/Entity.ts +4 -0
  1023. package/src/cluster/MessageStorage.ts +26 -14
  1024. package/src/cluster/Runners.ts +76 -25
  1025. package/src/cluster/Sharding.ts +200 -58
  1026. package/src/cluster/ShardingConfig.ts +20 -0
  1027. package/src/cluster/Snowflake.ts +3 -7
  1028. package/src/cluster/SqlMessageStorage.ts +58 -55
  1029. package/src/cluster/SqlRunnerStorage.ts +120 -51
  1030. package/src/cluster/internal/entityManager.ts +155 -32
  1031. package/src/devtools/DevTools.ts +3 -2
  1032. package/src/devtools/DevToolsClient.ts +29 -10
  1033. package/src/encoding/Base64.ts +38 -0
  1034. package/src/encoding/Base64Url.ts +31 -0
  1035. package/src/encoding/Ini.ts +3 -0
  1036. package/src/encoding/JsonArray.ts +849 -0
  1037. package/src/encoding/Ndjson.ts +211 -20
  1038. package/src/encoding/SchemaBinary.ts +14 -48
  1039. package/src/encoding/Sse.ts +4 -3
  1040. package/src/encoding/Tar.ts +1417 -0
  1041. package/src/encoding/Toml.ts +36 -19
  1042. package/src/encoding/Xml.ts +2037 -0
  1043. package/src/encoding/Yaml.ts +108 -36
  1044. package/src/encoding/Zip.ts +1558 -0
  1045. package/src/encoding/index.ts +24 -0
  1046. package/src/eventlog/EventJournal.ts +611 -227
  1047. package/src/eventlog/EventLog.ts +496 -196
  1048. package/src/eventlog/EventLogEncryption.ts +128 -43
  1049. package/src/eventlog/EventLogMessage.ts +62 -11
  1050. package/src/eventlog/EventLogRemote.ts +77 -21
  1051. package/src/eventlog/EventLogServer.ts +162 -20
  1052. package/src/eventlog/EventLogServerEncrypted.ts +121 -80
  1053. package/src/eventlog/EventLogServerUnencrypted.ts +180 -77
  1054. package/src/eventlog/EventRow.ts +706 -0
  1055. package/src/eventlog/SqlEventJournal.ts +496 -193
  1056. package/src/eventlog/SqlEventLogServerEncrypted.ts +212 -83
  1057. package/src/eventlog/SqlEventLogServerUnencrypted.ts +141 -62
  1058. package/src/eventlog/index.ts +6 -0
  1059. package/src/eventlog/internal/conflicts.ts +119 -0
  1060. package/src/graphql/GraphQLClientError.ts +5 -12
  1061. package/src/graphql/GraphQLProtocol.ts +12 -9
  1062. package/src/graphql/GraphQLResolver.ts +90 -239
  1063. package/src/http/Cookies.ts +10 -11
  1064. package/src/http/FetchHttpClient.ts +56 -6
  1065. package/src/http/FindMyWay/internal/router.ts +11 -0
  1066. package/src/http/Headers.ts +337 -154
  1067. package/src/http/HttpClient.ts +673 -142
  1068. package/src/http/HttpClientError.ts +35 -1
  1069. package/src/http/HttpClientRequest.ts +151 -5
  1070. package/src/http/HttpClientResponse.ts +71 -0
  1071. package/src/http/HttpEffect.ts +25 -33
  1072. package/src/http/HttpIncomingMessage.ts +3 -23
  1073. package/src/http/HttpMiddleware.ts +194 -40
  1074. package/src/http/HttpRouter.ts +10 -3
  1075. package/src/http/HttpServerError.ts +8 -5
  1076. package/src/http/HttpServerRequest.ts +172 -27
  1077. package/src/http/HttpServerResponse.ts +49 -23
  1078. package/src/http/HttpStaticServer.ts +71 -26
  1079. package/src/http/MultipartParser/internal/contentType.ts +109 -8
  1080. package/src/http/MultipartParser/internal/headers.ts +4 -16
  1081. package/src/http/MultipartParser/internal/multipart.ts +10 -32
  1082. package/src/http/Url.ts +6 -1
  1083. package/src/http/UrlParams.ts +6 -1
  1084. package/src/http/internal/compression.ts +4 -5
  1085. package/src/http/internal/decompression.ts +32 -17
  1086. package/src/http/internal/httpBody.ts +10 -2
  1087. package/src/http/internal/lazyStream.ts +25 -0
  1088. package/src/http/internal/requestState.ts +33 -0
  1089. package/src/http/internal/urlParams.ts +29 -0
  1090. package/src/http/internal/webResponse.ts +20 -0
  1091. package/src/http-api/HttpApi.ts +4 -7
  1092. package/src/http-api/HttpApiBuilder.ts +190 -32
  1093. package/src/http-api/HttpApiClient.ts +364 -90
  1094. package/src/http-api/HttpApiEndpoint.ts +248 -46
  1095. package/src/http-api/HttpApiError.ts +55 -0
  1096. package/src/http-api/HttpApiScalar.ts +4 -3
  1097. package/src/http-api/HttpApiSchema.ts +373 -18
  1098. package/src/http-api/HttpApiSwagger.ts +11 -4
  1099. package/src/http-api/HttpApiTest.ts +36 -11
  1100. package/src/http-api/OpenApi.ts +103 -58
  1101. package/src/http-api/internal/path.ts +40 -12
  1102. package/src/http-api/internal/toCodecHttpProperties.ts +56 -0
  1103. package/src/index.ts +24 -0
  1104. package/src/internal/arbitrary/runner.ts +133 -36
  1105. package/src/internal/core.ts +3 -1
  1106. package/src/internal/dateTime.ts +20 -7
  1107. package/src/internal/effect.ts +144 -100
  1108. package/src/internal/equal.ts +17 -0
  1109. package/src/internal/hashMap.ts +2 -2
  1110. package/src/internal/hydration.ts +15 -0
  1111. package/src/internal/inflate.ts +710 -0
  1112. package/src/internal/jsonSchema.ts +27 -0
  1113. package/src/internal/matcher.ts +1 -1
  1114. package/src/internal/record.ts +6 -0
  1115. package/src/internal/request.ts +21 -6
  1116. package/src/internal/schedule.ts +20 -39
  1117. package/src/internal/schema/compilerRegistry.ts +6 -1
  1118. package/src/internal/schema/content.ts +18 -0
  1119. package/src/internal/schema/fromJsonSchemaDocument.ts +458 -351
  1120. package/src/internal/schema/fromRepresentation.ts +2 -1
  1121. package/src/internal/schema/interpreter.ts +58 -45
  1122. package/src/internal/schema/standardSchema.ts +34 -32
  1123. package/src/internal/schema/toCodeDocument.ts +12 -7
  1124. package/src/internal/schema/toCodec.ts +134 -15
  1125. package/src/internal/schema/toFormatter.ts +6 -6
  1126. package/src/internal/schema/toJsonSchemaDocument.ts +246 -194
  1127. package/src/internal/schema/toRepresentation.ts +122 -140
  1128. package/src/internal/sql.ts +14 -0
  1129. package/src/internal/trie.ts +1 -3
  1130. package/src/internal/uuid.ts +15 -10
  1131. package/src/internal/version.ts +1 -1
  1132. package/src/net/NetAddress.ts +2 -9
  1133. package/src/observability/OtlpExporter.ts +5 -12
  1134. package/src/observability/OtlpMetrics.ts +5 -3
  1135. package/src/observability/OtlpProxy.ts +314 -0
  1136. package/src/observability/OtlpResource.ts +16 -6
  1137. package/src/observability/OtlpSerialization.ts +17 -3
  1138. package/src/observability/OtlpTracer.ts +4 -0
  1139. package/src/observability/index.ts +6 -0
  1140. package/src/observability/internal/protobuf.ts +2 -10
  1141. package/src/persistence/CircuitBreaker.ts +1678 -0
  1142. package/src/persistence/PersistedCache.ts +3 -1
  1143. package/src/persistence/PersistedQueue.ts +223 -153
  1144. package/src/persistence/Persistence.ts +64 -30
  1145. package/src/persistence/RateLimiter.ts +18 -21
  1146. package/src/persistence/Redis.ts +129 -8
  1147. package/src/persistence/UserDirectories.ts +273 -0
  1148. package/src/persistence/index.ts +12 -0
  1149. package/src/process/ChildProcess.ts +32 -5
  1150. package/src/process/ChildProcessSpawner.ts +41 -2
  1151. package/src/reactivity/AsyncResult.ts +5 -39
  1152. package/src/reactivity/Atom.ts +134 -166
  1153. package/src/reactivity/AtomHttpApi.ts +10 -16
  1154. package/src/reactivity/AtomRegistry.ts +50 -29
  1155. package/src/reactivity/AtomRpc.ts +6 -22
  1156. package/src/reactivity/Hydration.ts +53 -12
  1157. package/src/reactivity/Reactivity.ts +97 -39
  1158. package/src/rpc/Rpc.ts +21 -0
  1159. package/src/rpc/RpcClient.ts +283 -104
  1160. package/src/rpc/RpcSerialization.ts +53 -14
  1161. package/src/rpc/RpcServer.ts +27 -21
  1162. package/src/rpc/RpcTest.ts +3 -0
  1163. package/src/schema/VariantSchema.ts +86 -22
  1164. package/src/socket/Socket.ts +45 -20
  1165. package/src/sql/Migrator.ts +26 -11
  1166. package/src/sql/SqlClient.ts +273 -29
  1167. package/src/sql/SqlResolver.ts +32 -9
  1168. package/src/sql/Statement.ts +65 -10
  1169. package/src/testing/TestClock.ts +4 -1
  1170. package/src/testing/TestSchema.ts +9 -3
  1171. package/src/workflow/DurableDeferred.ts +23 -6
  1172. package/src/workflow/WorkflowEngine.ts +34 -10
  1173. package/dist/http/internal/preResponseHandler.d.ts +0 -2
  1174. package/dist/http/internal/preResponseHandler.d.ts.map +0 -1
  1175. package/dist/http/internal/preResponseHandler.js +0 -14
  1176. package/dist/http/internal/preResponseHandler.js.map +0 -1
  1177. package/src/http/internal/preResponseHandler.ts +0 -19
@@ -0,0 +1,1619 @@
1
+ /**
2
+ * Decodes and encodes XML 1.0 documents as streams of events in Effect
3
+ * channels.
4
+ *
5
+ * `decode` and `decodeString` turn UTF-8 bytes or text into events, and
6
+ * `encode` and `encodeString` write events back as XML. `elements` collects
7
+ * repeated elements, such as the items of a feed, into small trees, so that a
8
+ * large document can be processed one record at a time.
9
+ *
10
+ * The decoder checks that documents are well-formed. It never reads external
11
+ * resources and never expands entities declared in a DOCTYPE, so external
12
+ * entity (XXE) and entity expansion attacks do not apply. It does not validate
13
+ * documents against a DTD or schema, and reports names as written, without
14
+ * resolving namespaces.
15
+ *
16
+ * @stability experimental
17
+ * @since 4.0.6
18
+ */
19
+ import * as Arr from "../Array.js";
20
+ import * as Cause from "../Cause.js";
21
+ import * as Channel from "../Channel.js";
22
+ import * as Data from "../Data.js";
23
+ import * as Effect from "../Effect.js";
24
+ import * as Predicate from "../Predicate.js";
25
+ import * as Pull from "../Pull.js";
26
+ const XmlErrorTypeId = "~effect/encoding/Xml/XmlError";
27
+ /**
28
+ * Error raised when XML cannot be decoded or encoded.
29
+ *
30
+ * **Details**
31
+ *
32
+ * The `kind` field identifies the failure:
33
+ *
34
+ * - `Syntax`: the input is not well-formed XML or not valid UTF-8.
35
+ * - `Unsupported`: the input uses a feature this module does not process, such
36
+ * as an entity declared in a DOCTYPE or a byte encoding other than UTF-8.
37
+ * - `Limit`: the input exceeds `maxTokenSize`, `maxDepth` or `maxElementSize`.
38
+ * - `InvalidEvent`: the events do not form a well-formed document, such as an
39
+ * end tag that does not match its start tag.
40
+ *
41
+ * Errors from `decode` and `decodeString` carry the one-based `line` and
42
+ * `column` where the problem was found, also appended to `message`. Columns
43
+ * count UTF-16 code units, and lines end at LF, CR or CRLF.
44
+ *
45
+ * @stability experimental
46
+ * @category errors
47
+ * @since 4.0.6
48
+ */
49
+ export class XmlError extends /*#__PURE__*/Data.TaggedError("XmlError") {
50
+ /**
51
+ * Marks this value as an XML error for runtime guards.
52
+ *
53
+ * @stability experimental
54
+ * @since 4.0.6
55
+ */
56
+ [XmlErrorTypeId] = XmlErrorTypeId;
57
+ }
58
+ /**
59
+ * Checks whether a value is an `XmlError`.
60
+ *
61
+ * @stability experimental
62
+ * @category guards
63
+ * @since 4.0.6
64
+ */
65
+ export const isXmlError = u => Predicate.hasProperty(u, XmlErrorTypeId);
66
+ /**
67
+ * Creates a channel that decodes XML text chunks into events.
68
+ *
69
+ * **Details**
70
+ *
71
+ * - Tokens can be split anywhere between chunks. Each output chunk holds the
72
+ * events completed by one input chunk.
73
+ * - The document must have one root element. Whitespace outside it is not
74
+ * reported.
75
+ * - A leading byte order mark is skipped, and the encoding named by the XML
76
+ * declaration is ignored.
77
+ * - Events completed before an error are emitted before the channel fails.
78
+ *
79
+ * **Gotchas**
80
+ *
81
+ * - End of input inside the root fails with a `Syntax` error ("unclosed
82
+ * element"); interruption ends the stream without this check.
83
+ * - A DOCTYPE is reported as a `Doctype` event, and its internal subset is
84
+ * skipped without checking its declarations. They are not applied, so
85
+ * default attribute values are not added, and parameter entities are not
86
+ * expanded.
87
+ * - References to entities other than `<`, `>`, `&`, `'` and
88
+ * `"` fail with an `Unsupported` `XmlError` when the document has a
89
+ * DOCTYPE, and with a `Syntax` `XmlError` otherwise. Character references
90
+ * such as `é` are always decoded.
91
+ * - Names are reported as written, including namespace prefixes, and `xmlns`
92
+ * declarations are ordinary attributes.
93
+ * - Tokens or aggregate open element names longer than `maxTokenSize`, and
94
+ * elements nested deeper than `maxDepth`, fail with a `Limit` `XmlError`. A
95
+ * long token can instead fail with an error found in its first
96
+ * `maxTokenSize + 1` characters.
97
+ * - Strings in events can share memory with their input chunk, so keeping a
98
+ * short string, such as an id from each record, can keep the whole chunk in
99
+ * memory. Copy strings that are kept long, for example with
100
+ * `structuredClone`.
101
+ *
102
+ * **Example** (Decoding events)
103
+ *
104
+ * ```ts import.meta.vitest
105
+ * import { Effect, Stream } from "effect"
106
+ * import { Xml } from "effect/encoding"
107
+ *
108
+ * const events = Stream.make("<note id=\"1\">Hi &amp; bye<br/></note>").pipe(
109
+ * Stream.pipeThroughChannel(Xml.decodeString()),
110
+ * Stream.map((event) => event._tag),
111
+ * Stream.runCollect
112
+ * )
113
+ * await Effect.runPromise(events) // => ["StartElement", "Text", "StartElement", "EndElement", "EndElement"]
114
+ * ```
115
+ *
116
+ * @see {@link decode} for UTF-8 byte input
117
+ * @see {@link elements} for collecting repeated elements into trees
118
+ * @see {@link encodeString} for the inverse operation
119
+ *
120
+ * @stability experimental
121
+ * @category decoding
122
+ * @since 4.0.6
123
+ */
124
+ export const decodeString = options => {
125
+ const parser = makeParser(options, false);
126
+ return makeChannel(() => new TextInput(parser()));
127
+ };
128
+ /**
129
+ * Creates a channel that decodes UTF-8 XML bytes into events.
130
+ *
131
+ * **Details**
132
+ *
133
+ * Works like `decodeString` after decoding the bytes as UTF-8. Multi-byte
134
+ * characters can be split between chunks, and a leading byte order mark is
135
+ * skipped.
136
+ *
137
+ * **Gotchas**
138
+ *
139
+ * - Invalid or truncated UTF-8 fails with a `Syntax` `XmlError`.
140
+ * - An initial UTF-16 byte order mark or an XML declaration naming an encoding
141
+ * other than UTF-8 or US-ASCII fails with an `Unsupported` `XmlError`.
142
+ * Decode such bytes with a `TextDecoder` for that encoding and use `decodeString`.
143
+ *
144
+ * @see {@link decodeString} for text input and the shared gotchas
145
+ *
146
+ * @stability experimental
147
+ * @category decoding
148
+ * @since 4.0.6
149
+ */
150
+ export const decode = options => {
151
+ const parser = makeParser(options, true);
152
+ return makeChannel(() => new Utf8Input(parser()));
153
+ };
154
+ /**
155
+ * Creates a channel that collects the elements at a path into trees.
156
+ *
157
+ * **When to use**
158
+ *
159
+ * Use to process large documents such as feeds, sitemaps or exports one record
160
+ * at a time, without holding the whole document in memory.
161
+ *
162
+ * **Details**
163
+ *
164
+ * `path` lists element names from the root, and `"*"` matches any name. Each
165
+ * element whose ancestors and own name match the path is emitted once its end
166
+ * tag arrives, with all of its descendants; everything outside the matched
167
+ * elements is skipped. Because paths start at the root, an element nested in a
168
+ * matched element is part of its tree and is not emitted separately.
169
+ *
170
+ * **Gotchas**
171
+ *
172
+ * - A path that does not start at the root element matches nothing.
173
+ * - Whitespace between child elements, such as indentation, is kept as string
174
+ * children.
175
+ * - A collected element larger than `maxElementSize` fails with a `Limit`
176
+ * `XmlError`. The size counts characters, not memory: an element with many
177
+ * small children can take many times its size in memory, so use a lower
178
+ * limit for untrusted input.
179
+ * - Events that end inside an element, or end an element that was never
180
+ * started, fail with an `InvalidEvent` `XmlError`.
181
+ * - A path that is empty or contains an invalid name throws when the channel is
182
+ * created.
183
+ *
184
+ * **Example** (Reading feed items)
185
+ *
186
+ * ```ts import.meta.vitest
187
+ * import { Effect, Stream } from "effect"
188
+ * import { Xml } from "effect/encoding"
189
+ *
190
+ * const feed = `<rss><channel><title>News</title>
191
+ * <item><title>First</title></item>
192
+ * <item><title>Second</title></item>
193
+ * </channel></rss>`
194
+ *
195
+ * const items = await Effect.runPromise(
196
+ * Stream.make(feed).pipe(
197
+ * Stream.pipeThroughChannel(Xml.decodeString()),
198
+ * Stream.pipeThroughChannel(Xml.elements(["rss", "channel", "item"])),
199
+ * Stream.runCollect
200
+ * )
201
+ * )
202
+ * items.length // => 2
203
+ * items[1] // => { name: "item", attributes: {}, children: [{ name: "title", attributes: {}, children: ["Second"] }] }
204
+ * ```
205
+ *
206
+ * @see {@link decode} for producing events from bytes
207
+ *
208
+ * @stability experimental
209
+ * @category decoding
210
+ * @since 4.0.6
211
+ */
212
+ export const elements = (path, options) => {
213
+ if (path.length === 0) {
214
+ throw new Error("Xml: elements path must not be empty");
215
+ }
216
+ for (const name of path) {
217
+ if (name !== "*" && !isName(name)) {
218
+ throw new Error(`Xml: invalid element name in path: ${JSON.stringify(name)}`);
219
+ }
220
+ }
221
+ const maxElementSize = checkLimit("maxElementSize", options?.maxElementSize, defaultMaxElementSize);
222
+ const segments = Array.from(path);
223
+ return makeChannel(() => new Collector(segments, maxElementSize));
224
+ };
225
+ /**
226
+ * Creates a channel that writes events as XML text.
227
+ *
228
+ * **Details**
229
+ *
230
+ * - Each input chunk is written as one string.
231
+ * - Text escapes `&`, `<` and `>`. Attribute values are double-quoted and
232
+ * escape `&`, `<`, `"`, tabs and line breaks. Carriage returns are written
233
+ * as `&#13;` so that they survive decoding.
234
+ * - Start tags are written completely on their event. Empty elements use
235
+ * explicit closing tags, such as `<br></br>`, never self-closing tags.
236
+ * - Nothing is added between events, so whitespace comes only from `Text`
237
+ * events.
238
+ *
239
+ * **Gotchas**
240
+ *
241
+ * Events that do not form one well-formed document fail with an
242
+ * `InvalidEvent` `XmlError`, such as an end tag that does not match the open
243
+ * element, a second root element, non-whitespace text outside the root
244
+ * element, invalid names or characters, `--` in a comment, `?>` in processing
245
+ * instruction data, or a declaration that is not the first event. The stream
246
+ * must end with the root element closed.
247
+ *
248
+ * **Example** (Writing a document)
249
+ *
250
+ * ```ts import.meta.vitest
251
+ * import { Effect, Stream } from "effect"
252
+ * import { Xml } from "effect/encoding"
253
+ *
254
+ * const events: ReadonlyArray<Xml.Event> = [
255
+ * { _tag: "StartElement", name: "a", attributes: { href: "x?a=1&b=2" } },
256
+ * { _tag: "Text", text: "1 < 2" },
257
+ * { _tag: "EndElement", name: "a" }
258
+ * ]
259
+ *
260
+ * const xml = Stream.fromIterable(events).pipe(
261
+ * Stream.pipeThroughChannel(Xml.encodeString()),
262
+ * Stream.mkString
263
+ * )
264
+ * await Effect.runPromise(xml) // => '<a href="x?a=1&amp;b=2">1 &lt; 2</a>'
265
+ * ```
266
+ *
267
+ * @see {@link encode} for UTF-8 byte output
268
+ * @see {@link decodeString} for the inverse operation
269
+ *
270
+ * @stability experimental
271
+ * @category encoding
272
+ * @since 4.0.6
273
+ */
274
+ export const encodeString = () => makeChannel(() => new Writer(false));
275
+ /**
276
+ * Creates a channel that writes events as UTF-8 XML bytes.
277
+ *
278
+ * **Details**
279
+ *
280
+ * Works like `encodeString`, with one byte array per input chunk.
281
+ *
282
+ * **Gotchas**
283
+ *
284
+ * A `Declaration` event naming an encoding other than UTF-8 fails
285
+ * with an `InvalidEvent` `XmlError`.
286
+ *
287
+ * @see {@link encodeString} for text output and the shared gotchas
288
+ *
289
+ * @stability experimental
290
+ * @category encoding
291
+ * @since 4.0.6
292
+ */
293
+ export const encode = () => Channel.map(makeChannel(() => new Writer(true)), Arr.map(text => textEncoder.encode(text)));
294
+ const defaultMaxTokenSize = 10 * 1024 * 1024;
295
+ const defaultMaxDepth = 1024;
296
+ const defaultMaxElementSize = 16 * 1024 * 1024;
297
+ const checkLimit = (name, value, defaultValue) => {
298
+ const limit = value ?? defaultValue;
299
+ if (!(limit > 0)) {
300
+ throw new Error(`Xml: ${name} must be positive, got ${limit}`);
301
+ }
302
+ return limit;
303
+ };
304
+ const makeChannel = make => Channel.fromTransform((upstream, _scope) => Effect.sync(() => {
305
+ const machine = make();
306
+ let done;
307
+ let failure;
308
+ // Output completed before an error is emitted before the failure
309
+ const emit = inputs => {
310
+ try {
311
+ if (inputs === undefined) machine.end();else for (let i = 0; i < inputs.length; i++) machine.push(inputs[i]);
312
+ } catch (error) {
313
+ if (!isXmlError(error)) throw error;
314
+ failure = error;
315
+ }
316
+ const out = machine.out;
317
+ if (Arr.isArrayNonEmpty(out)) {
318
+ machine.out = [];
319
+ return Effect.succeed(out);
320
+ }
321
+ return pull;
322
+ };
323
+ const step = Pull.matchEffect(upstream, {
324
+ onSuccess: emit,
325
+ onFailure: Effect.failCause,
326
+ onDone: value => {
327
+ done = Cause.done(value);
328
+ return emit(undefined);
329
+ }
330
+ });
331
+ const pull = Effect.suspend(() => failure !== undefined ? Effect.fail(failure) : done ?? step);
332
+ return pull;
333
+ }));
334
+ const makeParser = (options, bytes) => {
335
+ const maxTokenSize = checkLimit("maxTokenSize", options?.maxTokenSize, defaultMaxTokenSize);
336
+ const maxDepth = checkLimit("maxDepth", options?.maxDepth, defaultMaxDepth);
337
+ return () => new Parser(maxTokenSize, maxDepth, bytes);
338
+ };
339
+ const textEncoder = /*#__PURE__*/new TextEncoder();
340
+ const TAB = 9;
341
+ const LF = 10;
342
+ const CR = 13;
343
+ const SPACE = 32;
344
+ const BANG = 33;
345
+ const DQUOTE = 34;
346
+ const HASH = 35;
347
+ const AMPERSAND = 38;
348
+ const SQUOTE = 39;
349
+ const DASH = 45;
350
+ const SLASH = 47;
351
+ const LT = 60;
352
+ const EQUALS = 61;
353
+ const GT = 62;
354
+ const QUESTION = 63;
355
+ const LBRACKET = 91;
356
+ const RBRACKET = 93;
357
+ const LOWER_X = 120;
358
+ const isSpace = c => c === SPACE || c === LF || c === TAB || c === CR;
359
+ // Characters outside the XML `Char` production, including unpaired surrogates
360
+ // oxlint-disable-next-line no-control-regex
361
+ const invalidChar = /[\0-\x08\x0B\x0C\x0E-\x1F\uFFFE\uFFFF\uD800-\uDFFF]/u;
362
+ // Decoded UTF-8 has no unpaired surrogates, and without the `u` flag the
363
+ // search runs several times faster on non-ASCII text
364
+ // oxlint-disable-next-line no-control-regex
365
+ const invalidDecodedChar = /[\0-\x08\x0B\x0C\x0E-\x1F\uFFFE\uFFFF]/;
366
+ // `isWellFormed` (ES2024) finds unpaired surrogates much faster than a `u`
367
+ // regex, which is slow on non-ASCII text
368
+ const isWellFormed = typeof String.prototype.isWellFormed === "function" ? s => s.isWellFormed() : undefined;
369
+ // Returns the index of the first character outside the XML `Char` production,
370
+ // or -1
371
+ const searchInvalid = s => isWellFormed !== undefined && s.search(invalidDecodedChar) === -1 && isWellFormed(s) ? -1 : s.search(invalidChar);
372
+ const isChar = c => c === TAB || c === LF || c === CR || c >= 0x20 && c <= 0xD7FF || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
373
+ const NAME_START = 1;
374
+ const NAME_CHAR = 2;
375
+ const asciiName = /*#__PURE__*/new Uint8Array(128);
376
+ for (let c = 0; c < 128; c++) {
377
+ if (c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 95 || c === 58) asciiName[c] = NAME_START | NAME_CHAR;else if (c >= 48 && c <= 57 || c === DASH || c === 46) asciiName[c] = NAME_CHAR;
378
+ }
379
+ // Name characters of XML 1.0 fifth edition. Supplementary characters are
380
+ // accepted by their surrogates, which are paired once input is validated.
381
+ const isNameStartCode = c => c < 128 ? (asciiName[c] & NAME_START) !== 0 : c >= 0xC0 && c <= 0xD6 || c >= 0xD8 && c <= 0xF6 || c >= 0xF8 && c <= 0x2FF || c >= 0x370 && c <= 0x37D || c >= 0x37F && c <= 0x1FFF || c >= 0x200C && c <= 0x200D || c >= 0x2070 && c <= 0x218F || c >= 0x2C00 && c <= 0x2FEF || c >= 0x3001 && c <= 0xD7FF || c >= 0xF900 && c <= 0xFDCF || c >= 0xFDF0 && c <= 0xFFFD || c >= 0xD800 && c <= 0xDB7F;
382
+ const isNameCode = c => c < 128 ? (asciiName[c] & NAME_CHAR) !== 0 : isNameStartCode(c) || c === 0xB7 || c >= 0x300 && c <= 0x36F || c >= 0x203F && c <= 0x2040 || c >= 0xDC00 && c <= 0xDFFF;
383
+ // Returns the end of the name starting at `i`, or `i` when there is none
384
+ const scanName = (s, i, end) => {
385
+ if (i >= end || !isNameStartCode(s.charCodeAt(i))) return i;
386
+ i++;
387
+ while (i < end && isNameCode(s.charCodeAt(i))) i++;
388
+ return i;
389
+ };
390
+ // Name characters exclude every invalid character but unpaired surrogates
391
+ const isName = s => s.length > 0 && scanName(s, 0, s.length) === s.length && (isWellFormed !== undefined ? isWellFormed(s) : !invalidChar.test(s));
392
+ const skipSpace = (s, i, end) => {
393
+ while (i < end && isSpace(s.charCodeAt(i))) i++;
394
+ return i;
395
+ };
396
+ const lineEndings = /\r\n?/g;
397
+ const attributeWhitespace = /\r\n|[\t\n\r]/g;
398
+ // Characters of an attribute value that need decoding, or are not allowed
399
+ const attributeSpecial = /[&<\t\n\r]/;
400
+ const attributeWhitespaceChar = /[\t\n\r]/;
401
+ // Attribute values shorter than this are scanned with a loop
402
+ const shortValue = 24;
403
+ const publicIdWhitespace = /[ \r\n]+/g;
404
+ const decimalDigits = /^[0-9]+$/;
405
+ const hexDigits = /^[0-9a-fA-F]+$/;
406
+ const versionPattern = /^1\.[0-9]+$/;
407
+ const encodingPattern = /^[A-Za-z][A-Za-z0-9._-]*$/;
408
+ const normalizeLines = s => s.indexOf("\r") === -1 ? s : s.replace(lineEndings, "\n");
409
+ // Normalizes the line endings and whitespace of a literal attribute value part
410
+ const normalizeAttribute = s => s.replace(attributeWhitespace, " ");
411
+ const isReservedTarget = target => target.length === 3 && target.toLowerCase() === "xml";
412
+ const isUtf8 = encoding => {
413
+ const lower = encoding.toLowerCase();
414
+ return lower === "utf-8" || lower === "us-ascii";
415
+ };
416
+ const declarationPattern = /^[ \t\r\n]+version[ \t\r\n]*=[ \t\r\n]*(?:"(1\.[0-9]+)"|'(1\.[0-9]+)')(?:[ \t\r\n]+encoding[ \t\r\n]*=[ \t\r\n]*(?:"([A-Za-z][A-Za-z0-9._-]*)"|'([A-Za-z][A-Za-z0-9._-]*)'))?(?:[ \t\r\n]+standalone[ \t\r\n]*=[ \t\r\n]*(?:"(yes|no)"|'(yes|no)'))?[ \t\r\n]*$/;
417
+ const pubidPattern = /^[ \r\na-zA-Z0-9\-'()+,./:=?;!*#@$_%]*$/;
418
+ // States of `Scanner`, which finds where a token split between chunks ends
419
+ const S_START = 0;
420
+ const S_TEXT = 1;
421
+ const S_LT = 2; // after "<"
422
+ const S_BANG = 3; // after "<!"
423
+ const S_KEYWORD = 4; // matching the rest of "<!--", "<![CDATA[" or "<!DOCTYPE"
424
+ const S_COMMENT = 5;
425
+ const S_CDATA = 6;
426
+ const S_PI = 7;
427
+ const S_TAG = 8;
428
+ const S_DOCTYPE = 9; // a DOCTYPE before its internal subset
429
+ const S_SUBSET = 10;
430
+ const S_SUBSET_LT = 11;
431
+ const S_SUBSET_BANG = 12;
432
+ const S_SUBSET_BANG_DASH = 13;
433
+ const S_SUBSET_COMMENT = 14;
434
+ const S_SUBSET_PI = 15;
435
+ const S_DECLARATION = 16; // a markup declaration in the internal subset
436
+ const S_AFTER_SUBSET = 17;
437
+ // Scans a token one character at a time, so that the scan can resume in the
438
+ // next chunk. A token "ends" where it is complete or where it is known to be
439
+ // malformed; the parser then reads the complete token from a single string.
440
+ class Scanner {
441
+ state = S_START;
442
+ // A count of matched keyword characters or trailing "-", "]" or "?"
443
+ // characters, or an open quote
444
+ aux = 0;
445
+ keyword = "";
446
+ reset(state) {
447
+ this.state = state;
448
+ this.aux = 0;
449
+ }
450
+ // Returns an index of `s` at which the token has ended, or -1
451
+ scan(s, i) {
452
+ const n = s.length;
453
+ while (i < n) {
454
+ const c = s.charCodeAt(i);
455
+ switch (this.state) {
456
+ case S_START:
457
+ {
458
+ this.state = c === LT ? S_LT : S_TEXT;
459
+ if (c !== LT) continue;
460
+ break;
461
+ }
462
+ case S_TEXT:
463
+ {
464
+ return s.indexOf("<", i);
465
+ }
466
+ case S_LT:
467
+ {
468
+ if (c === BANG) {
469
+ this.state = S_BANG;
470
+ } else if (c === QUESTION) {
471
+ this.reset(S_PI);
472
+ } else {
473
+ this.reset(S_TAG);
474
+ continue;
475
+ }
476
+ break;
477
+ }
478
+ case S_BANG:
479
+ {
480
+ if (c === DASH) this.keyword = "--";else if (c === LBRACKET) this.keyword = "[CDATA[";else if (c === 68) this.keyword = "DOCTYPE";else return i;
481
+ this.state = S_KEYWORD;
482
+ this.aux = 1;
483
+ break;
484
+ }
485
+ case S_KEYWORD:
486
+ {
487
+ if (c !== this.keyword.charCodeAt(this.aux)) return i;
488
+ if (++this.aux === this.keyword.length) {
489
+ this.reset(this.keyword === "--" ? S_COMMENT : this.keyword === "DOCTYPE" ? S_DOCTYPE : S_CDATA);
490
+ }
491
+ break;
492
+ }
493
+ case S_COMMENT:
494
+ case S_SUBSET_COMMENT:
495
+ {
496
+ if (c === DASH) {
497
+ this.aux++;
498
+ } else if (c === GT && this.aux >= 2) {
499
+ if (this.state === S_COMMENT) return i + 1;
500
+ this.reset(S_SUBSET);
501
+ } else {
502
+ this.aux = 0;
503
+ }
504
+ break;
505
+ }
506
+ case S_CDATA:
507
+ {
508
+ if (c === RBRACKET) this.aux++;else if (c === GT && this.aux >= 2) return i + 1;else this.aux = 0;
509
+ break;
510
+ }
511
+ case S_PI:
512
+ case S_SUBSET_PI:
513
+ {
514
+ if (c === GT && this.aux === 1) {
515
+ if (this.state === S_PI) return i + 1;
516
+ this.reset(S_SUBSET);
517
+ } else {
518
+ this.aux = c === QUESTION ? 1 : 0;
519
+ }
520
+ break;
521
+ }
522
+ case S_TAG:
523
+ {
524
+ // Attribute values cannot contain "<"
525
+ if (c === LT) return i;
526
+ if (this.aux === 0) {
527
+ if (c === GT) return i + 1;
528
+ if (c === DQUOTE || c === SQUOTE) this.aux = c;
529
+ } else if (c === this.aux) {
530
+ this.aux = 0;
531
+ }
532
+ break;
533
+ }
534
+ case S_DOCTYPE:
535
+ case S_DECLARATION:
536
+ {
537
+ if (this.aux === 0) {
538
+ if (c === LT) return i;
539
+ if (c === GT) {
540
+ if (this.state === S_DOCTYPE) return i + 1;
541
+ this.reset(S_SUBSET);
542
+ } else if (c === LBRACKET && this.state === S_DOCTYPE) {
543
+ this.reset(S_SUBSET);
544
+ } else if (c === DQUOTE || c === SQUOTE) {
545
+ this.aux = c;
546
+ }
547
+ } else if (c === this.aux) {
548
+ this.aux = 0;
549
+ }
550
+ break;
551
+ }
552
+ case S_SUBSET:
553
+ {
554
+ if (c === RBRACKET) this.state = S_AFTER_SUBSET;else if (c === LT) this.state = S_SUBSET_LT;else if (c === DQUOTE || c === SQUOTE || c === GT) return i;
555
+ break;
556
+ }
557
+ case S_SUBSET_LT:
558
+ {
559
+ if (c === BANG) this.state = S_SUBSET_BANG;else if (c === QUESTION) this.reset(S_SUBSET_PI);else return i;
560
+ break;
561
+ }
562
+ case S_SUBSET_BANG:
563
+ {
564
+ if (c === DASH) {
565
+ this.state = S_SUBSET_BANG_DASH;
566
+ } else {
567
+ this.reset(S_DECLARATION);
568
+ continue;
569
+ }
570
+ break;
571
+ }
572
+ case S_SUBSET_BANG_DASH:
573
+ {
574
+ if (c !== DASH) return i;
575
+ this.reset(S_SUBSET_COMMENT);
576
+ break;
577
+ }
578
+ case S_AFTER_SUBSET:
579
+ {
580
+ if (c === GT) return i + 1;
581
+ if (!isSpace(c)) return i;
582
+ break;
583
+ }
584
+ }
585
+ i++;
586
+ }
587
+ return -1;
588
+ }
589
+ }
590
+ const PROLOG = 0;
591
+ const CONTENT = 1;
592
+ const EPILOG = 2;
593
+ const describeToken = (s, i) => s.startsWith("<!--", i) ? "comment" : s.startsWith("<![CDATA[", i) ? "CDATA section" : s.startsWith("<!DOCTYPE", i) ? "DOCTYPE" : s.startsWith("<?", i) ? "processing instruction" : s.startsWith("</", i) ? "end tag" : "start tag";
594
+ // Attribute maps inherit nothing, so "__proto__" is an ordinary key and no
595
+ // attribute is inherited. Instances of a constructor are fast-mode objects in
596
+ // V8, several times faster to fill and iterate than the dictionary-mode
597
+ // objects that `Object.create(null)` makes, but V8 makes a hidden class for
598
+ // every distinct key sequence, so `Parser.shapes` decides which tags get one.
599
+ const Attributes = function () {};
600
+ Attributes.prototype = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.create(null));
601
+ const emptyAttributes = /*#__PURE__*/Object.freeze(/*#__PURE__*/new Attributes());
602
+ // The number of element names whose attribute order is tracked, and the
603
+ // number of attributes beyond which V8 would turn a fast-mode map into a
604
+ // dictionary anyway
605
+ const maxShapes = 256;
606
+ const maxFastAttributes = 16;
607
+ const pendingRun = 256;
608
+ class Parser {
609
+ out = [];
610
+ // The text being parsed, which starts at document offset `base`
611
+ buf = "";
612
+ base = 0;
613
+ // Number of characters received, excluding a byte order mark
614
+ received = 0;
615
+ started = false;
616
+ // A token that continues in the next chunk
617
+ pending;
618
+ pendingStart = 0;
619
+ pendingLength = 0;
620
+ // Number of chunks added to `pending` since its last chunks were joined
621
+ pendingAdded = 0;
622
+ scanner = /*#__PURE__*/new Scanner();
623
+ // Line and column of document offset `counted`
624
+ line = 1;
625
+ lineStart = 0;
626
+ counted = 0;
627
+ state = PROLOG;
628
+ stack = [];
629
+ openNameSize = 0;
630
+ // The attribute names of each element name, in the order they were first
631
+ // seen. A tag whose attributes follow that order, or extend it, gets a
632
+ // fast-mode map; one that diverges marks the element `null`, so that later
633
+ // tags get dictionary-mode maps and V8 does not get a hidden class per tag.
634
+ shapes = /*#__PURE__*/new Map();
635
+ doctype = false;
636
+ literalEnd = 0;
637
+ // Character data that has not been emitted yet, and its size in the input
638
+ text = "";
639
+ textSize = 0;
640
+ maxTokenSize;
641
+ maxDepth;
642
+ bytes;
643
+ ascii = false;
644
+ constructor(maxTokenSize, maxDepth, bytes) {
645
+ this.maxTokenSize = maxTokenSize;
646
+ this.maxDepth = maxDepth;
647
+ this.bytes = bytes;
648
+ }
649
+ // `force` parses a pending token without waiting for its end, so that an
650
+ // error found before invalid input is reported however the input is chunked
651
+ feed(chunk, force = false) {
652
+ if (chunk.length === 0 && !force) return;
653
+ if (!this.started) {
654
+ this.started = true;
655
+ if (chunk.charCodeAt(0) === 0xFEFF) chunk = chunk.slice(1);
656
+ }
657
+ if (this.bytes) {
658
+ const nonAscii = chunk.search(/[\u0080-\uFFFF]/);
659
+ if (nonAscii !== -1) {
660
+ // The prefix may contain the declaration that selects US-ASCII.
661
+ this.feed(chunk.slice(0, nonAscii), true);
662
+ if (this.ascii) throw this.error("Syntax", "invalid US-ASCII byte", this.received);
663
+ chunk = chunk.slice(nonAscii);
664
+ }
665
+ }
666
+ const invalid = this.bytes ? chunk.search(invalidDecodedChar) : searchInvalid(chunk);
667
+ if (invalid !== -1) {
668
+ // Parse up to the invalid character first, so that earlier errors are
669
+ // reported first however the input is chunked
670
+ this.consume(chunk.slice(0, invalid), true);
671
+ const code = chunk.codePointAt(invalid).toString(16).toUpperCase().padStart(4, "0");
672
+ throw this.error("Syntax", `invalid character U+${code}`, this.received);
673
+ }
674
+ this.consume(chunk, force);
675
+ }
676
+ end() {
677
+ if (this.pending !== undefined) {
678
+ this.load(this.pending.join(""), this.pendingStart);
679
+ this.pending = undefined;
680
+ }
681
+ this.parse(true);
682
+ if (this.state === PROLOG) throw this.error("Syntax", "no root element", this.received);
683
+ if (this.state === CONTENT) {
684
+ throw this.error("Syntax", `unclosed element <${this.stack[this.stack.length - 1]}>`, this.received);
685
+ }
686
+ }
687
+ error(kind, message, at) {
688
+ if (at > this.counted) {
689
+ if (this.pending !== undefined) this.count(this.pending.join(""), this.pendingStart, at - this.pendingStart);else this.count(this.buf, this.base, at - this.base);
690
+ }
691
+ const line = this.line;
692
+ const column = at - this.lineStart + 1;
693
+ return new XmlError({
694
+ kind,
695
+ message: `${message} at line ${line}, column ${column}`,
696
+ line,
697
+ column
698
+ });
699
+ }
700
+ // Advances the line count from `counted` to `to`, an index of `s`, which
701
+ // starts at document offset `base`. Counting resumes only where parsing
702
+ // stopped, which is never between a CR and an LF.
703
+ count(s, base, to) {
704
+ const i = this.counted - base;
705
+ if (i >= to) return;
706
+ let cr = s.indexOf("\r", i);
707
+ let lf = s.indexOf("\n", i);
708
+ while (true) {
709
+ if (cr !== -1 && cr < to && (lf === -1 || cr < lf)) {
710
+ this.line++;
711
+ this.lineStart = base + cr + 1;
712
+ cr = s.indexOf("\r", cr + 1);
713
+ } else if (lf !== -1 && lf < to) {
714
+ // The LF of a CRLF does not start a new line
715
+ if (!(lf > 0 && s.charCodeAt(lf - 1) === CR)) this.line++;
716
+ this.lineStart = base + lf + 1;
717
+ lf = s.indexOf("\n", lf + 1);
718
+ } else {
719
+ break;
720
+ }
721
+ }
722
+ this.counted = base + to;
723
+ }
724
+ syntax(message, i) {
725
+ return this.error("Syntax", message, this.base + i);
726
+ }
727
+ tokenLimit(at) {
728
+ return this.error("Limit", `token exceeds maxTokenSize of ${this.maxTokenSize}`, at);
729
+ }
730
+ consume(chunk, force = false) {
731
+ this.received += chunk.length;
732
+ if (this.pending !== undefined) {
733
+ if (!force && this.scanner.scan(chunk, 0) === -1) {
734
+ this.pending.push(chunk);
735
+ this.pendingLength += chunk.length;
736
+ // Joins runs of chunks, so that a token split into many tiny chunks
737
+ // does not take an array slot for each
738
+ if (++this.pendingAdded === pendingRun) {
739
+ this.pending.push(this.pending.splice(-pendingRun).join(""));
740
+ this.pendingAdded = 0;
741
+ }
742
+ this.checkPending();
743
+ return;
744
+ }
745
+ // Joining makes a flat string, which V8 reads faster than the rope that
746
+ // concatenation makes
747
+ this.pending.push(chunk);
748
+ this.load(this.pending.join(""), this.pendingStart);
749
+ this.pending = undefined;
750
+ } else {
751
+ this.load(chunk, this.received - chunk.length);
752
+ }
753
+ this.parse(false);
754
+ }
755
+ load(buf, base) {
756
+ this.buf = buf;
757
+ this.base = base;
758
+ }
759
+ // Fails an incomplete token over maxTokenSize, preferring an error in the
760
+ // first maxTokenSize + 1 characters of markup, as `parse` does
761
+ checkPending() {
762
+ const text = this.scanner.state === S_TEXT;
763
+ if (this.pendingLength + (text ? this.textSize : 0) <= this.maxTokenSize) return;
764
+ if (!text) {
765
+ this.load(this.pending.join("").slice(0, this.maxTokenSize + 1), this.pendingStart);
766
+ this.markup(this.buf, 0);
767
+ }
768
+ throw this.tokenLimit(this.pendingStart);
769
+ }
770
+ parse(final) {
771
+ const s = this.buf;
772
+ const n = s.length;
773
+ // Positions of the next "&", CR and "]]>", so that text runs are checked
774
+ // without searching past them repeatedly
775
+ let nextAmp = -1;
776
+ let nextCR = -1;
777
+ let nextCdataEnd = -1;
778
+ let i = 0;
779
+ while (i < n) {
780
+ if (s.charCodeAt(i) !== LT) {
781
+ let j = s.indexOf("<", i);
782
+ if (j === -1) {
783
+ if (!final) break;
784
+ j = n;
785
+ }
786
+ if (this.state !== CONTENT) {
787
+ this.checkSize(i, j);
788
+ this.whitespace(s, i, j);
789
+ } else {
790
+ this.addText(i, j - i);
791
+ if (nextCdataEnd < i) nextCdataEnd = indexOrEnd(s, "]]>", i);
792
+ if (nextCdataEnd < j) throw this.syntax("\"]]>\" is not allowed in text", nextCdataEnd);
793
+ if (nextAmp < i) nextAmp = indexOrEnd(s, "&", i);
794
+ if (nextCR < i) nextCR = indexOrEnd(s, "\r", i);
795
+ const raw = s.slice(i, j);
796
+ this.text += nextAmp >= j ? nextCR >= j ? raw : normalizeLines(raw) : this.decodeText(raw, i, false, nextCR < j);
797
+ }
798
+ i = j;
799
+ continue;
800
+ }
801
+ // Markup is parsed from at most maxTokenSize + 1 characters, so that its
802
+ // errors do not depend on how the input is chunked
803
+ const long = n - i > this.maxTokenSize;
804
+ const end = this.markup(long ? s.slice(0, i + this.maxTokenSize + 1) : s, i);
805
+ if (end === -1) {
806
+ if (long) throw this.tokenLimit(this.base + i);
807
+ if (final) throw this.syntax(`unterminated ${describeToken(s, i)}`, i);
808
+ break;
809
+ }
810
+ i = end;
811
+ }
812
+ this.count(s, this.base, i);
813
+ this.buf = "";
814
+ if (i < n) {
815
+ const rest = i === 0 ? s : s.slice(i);
816
+ this.pending = [rest];
817
+ this.pendingStart = this.base + i;
818
+ this.pendingLength = rest.length;
819
+ this.pendingAdded = 0;
820
+ // Brings the scanner to the end of the incomplete token
821
+ this.scanner.reset(S_START);
822
+ this.scanner.scan(rest, 0);
823
+ this.checkPending();
824
+ }
825
+ }
826
+ flushText() {
827
+ if (this.text.length > 0) {
828
+ this.out.push({
829
+ _tag: "Text",
830
+ text: this.text
831
+ });
832
+ this.text = "";
833
+ }
834
+ this.textSize = 0;
835
+ }
836
+ // Adds the size of the text run or CDATA section at `i`. Exceeding the limit
837
+ // is reported there, rather than at the start of the text.
838
+ addText(i, size) {
839
+ this.textSize += size;
840
+ if (this.textSize > this.maxTokenSize) {
841
+ throw this.tokenLimit(this.base + i);
842
+ }
843
+ }
844
+ // Checks that the text run `s[i, j)` outside the root element is whitespace
845
+ whitespace(s, i, j) {
846
+ for (let k = i; k < j; k++) {
847
+ if (!isSpace(s.charCodeAt(k))) {
848
+ throw this.syntax(this.state === PROLOG ? "text before the root element" : "text after the root element", k);
849
+ }
850
+ }
851
+ }
852
+ // Replaces references and normalizes line endings, or attribute whitespace.
853
+ // `whitespace` is false when `raw` has nothing to normalize.
854
+ decodeText(raw, offset, attribute, whitespace) {
855
+ let out = "";
856
+ let k = 0;
857
+ while (true) {
858
+ const amp = raw.indexOf("&", k);
859
+ const literal = raw.slice(k, amp === -1 ? raw.length : amp);
860
+ out += !whitespace ? literal : attribute ? normalizeAttribute(literal) : normalizeLines(literal);
861
+ if (amp === -1) return out;
862
+ const semicolon = raw.indexOf(";", amp + 1);
863
+ if (semicolon === -1) throw this.syntax("unterminated reference", offset + amp);
864
+ out += this.reference(raw, amp, semicolon, offset);
865
+ k = semicolon + 1;
866
+ }
867
+ }
868
+ // Decodes the reference `raw[amp, semicolon]`
869
+ reference(raw, amp, semicolon, offset) {
870
+ const c = raw.charCodeAt(amp + 1);
871
+ // The predefined entities, without slicing their names
872
+ if (c === 97) {
873
+ if (raw.startsWith("amp;", amp + 1)) return "&";
874
+ if (raw.startsWith("apos;", amp + 1)) return "'";
875
+ } else if (c === 108) {
876
+ if (raw.startsWith("lt;", amp + 1)) return "<";
877
+ } else if (c === 103) {
878
+ if (raw.startsWith("gt;", amp + 1)) return ">";
879
+ } else if (c === 113) {
880
+ if (raw.startsWith("quot;", amp + 1)) return "\"";
881
+ }
882
+ if (c === HASH) {
883
+ const hex = raw.charCodeAt(amp + 2) === LOWER_X;
884
+ const digits = raw.slice(amp + (hex ? 3 : 2), semicolon);
885
+ const code = (hex ? hexDigits : decimalDigits).test(digits) ? parseInt(digits, hex ? 16 : 10) : -1;
886
+ if (!isChar(code)) throw this.syntax("invalid character reference", offset + amp);
887
+ return String.fromCodePoint(code);
888
+ }
889
+ const name = raw.slice(amp + 1, semicolon);
890
+ if (!isName(name)) throw this.syntax("invalid reference", offset + amp);
891
+ if (this.doctype) {
892
+ throw this.error("Unsupported", `entity references other than the predefined entities are not supported: &${name};`, this.base + offset + amp);
893
+ }
894
+ throw this.syntax(`undefined entity &${name};`, offset + amp);
895
+ }
896
+ // Parses the markup at `i`, and returns its end or -1 when it is incomplete
897
+ markup(s, i) {
898
+ const n = s.length;
899
+ if (i + 1 >= n) return -1;
900
+ const c = s.charCodeAt(i + 1);
901
+ if (c === SLASH) return this.endTag(s, i);
902
+ if (c === QUESTION) return this.processingInstruction(s, i);
903
+ if (c !== BANG) return this.startTag(s, i);
904
+ if (i + 2 >= n) return -1;
905
+ const keyword = s.charCodeAt(i + 2) === DASH ? "<!--" : s.charCodeAt(i + 2) === LBRACKET ? "<![CDATA[" : "<!DOCTYPE";
906
+ if (!s.startsWith(keyword, i)) {
907
+ if (n - i < keyword.length && keyword.startsWith(s.slice(i))) return -1;
908
+ throw this.syntax("invalid markup", i);
909
+ }
910
+ return keyword === "<!--" ? this.comment(s, i) : keyword === "<!DOCTYPE" ? this.doctypeDeclaration(s, i) : this.cdata(s, i);
911
+ }
912
+ checkSize(i, end) {
913
+ if (end - i > this.maxTokenSize) {
914
+ throw this.tokenLimit(this.base + i);
915
+ }
916
+ }
917
+ startTag(s, i) {
918
+ const n = s.length;
919
+ if (this.state === EPILOG) throw this.syntax("content after the root element", i);
920
+ let j = scanName(s, i + 1, n);
921
+ if (j === i + 1) throw this.syntax("invalid element name", i + 1);
922
+ if (j >= n) return -1;
923
+ // In V8, a slice of 13 or more characters keeps its whole input chunk
924
+ // alive, and the name of an open element is held until its end tag, so
925
+ // long names are copied
926
+ const name = j - i - 1 < 13 ? s.slice(i + 1, j) : (" " + s.slice(i + 1, j)).slice(1);
927
+ let attributes;
928
+ let shape;
929
+ let index = 0;
930
+ let selfClosing = false;
931
+ while (true) {
932
+ let c = s.charCodeAt(j);
933
+ const space = isSpace(c);
934
+ if (space) {
935
+ j = skipSpace(s, j, n);
936
+ if (j >= n) return -1;
937
+ c = s.charCodeAt(j);
938
+ }
939
+ if (c === GT) {
940
+ j++;
941
+ break;
942
+ }
943
+ if (c === SLASH) {
944
+ if (j + 1 >= n) return -1;
945
+ if (s.charCodeAt(j + 1) !== GT) throw this.syntax("expected \">\"", j + 1);
946
+ j += 2;
947
+ selfClosing = true;
948
+ break;
949
+ }
950
+ if (!space) throw this.syntax("expected whitespace, \">\" or \"/>\"", j);
951
+ const nameStart = j;
952
+ j = scanName(s, j, n);
953
+ if (j === nameStart) throw this.syntax("invalid attribute name", j);
954
+ if (j >= n) return -1;
955
+ const attribute = s.slice(nameStart, j);
956
+ j = skipSpace(s, j, n);
957
+ if (j >= n) return -1;
958
+ if (s.charCodeAt(j) !== EQUALS) throw this.syntax("expected \"=\"", j);
959
+ j = skipSpace(s, j + 1, n);
960
+ if (j >= n) return -1;
961
+ const quote = s.charCodeAt(j);
962
+ if (quote !== DQUOTE && quote !== SQUOTE) throw this.syntax("expected a quoted attribute value", j);
963
+ const close = s.indexOf(quote === DQUOTE ? "\"" : "'", j + 1);
964
+ if (close === -1) {
965
+ const lt = s.indexOf("<", j + 1);
966
+ if (lt !== -1) throw this.syntax("\"<\" is not allowed in attribute values", lt);
967
+ return -1;
968
+ }
969
+ const value = this.attributeValue(s, j + 1, close);
970
+ if (attributes === undefined) {
971
+ shape = this.shapes.get(name);
972
+ if (shape === undefined && this.shapes.size < maxShapes) {
973
+ shape = [];
974
+ this.shapes.set(name, shape);
975
+ }
976
+ attributes = shape === undefined || shape === null || shape.length > maxFastAttributes ? Object.create(null) : new Attributes();
977
+ } else if (attributes[attribute] !== undefined) {
978
+ throw this.syntax(`duplicate attribute ${attribute}`, nameStart);
979
+ }
980
+ if (shape !== undefined && shape !== null && shape.length <= maxFastAttributes) {
981
+ // Stored names are copied, as they outlive the chunk
982
+ if (index === shape.length) shape.push((" " + attribute).slice(1));else if (shape[index] !== attribute) {
983
+ this.shapes.set(name, null);
984
+ shape = null;
985
+ }
986
+ }
987
+ index++;
988
+ attributes[attribute] = value;
989
+ j = close + 1;
990
+ if (j >= n) return -1;
991
+ }
992
+ this.checkSize(i, j);
993
+ if (this.stack.length >= this.maxDepth) {
994
+ throw this.error("Limit", `element nesting exceeds maxDepth of ${this.maxDepth}`, this.base + i);
995
+ }
996
+ if (!selfClosing && this.openNameSize + name.length > this.maxTokenSize) {
997
+ throw this.error("Limit", `open element names exceed maxTokenSize of ${this.maxTokenSize}`, this.base + i);
998
+ }
999
+ this.flushText();
1000
+ this.out.push({
1001
+ _tag: "StartElement",
1002
+ name,
1003
+ attributes: attributes ?? emptyAttributes
1004
+ });
1005
+ if (selfClosing) {
1006
+ this.out.push({
1007
+ _tag: "EndElement",
1008
+ name
1009
+ });
1010
+ if (this.stack.length === 0) this.state = EPILOG;
1011
+ } else {
1012
+ this.stack.push(name);
1013
+ this.openNameSize += name.length;
1014
+ this.state = CONTENT;
1015
+ }
1016
+ return j;
1017
+ }
1018
+ attributeValue(s, i, j) {
1019
+ let reference = false;
1020
+ let whitespace = false;
1021
+ if (j - i < shortValue) {
1022
+ for (let k = i; k < j; k++) {
1023
+ const c = s.charCodeAt(k);
1024
+ if (c === LT) throw this.syntax("\"<\" is not allowed in attribute values", k);
1025
+ if (c === AMPERSAND) reference = true;else if (c === TAB || c === LF || c === CR) whitespace = true;
1026
+ }
1027
+ if (!reference && !whitespace) return s.slice(i, j);
1028
+ } else {
1029
+ // A regex search beats the loop above on long values
1030
+ const value = s.slice(i, j);
1031
+ const special = value.search(attributeSpecial);
1032
+ if (special === -1) return value;
1033
+ const lt = value.indexOf("<", special);
1034
+ if (lt !== -1) throw this.syntax("\"<\" is not allowed in attribute values", i + lt);
1035
+ reference = value.indexOf("&", special) !== -1;
1036
+ whitespace = !reference || attributeWhitespaceChar.test(value);
1037
+ }
1038
+ const raw = s.slice(i, j);
1039
+ return reference ? this.decodeText(raw, i, true, whitespace) : normalizeAttribute(raw);
1040
+ }
1041
+ endTag(s, i) {
1042
+ const n = s.length;
1043
+ const j = scanName(s, i + 2, n);
1044
+ if (j === i + 2) {
1045
+ if (j >= n) return -1;
1046
+ throw this.syntax("invalid element name", j);
1047
+ }
1048
+ const k = skipSpace(s, j, n);
1049
+ if (k >= n) return -1;
1050
+ if (s.charCodeAt(k) !== GT) throw this.syntax("expected \">\"", k);
1051
+ const open = this.stack.length > 0 ? this.stack[this.stack.length - 1] : undefined;
1052
+ if (open === undefined) throw this.syntax("end tag without a start tag", i);
1053
+ if (j - i - 2 !== open.length || !s.startsWith(open, i + 2)) {
1054
+ throw this.syntax(`end tag </${s.slice(i + 2, j)}> does not match <${open}>`, i);
1055
+ }
1056
+ this.checkSize(i, k + 1);
1057
+ this.flushText();
1058
+ this.stack.pop();
1059
+ this.openNameSize -= open.length;
1060
+ this.out.push({
1061
+ _tag: "EndElement",
1062
+ name: open
1063
+ });
1064
+ if (this.stack.length === 0) this.state = EPILOG;
1065
+ return k + 1;
1066
+ }
1067
+ comment(s, i) {
1068
+ const end = s.indexOf("-->", i + 4);
1069
+ if (end === -1) return -1;
1070
+ const dashes = s.indexOf("--", i + 4);
1071
+ if (dashes < end) throw this.syntax("\"--\" is not allowed in comments", dashes);
1072
+ this.checkSize(i, end + 3);
1073
+ this.flushText();
1074
+ this.out.push({
1075
+ _tag: "Comment",
1076
+ text: normalizeLines(s.slice(i + 4, end))
1077
+ });
1078
+ return end + 3;
1079
+ }
1080
+ processingInstruction(s, i) {
1081
+ const end = s.indexOf("?>", i + 2);
1082
+ if (end === -1) return -1;
1083
+ const t = scanName(s, i + 2, end);
1084
+ if (t === i + 2) throw this.syntax("invalid processing instruction target", i + 2);
1085
+ const target = s.slice(i + 2, t);
1086
+ if (isReservedTarget(target)) {
1087
+ if (target === "xml" && this.base + i === 0) return this.declaration(s, i, t, end);
1088
+ throw this.syntax(target === "xml" ? "the XML declaration is only allowed at the start of the document" : `processing instruction target ${target} is reserved`, i);
1089
+ }
1090
+ let data = "";
1091
+ if (t < end) {
1092
+ if (!isSpace(s.charCodeAt(t))) throw this.syntax("expected whitespace after the target", t);
1093
+ data = normalizeLines(s.slice(skipSpace(s, t, end), end));
1094
+ }
1095
+ this.checkSize(i, end + 2);
1096
+ this.flushText();
1097
+ this.out.push({
1098
+ _tag: "ProcessingInstruction",
1099
+ target,
1100
+ data
1101
+ });
1102
+ return end + 2;
1103
+ }
1104
+ declaration(s, i, t, end) {
1105
+ this.checkSize(i, end + 2);
1106
+ const match = declarationPattern.exec(s.slice(t, end));
1107
+ if (match === null) throw this.syntax("invalid XML declaration", i);
1108
+ const encoding = match[3] ?? match[4];
1109
+ const standalone = match[5] ?? match[6];
1110
+ if (this.bytes && encoding !== undefined && !isUtf8(encoding)) {
1111
+ throw this.error("Unsupported", `encoding ${encoding} is not supported for byte input, decode the bytes to text first`, this.base + i);
1112
+ }
1113
+ this.ascii = this.bytes && encoding?.toLowerCase() === "us-ascii";
1114
+ const event = {
1115
+ _tag: "Declaration",
1116
+ version: match[1] ?? match[2]
1117
+ };
1118
+ if (encoding !== undefined) event.encoding = encoding;
1119
+ if (standalone !== undefined) event.standalone = standalone === "yes";
1120
+ this.out.push(event);
1121
+ return end + 2;
1122
+ }
1123
+ cdata(s, i) {
1124
+ const end = s.indexOf("]]>", i + 9);
1125
+ if (end === -1) return -1;
1126
+ if (this.state !== CONTENT) throw this.syntax("CDATA sections are only allowed inside the root element", i);
1127
+ this.addText(i, end + 3 - i);
1128
+ this.text += normalizeLines(s.slice(i + 9, end));
1129
+ return end + 3;
1130
+ }
1131
+ doctypeDeclaration(s, i) {
1132
+ if (this.state !== PROLOG || this.doctype) {
1133
+ throw this.syntax("a DOCTYPE is only allowed once, before the root element", i);
1134
+ }
1135
+ const scanner = new Scanner();
1136
+ scanner.reset(S_DOCTYPE);
1137
+ const end = scanner.scan(s, i + 9);
1138
+ if (end === -1) return -1;
1139
+ this.checkSize(i, end);
1140
+ this.doctype = true;
1141
+ let j = this.space(s, i + 9, end);
1142
+ const nameEnd = this.name(s, j, end);
1143
+ const event = {
1144
+ _tag: "Doctype",
1145
+ name: s.slice(j, nameEnd)
1146
+ };
1147
+ j = skipSpace(s, nameEnd, end);
1148
+ if (j > nameEnd && (s.startsWith("PUBLIC", j) || s.startsWith("SYSTEM", j))) {
1149
+ if (s.charCodeAt(j) === 80) {
1150
+ // Whitespace in public identifiers is normalized for matching
1151
+ event.publicId = this.publicLiteral(s, this.space(s, j + 6, end), end).replace(publicIdWhitespace, " ").trim();
1152
+ j = this.literalEnd;
1153
+ }
1154
+ event.systemId = normalizeLines(this.literal(s, this.space(s, j + (event.publicId === undefined ? 6 : 0), end), end));
1155
+ j = skipSpace(s, this.literalEnd, end);
1156
+ }
1157
+ if (s.charCodeAt(j) === LBRACKET) {
1158
+ // The scanner skips the internal subset, whose declarations are not
1159
+ // checked, and ends the token early only at malformed markup
1160
+ if (scanner.state !== S_AFTER_SUBSET) throw this.syntax("invalid markup in the internal subset", end);
1161
+ j = skipSpace(s, s.lastIndexOf("]", end - 1) + 1, end);
1162
+ }
1163
+ if (j !== end - 1 || s.charCodeAt(j) !== GT) throw this.syntax("invalid DOCTYPE", j);
1164
+ this.out.push(event);
1165
+ return end;
1166
+ }
1167
+ // Skips the whitespace that is required at `i`
1168
+ space(s, i, end) {
1169
+ if (i >= end || !isSpace(s.charCodeAt(i))) throw this.syntax("expected whitespace", i);
1170
+ return skipSpace(s, i, end);
1171
+ }
1172
+ // Returns the end of the name that is required at `i`
1173
+ name(s, i, end) {
1174
+ const nameEnd = scanName(s, i, end);
1175
+ if (nameEnd === i) throw this.syntax("expected a name", i);
1176
+ return nameEnd;
1177
+ }
1178
+ // Reads the quoted literal at `i`, and sets `literalEnd` to the index after it
1179
+ literal(s, i, end) {
1180
+ const quote = s.charCodeAt(i);
1181
+ if (quote !== DQUOTE && quote !== SQUOTE) throw this.syntax("expected a quoted literal", i);
1182
+ const close = s.indexOf(quote === DQUOTE ? "\"" : "'", i + 1);
1183
+ // Unreachable while the scanner ends a DOCTYPE only after its literals close
1184
+ if (close === -1 || close >= end) throw this.syntax("unterminated literal", i);
1185
+ this.literalEnd = close + 1;
1186
+ return s.slice(i + 1, close);
1187
+ }
1188
+ publicLiteral(s, i, end) {
1189
+ const literal = this.literal(s, i, end);
1190
+ if (!pubidPattern.test(literal)) throw this.syntax("invalid public identifier", i);
1191
+ return literal;
1192
+ }
1193
+ }
1194
+ const indexOrEnd = (s, search, from) => {
1195
+ const i = s.indexOf(search, from);
1196
+ return i === -1 ? s.length : i;
1197
+ };
1198
+ class TextInput {
1199
+ parser;
1200
+ // A high surrogate at the end of a chunk, which pairs with the next chunk
1201
+ surrogate = "";
1202
+ constructor(parser) {
1203
+ this.parser = parser;
1204
+ }
1205
+ get out() {
1206
+ return this.parser.out;
1207
+ }
1208
+ set out(out) {
1209
+ this.parser.out = out;
1210
+ }
1211
+ push(chunk) {
1212
+ if (this.surrogate !== "") {
1213
+ chunk = this.surrogate + chunk;
1214
+ this.surrogate = "";
1215
+ }
1216
+ const last = chunk.charCodeAt(chunk.length - 1);
1217
+ if (last >= 0xD800 && last <= 0xDBFF) {
1218
+ this.surrogate = chunk.slice(-1);
1219
+ chunk = chunk.slice(0, -1);
1220
+ }
1221
+ this.parser.feed(chunk);
1222
+ }
1223
+ end() {
1224
+ // An unpaired high surrogate fails as an invalid character
1225
+ this.parser.feed(this.surrogate);
1226
+ this.parser.end();
1227
+ }
1228
+ }
1229
+ const utf8Length = lead => lead >= 0xF0 ? 4 : lead >= 0xE0 ? 3 : lead >= 0xC0 ? 2 : 1;
1230
+ // Returns the length of the valid UTF-8 prefix of `bytes`
1231
+ const validUtf8 = bytes => {
1232
+ let i = 0;
1233
+ while (i < bytes.length) {
1234
+ const lead = bytes[i];
1235
+ if (lead < 0x80) {
1236
+ i++;
1237
+ continue;
1238
+ }
1239
+ const length = lead >= 0xC2 && lead <= 0xF4 ? utf8Length(lead) : 0;
1240
+ if (length === 0 || i + length > bytes.length) return i;
1241
+ let code = lead & 0xFF >> length + 1;
1242
+ for (let k = 1; k < length; k++) {
1243
+ const c = bytes[i + k];
1244
+ if ((c & 0xC0) !== 0x80) return i;
1245
+ code = code << 6 | c & 0x3F;
1246
+ }
1247
+ const min = length === 2 ? 0x80 : length === 3 ? 0x800 : 0x10000;
1248
+ if (code < min || code > 0x10FFFF || code >= 0xD800 && code <= 0xDFFF) return i;
1249
+ i += length;
1250
+ }
1251
+ return i;
1252
+ };
1253
+ const utf8Decoder = /*#__PURE__*/new TextDecoder("utf-8", {
1254
+ fatal: true,
1255
+ ignoreBOM: true
1256
+ });
1257
+ // Decodes UTF-8 without streaming state, so that the position of invalid bytes
1258
+ // is known: an incomplete sequence at the end of a chunk is carried over.
1259
+ class Utf8Input {
1260
+ parser;
1261
+ carry;
1262
+ started = false;
1263
+ constructor(parser) {
1264
+ this.parser = parser;
1265
+ }
1266
+ get out() {
1267
+ return this.parser.out;
1268
+ }
1269
+ set out(out) {
1270
+ this.parser.out = out;
1271
+ }
1272
+ push(chunk) {
1273
+ if (!this.started && chunk.length > 0) {
1274
+ const first = this.carry === undefined ? chunk[0] : this.carry[0];
1275
+ const second = this.carry === undefined ? chunk[1] : chunk[0];
1276
+ if (first === 0xFE && second === 0xFF || first === 0xFF && second === 0xFE) {
1277
+ throw this.parser.error("Unsupported", "UTF-16 is not supported for byte input, decode the bytes to text first", 0);
1278
+ }
1279
+ // Keep a lone BOM prefix pending in the UTF-8 carry below
1280
+ this.started = second !== undefined || first !== 0xFE && first !== 0xFF;
1281
+ }
1282
+ let start = 0;
1283
+ if (this.carry !== undefined) {
1284
+ const need = utf8Length(this.carry[0]) - this.carry.length;
1285
+ const head = new Uint8Array(this.carry.length + Math.min(need, chunk.length));
1286
+ head.set(this.carry);
1287
+ head.set(chunk.subarray(0, need), this.carry.length);
1288
+ if (chunk.length < need) {
1289
+ this.carry = head;
1290
+ return;
1291
+ }
1292
+ this.carry = undefined;
1293
+ this.decode(head);
1294
+ start = need;
1295
+ }
1296
+ const n = chunk.length;
1297
+ let end = n;
1298
+ for (let k = 1; k <= 3 && n - k >= start; k++) {
1299
+ const b = chunk[n - k];
1300
+ if ((b & 0xC0) === 0x80) continue;
1301
+ if (b >= 0xC0 && k < utf8Length(b)) end = n - k;
1302
+ break;
1303
+ }
1304
+ if (end < n) this.carry = chunk.slice(end);
1305
+ if (end > start) this.decode(start === 0 && end === n ? chunk : chunk.subarray(start, end));
1306
+ }
1307
+ end() {
1308
+ // The carried bytes may also be an invalid sequence, such as a single 0xFF
1309
+ if (this.carry !== undefined) {
1310
+ this.parser.feed("", true);
1311
+ throw this.parser.error("Syntax", "invalid UTF-8", this.parser.received);
1312
+ }
1313
+ this.parser.end();
1314
+ }
1315
+ decode(bytes) {
1316
+ let text;
1317
+ try {
1318
+ text = utf8Decoder.decode(bytes);
1319
+ } catch {
1320
+ this.parser.feed(utf8Decoder.decode(bytes.subarray(0, validUtf8(bytes))), true);
1321
+ throw this.parser.error("Syntax", "invalid UTF-8", this.parser.received);
1322
+ }
1323
+ this.parser.feed(text);
1324
+ }
1325
+ }
1326
+ class Collector {
1327
+ out = [];
1328
+ depth = 0;
1329
+ // Number of open elements, from the root, that match the path
1330
+ matched = 0;
1331
+ // The element being collected and its open descendants
1332
+ stack = [];
1333
+ size = 0;
1334
+ path;
1335
+ maxElementSize;
1336
+ constructor(path, maxElementSize) {
1337
+ this.path = path;
1338
+ this.maxElementSize = maxElementSize;
1339
+ }
1340
+ push(event) {
1341
+ switch (event._tag) {
1342
+ case "StartElement":
1343
+ {
1344
+ const depth = this.depth++;
1345
+ if (this.stack.length === 0) {
1346
+ const segment = this.path[depth];
1347
+ if (this.matched !== depth || segment !== "*" && segment !== event.name) return;
1348
+ if (++this.matched < this.path.length) return;
1349
+ this.size = 0;
1350
+ }
1351
+ const element = {
1352
+ name: event.name,
1353
+ attributes: event.attributes,
1354
+ children: []
1355
+ };
1356
+ if (this.stack.length > 0) this.stack[this.stack.length - 1].children.push(element);
1357
+ this.stack.push(element);
1358
+ let size = event.name.length;
1359
+ for (const key in event.attributes) size += key.length + event.attributes[key].length;
1360
+ this.grow(size);
1361
+ return;
1362
+ }
1363
+ case "EndElement":
1364
+ {
1365
+ if (this.depth === 0) throw invalidEvent(`end tag </${event.name}> without a start tag`);
1366
+ if (this.stack.length > 0) {
1367
+ const element = this.stack.pop();
1368
+ if (this.stack.length === 0) this.out.push(element);
1369
+ }
1370
+ if (this.matched === this.depth) this.matched--;
1371
+ this.depth--;
1372
+ return;
1373
+ }
1374
+ case "Text":
1375
+ {
1376
+ if (this.stack.length === 0 || event.text.length === 0) return;
1377
+ this.grow(event.text.length);
1378
+ const children = this.stack[this.stack.length - 1].children;
1379
+ const last = children.length - 1;
1380
+ if (last >= 0 && typeof children[last] === "string") children[last] += event.text;else children.push(event.text);
1381
+ return;
1382
+ }
1383
+ }
1384
+ }
1385
+ end() {
1386
+ if (this.depth > 0) throw invalidEvent("events ended inside an element");
1387
+ }
1388
+ grow(size) {
1389
+ this.size += size;
1390
+ if (this.size > this.maxElementSize) {
1391
+ throw positionless("Limit", `element <${this.stack[0].name}> exceeds maxElementSize of ${this.maxElementSize}`);
1392
+ }
1393
+ }
1394
+ }
1395
+ // JavaScriptCore gives every Error its own source `line` and `column`, which
1396
+ // would pass for an XML position, so errors without one set both to undefined
1397
+ const positionless = (kind, message) => new XmlError({
1398
+ kind,
1399
+ message,
1400
+ line: undefined,
1401
+ column: undefined
1402
+ });
1403
+ const invalidEvent = message => positionless("InvalidEvent", message);
1404
+ const textSpecial = /[&<>\r]/;
1405
+ const attributeSpecials = /[&<"\t\n\r]/;
1406
+ // The regex finds the first special character, which is fast when there is
1407
+ // none; the rest is copied in runs between escapes. Invalid characters are
1408
+ // kept, so that the writer can check them in the output.
1409
+ const escapeText = s => {
1410
+ const first = s.search(textSpecial);
1411
+ if (first === -1) return s;
1412
+ let out = "";
1413
+ let last = 0;
1414
+ for (let i = first; i < s.length; i++) {
1415
+ const c = s.charCodeAt(i);
1416
+ const escaped = c === AMPERSAND ? "&amp;" : c === LT ? "&lt;" : c === GT ? "&gt;" : c === CR ? "&#13;" : undefined;
1417
+ if (escaped !== undefined) {
1418
+ out += s.slice(last, i) + escaped;
1419
+ last = i + 1;
1420
+ }
1421
+ }
1422
+ return out + s.slice(last);
1423
+ };
1424
+ const escapeAttribute = s => {
1425
+ const first = s.search(attributeSpecials);
1426
+ if (first === -1) return s;
1427
+ let out = "";
1428
+ let last = 0;
1429
+ for (let i = first; i < s.length; i++) {
1430
+ const c = s.charCodeAt(i);
1431
+ const escaped = c === AMPERSAND ? "&amp;" : c === LT ? "&lt;" : c === DQUOTE ? "&quot;" : c === TAB ? "&#9;" : c === LF ? "&#10;" : c === CR ? "&#13;" : undefined;
1432
+ if (escaped !== undefined) {
1433
+ out += s.slice(last, i) + escaped;
1434
+ last = i + 1;
1435
+ }
1436
+ }
1437
+ return out + s.slice(last);
1438
+ };
1439
+ const checkChars = (what, s) => {
1440
+ const invalid = searchInvalid(s);
1441
+ if (invalid !== -1) {
1442
+ const code = s.codePointAt(invalid).toString(16).toUpperCase().padStart(4, "0");
1443
+ throw invalidEvent(`${what} contains the invalid character U+${code}`);
1444
+ }
1445
+ };
1446
+ const checkName = (what, name) => {
1447
+ if (typeof name !== "string" || !isName(name)) throw invalidEvent(`invalid ${what} ${JSON.stringify(name)}`);
1448
+ };
1449
+ const isWhitespace = s => {
1450
+ for (let i = 0; i < s.length; i++) {
1451
+ if (!isSpace(s.charCodeAt(i))) return false;
1452
+ }
1453
+ return true;
1454
+ };
1455
+ const NOTHING_WRITTEN = 3;
1456
+ class Writer {
1457
+ out = [];
1458
+ stack = [];
1459
+ state = NOTHING_WRITTEN;
1460
+ doctype = false;
1461
+ bytes;
1462
+ // Element and attribute names already checked, which repeat in most
1463
+ // documents. Cleared when full, so that it stays small.
1464
+ names = /*#__PURE__*/new Set();
1465
+ constructor(bytes) {
1466
+ this.bytes = bytes;
1467
+ }
1468
+ checkName(what, name) {
1469
+ if (!this.isName(name)) checkName(what, name);
1470
+ }
1471
+ isName(name) {
1472
+ if (this.names.has(name)) return true;
1473
+ if (typeof name !== "string" || !isName(name)) return false;
1474
+ if (this.names.size >= 1024) this.names.clear();
1475
+ this.names.add(name);
1476
+ return true;
1477
+ }
1478
+ // Checks attributes one by one, in order, after a batched check has failed
1479
+ checkAttributes(attributes) {
1480
+ for (const name in attributes) {
1481
+ if (!Object.hasOwn(attributes, name)) continue;
1482
+ const value = attributes[name];
1483
+ this.checkName("attribute name", name);
1484
+ if (typeof value !== "string") throw invalidEvent(`attribute ${name} must be a string`);
1485
+ checkChars(`attribute ${name}`, value);
1486
+ }
1487
+ }
1488
+ push(event) {
1489
+ const text = this.write(event);
1490
+ if (text.length > 0) {
1491
+ const out = this.out;
1492
+ if (out.length > 0) out[0] += text;else out.push(text);
1493
+ }
1494
+ }
1495
+ end() {
1496
+ if (this.stack.length > 0) throw invalidEvent(`unclosed element <${this.stack[this.stack.length - 1]}>`);
1497
+ if (this.state !== EPILOG) throw invalidEvent("no root element");
1498
+ }
1499
+ write(event) {
1500
+ if (event._tag === "EndElement") {
1501
+ const open = this.stack.length > 0 ? this.stack[this.stack.length - 1] : undefined;
1502
+ if (open === undefined || event.name !== open) {
1503
+ // Only valid names are written into messages
1504
+ checkName("element name", event.name);
1505
+ throw invalidEvent(open === undefined ? `end tag </${event.name}> without a start tag` : `end tag </${event.name}> does not match <${open}>`);
1506
+ }
1507
+ this.stack.pop();
1508
+ if (this.stack.length === 0) this.state = EPILOG;
1509
+ return `</${open}>`;
1510
+ }
1511
+ switch (event._tag) {
1512
+ case "StartElement":
1513
+ {
1514
+ this.checkName("element name", event.name);
1515
+ if (this.state === EPILOG) throw invalidEvent(`second root element <${event.name}>`);
1516
+ let tag = "<" + event.name;
1517
+ let valid = true;
1518
+ for (const name in event.attributes) {
1519
+ if (!Object.hasOwn(event.attributes, name)) continue;
1520
+ const value = event.attributes[name];
1521
+ if (typeof value !== "string" || !this.isName(name)) {
1522
+ valid = false;
1523
+ break;
1524
+ }
1525
+ tag += ` ${name}="${escapeAttribute(value)}"`;
1526
+ }
1527
+ // Escaping keeps invalid characters, so one search of the tag checks
1528
+ // every value; the first error is then found in attribute order
1529
+ if (!valid || tag.length > event.name.length + 1 && searchInvalid(tag) !== -1) {
1530
+ this.checkAttributes(event.attributes);
1531
+ }
1532
+ this.stack.push(event.name);
1533
+ this.state = CONTENT;
1534
+ return tag + ">";
1535
+ }
1536
+ case "Text":
1537
+ {
1538
+ if (this.state !== CONTENT) {
1539
+ checkChars("text", event.text);
1540
+ if (!isWhitespace(event.text)) throw invalidEvent("text outside the root element must be whitespace");
1541
+ if (this.state === NOTHING_WRITTEN && event.text.length > 0) this.state = PROLOG;
1542
+ return event.text;
1543
+ }
1544
+ checkChars("text", event.text);
1545
+ return escapeText(event.text);
1546
+ }
1547
+ case "Comment":
1548
+ {
1549
+ checkChars("comment", event.text);
1550
+ if (event.text.includes("--") || event.text.endsWith("-")) {
1551
+ throw invalidEvent("comments cannot contain \"--\" or end with \"-\"");
1552
+ }
1553
+ if (this.state === NOTHING_WRITTEN) this.state = PROLOG;
1554
+ return `<!--${event.text}-->`;
1555
+ }
1556
+ case "ProcessingInstruction":
1557
+ {
1558
+ checkName("processing instruction target", event.target);
1559
+ if (isReservedTarget(event.target)) {
1560
+ throw invalidEvent(`processing instruction target ${event.target} is reserved`);
1561
+ }
1562
+ checkChars("processing instruction", event.data);
1563
+ if (event.data.includes("?>")) throw invalidEvent("processing instruction data cannot contain \"?>\"");
1564
+ if (this.state === NOTHING_WRITTEN) this.state = PROLOG;
1565
+ return `<?${event.target}${event.data === "" ? "" : " " + event.data}?>`;
1566
+ }
1567
+ case "Declaration":
1568
+ {
1569
+ if (this.state !== NOTHING_WRITTEN) throw invalidEvent("the XML declaration must be the first event");
1570
+ if (!versionPattern.test(event.version)) {
1571
+ throw invalidEvent(`invalid XML version ${JSON.stringify(event.version)}`);
1572
+ }
1573
+ let declaration = `<?xml version="${event.version}"`;
1574
+ if (event.encoding !== undefined) {
1575
+ if (!encodingPattern.test(event.encoding)) {
1576
+ throw invalidEvent(`invalid encoding name ${JSON.stringify(event.encoding)}`);
1577
+ }
1578
+ if (this.bytes && event.encoding.toLowerCase() !== "utf-8") {
1579
+ throw invalidEvent(`encoding ${event.encoding} cannot be declared for UTF-8 output`);
1580
+ }
1581
+ declaration += ` encoding="${event.encoding}"`;
1582
+ }
1583
+ if (event.standalone !== undefined) declaration += ` standalone="${event.standalone ? "yes" : "no"}"`;
1584
+ this.state = PROLOG;
1585
+ return declaration + "?>";
1586
+ }
1587
+ case "Doctype":
1588
+ {
1589
+ if (this.state === CONTENT || this.state === EPILOG || this.doctype) {
1590
+ throw invalidEvent("a DOCTYPE must appear once, before the root element");
1591
+ }
1592
+ checkName("DOCTYPE name", event.name);
1593
+ let doctype = `<!DOCTYPE ${event.name}`;
1594
+ if (event.publicId !== undefined) {
1595
+ if (event.systemId === undefined) {
1596
+ throw invalidEvent("a DOCTYPE with a public identifier needs a system identifier");
1597
+ }
1598
+ if (!pubidPattern.test(event.publicId)) {
1599
+ throw invalidEvent(`invalid public identifier ${JSON.stringify(event.publicId)}`);
1600
+ }
1601
+ doctype += ` PUBLIC "${event.publicId}"`;
1602
+ }
1603
+ if (event.systemId !== undefined) {
1604
+ checkChars("system identifier", event.systemId);
1605
+ const hasDouble = event.systemId.includes("\"");
1606
+ if (hasDouble && event.systemId.includes("'")) {
1607
+ throw invalidEvent("a system identifier cannot contain both quote characters");
1608
+ }
1609
+ if (event.publicId === undefined) doctype += " SYSTEM";
1610
+ doctype += hasDouble ? ` '${event.systemId}'` : ` "${event.systemId}"`;
1611
+ }
1612
+ this.doctype = true;
1613
+ this.state = PROLOG;
1614
+ return doctype + ">";
1615
+ }
1616
+ }
1617
+ }
1618
+ }
1619
+ //# sourceMappingURL=Xml.js.map