wasm-idle 0.7.2 → 1.0.0

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 (386) hide show
  1. package/README.md +760 -81
  2. package/dist/index.d.ts +4 -9
  3. package/dist/index.js +2 -4
  4. package/dist/playground/applicationAssets.d.ts +4 -0
  5. package/dist/playground/applicationAssets.js +277 -0
  6. package/dist/playground/assemblyscript.d.ts +41 -0
  7. package/dist/playground/assemblyscript.js +630 -0
  8. package/dist/playground/assetBridge.d.ts +18 -7
  9. package/dist/playground/assetBridge.js +824 -100
  10. package/dist/playground/assets.d.ts +813 -19
  11. package/dist/playground/assets.js +2096 -156
  12. package/dist/playground/awk.d.ts +5 -0
  13. package/dist/playground/awk.js +60 -0
  14. package/dist/playground/bash.d.ts +53 -0
  15. package/dist/playground/bash.js +1096 -0
  16. package/dist/playground/bashWorkerProtocol.d.ts +88 -0
  17. package/dist/playground/bashWorkerProtocol.js +135 -0
  18. package/dist/playground/bqn.d.ts +5 -0
  19. package/dist/playground/bqn.js +57 -0
  20. package/dist/playground/bqnPreflight.d.ts +26 -0
  21. package/dist/playground/bqnPreflight.js +399 -0
  22. package/dist/playground/c3.d.ts +15 -0
  23. package/dist/playground/c3.js +154 -0
  24. package/dist/playground/clang.d.ts +35 -19
  25. package/dist/playground/clang.js +241 -52
  26. package/dist/playground/clangAssetIntegrity.d.ts +32 -0
  27. package/dist/playground/clangAssetIntegrity.js +8 -0
  28. package/dist/playground/clojurescript.d.ts +5 -0
  29. package/dist/playground/clojurescript.js +59 -0
  30. package/dist/playground/clojurescriptPreflight.d.ts +26 -0
  31. package/dist/playground/clojurescriptPreflight.js +383 -0
  32. package/dist/playground/cobol.d.ts +46 -0
  33. package/dist/playground/cobol.js +703 -0
  34. package/dist/playground/d.d.ts +47 -0
  35. package/dist/playground/d.js +644 -0
  36. package/dist/playground/dOuterAssets.d.ts +16 -0
  37. package/dist/playground/dOuterAssets.js +163 -0
  38. package/dist/playground/dotnet.d.ts +99 -0
  39. package/dist/playground/dotnet.js +1131 -0
  40. package/dist/playground/duckdb.d.ts +36 -0
  41. package/dist/playground/duckdb.js +542 -0
  42. package/dist/playground/elixir.d.ts +18 -10
  43. package/dist/playground/elixir.js +630 -96
  44. package/dist/playground/elixirAssets.d.ts +6 -0
  45. package/dist/playground/elixirAssets.js +33 -0
  46. package/dist/playground/executionObservation.d.ts +22 -0
  47. package/dist/playground/executionObservation.js +65 -0
  48. package/dist/playground/forth.d.ts +5 -0
  49. package/dist/playground/forth.js +53 -0
  50. package/dist/playground/forthPreflight.d.ts +24 -0
  51. package/dist/playground/forthPreflight.js +198 -0
  52. package/dist/playground/fortran.d.ts +47 -0
  53. package/dist/playground/fortran.js +651 -0
  54. package/dist/playground/fortranAssets.d.ts +6 -0
  55. package/dist/playground/fortranAssets.js +27 -0
  56. package/dist/playground/gleam.d.ts +6 -0
  57. package/dist/playground/gleam.js +33 -0
  58. package/dist/playground/go.d.ts +17 -11
  59. package/dist/playground/go.js +376 -72
  60. package/dist/playground/goDebugInstrumentation.d.ts +1 -0
  61. package/dist/playground/goDebugInstrumentation.js +229 -0
  62. package/dist/playground/haskell.d.ts +44 -0
  63. package/dist/playground/haskell.js +678 -0
  64. package/dist/playground/haskellAssets.d.ts +24 -0
  65. package/dist/playground/haskellAssets.js +93 -0
  66. package/dist/playground/index.d.ts +1 -1
  67. package/dist/playground/index.js +360 -111
  68. package/dist/playground/j.d.ts +5 -0
  69. package/dist/playground/j.js +60 -0
  70. package/dist/playground/jPreflight.d.ts +26 -0
  71. package/dist/playground/jPreflight.js +372 -0
  72. package/dist/playground/janet.d.ts +5 -0
  73. package/dist/playground/janet.js +64 -0
  74. package/dist/playground/java.d.ts +24 -10
  75. package/dist/playground/java.js +706 -84
  76. package/dist/playground/javaSource.d.ts +5 -0
  77. package/dist/playground/javaSource.js +16 -0
  78. package/dist/playground/javaStdin.d.ts +1 -1
  79. package/dist/playground/javaStdin.js +13 -4
  80. package/dist/playground/julia.d.ts +5 -0
  81. package/dist/playground/julia.js +64 -0
  82. package/dist/playground/lfortran.d.ts +8 -0
  83. package/dist/playground/lfortran.js +30 -0
  84. package/dist/playground/lfortranAssets.d.ts +21 -0
  85. package/dist/playground/lfortranAssets.js +118 -0
  86. package/dist/playground/lisp.d.ts +45 -0
  87. package/dist/playground/lisp.js +640 -0
  88. package/dist/playground/lispAssets.d.ts +9 -0
  89. package/dist/playground/lispAssets.js +74 -0
  90. package/dist/playground/lldbManifest.d.ts +3 -0
  91. package/dist/playground/lldbManifest.js +155 -0
  92. package/dist/playground/lldbSession.d.ts +115 -0
  93. package/dist/playground/lldbSession.js +1347 -0
  94. package/dist/playground/loadingProgress.d.ts +16 -0
  95. package/dist/playground/loadingProgress.js +166 -0
  96. package/dist/playground/lua.d.ts +44 -0
  97. package/dist/playground/lua.js +630 -0
  98. package/dist/playground/nim.d.ts +5 -0
  99. package/dist/playground/nim.js +76 -0
  100. package/dist/playground/objectivec.d.ts +39 -0
  101. package/dist/playground/objectivec.js +288 -0
  102. package/dist/playground/ocaml.d.ts +28 -10
  103. package/dist/playground/ocaml.js +815 -253
  104. package/dist/playground/octave.d.ts +43 -0
  105. package/dist/playground/octave.js +783 -0
  106. package/dist/playground/options.d.ts +19 -40
  107. package/dist/playground/options.js +2 -1
  108. package/dist/playground/pascal.d.ts +5 -0
  109. package/dist/playground/pascal.js +60 -0
  110. package/dist/playground/perl.d.ts +5 -0
  111. package/dist/playground/perl.js +61 -0
  112. package/dist/playground/php.d.ts +44 -0
  113. package/dist/playground/php.js +665 -0
  114. package/dist/playground/prolog.d.ts +6 -0
  115. package/dist/playground/prolog.js +75 -0
  116. package/dist/playground/python.d.ts +20 -14
  117. package/dist/playground/python.js +445 -101
  118. package/dist/playground/pythonPackageLock.d.ts +6 -0
  119. package/dist/playground/pythonPackageLock.js +56 -0
  120. package/dist/playground/r.d.ts +44 -0
  121. package/dist/playground/r.js +637 -0
  122. package/dist/playground/ruby.d.ts +46 -0
  123. package/dist/playground/ruby.js +732 -0
  124. package/dist/playground/rubyAssets.d.ts +23 -0
  125. package/dist/playground/rubyAssets.js +68 -0
  126. package/dist/playground/rubyTestPreflight.d.ts +2 -0
  127. package/dist/playground/rubyTestPreflight.js +18 -0
  128. package/dist/playground/runtimeModule.d.ts +1 -0
  129. package/dist/playground/runtimeModule.js +5 -0
  130. package/dist/playground/rust.d.ts +44 -13
  131. package/dist/playground/rust.js +714 -76
  132. package/dist/playground/rustExecutableGraph.d.ts +85 -0
  133. package/dist/playground/rustExecutableGraph.js +946 -0
  134. package/dist/playground/rustWorkerLimits.d.ts +17 -0
  135. package/dist/playground/rustWorkerLimits.js +34 -0
  136. package/dist/playground/sandbox.d.ts +16 -10
  137. package/dist/playground/sharedBuffer.d.ts +6 -0
  138. package/dist/playground/sharedBuffer.js +12 -0
  139. package/dist/playground/sqlite.d.ts +38 -0
  140. package/dist/playground/sqlite.js +550 -0
  141. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
  142. package/dist/playground/staticRuntimeModuleVersion.js +2 -0
  143. package/dist/playground/staticRuntimePreflight.d.ts +13 -0
  144. package/dist/playground/staticRuntimePreflight.js +231 -0
  145. package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
  146. package/dist/playground/staticRuntimePreflightExecute.js +66 -0
  147. package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
  148. package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
  149. package/dist/playground/staticStdinRing.d.ts +45 -0
  150. package/dist/playground/staticStdinRing.js +158 -0
  151. package/dist/playground/staticWorkerRuntime.d.ts +154 -0
  152. package/dist/playground/staticWorkerRuntime.js +1917 -0
  153. package/dist/playground/stdinBuffer.d.ts +9 -7
  154. package/dist/playground/stdinBuffer.js +9 -18
  155. package/dist/playground/swift.d.ts +5 -0
  156. package/dist/playground/swift.js +17 -0
  157. package/dist/playground/tcl.d.ts +5 -0
  158. package/dist/playground/tcl.js +62 -0
  159. package/dist/playground/teavmConfig.d.ts +1 -1
  160. package/dist/playground/teavmConfig.js +2 -2
  161. package/dist/playground/tinygo.d.ts +48 -18
  162. package/dist/playground/tinygo.js +1202 -329
  163. package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
  164. package/dist/playground/tinygoExecutableGraph.js +449 -0
  165. package/dist/playground/typescript.d.ts +55 -0
  166. package/dist/playground/typescript.js +924 -0
  167. package/dist/playground/wasm.d.ts +43 -0
  168. package/dist/playground/wasm.js +608 -0
  169. package/dist/playground/wasmAwkVersion.d.ts +59 -0
  170. package/dist/playground/wasmAwkVersion.js +31 -0
  171. package/dist/playground/wasmBashVersion.d.ts +63 -0
  172. package/dist/playground/wasmBashVersion.js +36 -0
  173. package/dist/playground/wasmBqnVersion.d.ts +24 -0
  174. package/dist/playground/wasmBqnVersion.js +24 -0
  175. package/dist/playground/wasmC3Version.d.ts +20 -0
  176. package/dist/playground/wasmC3Version.js +21 -0
  177. package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
  178. package/dist/playground/wasmClojureScriptVersion.js +21 -0
  179. package/dist/playground/wasmDIntegrity.d.ts +15 -0
  180. package/dist/playground/wasmDIntegrity.js +15 -0
  181. package/dist/playground/wasmDVersion.d.ts +1 -0
  182. package/dist/playground/wasmDVersion.js +1 -0
  183. package/dist/playground/wasmDebugVersion.d.ts +6 -0
  184. package/dist/playground/wasmDebugVersion.js +6 -0
  185. package/dist/playground/wasmDotnetVersion.d.ts +1 -0
  186. package/dist/playground/wasmDotnetVersion.js +1 -0
  187. package/dist/playground/wasmElixirVersion.d.ts +21 -1
  188. package/dist/playground/wasmElixirVersion.js +21 -1
  189. package/dist/playground/wasmForthVersion.d.ts +18 -0
  190. package/dist/playground/wasmForthVersion.js +18 -0
  191. package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
  192. package/dist/playground/wasmFortranExecutionAssets.js +15 -0
  193. package/dist/playground/wasmFortranVersion.d.ts +1 -0
  194. package/dist/playground/wasmFortranVersion.js +1 -0
  195. package/dist/playground/wasmGleamVersion.d.ts +5 -0
  196. package/dist/playground/wasmGleamVersion.js +5 -0
  197. package/dist/playground/wasmGoVersion.d.ts +1 -1
  198. package/dist/playground/wasmGoVersion.js +1 -1
  199. package/dist/playground/wasmHaskellVersion.d.ts +1 -0
  200. package/dist/playground/wasmHaskellVersion.js +1 -0
  201. package/dist/playground/wasmJVersion.d.ts +24 -0
  202. package/dist/playground/wasmJVersion.js +24 -0
  203. package/dist/playground/wasmJanetVersion.d.ts +53 -0
  204. package/dist/playground/wasmJanetVersion.js +30 -0
  205. package/dist/playground/wasmJuliaVersion.d.ts +71 -0
  206. package/dist/playground/wasmJuliaVersion.js +39 -0
  207. package/dist/playground/wasmLfortranVersion.d.ts +28 -0
  208. package/dist/playground/wasmLfortranVersion.js +29 -0
  209. package/dist/playground/wasmLispVersion.d.ts +1 -0
  210. package/dist/playground/wasmLispVersion.js +1 -0
  211. package/dist/playground/wasmLuaVersion.d.ts +1 -0
  212. package/dist/playground/wasmLuaVersion.js +1 -0
  213. package/dist/playground/wasmNimVersion.d.ts +125 -0
  214. package/dist/playground/wasmNimVersion.js +66 -0
  215. package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
  216. package/dist/playground/wasmObjectiveCVersion.js +27 -0
  217. package/dist/playground/wasmOcamlVersion.d.ts +12 -1
  218. package/dist/playground/wasmOcamlVersion.js +12 -1
  219. package/dist/playground/wasmOctaveVersion.d.ts +1 -0
  220. package/dist/playground/wasmOctaveVersion.js +1 -0
  221. package/dist/playground/wasmPascalVersion.d.ts +61 -0
  222. package/dist/playground/wasmPascalVersion.js +34 -0
  223. package/dist/playground/wasmPerlVersion.d.ts +71 -0
  224. package/dist/playground/wasmPerlVersion.js +39 -0
  225. package/dist/playground/wasmPrologVersion.d.ts +31 -0
  226. package/dist/playground/wasmPrologVersion.js +31 -0
  227. package/dist/playground/wasmRVersion.d.ts +1 -0
  228. package/dist/playground/wasmRVersion.js +1 -0
  229. package/dist/playground/wasmRustVersion.d.ts +1306 -1
  230. package/dist/playground/wasmRustVersion.js +1458 -1
  231. package/dist/playground/wasmSwiftVersion.d.ts +1 -0
  232. package/dist/playground/wasmSwiftVersion.js +1 -0
  233. package/dist/playground/wasmTclVersion.d.ts +85 -0
  234. package/dist/playground/wasmTclVersion.js +46 -0
  235. package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
  236. package/dist/playground/wasmTinyGoVersion.js +107 -1
  237. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
  238. package/dist/playground/wasmTypeScriptVersion.js +5 -0
  239. package/dist/playground/wasmWatVersion.d.ts +1 -0
  240. package/dist/playground/wasmWatVersion.js +1 -0
  241. package/dist/playground/wasmZigVersion.d.ts +13 -0
  242. package/dist/playground/wasmZigVersion.js +13 -0
  243. package/dist/playground/wat.d.ts +44 -0
  244. package/dist/playground/wat.js +622 -0
  245. package/dist/playground/worker/assemblyscript.js +339 -0
  246. package/dist/playground/worker/assets.d.ts +7 -0
  247. package/dist/playground/worker/assets.js +288 -39
  248. package/dist/playground/worker/bash.js +338 -0
  249. package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
  250. package/dist/playground/worker/bashNestedBootstrap.js +59 -0
  251. package/dist/playground/worker/bashRuntime.d.ts +89 -0
  252. package/dist/playground/worker/bashRuntime.js +982 -0
  253. package/dist/playground/worker/clang.js +92 -13
  254. package/dist/playground/worker/cobol.js +107 -0
  255. package/dist/playground/worker/d.js +199 -0
  256. package/dist/playground/worker/dotnet.js +141 -0
  257. package/dist/playground/worker/duckdb.d.ts +1 -0
  258. package/dist/playground/worker/duckdb.js +136 -0
  259. package/dist/playground/worker/elixir.js +307 -41
  260. package/dist/playground/worker/fortran.d.ts +1 -0
  261. package/dist/playground/worker/fortran.js +295 -0
  262. package/dist/playground/worker/go.js +246 -40
  263. package/dist/playground/worker/haskell.d.ts +7 -0
  264. package/dist/playground/worker/haskell.js +465 -0
  265. package/dist/playground/worker/java.js +59 -20
  266. package/dist/playground/worker/lisp.d.ts +1 -0
  267. package/dist/playground/worker/lisp.js +195 -0
  268. package/dist/playground/worker/lua.d.ts +1 -0
  269. package/dist/playground/worker/lua.js +163 -0
  270. package/dist/playground/worker/objectivec.d.ts +1 -0
  271. package/dist/playground/worker/objectivec.js +10 -0
  272. package/dist/playground/worker/ocaml.js +206 -58
  273. package/dist/playground/worker/php.d.ts +1 -0
  274. package/dist/playground/worker/php.js +261 -0
  275. package/dist/playground/worker/python.js +201 -44
  276. package/dist/playground/worker/r.d.ts +1 -0
  277. package/dist/playground/worker/r.js +192 -0
  278. package/dist/playground/worker/ruby.d.ts +1 -0
  279. package/dist/playground/worker/ruby.js +248 -0
  280. package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
  281. package/dist/playground/worker/runtimeAssetFetch.js +375 -0
  282. package/dist/playground/worker/rust.js +546 -20
  283. package/dist/playground/worker/sqlite.d.ts +1 -0
  284. package/dist/playground/worker/sqlite.js +112 -0
  285. package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
  286. package/dist/playground/worker/staticRuntimePreflight.js +56 -0
  287. package/dist/playground/worker/tinygo.js +34 -9
  288. package/dist/playground/worker/typescript.d.ts +1 -0
  289. package/dist/playground/worker/typescript.js +251 -0
  290. package/dist/playground/worker/wasm.d.ts +1 -0
  291. package/dist/playground/worker/wasm.js +273 -0
  292. package/dist/playground/worker/wat.d.ts +1 -0
  293. package/dist/playground/worker/wat.js +188 -0
  294. package/dist/playground/worker/zig.d.ts +8 -0
  295. package/dist/playground/worker/zig.js +578 -0
  296. package/dist/playground/workerProgress.d.ts +15 -0
  297. package/dist/playground/workerProgress.js +72 -0
  298. package/dist/playground/workerSession.d.ts +28 -0
  299. package/dist/playground/workerSession.js +164 -0
  300. package/dist/playground/zig.d.ts +46 -0
  301. package/dist/playground/zig.js +690 -0
  302. package/dist/playground/zigAssets.d.ts +6 -0
  303. package/dist/playground/zigAssets.js +49 -0
  304. package/package.json +234 -105
  305. package/dist/clang/app.d.ts +0 -75
  306. package/dist/clang/app.js +0 -744
  307. package/dist/clang/apply.d.ts +0 -2
  308. package/dist/clang/apply.js +0 -11
  309. package/dist/clang/color.d.ts +0 -3
  310. package/dist/clang/color.js +0 -3
  311. package/dist/clang/encode.d.ts +0 -4
  312. package/dist/clang/encode.js +0 -20
  313. package/dist/clang/error.d.ts +0 -14
  314. package/dist/clang/error.js +0 -27
  315. package/dist/clang/gccCompat.d.ts +0 -15
  316. package/dist/clang/gccCompat.js +0 -767
  317. package/dist/clang/index.d.ts +0 -85
  318. package/dist/clang/index.js +0 -1077
  319. package/dist/clang/memory/index.d.ts +0 -4
  320. package/dist/clang/memory/index.js +0 -4
  321. package/dist/clang/memory/memFs.d.ts +0 -35
  322. package/dist/clang/memory/memFs.js +0 -132
  323. package/dist/clang/memory/memory.d.ts +0 -22
  324. package/dist/clang/memory/memory.js +0 -73
  325. package/dist/clang/memory/tar.d.ts +0 -2
  326. package/dist/clang/memory/tar.js +0 -59
  327. package/dist/clang/url.d.ts +0 -4
  328. package/dist/clang/url.js +0 -5
  329. package/dist/clang/wasm.d.ts +0 -4
  330. package/dist/clang/wasm.js +0 -50
  331. package/dist/clangd/config.d.ts +0 -18
  332. package/dist/clangd/config.js +0 -14
  333. package/dist/clangd/jsonStream.d.ts +0 -9
  334. package/dist/clangd/jsonStream.js +0 -48
  335. package/dist/clangd/session.d.ts +0 -18
  336. package/dist/clangd/session.js +0 -112
  337. package/dist/clangd/worker.js +0 -131
  338. package/dist/debug/controller.svelte.d.ts +0 -43
  339. package/dist/debug/controller.svelte.js +0 -268
  340. package/dist/debug/editor/index.d.ts +0 -2
  341. package/dist/debug/editor/index.js +0 -1
  342. package/dist/debug/editor/monaco.d.ts +0 -26
  343. package/dist/debug/editor/monaco.js +0 -128
  344. package/dist/debug/expression.d.ts +0 -26
  345. package/dist/debug/expression.js +0 -547
  346. package/dist/debug/index.d.ts +0 -8
  347. package/dist/debug/index.js +0 -5
  348. package/dist/debug/language/cpp.d.ts +0 -2
  349. package/dist/debug/language/cpp.js +0 -7
  350. package/dist/debug/language/index.d.ts +0 -3
  351. package/dist/debug/language/index.js +0 -2
  352. package/dist/debug/language/python.d.ts +0 -2
  353. package/dist/debug/language/python.js +0 -14
  354. package/dist/debug/language/types.d.ts +0 -6
  355. package/dist/debug/locals.d.ts +0 -2
  356. package/dist/debug/locals.js +0 -8
  357. package/dist/lsp/cpp/server.d.ts +0 -2
  358. package/dist/lsp/cpp/server.js +0 -68
  359. package/dist/lsp/index.d.ts +0 -5
  360. package/dist/lsp/index.js +0 -4
  361. package/dist/lsp/python/main.worker.js +0 -92
  362. package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
  363. package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
  364. package/dist/lsp/python/server.d.ts +0 -2
  365. package/dist/lsp/python/server.js +0 -54
  366. package/dist/lsp/registry.d.ts +0 -2
  367. package/dist/lsp/registry.js +0 -12
  368. package/dist/lsp/runtime.d.ts +0 -5
  369. package/dist/lsp/runtime.js +0 -31
  370. package/dist/lsp/types.d.ts +0 -17
  371. package/dist/terminal/Terminal.svelte +0 -422
  372. package/dist/terminal/Terminal.svelte.d.ts +0 -26
  373. package/dist/terminal/index.d.ts +0 -7
  374. package/dist/terminal/index.js +0 -5
  375. package/dist/terminal/plugin/index.d.ts +0 -9
  376. package/dist/terminal/plugin/index.js +0 -19
  377. package/dist/terminal/theme.d.ts +0 -49
  378. package/dist/terminal/theme.js +0 -49
  379. package/dist/terminal/types.d.ts +0 -18
  380. package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
  381. package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
  382. /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
  383. /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
  384. /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
  385. /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
  386. /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
@@ -0,0 +1,946 @@
1
+ import { RUNTIME_REGISTRY_MANIFEST_SCHEMA_VERSION, RuntimeConfigurationError, preflightRuntimeAssets } from '@wasm-idle/core';
2
+ export const RUST_EXECUTABLE_GRAPH_FORMAT = 'wasm-idle-rust-executable-graph-v1';
3
+ export const RUST_EXECUTABLE_GRAPH_FINGERPRINT_DOMAIN = 'wasm-idle:rust-executable-graph:v1\n';
4
+ const SHA256_PATTERN = /^[a-f0-9]{64}$/u;
5
+ const SAFE_PATH_PATTERN = /^[A-Za-z0-9._/-]+$/u;
6
+ const SAFE_SPECIFIER_PATTERN = /^[A-Za-z0-9._/-]+$/u;
7
+ const SAFE_BLOB_URL_PATTERN = /^blob:[^'"`\\\r\n]+$/u;
8
+ const MAX_MODULES = 256;
9
+ const MAX_EDGES = 4096;
10
+ const MAX_MODULE_STORAGE_BYTES = 32 * 1024 * 1024;
11
+ const MAX_MODULE_LOGICAL_BYTES = 32 * 1024 * 1024;
12
+ const encoder = new TextEncoder();
13
+ const fatalDecoder = new TextDecoder('utf-8', { fatal: true });
14
+ const RUNTIME_DYNAMIC_MODULE_SPECIFIERS = new Set([
15
+ '../vendor/jco/src/browser.js',
16
+ '../vendor/jco/obj/wasm-tools.js',
17
+ '../vendor/preview2-shim/lib/browser/cli.js',
18
+ '../vendor/preview2-shim/lib/browser/clocks.js',
19
+ '../vendor/preview2-shim/lib/browser/filesystem.js',
20
+ '../vendor/preview2-shim/lib/browser/http.js',
21
+ '../vendor/preview2-shim/lib/browser/io.js',
22
+ '../vendor/preview2-shim/lib/browser/random.js',
23
+ '../vendor/preview2-shim/lib/browser/sockets.js'
24
+ ]);
25
+ const EXPECTED_CORE_ASSETS = Object.freeze({
26
+ 'vendor/jco/obj/js-component-bindgen-component.js': Object.freeze([
27
+ Object.freeze({
28
+ specifier: './js-component-bindgen-component.core.wasm',
29
+ target: 'vendor/jco/obj/js-component-bindgen-component.core.wasm.gz'
30
+ }),
31
+ Object.freeze({
32
+ specifier: './js-component-bindgen-component.core2.wasm',
33
+ target: 'vendor/jco/obj/js-component-bindgen-component.core2.wasm'
34
+ })
35
+ ]),
36
+ 'vendor/jco/obj/wasm-tools.js': Object.freeze([
37
+ Object.freeze({
38
+ specifier: './wasm-tools.core.wasm',
39
+ target: 'vendor/jco/obj/wasm-tools.core.wasm.gz'
40
+ }),
41
+ Object.freeze({
42
+ specifier: './wasm-tools.core2.wasm',
43
+ target: 'vendor/jco/obj/wasm-tools.core2.wasm'
44
+ })
45
+ ])
46
+ });
47
+ const EXPECTED_NODE_EXTERNALS = Object.freeze({
48
+ 'vendor/jco/obj/js-component-bindgen-component.js': 'node:fs/promises',
49
+ 'vendor/jco/obj/wasm-tools.js': 'node:fs/promises'
50
+ });
51
+ const EXPECTED_WORKER_EDGES = Object.freeze({
52
+ 'compiler.js': Object.freeze({
53
+ specifier: './compiler-worker.js',
54
+ target: 'compiler-worker.js'
55
+ }),
56
+ 'compiler-worker.js': Object.freeze({
57
+ specifier: './rustc-thread-worker.js',
58
+ target: 'rustc-thread-worker.js'
59
+ }),
60
+ 'rustc-thread-worker.js': Object.freeze({
61
+ specifier: './rustc-thread-worker.js',
62
+ target: 'rustc-thread-worker.js'
63
+ })
64
+ });
65
+ const compareCodeUnits = (left, right) => left < right ? -1 : left > right ? 1 : 0;
66
+ const configurationError = (message, cause) => new RuntimeConfigurationError(message, {
67
+ phase: 'asset',
68
+ runtimeId: 'RUST',
69
+ ...(cause === undefined ? {} : { cause })
70
+ });
71
+ function requireExactKeys(value, expected, label) {
72
+ const received = Object.keys(value).sort(compareCodeUnits);
73
+ const sortedExpected = [...expected].sort(compareCodeUnits);
74
+ if (received.length !== sortedExpected.length ||
75
+ received.some((key, index) => key !== sortedExpected[index])) {
76
+ throw configurationError(`${label} must contain exactly ${sortedExpected.join(', ')}`);
77
+ }
78
+ }
79
+ function requireRecord(value, label) {
80
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
81
+ throw configurationError(`${label} must be an object`);
82
+ }
83
+ return value;
84
+ }
85
+ function requireSafePath(value, label) {
86
+ if (typeof value !== 'string' ||
87
+ !value ||
88
+ value.length > 512 ||
89
+ !SAFE_PATH_PATTERN.test(value) ||
90
+ value.startsWith('/') ||
91
+ value.includes('\\') ||
92
+ value.includes('\0') ||
93
+ value.includes('?') ||
94
+ value.includes('#') ||
95
+ value.includes(':') ||
96
+ value.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
97
+ throw configurationError(`${label} must be a normalized safe relative path`);
98
+ }
99
+ return value;
100
+ }
101
+ function requireSpecifier(value, label) {
102
+ if (typeof value !== 'string' ||
103
+ !value ||
104
+ value.length > 512 ||
105
+ !SAFE_SPECIFIER_PATTERN.test(value) ||
106
+ value.startsWith('/') ||
107
+ value.includes('\\') ||
108
+ value.includes('\0') ||
109
+ value.includes('?') ||
110
+ value.includes('#') ||
111
+ value.includes(':')) {
112
+ throw configurationError(`${label} must be a safe module specifier`);
113
+ }
114
+ return value;
115
+ }
116
+ function requireReceipt(value, label, maximum) {
117
+ const receipt = requireRecord(value, label);
118
+ requireExactKeys(receipt, ['bytes', 'sha256'], label);
119
+ if (!Number.isSafeInteger(receipt.bytes) ||
120
+ Number(receipt.bytes) <= 0 ||
121
+ Number(receipt.bytes) > maximum) {
122
+ throw configurationError(`${label} has an invalid size`);
123
+ }
124
+ if (typeof receipt.sha256 !== 'string' || !SHA256_PATTERN.test(receipt.sha256)) {
125
+ throw configurationError(`${label} has an invalid SHA-256`);
126
+ }
127
+ return Object.freeze({ bytes: Number(receipt.bytes), sha256: receipt.sha256 });
128
+ }
129
+ function snapshotPinnedRustRuntimeProfile(value) {
130
+ const profile = requireRecord(value, 'Rust runtime profile');
131
+ if (profile.protocolVersion !== 1 ||
132
+ profile.manifestPath !== 'runtime/runtime-manifest.v3.json' ||
133
+ typeof profile.manifestFingerprint !== 'string' ||
134
+ !SHA256_PATTERN.test(profile.manifestFingerprint) ||
135
+ profile.profileId !== `wasm-rust-${profile.manifestFingerprint}`) {
136
+ throw configurationError('Rust runtime profile is invalid');
137
+ }
138
+ return Object.freeze({
139
+ profileId: profile.profileId,
140
+ protocolVersion: 1,
141
+ manifestPath: 'runtime/runtime-manifest.v3.json',
142
+ manifestFingerprint: profile.manifestFingerprint,
143
+ manifestReceipt: requireReceipt(profile.manifestReceipt, 'Rust runtime manifest receipt', 16 * 1024 * 1024)
144
+ });
145
+ }
146
+ function resolveRelativeTarget(importer, specifier) {
147
+ const segments = importer.split('/');
148
+ segments.pop();
149
+ for (const segment of specifier.split('/')) {
150
+ if (!segment || segment === '.')
151
+ continue;
152
+ if (segment === '..') {
153
+ if (segments.length === 0) {
154
+ throw configurationError(`Rust executable import ${specifier} escapes its graph root`);
155
+ }
156
+ segments.pop();
157
+ continue;
158
+ }
159
+ if (!/^[A-Za-z0-9._-]+$/u.test(segment)) {
160
+ throw configurationError(`Rust executable import ${specifier} is unsafe`);
161
+ }
162
+ segments.push(segment);
163
+ }
164
+ return segments.join('/');
165
+ }
166
+ function resolveDeclaredImportTarget(importer, specifier, kind) {
167
+ if (kind === 'dynamic' &&
168
+ (importer === 'browser-linker.js' || importer === 'compiler-preload.js')) {
169
+ return resolveRelativeTarget('runtime/placeholder.js', specifier);
170
+ }
171
+ if (kind === 'dynamic' && RUNTIME_DYNAMIC_MODULE_SPECIFIERS.has(specifier)) {
172
+ return resolveRelativeTarget('runtime/placeholder.js', specifier);
173
+ }
174
+ return resolveRelativeTarget(importer, specifier);
175
+ }
176
+ function isAllowedThreadSelfEdge(modulePath, graphImport) {
177
+ return (modulePath === 'rustc-thread-worker.js' &&
178
+ graphImport.kind === 'worker' &&
179
+ graphImport.specifier === './rustc-thread-worker.js' &&
180
+ graphImport.target === modulePath);
181
+ }
182
+ function assertExpectedBoundaryDeclarations(modulePath, imports, assets, externals) {
183
+ const workerEdges = imports.filter(({ kind }) => kind === 'worker');
184
+ const expectedWorker = EXPECTED_WORKER_EDGES[modulePath];
185
+ if ((expectedWorker === undefined && workerEdges.length !== 0) ||
186
+ (expectedWorker !== undefined &&
187
+ (workerEdges.length !== 1 ||
188
+ workerEdges[0]?.specifier !== expectedWorker.specifier ||
189
+ workerEdges[0]?.target !== expectedWorker.target))) {
190
+ throw configurationError(`Rust executable module ${modulePath} changed its declared worker boundary`);
191
+ }
192
+ const expectedAssets = EXPECTED_CORE_ASSETS[modulePath] ?? [];
193
+ if (assets.length !== expectedAssets.length ||
194
+ assets.some((asset, index) => asset.specifier !== expectedAssets[index]?.specifier ||
195
+ asset.target !== expectedAssets[index]?.target)) {
196
+ throw configurationError(`Rust executable module ${modulePath} changed its declared core Wasm boundary`);
197
+ }
198
+ const expectedExternal = EXPECTED_NODE_EXTERNALS[modulePath];
199
+ if ((expectedExternal === undefined && externals.length !== 0) ||
200
+ (expectedExternal !== undefined &&
201
+ (externals.length !== 1 || externals[0]?.specifier !== expectedExternal))) {
202
+ throw configurationError(`Rust executable module ${modulePath} changed its declared node-only boundary`);
203
+ }
204
+ }
205
+ export function snapshotRustExecutableGraphProfile(value) {
206
+ const profile = requireRecord(value, 'Rust executable graph profile');
207
+ requireExactKeys(profile, ['schemaVersion', 'format', 'authority', 'entryPath', 'fingerprint', 'modules'], 'Rust executable graph profile');
208
+ if (profile.schemaVersion !== 1 || profile.format !== RUST_EXECUTABLE_GRAPH_FORMAT) {
209
+ throw configurationError('Rust executable graph profile has an unsupported format');
210
+ }
211
+ if (profile.authority !== 'published-static') {
212
+ throw configurationError('Rust executable graph profile must describe published static assets');
213
+ }
214
+ const entryPath = requireSafePath(profile.entryPath, 'Rust executable graph entry path');
215
+ if (entryPath !== 'index.js') {
216
+ throw configurationError('Rust executable graph entry path must be index.js');
217
+ }
218
+ if (typeof profile.fingerprint !== 'string' || !SHA256_PATTERN.test(profile.fingerprint)) {
219
+ throw configurationError('Rust executable graph fingerprint must be a lowercase SHA-256');
220
+ }
221
+ const sourceModules = requireRecord(profile.modules, 'Rust executable graph modules');
222
+ const modulePaths = Object.keys(sourceModules).sort(compareCodeUnits);
223
+ if (modulePaths.length === 0 || modulePaths.length > MAX_MODULES) {
224
+ throw configurationError(`Rust executable graph must contain 1 through ${MAX_MODULES} modules`);
225
+ }
226
+ let edgeCount = 0;
227
+ const storagePaths = new Set();
228
+ const modules = {};
229
+ for (const rawPath of modulePaths) {
230
+ const modulePath = requireSafePath(rawPath, 'Rust executable module path');
231
+ if (!modulePath.endsWith('.js')) {
232
+ throw configurationError(`Rust executable module ${modulePath} must be JavaScript`);
233
+ }
234
+ const sourceModule = requireRecord(sourceModules[rawPath], `Rust executable module ${modulePath}`);
235
+ requireExactKeys(sourceModule, ['delivery', 'storage', 'logical', 'imports', 'assets', 'externals'], `Rust executable module ${modulePath}`);
236
+ const delivery = requireRecord(sourceModule.delivery, `Rust executable module ${modulePath} delivery`);
237
+ requireExactKeys(delivery, ['storagePath', 'encoding'], `Rust executable module ${modulePath} delivery`);
238
+ const storagePath = requireSafePath(delivery.storagePath, `Rust executable module ${modulePath} storage path`);
239
+ if (delivery.encoding !== 'identity' && delivery.encoding !== 'gzip') {
240
+ throw configurationError(`Rust executable module ${modulePath} has an invalid encoding`);
241
+ }
242
+ if ((delivery.encoding === 'identity' && storagePath !== `${modulePath}.bin`) ||
243
+ (delivery.encoding === 'gzip' && storagePath !== `${modulePath}.gz.bin`)) {
244
+ throw configurationError(`Rust executable module ${modulePath} has an invalid authority or delivery path`);
245
+ }
246
+ if (storagePaths.has(storagePath)) {
247
+ throw configurationError(`Rust executable graph repeats storage path ${storagePath}`);
248
+ }
249
+ storagePaths.add(storagePath);
250
+ const storage = requireReceipt(sourceModule.storage, `Rust executable module ${modulePath} storage receipt`, MAX_MODULE_STORAGE_BYTES);
251
+ const logical = requireReceipt(sourceModule.logical, `Rust executable module ${modulePath} logical receipt`, MAX_MODULE_LOGICAL_BYTES);
252
+ if (delivery.encoding === 'identity' &&
253
+ (storage.bytes !== logical.bytes || storage.sha256 !== logical.sha256)) {
254
+ throw configurationError(`Rust executable module ${modulePath} identity receipts must match`);
255
+ }
256
+ if (!Array.isArray(sourceModule.imports)) {
257
+ throw configurationError(`Rust executable module ${modulePath} imports must be an array`);
258
+ }
259
+ if (!Array.isArray(sourceModule.assets)) {
260
+ throw configurationError(`Rust executable module ${modulePath} assets must be an array`);
261
+ }
262
+ if (!Array.isArray(sourceModule.externals)) {
263
+ throw configurationError(`Rust executable module ${modulePath} externals must be an array`);
264
+ }
265
+ const declaredSpecifiers = new Set();
266
+ const imports = sourceModule.imports.map((rawImport, index) => {
267
+ const graphImport = requireRecord(rawImport, `Rust executable module ${modulePath} import ${index}`);
268
+ requireExactKeys(graphImport, ['specifier', 'target', 'kind'], `Rust executable module ${modulePath} import ${index}`);
269
+ const specifier = requireSpecifier(graphImport.specifier, `Rust executable module ${modulePath} import specifier`);
270
+ const target = requireSafePath(graphImport.target, `Rust executable module ${modulePath} import target`);
271
+ if (!target.endsWith('.js')) {
272
+ throw configurationError(`Rust executable module ${modulePath} import target must be JavaScript`);
273
+ }
274
+ if (!['static', 'dynamic', 'worker'].includes(String(graphImport.kind))) {
275
+ throw configurationError(`Rust executable module ${modulePath} import ${specifier} has an invalid kind`);
276
+ }
277
+ const kind = graphImport.kind;
278
+ if (resolveDeclaredImportTarget(modulePath, specifier, kind) !== target) {
279
+ throw configurationError(`Rust executable module ${modulePath} import ${specifier} does not resolve to ${target}`);
280
+ }
281
+ if (declaredSpecifiers.has(specifier)) {
282
+ throw configurationError(`Rust executable module ${modulePath} has a duplicate declared specifier`);
283
+ }
284
+ declaredSpecifiers.add(specifier);
285
+ edgeCount += 1;
286
+ return Object.freeze({ specifier, target, kind });
287
+ });
288
+ const assets = sourceModule.assets.map((rawAsset, index) => {
289
+ const asset = requireRecord(rawAsset, `Rust executable module ${modulePath} asset ${index}`);
290
+ requireExactKeys(asset, ['specifier', 'target', 'kind'], `Rust executable module ${modulePath} asset ${index}`);
291
+ const specifier = requireSpecifier(asset.specifier, `Rust executable module ${modulePath} asset specifier`);
292
+ const target = requireSafePath(asset.target, `Rust executable module ${modulePath} asset target`);
293
+ if (asset.kind !== 'core-wasm') {
294
+ throw configurationError(`Rust executable module ${modulePath} asset ${specifier} has an invalid kind`);
295
+ }
296
+ const logicalTarget = resolveRelativeTarget(modulePath, specifier);
297
+ if (target !== logicalTarget && target !== `${logicalTarget}.gz`) {
298
+ throw configurationError(`Rust executable module ${modulePath} asset ${specifier} does not resolve to ${target}`);
299
+ }
300
+ if (declaredSpecifiers.has(specifier)) {
301
+ throw configurationError(`Rust executable module ${modulePath} has a duplicate declared specifier`);
302
+ }
303
+ declaredSpecifiers.add(specifier);
304
+ edgeCount += 1;
305
+ return Object.freeze({ specifier, target, kind: 'core-wasm' });
306
+ });
307
+ const externals = sourceModule.externals.map((rawExternal, index) => {
308
+ const external = requireRecord(rawExternal, `Rust executable module ${modulePath} external ${index}`);
309
+ requireExactKeys(external, ['specifier', 'kind', 'condition'], `Rust executable module ${modulePath} external ${index}`);
310
+ if (external.specifier !== 'node:fs/promises' ||
311
+ external.kind !== 'dynamic' ||
312
+ external.condition !== 'node-only') {
313
+ throw configurationError(`Rust executable module ${modulePath} has an unapproved external`);
314
+ }
315
+ if (declaredSpecifiers.has(external.specifier)) {
316
+ throw configurationError(`Rust executable module ${modulePath} has a duplicate declared specifier`);
317
+ }
318
+ declaredSpecifiers.add(external.specifier);
319
+ edgeCount += 1;
320
+ return Object.freeze({
321
+ specifier: external.specifier,
322
+ kind: 'dynamic',
323
+ condition: 'node-only'
324
+ });
325
+ });
326
+ if (edgeCount > MAX_EDGES) {
327
+ throw configurationError(`Rust executable graph exceeds ${MAX_EDGES} declarations`);
328
+ }
329
+ assertExpectedBoundaryDeclarations(modulePath, imports, assets, externals);
330
+ modules[modulePath] = Object.freeze({
331
+ delivery: Object.freeze({
332
+ storagePath,
333
+ encoding: delivery.encoding
334
+ }),
335
+ storage,
336
+ logical,
337
+ imports: Object.freeze(imports),
338
+ assets: Object.freeze(assets),
339
+ externals: Object.freeze(externals)
340
+ });
341
+ }
342
+ if (!Object.prototype.hasOwnProperty.call(modules, entryPath)) {
343
+ throw configurationError('Rust executable graph entry module is missing');
344
+ }
345
+ for (const [modulePath, module] of Object.entries(modules)) {
346
+ for (const graphImport of module.imports) {
347
+ if (!Object.prototype.hasOwnProperty.call(modules, graphImport.target)) {
348
+ throw configurationError(`Rust executable module ${modulePath} imports undeclared ${graphImport.target}`);
349
+ }
350
+ }
351
+ }
352
+ const visiting = new Set();
353
+ const visited = new Set();
354
+ const visit = (modulePath) => {
355
+ if (visiting.has(modulePath)) {
356
+ throw configurationError(`Rust executable graph contains a cycle at ${modulePath}`);
357
+ }
358
+ if (visited.has(modulePath))
359
+ return;
360
+ visiting.add(modulePath);
361
+ for (const graphImport of modules[modulePath].imports) {
362
+ if (isAllowedThreadSelfEdge(modulePath, graphImport))
363
+ continue;
364
+ visit(graphImport.target);
365
+ }
366
+ visiting.delete(modulePath);
367
+ visited.add(modulePath);
368
+ };
369
+ visit(entryPath);
370
+ if (visited.size !== modulePaths.length) {
371
+ throw configurationError('Rust executable graph contains unreachable modules');
372
+ }
373
+ return Object.freeze({
374
+ schemaVersion: 1,
375
+ format: RUST_EXECUTABLE_GRAPH_FORMAT,
376
+ authority: profile.authority,
377
+ entryPath: 'index.js',
378
+ fingerprint: profile.fingerprint,
379
+ modules: Object.freeze(modules)
380
+ });
381
+ }
382
+ export function canonicalRustExecutableGraphProfile(profile) {
383
+ let canonical = RUST_EXECUTABLE_GRAPH_FINGERPRINT_DOMAIN;
384
+ canonical += `schema\0${profile.format}\0${profile.schemaVersion}\n`;
385
+ canonical += `authority\0${profile.authority}\n`;
386
+ canonical += `entry\0${profile.entryPath}\n`;
387
+ const paths = Object.keys(profile.modules).sort(compareCodeUnits);
388
+ for (const modulePath of paths) {
389
+ const module = profile.modules[modulePath];
390
+ canonical += `module\0${modulePath}\0${module.delivery.storagePath}\0${module.delivery.encoding}\0${module.storage.bytes}\0${module.storage.sha256}\0${module.logical.bytes}\0${module.logical.sha256}\n`;
391
+ }
392
+ const edges = paths.flatMap((modulePath) => profile.modules[modulePath].imports.map((graphImport) => ({
393
+ importer: modulePath,
394
+ ...graphImport
395
+ })));
396
+ edges.sort((left, right) => {
397
+ for (const field of ['importer', 'kind', 'specifier', 'target']) {
398
+ const compared = compareCodeUnits(left[field], right[field]);
399
+ if (compared !== 0)
400
+ return compared;
401
+ }
402
+ return 0;
403
+ });
404
+ for (const edge of edges) {
405
+ canonical += `edge\0${edge.importer}\0${edge.kind}\0${edge.specifier}\0${edge.target}\n`;
406
+ }
407
+ const assets = paths.flatMap((modulePath) => profile.modules[modulePath].assets.map((asset) => ({ importer: modulePath, ...asset })));
408
+ assets.sort((left, right) => compareCodeUnits(left.importer, right.importer) ||
409
+ compareCodeUnits(left.specifier, right.specifier) ||
410
+ compareCodeUnits(left.target, right.target));
411
+ for (const asset of assets) {
412
+ canonical += `asset\0${asset.importer}\0${asset.kind}\0${asset.specifier}\0${asset.target}\n`;
413
+ }
414
+ const externals = paths.flatMap((modulePath) => profile.modules[modulePath].externals.map((external) => ({
415
+ importer: modulePath,
416
+ ...external
417
+ })));
418
+ externals.sort((left, right) => compareCodeUnits(left.importer, right.importer) ||
419
+ compareCodeUnits(left.specifier, right.specifier));
420
+ for (const external of externals) {
421
+ canonical += `external\0${external.importer}\0${external.kind}\0${external.specifier}\0${external.condition}\n`;
422
+ }
423
+ return encoder.encode(canonical);
424
+ }
425
+ async function sha256Hex(bytes, signal) {
426
+ if (!globalThis.crypto?.subtle) {
427
+ throw configurationError('Rust executable graph verification requires Web Crypto');
428
+ }
429
+ const pending = globalThis.crypto.subtle.digest('SHA-256', Uint8Array.from(bytes).buffer);
430
+ if (!signal) {
431
+ return Array.from(new Uint8Array(await pending), (value) => value.toString(16).padStart(2, '0')).join('');
432
+ }
433
+ const digest = await new Promise((resolve, reject) => {
434
+ let settled = false;
435
+ const abort = () => {
436
+ if (settled)
437
+ return;
438
+ settled = true;
439
+ signal.removeEventListener('abort', abort);
440
+ reject(signal.reason ?? new Error('Rust executable graph verification aborted'));
441
+ };
442
+ signal.addEventListener('abort', abort, { once: true });
443
+ pending.then((value) => {
444
+ if (settled)
445
+ return;
446
+ settled = true;
447
+ signal.removeEventListener('abort', abort);
448
+ resolve(value);
449
+ }, (error) => {
450
+ if (settled)
451
+ return;
452
+ settled = true;
453
+ signal.removeEventListener('abort', abort);
454
+ reject(error);
455
+ });
456
+ if (signal.aborted)
457
+ abort();
458
+ });
459
+ return Array.from(new Uint8Array(digest), (value) => value.toString(16).padStart(2, '0')).join('');
460
+ }
461
+ function resolveSourceNetworkContext(moduleUrl, currentUrl, profile, runtimeProfile) {
462
+ let sourceModule;
463
+ try {
464
+ sourceModule = new URL(moduleUrl, currentUrl);
465
+ }
466
+ catch (cause) {
467
+ throw configurationError('Rust executable entry URL is invalid', cause);
468
+ }
469
+ if ((sourceModule.protocol !== 'http:' && sourceModule.protocol !== 'https:') ||
470
+ sourceModule.username ||
471
+ sourceModule.password ||
472
+ sourceModule.hash ||
473
+ /%(?:2e|2f|5c)/iu.test(sourceModule.pathname) ||
474
+ !sourceModule.pathname.endsWith(`/${profile.entryPath}`)) {
475
+ throw configurationError('Rust executable entry URL is unsafe or has the wrong path');
476
+ }
477
+ const queryKeys = [...sourceModule.searchParams.keys()].sort(compareCodeUnits);
478
+ if (queryKeys.length !== 3 ||
479
+ queryKeys[0] !== 'rustManifestBytes' ||
480
+ queryKeys[1] !== 'rustManifestSha256' ||
481
+ queryKeys[2] !== 'v' ||
482
+ sourceModule.searchParams.getAll('v').length !== 1 ||
483
+ sourceModule.searchParams.getAll('rustManifestBytes').length !== 1 ||
484
+ sourceModule.searchParams.getAll('rustManifestSha256').length !== 1) {
485
+ throw configurationError('Rust executable entry URL must contain one exact runtime profile');
486
+ }
487
+ const generation = sourceModule.searchParams.get('v');
488
+ const manifestBytesText = sourceModule.searchParams.get('rustManifestBytes');
489
+ const manifestSha256 = sourceModule.searchParams.get('rustManifestSha256');
490
+ const manifestBytes = Number(manifestBytesText);
491
+ const canonicalRuntimeProfileQuery = `?v=${runtimeProfile.manifestFingerprint}&rustManifestBytes=${runtimeProfile.manifestReceipt.bytes}&rustManifestSha256=${runtimeProfile.manifestReceipt.sha256}`;
492
+ if (generation !== runtimeProfile.manifestFingerprint ||
493
+ manifestSha256 !== runtimeProfile.manifestReceipt.sha256 ||
494
+ manifestBytesText !== String(runtimeProfile.manifestReceipt.bytes) ||
495
+ sourceModule.search !== canonicalRuntimeProfileQuery ||
496
+ !/^\d+$/u.test(manifestBytesText) ||
497
+ !Number.isSafeInteger(manifestBytes) ||
498
+ manifestBytes <= 0) {
499
+ throw configurationError('Rust executable entry URL has an invalid runtime profile');
500
+ }
501
+ const sourceBase = new URL('./', sourceModule);
502
+ sourceBase.search = sourceModule.search;
503
+ const storageUrls = {};
504
+ const keysByPath = {};
505
+ const networkUrlsByPath = {};
506
+ const modulePaths = Object.keys(profile.modules).sort(compareCodeUnits);
507
+ for (const [index, modulePath] of modulePaths.entries()) {
508
+ const key = `module-${index}`;
509
+ const module = profile.modules[modulePath];
510
+ const storageUrl = new URL(module.delivery.storagePath, sourceBase);
511
+ storageUrl.search = `?v=${module.storage.sha256}`;
512
+ storageUrls[key] = storageUrl.href;
513
+ keysByPath[modulePath] = key;
514
+ const networkUrl = new URL(modulePath, sourceBase);
515
+ networkUrl.search = sourceModule.search;
516
+ networkUrlsByPath[modulePath] = networkUrl.href;
517
+ }
518
+ const expectedNetworkModuleUrls = Object.freeze(modulePaths.map((modulePath) => networkUrlsByPath[modulePath]));
519
+ return Object.freeze({
520
+ sourceModuleUrl: sourceModule.href,
521
+ assetBaseUrl: sourceBase.href,
522
+ storageRootUrl: new URL('./', sourceModule).href,
523
+ storageUrls: Object.freeze(storageUrls),
524
+ keysByPath: Object.freeze(keysByPath),
525
+ networkUrlsByPath: Object.freeze(networkUrlsByPath),
526
+ expectedNetworkModuleUrls,
527
+ runtimeProfile: Object.freeze({
528
+ ...runtimeProfile,
529
+ moduleUrl: sourceModule.href
530
+ })
531
+ });
532
+ }
533
+ function createPreflightManifest(profile, keysByPath) {
534
+ return {
535
+ schemaVersion: RUNTIME_REGISTRY_MANIFEST_SCHEMA_VERSION,
536
+ manifestId: 'wasm-idle/rust-executable-graph',
537
+ revision: profile.fingerprint,
538
+ runtimes: [
539
+ {
540
+ runtimeId: 'rust/executable-graph',
541
+ identity: {
542
+ languageId: 'RUST',
543
+ implementationId: 'wasm-rust-browser',
544
+ implementationVersion: '1',
545
+ profile: {
546
+ profileId: 'rust-executable-graph-v1',
547
+ manifestSchemaVersion: 1,
548
+ manifestSha256: profile.fingerprint,
549
+ protocolVersion: 1,
550
+ trustProfileId: 'receipt-verified-module-graph-v1',
551
+ trustProfileSchemaVersion: 1
552
+ }
553
+ },
554
+ capabilities: {
555
+ stdin: 'streaming',
556
+ workspace: true,
557
+ abort: true,
558
+ artifacts: true,
559
+ streamingOutput: true
560
+ },
561
+ workerLifetime: { mode: 'per-run' },
562
+ requiredBrowserFeatures: [
563
+ 'blob',
564
+ 'crypto.subtle',
565
+ 'decompression-stream',
566
+ 'module-worker'
567
+ ],
568
+ assetRoot: '.',
569
+ assets: Object.keys(profile.modules)
570
+ .sort(compareCodeUnits)
571
+ .map((modulePath) => {
572
+ const module = profile.modules[modulePath];
573
+ return {
574
+ key: keysByPath[modulePath],
575
+ path: module.delivery.storagePath,
576
+ compressedSha256: module.storage.sha256,
577
+ uncompressedSha256: module.storage.sha256,
578
+ compressedBytes: module.storage.bytes,
579
+ uncompressedBytes: module.storage.bytes,
580
+ mediaType: 'application/octet-stream',
581
+ encoding: 'identity'
582
+ };
583
+ }),
584
+ contracts: {
585
+ routeId: 'rust',
586
+ runtimeAssetKey: 'rust-executable-graph',
587
+ documentationId: 'RUST',
588
+ syncTarget: 'wasm-rust',
589
+ browserTestId: 'rust-executable-graph'
590
+ }
591
+ }
592
+ ]
593
+ };
594
+ }
595
+ async function decodeGzipBounded(bytes, expectedBytes, signal) {
596
+ if (typeof DecompressionStream !== 'function') {
597
+ throw configurationError('Rust executable graph gzip requires DecompressionStream');
598
+ }
599
+ const body = new Response(Uint8Array.from(bytes)).body;
600
+ if (!body) {
601
+ throw configurationError('Rust executable graph gzip requires readable response bodies');
602
+ }
603
+ let reader;
604
+ try {
605
+ reader = body.pipeThrough(new DecompressionStream('gzip')).getReader();
606
+ }
607
+ catch (cause) {
608
+ throw configurationError('Rust executable graph gzip decoder initialization failed', cause);
609
+ }
610
+ const output = new Uint8Array(expectedBytes);
611
+ let offset = 0;
612
+ const abort = () => {
613
+ try {
614
+ void reader.cancel(signal?.reason).catch(() => { });
615
+ }
616
+ catch {
617
+ // Preserve the abort reason rather than a decoder cleanup failure.
618
+ }
619
+ };
620
+ signal?.addEventListener('abort', abort, { once: true });
621
+ try {
622
+ for (;;) {
623
+ if (signal?.aborted) {
624
+ throw signal.reason ?? new Error('Rust executable graph verification aborted');
625
+ }
626
+ const { done, value } = await reader.read();
627
+ if (done)
628
+ break;
629
+ if (offset + value.byteLength > expectedBytes) {
630
+ throw configurationError('Rust executable graph gzip exceeds its logical receipt size');
631
+ }
632
+ output.set(value, offset);
633
+ offset += value.byteLength;
634
+ }
635
+ }
636
+ catch (cause) {
637
+ try {
638
+ await reader.cancel(cause);
639
+ }
640
+ catch { }
641
+ if (signal?.aborted) {
642
+ throw signal.reason ?? cause;
643
+ }
644
+ if (cause instanceof RuntimeConfigurationError)
645
+ throw cause;
646
+ throw configurationError('Rust executable graph gzip decoding failed', cause);
647
+ }
648
+ finally {
649
+ signal?.removeEventListener('abort', abort);
650
+ }
651
+ if (signal?.aborted) {
652
+ throw signal.reason ?? new Error('Rust executable graph verification aborted');
653
+ }
654
+ if (offset !== expectedBytes) {
655
+ throw configurationError('Rust executable graph gzip logical size mismatch');
656
+ }
657
+ return output;
658
+ }
659
+ function scanUnescapedStringLiterals(source) {
660
+ const literals = [];
661
+ let index = 0;
662
+ while (index < source.length) {
663
+ const character = source[index];
664
+ if (character === '/' && source[index + 1] === '/') {
665
+ index += 2;
666
+ while (index < source.length && source[index] !== '\n' && source[index] !== '\r')
667
+ index++;
668
+ continue;
669
+ }
670
+ if (character === '/' && source[index + 1] === '*') {
671
+ const end = source.indexOf('*/', index + 2);
672
+ index = end < 0 ? source.length : end + 2;
673
+ continue;
674
+ }
675
+ if (character === '`') {
676
+ index += 1;
677
+ while (index < source.length) {
678
+ if (source[index] === '\\') {
679
+ index += 2;
680
+ continue;
681
+ }
682
+ if (source[index++] === '`')
683
+ break;
684
+ }
685
+ continue;
686
+ }
687
+ if (character !== "'" && character !== '"') {
688
+ index += 1;
689
+ continue;
690
+ }
691
+ const quote = character;
692
+ const start = index++;
693
+ let escaped = false;
694
+ let closed = false;
695
+ while (index < source.length) {
696
+ const next = source[index];
697
+ if (next === '\\') {
698
+ escaped = true;
699
+ index += 2;
700
+ continue;
701
+ }
702
+ index += 1;
703
+ if (next === quote) {
704
+ closed = true;
705
+ break;
706
+ }
707
+ if (next === '\n' || next === '\r')
708
+ break;
709
+ }
710
+ if (closed && !escaped) {
711
+ literals.push({ value: source.slice(start + 1, index - 1), start, end: index });
712
+ }
713
+ }
714
+ return literals;
715
+ }
716
+ function planSourceReplacements(modulePath, source, module) {
717
+ const literals = scanUnescapedStringLiterals(source);
718
+ const replacements = [];
719
+ for (const graphImport of module.imports) {
720
+ if (isAllowedThreadSelfEdge(modulePath, graphImport))
721
+ continue;
722
+ const matches = literals.filter((literal) => literal.value === graphImport.specifier);
723
+ if (matches.length === 0 && graphImport.kind !== 'dynamic') {
724
+ throw configurationError(`Rust executable module ${modulePath} must contain ${graphImport.kind} import ${graphImport.specifier}`);
725
+ }
726
+ for (const match of matches) {
727
+ replacements.push({
728
+ start: match.start,
729
+ end: match.end,
730
+ target: graphImport.target,
731
+ type: 'module'
732
+ });
733
+ }
734
+ }
735
+ for (const asset of module.assets) {
736
+ const matches = literals.filter((literal) => literal.value === asset.specifier);
737
+ if (matches.length !== 1) {
738
+ throw configurationError(`Rust executable module ${modulePath} must contain core Wasm asset ${asset.specifier} exactly once`);
739
+ }
740
+ replacements.push({
741
+ start: matches[0].start,
742
+ end: matches[0].end,
743
+ // The generated JCO loader appends `.gz` to `.core.wasm` itself. The
744
+ // declared target remains the storage/receipt cross-check above.
745
+ target: resolveRelativeTarget(modulePath, asset.specifier),
746
+ type: 'asset'
747
+ });
748
+ }
749
+ for (const external of module.externals) {
750
+ if (literals.filter((literal) => literal.value === external.specifier).length !== 1) {
751
+ throw configurationError(`Rust executable module ${modulePath} must contain node-only import ${external.specifier} exactly once`);
752
+ }
753
+ }
754
+ const offsets = new Set(replacements.map(({ start }) => start));
755
+ if (offsets.size !== replacements.length) {
756
+ throw configurationError(`Rust executable module ${modulePath} has ambiguous declarations`);
757
+ }
758
+ return Object.freeze(replacements.sort((left, right) => right.start - left.start));
759
+ }
760
+ function applySourceReplacements(source, replacements, moduleUrls, sourceContext) {
761
+ let rewritten = source;
762
+ for (const replacement of replacements) {
763
+ let targetUrl;
764
+ if (replacement.type === 'module') {
765
+ targetUrl = moduleUrls[replacement.target];
766
+ if (!isSafeBlobUrl(targetUrl)) {
767
+ throw configurationError('Rust executable graph Blob URL is unsafe for source rewriting');
768
+ }
769
+ }
770
+ else {
771
+ const assetUrl = new URL(replacement.target, sourceContext.assetBaseUrl);
772
+ assetUrl.search = new URL(sourceContext.sourceModuleUrl).search;
773
+ targetUrl = assetUrl.href;
774
+ if ((assetUrl.protocol !== 'http:' && assetUrl.protocol !== 'https:') ||
775
+ assetUrl.username ||
776
+ assetUrl.password ||
777
+ assetUrl.hash ||
778
+ /[\r\n]/u.test(targetUrl)) {
779
+ throw configurationError('Rust executable graph core Wasm URL is unsafe');
780
+ }
781
+ }
782
+ rewritten = `${rewritten.slice(0, replacement.start)}${JSON.stringify(targetUrl)}${rewritten.slice(replacement.end)}`;
783
+ }
784
+ return rewritten;
785
+ }
786
+ function isSafeBlobUrl(value) {
787
+ if (!SAFE_BLOB_URL_PATTERN.test(value))
788
+ return false;
789
+ try {
790
+ const url = new URL(value);
791
+ return url.protocol === 'blob:' && !url.search && !url.hash && url.href === value;
792
+ }
793
+ catch {
794
+ return false;
795
+ }
796
+ }
797
+ export async function loadVerifiedRustExecutableGraph(options) {
798
+ const profile = snapshotRustExecutableGraphProfile(options.profile);
799
+ const runtimeProfile = snapshotPinnedRustRuntimeProfile(options.runtimeProfile);
800
+ const sourceContext = resolveSourceNetworkContext(options.moduleUrl, options.currentUrl, profile, runtimeProfile);
801
+ const actualFingerprint = await sha256Hex(canonicalRustExecutableGraphProfile(profile), options.signal);
802
+ if (actualFingerprint !== profile.fingerprint) {
803
+ throw configurationError('Rust executable graph fingerprint does not match its receipts');
804
+ }
805
+ let totalStorageBytes = 0;
806
+ let totalLogicalBytes = 0;
807
+ for (const module of Object.values(profile.modules)) {
808
+ totalStorageBytes += module.storage.bytes;
809
+ totalLogicalBytes += module.logical.bytes;
810
+ }
811
+ if (!Number.isSafeInteger(totalStorageBytes) || !Number.isSafeInteger(totalLogicalBytes)) {
812
+ throw configurationError('Rust executable graph aggregate size is unsafe');
813
+ }
814
+ const maxAssetBytes = options.maxAssetBytes;
815
+ if (maxAssetBytes !== undefined &&
816
+ Object.values(profile.modules).some((module) => module.storage.bytes > maxAssetBytes || module.logical.bytes > maxAssetBytes)) {
817
+ throw configurationError('Rust executable graph module exceeds the configured asset limit');
818
+ }
819
+ const limits = {};
820
+ if (maxAssetBytes !== undefined)
821
+ limits.maxAssetBytes = maxAssetBytes;
822
+ if (options.assetTimeoutMs !== undefined)
823
+ limits.assetTimeoutMs = options.assetTimeoutMs;
824
+ const preflight = await preflightRuntimeAssets({
825
+ manifest: createPreflightManifest(profile, sourceContext.keysByPath),
826
+ runtimeId: 'rust/executable-graph',
827
+ rootUrl: sourceContext.storageRootUrl,
828
+ assetUrls: sourceContext.storageUrls,
829
+ ...(options.fetch ? { fetch: options.fetch } : {}),
830
+ ...(options.signal ? { signal: options.signal } : {}),
831
+ limits,
832
+ cache: 'no-store',
833
+ redirect: 'error',
834
+ requireExactResponseUrl: true,
835
+ maxConcurrentDownloads: Math.min(5, Object.keys(profile.modules).length),
836
+ maxTotalDeliveryBytes: totalStorageBytes,
837
+ reportProgress: options.reportProgress
838
+ ? ({ assetKey, loadedBytes, totalBytes }) => {
839
+ const path = Object.keys(sourceContext.keysByPath).find((candidate) => sourceContext.keysByPath[candidate] === assetKey);
840
+ if (path)
841
+ options.reportProgress?.({ path, loadedBytes, totalBytes });
842
+ }
843
+ : undefined
844
+ });
845
+ const sources = {};
846
+ const replacementPlans = {};
847
+ for (const modulePath of Object.keys(profile.modules).sort(compareCodeUnits)) {
848
+ if (options.signal?.aborted) {
849
+ throw options.signal.reason ?? new Error('Rust executable graph verification aborted');
850
+ }
851
+ const module = profile.modules[modulePath];
852
+ const storageBytes = preflight.assets[sourceContext.keysByPath[modulePath]].bytes;
853
+ const logicalBytes = module.delivery.encoding === 'gzip'
854
+ ? await decodeGzipBounded(storageBytes, module.logical.bytes, options.signal)
855
+ : storageBytes;
856
+ if (logicalBytes.byteLength !== module.logical.bytes) {
857
+ throw configurationError(`Rust executable module ${modulePath} logical size mismatch`);
858
+ }
859
+ if ((await sha256Hex(logicalBytes, options.signal)) !== module.logical.sha256) {
860
+ throw configurationError(`Rust executable module ${modulePath} logical SHA-256 mismatch`);
861
+ }
862
+ let source;
863
+ try {
864
+ source = fatalDecoder.decode(logicalBytes);
865
+ }
866
+ catch (cause) {
867
+ throw configurationError(`Rust executable module ${modulePath} is not valid UTF-8`, cause);
868
+ }
869
+ sources[modulePath] = source;
870
+ replacementPlans[modulePath] = planSourceReplacements(modulePath, source, module);
871
+ }
872
+ if (typeof Blob !== 'function' ||
873
+ typeof URL?.createObjectURL !== 'function' ||
874
+ typeof URL?.revokeObjectURL !== 'function') {
875
+ throw configurationError('Rust executable graph requires Blob module URLs');
876
+ }
877
+ const order = [];
878
+ const visited = new Set();
879
+ const visit = (modulePath) => {
880
+ if (visited.has(modulePath))
881
+ return;
882
+ visited.add(modulePath);
883
+ for (const graphImport of profile.modules[modulePath].imports) {
884
+ if (isAllowedThreadSelfEdge(modulePath, graphImport))
885
+ continue;
886
+ visit(graphImport.target);
887
+ }
888
+ order.push(modulePath);
889
+ };
890
+ visit(profile.entryPath);
891
+ const moduleUrls = {};
892
+ const networkModuleUrls = {};
893
+ const ownedUrls = [];
894
+ const ownedUrlSet = new Set();
895
+ let disposed = false;
896
+ const dispose = () => {
897
+ if (disposed)
898
+ return;
899
+ disposed = true;
900
+ for (const url of ownedUrls.reverse()) {
901
+ try {
902
+ URL.revokeObjectURL(url);
903
+ }
904
+ catch {
905
+ // Cleanup is best effort and must remain idempotent.
906
+ }
907
+ }
908
+ };
909
+ try {
910
+ for (const modulePath of order) {
911
+ if (options.signal?.aborted) {
912
+ throw (options.signal.reason ?? new Error('Rust executable graph verification aborted'));
913
+ }
914
+ const source = applySourceReplacements(sources[modulePath], replacementPlans[modulePath], moduleUrls, sourceContext);
915
+ const blobUrl = URL.createObjectURL(new Blob([source], { type: 'text/javascript;charset=utf-8' }));
916
+ if (!isSafeBlobUrl(blobUrl) || ownedUrlSet.has(blobUrl)) {
917
+ try {
918
+ URL.revokeObjectURL(blobUrl);
919
+ }
920
+ catch { }
921
+ throw configurationError('Rust executable graph received an unsafe Blob URL');
922
+ }
923
+ moduleUrls[modulePath] = blobUrl;
924
+ networkModuleUrls[sourceContext.networkUrlsByPath[modulePath]] = blobUrl;
925
+ ownedUrls.push(blobUrl);
926
+ ownedUrlSet.add(blobUrl);
927
+ if (options.signal?.aborted) {
928
+ throw (options.signal.reason ?? new Error('Rust executable graph verification aborted'));
929
+ }
930
+ }
931
+ return Object.freeze({
932
+ entryUrl: moduleUrls[profile.entryPath],
933
+ sourceModuleUrl: sourceContext.sourceModuleUrl,
934
+ assetBaseUrl: sourceContext.assetBaseUrl,
935
+ runtimeProfile: sourceContext.runtimeProfile,
936
+ moduleUrls: Object.freeze({ ...moduleUrls }),
937
+ expectedNetworkModuleUrls: sourceContext.expectedNetworkModuleUrls,
938
+ networkModuleUrls: Object.freeze({ ...networkModuleUrls }),
939
+ dispose
940
+ });
941
+ }
942
+ catch (error) {
943
+ dispose();
944
+ throw error;
945
+ }
946
+ }