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.
- package/README.md +760 -81
- package/dist/index.d.ts +4 -9
- package/dist/index.js +2 -4
- package/dist/playground/applicationAssets.d.ts +4 -0
- package/dist/playground/applicationAssets.js +277 -0
- package/dist/playground/assemblyscript.d.ts +41 -0
- package/dist/playground/assemblyscript.js +630 -0
- package/dist/playground/assetBridge.d.ts +18 -7
- package/dist/playground/assetBridge.js +824 -100
- package/dist/playground/assets.d.ts +813 -19
- package/dist/playground/assets.js +2096 -156
- package/dist/playground/awk.d.ts +5 -0
- package/dist/playground/awk.js +60 -0
- package/dist/playground/bash.d.ts +53 -0
- package/dist/playground/bash.js +1096 -0
- package/dist/playground/bashWorkerProtocol.d.ts +88 -0
- package/dist/playground/bashWorkerProtocol.js +135 -0
- package/dist/playground/bqn.d.ts +5 -0
- package/dist/playground/bqn.js +57 -0
- package/dist/playground/bqnPreflight.d.ts +26 -0
- package/dist/playground/bqnPreflight.js +399 -0
- package/dist/playground/c3.d.ts +15 -0
- package/dist/playground/c3.js +154 -0
- package/dist/playground/clang.d.ts +35 -19
- package/dist/playground/clang.js +241 -52
- package/dist/playground/clangAssetIntegrity.d.ts +32 -0
- package/dist/playground/clangAssetIntegrity.js +8 -0
- package/dist/playground/clojurescript.d.ts +5 -0
- package/dist/playground/clojurescript.js +59 -0
- package/dist/playground/clojurescriptPreflight.d.ts +26 -0
- package/dist/playground/clojurescriptPreflight.js +383 -0
- package/dist/playground/cobol.d.ts +46 -0
- package/dist/playground/cobol.js +703 -0
- package/dist/playground/d.d.ts +47 -0
- package/dist/playground/d.js +644 -0
- package/dist/playground/dOuterAssets.d.ts +16 -0
- package/dist/playground/dOuterAssets.js +163 -0
- package/dist/playground/dotnet.d.ts +99 -0
- package/dist/playground/dotnet.js +1131 -0
- package/dist/playground/duckdb.d.ts +36 -0
- package/dist/playground/duckdb.js +542 -0
- package/dist/playground/elixir.d.ts +18 -10
- package/dist/playground/elixir.js +630 -96
- package/dist/playground/elixirAssets.d.ts +6 -0
- package/dist/playground/elixirAssets.js +33 -0
- package/dist/playground/executionObservation.d.ts +22 -0
- package/dist/playground/executionObservation.js +65 -0
- package/dist/playground/forth.d.ts +5 -0
- package/dist/playground/forth.js +53 -0
- package/dist/playground/forthPreflight.d.ts +24 -0
- package/dist/playground/forthPreflight.js +198 -0
- package/dist/playground/fortran.d.ts +47 -0
- package/dist/playground/fortran.js +651 -0
- package/dist/playground/fortranAssets.d.ts +6 -0
- package/dist/playground/fortranAssets.js +27 -0
- package/dist/playground/gleam.d.ts +6 -0
- package/dist/playground/gleam.js +33 -0
- package/dist/playground/go.d.ts +17 -11
- package/dist/playground/go.js +376 -72
- package/dist/playground/goDebugInstrumentation.d.ts +1 -0
- package/dist/playground/goDebugInstrumentation.js +229 -0
- package/dist/playground/haskell.d.ts +44 -0
- package/dist/playground/haskell.js +678 -0
- package/dist/playground/haskellAssets.d.ts +24 -0
- package/dist/playground/haskellAssets.js +93 -0
- package/dist/playground/index.d.ts +1 -1
- package/dist/playground/index.js +360 -111
- package/dist/playground/j.d.ts +5 -0
- package/dist/playground/j.js +60 -0
- package/dist/playground/jPreflight.d.ts +26 -0
- package/dist/playground/jPreflight.js +372 -0
- package/dist/playground/janet.d.ts +5 -0
- package/dist/playground/janet.js +64 -0
- package/dist/playground/java.d.ts +24 -10
- package/dist/playground/java.js +706 -84
- package/dist/playground/javaSource.d.ts +5 -0
- package/dist/playground/javaSource.js +16 -0
- package/dist/playground/javaStdin.d.ts +1 -1
- package/dist/playground/javaStdin.js +13 -4
- package/dist/playground/julia.d.ts +5 -0
- package/dist/playground/julia.js +64 -0
- package/dist/playground/lfortran.d.ts +8 -0
- package/dist/playground/lfortran.js +30 -0
- package/dist/playground/lfortranAssets.d.ts +21 -0
- package/dist/playground/lfortranAssets.js +118 -0
- package/dist/playground/lisp.d.ts +45 -0
- package/dist/playground/lisp.js +640 -0
- package/dist/playground/lispAssets.d.ts +9 -0
- package/dist/playground/lispAssets.js +74 -0
- package/dist/playground/lldbManifest.d.ts +3 -0
- package/dist/playground/lldbManifest.js +155 -0
- package/dist/playground/lldbSession.d.ts +115 -0
- package/dist/playground/lldbSession.js +1347 -0
- package/dist/playground/loadingProgress.d.ts +16 -0
- package/dist/playground/loadingProgress.js +166 -0
- package/dist/playground/lua.d.ts +44 -0
- package/dist/playground/lua.js +630 -0
- package/dist/playground/nim.d.ts +5 -0
- package/dist/playground/nim.js +76 -0
- package/dist/playground/objectivec.d.ts +39 -0
- package/dist/playground/objectivec.js +288 -0
- package/dist/playground/ocaml.d.ts +28 -10
- package/dist/playground/ocaml.js +815 -253
- package/dist/playground/octave.d.ts +43 -0
- package/dist/playground/octave.js +783 -0
- package/dist/playground/options.d.ts +19 -40
- package/dist/playground/options.js +2 -1
- package/dist/playground/pascal.d.ts +5 -0
- package/dist/playground/pascal.js +60 -0
- package/dist/playground/perl.d.ts +5 -0
- package/dist/playground/perl.js +61 -0
- package/dist/playground/php.d.ts +44 -0
- package/dist/playground/php.js +665 -0
- package/dist/playground/prolog.d.ts +6 -0
- package/dist/playground/prolog.js +75 -0
- package/dist/playground/python.d.ts +20 -14
- package/dist/playground/python.js +445 -101
- package/dist/playground/pythonPackageLock.d.ts +6 -0
- package/dist/playground/pythonPackageLock.js +56 -0
- package/dist/playground/r.d.ts +44 -0
- package/dist/playground/r.js +637 -0
- package/dist/playground/ruby.d.ts +46 -0
- package/dist/playground/ruby.js +732 -0
- package/dist/playground/rubyAssets.d.ts +23 -0
- package/dist/playground/rubyAssets.js +68 -0
- package/dist/playground/rubyTestPreflight.d.ts +2 -0
- package/dist/playground/rubyTestPreflight.js +18 -0
- package/dist/playground/runtimeModule.d.ts +1 -0
- package/dist/playground/runtimeModule.js +5 -0
- package/dist/playground/rust.d.ts +44 -13
- package/dist/playground/rust.js +714 -76
- package/dist/playground/rustExecutableGraph.d.ts +85 -0
- package/dist/playground/rustExecutableGraph.js +946 -0
- package/dist/playground/rustWorkerLimits.d.ts +17 -0
- package/dist/playground/rustWorkerLimits.js +34 -0
- package/dist/playground/sandbox.d.ts +16 -10
- package/dist/playground/sharedBuffer.d.ts +6 -0
- package/dist/playground/sharedBuffer.js +12 -0
- package/dist/playground/sqlite.d.ts +38 -0
- package/dist/playground/sqlite.js +550 -0
- package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
- package/dist/playground/staticRuntimeModuleVersion.js +2 -0
- package/dist/playground/staticRuntimePreflight.d.ts +13 -0
- package/dist/playground/staticRuntimePreflight.js +231 -0
- package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
- package/dist/playground/staticRuntimePreflightExecute.js +66 -0
- package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
- package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
- package/dist/playground/staticStdinRing.d.ts +45 -0
- package/dist/playground/staticStdinRing.js +158 -0
- package/dist/playground/staticWorkerRuntime.d.ts +154 -0
- package/dist/playground/staticWorkerRuntime.js +1917 -0
- package/dist/playground/stdinBuffer.d.ts +9 -7
- package/dist/playground/stdinBuffer.js +9 -18
- package/dist/playground/swift.d.ts +5 -0
- package/dist/playground/swift.js +17 -0
- package/dist/playground/tcl.d.ts +5 -0
- package/dist/playground/tcl.js +62 -0
- package/dist/playground/teavmConfig.d.ts +1 -1
- package/dist/playground/teavmConfig.js +2 -2
- package/dist/playground/tinygo.d.ts +48 -18
- package/dist/playground/tinygo.js +1202 -329
- package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
- package/dist/playground/tinygoExecutableGraph.js +449 -0
- package/dist/playground/typescript.d.ts +55 -0
- package/dist/playground/typescript.js +924 -0
- package/dist/playground/wasm.d.ts +43 -0
- package/dist/playground/wasm.js +608 -0
- package/dist/playground/wasmAwkVersion.d.ts +59 -0
- package/dist/playground/wasmAwkVersion.js +31 -0
- package/dist/playground/wasmBashVersion.d.ts +63 -0
- package/dist/playground/wasmBashVersion.js +36 -0
- package/dist/playground/wasmBqnVersion.d.ts +24 -0
- package/dist/playground/wasmBqnVersion.js +24 -0
- package/dist/playground/wasmC3Version.d.ts +20 -0
- package/dist/playground/wasmC3Version.js +21 -0
- package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
- package/dist/playground/wasmClojureScriptVersion.js +21 -0
- package/dist/playground/wasmDIntegrity.d.ts +15 -0
- package/dist/playground/wasmDIntegrity.js +15 -0
- package/dist/playground/wasmDVersion.d.ts +1 -0
- package/dist/playground/wasmDVersion.js +1 -0
- package/dist/playground/wasmDebugVersion.d.ts +6 -0
- package/dist/playground/wasmDebugVersion.js +6 -0
- package/dist/playground/wasmDotnetVersion.d.ts +1 -0
- package/dist/playground/wasmDotnetVersion.js +1 -0
- package/dist/playground/wasmElixirVersion.d.ts +21 -1
- package/dist/playground/wasmElixirVersion.js +21 -1
- package/dist/playground/wasmForthVersion.d.ts +18 -0
- package/dist/playground/wasmForthVersion.js +18 -0
- package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
- package/dist/playground/wasmFortranExecutionAssets.js +15 -0
- package/dist/playground/wasmFortranVersion.d.ts +1 -0
- package/dist/playground/wasmFortranVersion.js +1 -0
- package/dist/playground/wasmGleamVersion.d.ts +5 -0
- package/dist/playground/wasmGleamVersion.js +5 -0
- package/dist/playground/wasmGoVersion.d.ts +1 -1
- package/dist/playground/wasmGoVersion.js +1 -1
- package/dist/playground/wasmHaskellVersion.d.ts +1 -0
- package/dist/playground/wasmHaskellVersion.js +1 -0
- package/dist/playground/wasmJVersion.d.ts +24 -0
- package/dist/playground/wasmJVersion.js +24 -0
- package/dist/playground/wasmJanetVersion.d.ts +53 -0
- package/dist/playground/wasmJanetVersion.js +30 -0
- package/dist/playground/wasmJuliaVersion.d.ts +71 -0
- package/dist/playground/wasmJuliaVersion.js +39 -0
- package/dist/playground/wasmLfortranVersion.d.ts +28 -0
- package/dist/playground/wasmLfortranVersion.js +29 -0
- package/dist/playground/wasmLispVersion.d.ts +1 -0
- package/dist/playground/wasmLispVersion.js +1 -0
- package/dist/playground/wasmLuaVersion.d.ts +1 -0
- package/dist/playground/wasmLuaVersion.js +1 -0
- package/dist/playground/wasmNimVersion.d.ts +125 -0
- package/dist/playground/wasmNimVersion.js +66 -0
- package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
- package/dist/playground/wasmObjectiveCVersion.js +27 -0
- package/dist/playground/wasmOcamlVersion.d.ts +12 -1
- package/dist/playground/wasmOcamlVersion.js +12 -1
- package/dist/playground/wasmOctaveVersion.d.ts +1 -0
- package/dist/playground/wasmOctaveVersion.js +1 -0
- package/dist/playground/wasmPascalVersion.d.ts +61 -0
- package/dist/playground/wasmPascalVersion.js +34 -0
- package/dist/playground/wasmPerlVersion.d.ts +71 -0
- package/dist/playground/wasmPerlVersion.js +39 -0
- package/dist/playground/wasmPrologVersion.d.ts +31 -0
- package/dist/playground/wasmPrologVersion.js +31 -0
- package/dist/playground/wasmRVersion.d.ts +1 -0
- package/dist/playground/wasmRVersion.js +1 -0
- package/dist/playground/wasmRustVersion.d.ts +1306 -1
- package/dist/playground/wasmRustVersion.js +1458 -1
- package/dist/playground/wasmSwiftVersion.d.ts +1 -0
- package/dist/playground/wasmSwiftVersion.js +1 -0
- package/dist/playground/wasmTclVersion.d.ts +85 -0
- package/dist/playground/wasmTclVersion.js +46 -0
- package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
- package/dist/playground/wasmTinyGoVersion.js +107 -1
- package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
- package/dist/playground/wasmTypeScriptVersion.js +5 -0
- package/dist/playground/wasmWatVersion.d.ts +1 -0
- package/dist/playground/wasmWatVersion.js +1 -0
- package/dist/playground/wasmZigVersion.d.ts +13 -0
- package/dist/playground/wasmZigVersion.js +13 -0
- package/dist/playground/wat.d.ts +44 -0
- package/dist/playground/wat.js +622 -0
- package/dist/playground/worker/assemblyscript.js +339 -0
- package/dist/playground/worker/assets.d.ts +7 -0
- package/dist/playground/worker/assets.js +288 -39
- package/dist/playground/worker/bash.js +338 -0
- package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
- package/dist/playground/worker/bashNestedBootstrap.js +59 -0
- package/dist/playground/worker/bashRuntime.d.ts +89 -0
- package/dist/playground/worker/bashRuntime.js +982 -0
- package/dist/playground/worker/clang.js +92 -13
- package/dist/playground/worker/cobol.js +107 -0
- package/dist/playground/worker/d.js +199 -0
- package/dist/playground/worker/dotnet.js +141 -0
- package/dist/playground/worker/duckdb.d.ts +1 -0
- package/dist/playground/worker/duckdb.js +136 -0
- package/dist/playground/worker/elixir.js +307 -41
- package/dist/playground/worker/fortran.d.ts +1 -0
- package/dist/playground/worker/fortran.js +295 -0
- package/dist/playground/worker/go.js +246 -40
- package/dist/playground/worker/haskell.d.ts +7 -0
- package/dist/playground/worker/haskell.js +465 -0
- package/dist/playground/worker/java.js +59 -20
- package/dist/playground/worker/lisp.d.ts +1 -0
- package/dist/playground/worker/lisp.js +195 -0
- package/dist/playground/worker/lua.d.ts +1 -0
- package/dist/playground/worker/lua.js +163 -0
- package/dist/playground/worker/objectivec.d.ts +1 -0
- package/dist/playground/worker/objectivec.js +10 -0
- package/dist/playground/worker/ocaml.js +206 -58
- package/dist/playground/worker/php.d.ts +1 -0
- package/dist/playground/worker/php.js +261 -0
- package/dist/playground/worker/python.js +201 -44
- package/dist/playground/worker/r.d.ts +1 -0
- package/dist/playground/worker/r.js +192 -0
- package/dist/playground/worker/ruby.d.ts +1 -0
- package/dist/playground/worker/ruby.js +248 -0
- package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
- package/dist/playground/worker/runtimeAssetFetch.js +375 -0
- package/dist/playground/worker/rust.js +546 -20
- package/dist/playground/worker/sqlite.d.ts +1 -0
- package/dist/playground/worker/sqlite.js +112 -0
- package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
- package/dist/playground/worker/staticRuntimePreflight.js +56 -0
- package/dist/playground/worker/tinygo.js +34 -9
- package/dist/playground/worker/typescript.d.ts +1 -0
- package/dist/playground/worker/typescript.js +251 -0
- package/dist/playground/worker/wasm.d.ts +1 -0
- package/dist/playground/worker/wasm.js +273 -0
- package/dist/playground/worker/wat.d.ts +1 -0
- package/dist/playground/worker/wat.js +188 -0
- package/dist/playground/worker/zig.d.ts +8 -0
- package/dist/playground/worker/zig.js +578 -0
- package/dist/playground/workerProgress.d.ts +15 -0
- package/dist/playground/workerProgress.js +72 -0
- package/dist/playground/workerSession.d.ts +28 -0
- package/dist/playground/workerSession.js +164 -0
- package/dist/playground/zig.d.ts +46 -0
- package/dist/playground/zig.js +690 -0
- package/dist/playground/zigAssets.d.ts +6 -0
- package/dist/playground/zigAssets.js +49 -0
- package/package.json +234 -105
- package/dist/clang/app.d.ts +0 -75
- package/dist/clang/app.js +0 -744
- package/dist/clang/apply.d.ts +0 -2
- package/dist/clang/apply.js +0 -11
- package/dist/clang/color.d.ts +0 -3
- package/dist/clang/color.js +0 -3
- package/dist/clang/encode.d.ts +0 -4
- package/dist/clang/encode.js +0 -20
- package/dist/clang/error.d.ts +0 -14
- package/dist/clang/error.js +0 -27
- package/dist/clang/gccCompat.d.ts +0 -15
- package/dist/clang/gccCompat.js +0 -767
- package/dist/clang/index.d.ts +0 -85
- package/dist/clang/index.js +0 -1077
- package/dist/clang/memory/index.d.ts +0 -4
- package/dist/clang/memory/index.js +0 -4
- package/dist/clang/memory/memFs.d.ts +0 -35
- package/dist/clang/memory/memFs.js +0 -132
- package/dist/clang/memory/memory.d.ts +0 -22
- package/dist/clang/memory/memory.js +0 -73
- package/dist/clang/memory/tar.d.ts +0 -2
- package/dist/clang/memory/tar.js +0 -59
- package/dist/clang/url.d.ts +0 -4
- package/dist/clang/url.js +0 -5
- package/dist/clang/wasm.d.ts +0 -4
- package/dist/clang/wasm.js +0 -50
- package/dist/clangd/config.d.ts +0 -18
- package/dist/clangd/config.js +0 -14
- package/dist/clangd/jsonStream.d.ts +0 -9
- package/dist/clangd/jsonStream.js +0 -48
- package/dist/clangd/session.d.ts +0 -18
- package/dist/clangd/session.js +0 -112
- package/dist/clangd/worker.js +0 -131
- package/dist/debug/controller.svelte.d.ts +0 -43
- package/dist/debug/controller.svelte.js +0 -268
- package/dist/debug/editor/index.d.ts +0 -2
- package/dist/debug/editor/index.js +0 -1
- package/dist/debug/editor/monaco.d.ts +0 -26
- package/dist/debug/editor/monaco.js +0 -128
- package/dist/debug/expression.d.ts +0 -26
- package/dist/debug/expression.js +0 -547
- package/dist/debug/index.d.ts +0 -8
- package/dist/debug/index.js +0 -5
- package/dist/debug/language/cpp.d.ts +0 -2
- package/dist/debug/language/cpp.js +0 -7
- package/dist/debug/language/index.d.ts +0 -3
- package/dist/debug/language/index.js +0 -2
- package/dist/debug/language/python.d.ts +0 -2
- package/dist/debug/language/python.js +0 -14
- package/dist/debug/language/types.d.ts +0 -6
- package/dist/debug/locals.d.ts +0 -2
- package/dist/debug/locals.js +0 -8
- package/dist/lsp/cpp/server.d.ts +0 -2
- package/dist/lsp/cpp/server.js +0 -68
- package/dist/lsp/index.d.ts +0 -5
- package/dist/lsp/index.js +0 -4
- package/dist/lsp/python/main.worker.js +0 -92
- package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
- package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
- package/dist/lsp/python/server.d.ts +0 -2
- package/dist/lsp/python/server.js +0 -54
- package/dist/lsp/registry.d.ts +0 -2
- package/dist/lsp/registry.js +0 -12
- package/dist/lsp/runtime.d.ts +0 -5
- package/dist/lsp/runtime.js +0 -31
- package/dist/lsp/types.d.ts +0 -17
- package/dist/terminal/Terminal.svelte +0 -422
- package/dist/terminal/Terminal.svelte.d.ts +0 -26
- package/dist/terminal/index.d.ts +0 -7
- package/dist/terminal/index.js +0 -5
- package/dist/terminal/plugin/index.d.ts +0 -9
- package/dist/terminal/plugin/index.js +0 -19
- package/dist/terminal/theme.d.ts +0 -49
- package/dist/terminal/theme.js +0 -49
- package/dist/terminal/types.d.ts +0 -18
- package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
- package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
- /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
- /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
- /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
- /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
- /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const TINYGO_EXECUTABLE_GRAPH_FORMAT: "wasm-idle-tinygo-executable-graph-v1";
|
|
2
|
+
export declare const TINYGO_EXECUTABLE_GRAPH_FINGERPRINT_DOMAIN: "wasm-idle:tinygo-executable-graph:v1\n";
|
|
3
|
+
export type TinyGoExecutableImportKind = 'static' | 'dynamic' | 'worker';
|
|
4
|
+
export interface TinyGoExecutableGraphImport {
|
|
5
|
+
readonly specifier: string;
|
|
6
|
+
readonly target: string;
|
|
7
|
+
readonly kind: TinyGoExecutableImportKind;
|
|
8
|
+
}
|
|
9
|
+
export interface TinyGoExecutableGraphModule {
|
|
10
|
+
readonly bytes: number;
|
|
11
|
+
readonly sha256: string;
|
|
12
|
+
readonly imports: readonly TinyGoExecutableGraphImport[];
|
|
13
|
+
}
|
|
14
|
+
export interface TinyGoExecutableGraphProfile {
|
|
15
|
+
readonly schemaVersion: 1;
|
|
16
|
+
readonly format: typeof TINYGO_EXECUTABLE_GRAPH_FORMAT;
|
|
17
|
+
readonly entryPath: string;
|
|
18
|
+
readonly fingerprint: string;
|
|
19
|
+
readonly modules: Readonly<Record<string, TinyGoExecutableGraphModule>>;
|
|
20
|
+
}
|
|
21
|
+
export interface LoadedTinyGoExecutableGraph {
|
|
22
|
+
readonly entryUrl: string;
|
|
23
|
+
readonly assetBaseUrl: string;
|
|
24
|
+
readonly moduleUrls: Readonly<Record<string, string>>;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
export interface TinyGoExecutableGraphProgress {
|
|
28
|
+
readonly path: string;
|
|
29
|
+
readonly loadedBytes: number;
|
|
30
|
+
readonly totalBytes: number;
|
|
31
|
+
}
|
|
32
|
+
export interface LoadTinyGoExecutableGraphOptions {
|
|
33
|
+
readonly moduleUrl: string;
|
|
34
|
+
readonly currentUrl?: string;
|
|
35
|
+
readonly profile: unknown;
|
|
36
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
readonly maxAssetBytes?: number;
|
|
39
|
+
readonly assetTimeoutMs?: number;
|
|
40
|
+
readonly reportProgress?: (progress: TinyGoExecutableGraphProgress) => void;
|
|
41
|
+
}
|
|
42
|
+
export declare function snapshotTinyGoExecutableGraphProfile(value: unknown): Readonly<TinyGoExecutableGraphProfile>;
|
|
43
|
+
export declare function canonicalTinyGoExecutableGraphProfile(profile: Readonly<TinyGoExecutableGraphProfile>): Uint8Array;
|
|
44
|
+
export declare function loadVerifiedTinyGoExecutableGraph(options: LoadTinyGoExecutableGraphOptions): Promise<LoadedTinyGoExecutableGraph>;
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { RUNTIME_REGISTRY_MANIFEST_SCHEMA_VERSION, RuntimeConfigurationError, preflightRuntimeAssets } from '@wasm-idle/core';
|
|
2
|
+
export const TINYGO_EXECUTABLE_GRAPH_FORMAT = 'wasm-idle-tinygo-executable-graph-v1';
|
|
3
|
+
export const TINYGO_EXECUTABLE_GRAPH_FINGERPRINT_DOMAIN = 'wasm-idle:tinygo-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_BLOB_URL_PATTERN = /^blob:[^'"`\\\r\n]+$/u;
|
|
7
|
+
const MAX_MODULES = 32;
|
|
8
|
+
const MAX_IMPORTS = 128;
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
const fatalDecoder = new TextDecoder('utf-8', { fatal: true });
|
|
11
|
+
const compareCodeUnits = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
12
|
+
const configurationError = (message, cause) => new RuntimeConfigurationError(message, {
|
|
13
|
+
phase: 'asset',
|
|
14
|
+
runtimeId: 'TINYGO',
|
|
15
|
+
...(cause === undefined ? {} : { cause })
|
|
16
|
+
});
|
|
17
|
+
function requireExactKeys(value, expected, label) {
|
|
18
|
+
const received = Object.keys(value).sort(compareCodeUnits);
|
|
19
|
+
const sortedExpected = [...expected].sort(compareCodeUnits);
|
|
20
|
+
if (received.length !== sortedExpected.length ||
|
|
21
|
+
received.some((key, index) => key !== sortedExpected[index])) {
|
|
22
|
+
throw configurationError(`${label} must contain exactly ${sortedExpected.join(', ')}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function requireRecord(value, label) {
|
|
26
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
27
|
+
throw configurationError(`${label} must be an object`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function requireSafePath(value, label) {
|
|
32
|
+
if (typeof value !== 'string' ||
|
|
33
|
+
!value ||
|
|
34
|
+
!SAFE_PATH_PATTERN.test(value) ||
|
|
35
|
+
value.startsWith('/') ||
|
|
36
|
+
value.includes('\\') ||
|
|
37
|
+
value.includes('\0') ||
|
|
38
|
+
value.includes('?') ||
|
|
39
|
+
value.includes('#') ||
|
|
40
|
+
value.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
41
|
+
throw configurationError(`${label} must be a normalized safe relative path`);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
function resolveImportTarget(importer, specifier) {
|
|
46
|
+
if (!specifier ||
|
|
47
|
+
specifier.startsWith('/') ||
|
|
48
|
+
specifier.includes('\\') ||
|
|
49
|
+
specifier.includes('\0') ||
|
|
50
|
+
specifier.includes('\r') ||
|
|
51
|
+
specifier.includes('\n') ||
|
|
52
|
+
specifier.includes('?') ||
|
|
53
|
+
specifier.includes('#') ||
|
|
54
|
+
/^[A-Za-z][A-Za-z0-9+.-]*:/u.test(specifier)) {
|
|
55
|
+
throw configurationError(`TinyGo executable import ${specifier || '<empty>'} is unsafe`);
|
|
56
|
+
}
|
|
57
|
+
const segments = importer.split('/');
|
|
58
|
+
segments.pop();
|
|
59
|
+
for (const segment of specifier.split('/')) {
|
|
60
|
+
if (!segment || segment === '.')
|
|
61
|
+
continue;
|
|
62
|
+
if (segment === '..') {
|
|
63
|
+
if (segments.length === 0) {
|
|
64
|
+
throw configurationError(`TinyGo executable import ${specifier} escapes its graph root`);
|
|
65
|
+
}
|
|
66
|
+
segments.pop();
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!/^[A-Za-z0-9._-]+$/u.test(segment)) {
|
|
70
|
+
throw configurationError(`TinyGo executable import ${specifier} is unsafe`);
|
|
71
|
+
}
|
|
72
|
+
segments.push(segment);
|
|
73
|
+
}
|
|
74
|
+
return segments.join('/');
|
|
75
|
+
}
|
|
76
|
+
export function snapshotTinyGoExecutableGraphProfile(value) {
|
|
77
|
+
const profile = requireRecord(value, 'TinyGo executable graph profile');
|
|
78
|
+
requireExactKeys(profile, ['schemaVersion', 'format', 'entryPath', 'fingerprint', 'modules'], 'TinyGo executable graph profile');
|
|
79
|
+
if (profile.schemaVersion !== 1 || profile.format !== TINYGO_EXECUTABLE_GRAPH_FORMAT) {
|
|
80
|
+
throw configurationError('TinyGo executable graph profile has an unsupported format');
|
|
81
|
+
}
|
|
82
|
+
const entryPath = requireSafePath(profile.entryPath, 'TinyGo executable graph entry path');
|
|
83
|
+
if (typeof profile.fingerprint !== 'string' || !SHA256_PATTERN.test(profile.fingerprint)) {
|
|
84
|
+
throw configurationError('TinyGo executable graph fingerprint must be a lowercase SHA-256');
|
|
85
|
+
}
|
|
86
|
+
const sourceModules = requireRecord(profile.modules, 'TinyGo executable graph modules');
|
|
87
|
+
const modulePaths = Object.keys(sourceModules).sort(compareCodeUnits);
|
|
88
|
+
if (modulePaths.length === 0 || modulePaths.length > MAX_MODULES) {
|
|
89
|
+
throw configurationError(`TinyGo executable graph must contain 1 through ${MAX_MODULES} modules`);
|
|
90
|
+
}
|
|
91
|
+
let importCount = 0;
|
|
92
|
+
const modules = {};
|
|
93
|
+
for (const rawPath of modulePaths) {
|
|
94
|
+
const modulePath = requireSafePath(rawPath, 'TinyGo executable module path');
|
|
95
|
+
const sourceModule = requireRecord(sourceModules[rawPath], `TinyGo executable module ${modulePath}`);
|
|
96
|
+
requireExactKeys(sourceModule, ['bytes', 'sha256', 'imports'], `TinyGo executable module ${modulePath}`);
|
|
97
|
+
if (!Number.isSafeInteger(sourceModule.bytes) || Number(sourceModule.bytes) <= 0) {
|
|
98
|
+
throw configurationError(`TinyGo executable module ${modulePath} has an invalid size`);
|
|
99
|
+
}
|
|
100
|
+
if (typeof sourceModule.sha256 !== 'string' || !SHA256_PATTERN.test(sourceModule.sha256)) {
|
|
101
|
+
throw configurationError(`TinyGo executable module ${modulePath} has an invalid SHA-256`);
|
|
102
|
+
}
|
|
103
|
+
if (!Array.isArray(sourceModule.imports)) {
|
|
104
|
+
throw configurationError(`TinyGo executable module ${modulePath} imports must be an array`);
|
|
105
|
+
}
|
|
106
|
+
const specifiers = new Set();
|
|
107
|
+
const imports = sourceModule.imports.map((rawImport, index) => {
|
|
108
|
+
const graphImport = requireRecord(rawImport, `TinyGo executable module ${modulePath} import ${index}`);
|
|
109
|
+
requireExactKeys(graphImport, ['specifier', 'target', 'kind'], `TinyGo executable module ${modulePath} import ${index}`);
|
|
110
|
+
const specifier = graphImport.specifier;
|
|
111
|
+
const target = requireSafePath(graphImport.target, `TinyGo executable module ${modulePath} import target`);
|
|
112
|
+
if (typeof specifier !== 'string' || specifiers.has(specifier)) {
|
|
113
|
+
throw configurationError(`TinyGo executable module ${modulePath} has an invalid or duplicate import specifier`);
|
|
114
|
+
}
|
|
115
|
+
specifiers.add(specifier);
|
|
116
|
+
if (!['static', 'dynamic', 'worker'].includes(String(graphImport.kind))) {
|
|
117
|
+
throw configurationError(`TinyGo executable module ${modulePath} import ${specifier} has an invalid kind`);
|
|
118
|
+
}
|
|
119
|
+
if (resolveImportTarget(modulePath, specifier) !== target) {
|
|
120
|
+
throw configurationError(`TinyGo executable module ${modulePath} import ${specifier} does not resolve to ${target}`);
|
|
121
|
+
}
|
|
122
|
+
importCount += 1;
|
|
123
|
+
if (importCount > MAX_IMPORTS) {
|
|
124
|
+
throw configurationError(`TinyGo executable graph exceeds ${MAX_IMPORTS} imports`);
|
|
125
|
+
}
|
|
126
|
+
return Object.freeze({
|
|
127
|
+
specifier,
|
|
128
|
+
target,
|
|
129
|
+
kind: graphImport.kind
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
modules[modulePath] = Object.freeze({
|
|
133
|
+
bytes: Number(sourceModule.bytes),
|
|
134
|
+
sha256: sourceModule.sha256,
|
|
135
|
+
imports: Object.freeze(imports)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (!Object.prototype.hasOwnProperty.call(modules, entryPath)) {
|
|
139
|
+
throw configurationError('TinyGo executable graph entry module is missing');
|
|
140
|
+
}
|
|
141
|
+
for (const [modulePath, module] of Object.entries(modules)) {
|
|
142
|
+
for (const graphImport of module.imports) {
|
|
143
|
+
if (!Object.prototype.hasOwnProperty.call(modules, graphImport.target)) {
|
|
144
|
+
throw configurationError(`TinyGo executable module ${modulePath} imports undeclared ${graphImport.target}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const visiting = new Set();
|
|
149
|
+
const visited = new Set();
|
|
150
|
+
const visit = (modulePath) => {
|
|
151
|
+
if (visiting.has(modulePath)) {
|
|
152
|
+
throw configurationError(`TinyGo executable graph contains a cycle at ${modulePath}`);
|
|
153
|
+
}
|
|
154
|
+
if (visited.has(modulePath))
|
|
155
|
+
return;
|
|
156
|
+
visiting.add(modulePath);
|
|
157
|
+
for (const graphImport of modules[modulePath].imports)
|
|
158
|
+
visit(graphImport.target);
|
|
159
|
+
visiting.delete(modulePath);
|
|
160
|
+
visited.add(modulePath);
|
|
161
|
+
};
|
|
162
|
+
visit(entryPath);
|
|
163
|
+
if (visited.size !== modulePaths.length) {
|
|
164
|
+
throw configurationError('TinyGo executable graph contains unreachable modules');
|
|
165
|
+
}
|
|
166
|
+
return Object.freeze({
|
|
167
|
+
schemaVersion: 1,
|
|
168
|
+
format: TINYGO_EXECUTABLE_GRAPH_FORMAT,
|
|
169
|
+
entryPath,
|
|
170
|
+
fingerprint: profile.fingerprint,
|
|
171
|
+
modules: Object.freeze(modules)
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
export function canonicalTinyGoExecutableGraphProfile(profile) {
|
|
175
|
+
let canonical = TINYGO_EXECUTABLE_GRAPH_FINGERPRINT_DOMAIN;
|
|
176
|
+
canonical += `schema\0${profile.format}\0${profile.schemaVersion}\n`;
|
|
177
|
+
canonical += `entry\0${profile.entryPath}\n`;
|
|
178
|
+
const paths = Object.keys(profile.modules).sort(compareCodeUnits);
|
|
179
|
+
for (const modulePath of paths) {
|
|
180
|
+
const module = profile.modules[modulePath];
|
|
181
|
+
canonical += `module\0${modulePath}\0${module.bytes}\0${module.sha256}\n`;
|
|
182
|
+
}
|
|
183
|
+
const edges = paths.flatMap((modulePath) => profile.modules[modulePath].imports.map((graphImport) => ({
|
|
184
|
+
importer: modulePath,
|
|
185
|
+
...graphImport
|
|
186
|
+
})));
|
|
187
|
+
edges.sort((left, right) => {
|
|
188
|
+
for (const field of ['importer', 'kind', 'specifier', 'target']) {
|
|
189
|
+
const compared = compareCodeUnits(left[field], right[field]);
|
|
190
|
+
if (compared !== 0)
|
|
191
|
+
return compared;
|
|
192
|
+
}
|
|
193
|
+
return 0;
|
|
194
|
+
});
|
|
195
|
+
for (const edge of edges) {
|
|
196
|
+
canonical += `edge\0${edge.importer}\0${edge.kind}\0${edge.specifier}\0${edge.target}\n`;
|
|
197
|
+
}
|
|
198
|
+
return encoder.encode(canonical);
|
|
199
|
+
}
|
|
200
|
+
async function sha256Hex(bytes, signal) {
|
|
201
|
+
if (!globalThis.crypto?.subtle) {
|
|
202
|
+
throw configurationError('TinyGo executable graph verification requires Web Crypto');
|
|
203
|
+
}
|
|
204
|
+
const digestInput = Uint8Array.from(bytes).buffer;
|
|
205
|
+
const pending = globalThis.crypto.subtle.digest('SHA-256', digestInput);
|
|
206
|
+
const digest = signal
|
|
207
|
+
? await new Promise((resolve, reject) => {
|
|
208
|
+
let settled = false;
|
|
209
|
+
const abort = () => {
|
|
210
|
+
if (settled)
|
|
211
|
+
return;
|
|
212
|
+
settled = true;
|
|
213
|
+
signal.removeEventListener('abort', abort);
|
|
214
|
+
reject(signal.reason ?? new Error('TinyGo executable graph verification aborted'));
|
|
215
|
+
};
|
|
216
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
217
|
+
pending.then((value) => {
|
|
218
|
+
if (settled)
|
|
219
|
+
return;
|
|
220
|
+
settled = true;
|
|
221
|
+
signal.removeEventListener('abort', abort);
|
|
222
|
+
resolve(value);
|
|
223
|
+
}, (error) => {
|
|
224
|
+
if (settled)
|
|
225
|
+
return;
|
|
226
|
+
settled = true;
|
|
227
|
+
signal.removeEventListener('abort', abort);
|
|
228
|
+
reject(error);
|
|
229
|
+
});
|
|
230
|
+
if (signal.aborted)
|
|
231
|
+
abort();
|
|
232
|
+
})
|
|
233
|
+
: await pending;
|
|
234
|
+
return Array.from(new Uint8Array(digest), (value) => value.toString(16).padStart(2, '0')).join('');
|
|
235
|
+
}
|
|
236
|
+
function resolvePinnedGraphUrls(moduleUrl, currentUrl, profile) {
|
|
237
|
+
let entryUrl;
|
|
238
|
+
try {
|
|
239
|
+
entryUrl = new URL(moduleUrl, currentUrl);
|
|
240
|
+
}
|
|
241
|
+
catch (cause) {
|
|
242
|
+
throw configurationError('TinyGo executable entry URL is invalid', cause);
|
|
243
|
+
}
|
|
244
|
+
if ((entryUrl.protocol !== 'http:' && entryUrl.protocol !== 'https:') ||
|
|
245
|
+
entryUrl.username ||
|
|
246
|
+
entryUrl.password ||
|
|
247
|
+
entryUrl.hash ||
|
|
248
|
+
/%(?:2e|2f|5c)/iu.test(entryUrl.pathname) ||
|
|
249
|
+
!entryUrl.pathname.endsWith(`/${profile.entryPath}`)) {
|
|
250
|
+
throw configurationError('TinyGo executable entry URL is unsafe or has the wrong path');
|
|
251
|
+
}
|
|
252
|
+
const entryReceipt = profile.modules[profile.entryPath];
|
|
253
|
+
if (entryUrl.search && entryUrl.search !== `?v=${entryReceipt.sha256}`) {
|
|
254
|
+
throw configurationError('TinyGo executable entry URL must use its exact receipt query pin');
|
|
255
|
+
}
|
|
256
|
+
entryUrl.search = `?v=${entryReceipt.sha256}`;
|
|
257
|
+
const baseUrl = new URL('./', entryUrl);
|
|
258
|
+
const assetUrls = {};
|
|
259
|
+
const keysByPath = {};
|
|
260
|
+
for (const [index, modulePath] of Object.keys(profile.modules)
|
|
261
|
+
.sort(compareCodeUnits)
|
|
262
|
+
.entries()) {
|
|
263
|
+
const key = `module-${index}`;
|
|
264
|
+
const url = new URL(modulePath, baseUrl);
|
|
265
|
+
url.search = `?v=${profile.modules[modulePath].sha256}`;
|
|
266
|
+
assetUrls[key] = url.href;
|
|
267
|
+
keysByPath[modulePath] = key;
|
|
268
|
+
}
|
|
269
|
+
return Object.freeze({
|
|
270
|
+
entryUrl: entryUrl.href,
|
|
271
|
+
baseUrl: baseUrl.href,
|
|
272
|
+
assetUrls: Object.freeze(assetUrls),
|
|
273
|
+
keysByPath: Object.freeze(keysByPath)
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function createPreflightManifest(profile, keysByPath) {
|
|
277
|
+
return {
|
|
278
|
+
schemaVersion: RUNTIME_REGISTRY_MANIFEST_SCHEMA_VERSION,
|
|
279
|
+
manifestId: 'wasm-idle/tinygo-executable-graph',
|
|
280
|
+
revision: profile.fingerprint,
|
|
281
|
+
runtimes: [
|
|
282
|
+
{
|
|
283
|
+
runtimeId: 'tinygo/executable-graph',
|
|
284
|
+
identity: {
|
|
285
|
+
languageId: 'TINYGO',
|
|
286
|
+
implementationId: 'tinygo-upstream-browser',
|
|
287
|
+
implementationVersion: '0.40.1',
|
|
288
|
+
profile: {
|
|
289
|
+
profileId: 'tinygo-executable-graph-v1',
|
|
290
|
+
manifestSchemaVersion: 1,
|
|
291
|
+
manifestSha256: profile.fingerprint,
|
|
292
|
+
protocolVersion: 1,
|
|
293
|
+
trustProfileId: 'receipt-verified-module-graph-v1',
|
|
294
|
+
trustProfileSchemaVersion: 1
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
capabilities: {
|
|
298
|
+
stdin: 'prebuffered',
|
|
299
|
+
workspace: true,
|
|
300
|
+
abort: true,
|
|
301
|
+
artifacts: true,
|
|
302
|
+
streamingOutput: true
|
|
303
|
+
},
|
|
304
|
+
workerLifetime: { mode: 'per-run' },
|
|
305
|
+
requiredBrowserFeatures: ['blob', 'crypto.subtle', 'module-worker'],
|
|
306
|
+
assetRoot: '.',
|
|
307
|
+
assets: Object.keys(profile.modules)
|
|
308
|
+
.sort(compareCodeUnits)
|
|
309
|
+
.map((modulePath) => {
|
|
310
|
+
const receipt = profile.modules[modulePath];
|
|
311
|
+
return {
|
|
312
|
+
key: keysByPath[modulePath],
|
|
313
|
+
path: modulePath,
|
|
314
|
+
compressedSha256: receipt.sha256,
|
|
315
|
+
uncompressedSha256: receipt.sha256,
|
|
316
|
+
compressedBytes: receipt.bytes,
|
|
317
|
+
uncompressedBytes: receipt.bytes,
|
|
318
|
+
mediaType: 'text/javascript',
|
|
319
|
+
encoding: 'identity'
|
|
320
|
+
};
|
|
321
|
+
}),
|
|
322
|
+
contracts: {
|
|
323
|
+
routeId: 'tinygo',
|
|
324
|
+
runtimeAssetKey: 'tinygo-executable-graph',
|
|
325
|
+
documentationId: 'TINYGO',
|
|
326
|
+
syncTarget: 'wasm-tinygo',
|
|
327
|
+
browserTestId: 'tinygo-executable-graph'
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function replaceUniqueSpecifier(source, specifier, replacement, modulePath) {
|
|
334
|
+
const first = source.indexOf(specifier);
|
|
335
|
+
if (first < 0 || source.indexOf(specifier, first + specifier.length) >= 0) {
|
|
336
|
+
throw configurationError(`TinyGo executable module ${modulePath} must contain import ${specifier} exactly once`);
|
|
337
|
+
}
|
|
338
|
+
if (!SAFE_BLOB_URL_PATTERN.test(replacement)) {
|
|
339
|
+
throw configurationError('TinyGo executable Blob URL is unsafe for source rewriting');
|
|
340
|
+
}
|
|
341
|
+
return `${source.slice(0, first)}${replacement}${source.slice(first + specifier.length)}`;
|
|
342
|
+
}
|
|
343
|
+
export async function loadVerifiedTinyGoExecutableGraph(options) {
|
|
344
|
+
const profile = snapshotTinyGoExecutableGraphProfile(options.profile);
|
|
345
|
+
const urls = resolvePinnedGraphUrls(options.moduleUrl, options.currentUrl, profile);
|
|
346
|
+
const actualFingerprint = await sha256Hex(canonicalTinyGoExecutableGraphProfile(profile), options.signal);
|
|
347
|
+
if (actualFingerprint !== profile.fingerprint) {
|
|
348
|
+
throw configurationError('TinyGo executable graph fingerprint does not match its receipts');
|
|
349
|
+
}
|
|
350
|
+
const totalBytes = Object.values(profile.modules).reduce((total, module) => total + module.bytes, 0);
|
|
351
|
+
if (!Number.isSafeInteger(totalBytes)) {
|
|
352
|
+
throw configurationError('TinyGo executable graph aggregate size is unsafe');
|
|
353
|
+
}
|
|
354
|
+
const limits = {};
|
|
355
|
+
if (options.maxAssetBytes !== undefined)
|
|
356
|
+
limits.maxAssetBytes = options.maxAssetBytes;
|
|
357
|
+
if (options.assetTimeoutMs !== undefined)
|
|
358
|
+
limits.assetTimeoutMs = options.assetTimeoutMs;
|
|
359
|
+
const preflight = await preflightRuntimeAssets({
|
|
360
|
+
manifest: createPreflightManifest(profile, urls.keysByPath),
|
|
361
|
+
runtimeId: 'tinygo/executable-graph',
|
|
362
|
+
rootUrl: urls.baseUrl,
|
|
363
|
+
assetUrls: urls.assetUrls,
|
|
364
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
365
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
366
|
+
limits,
|
|
367
|
+
cache: 'no-store',
|
|
368
|
+
redirect: 'error',
|
|
369
|
+
requireExactResponseUrl: true,
|
|
370
|
+
maxConcurrentDownloads: Math.min(5, Object.keys(profile.modules).length),
|
|
371
|
+
maxTotalDeliveryBytes: totalBytes,
|
|
372
|
+
reportProgress: options.reportProgress
|
|
373
|
+
? ({ assetKey, loadedBytes, totalBytes }) => {
|
|
374
|
+
const path = Object.keys(urls.keysByPath).find((candidate) => urls.keysByPath[candidate] === assetKey);
|
|
375
|
+
if (path)
|
|
376
|
+
options.reportProgress?.({ path, loadedBytes, totalBytes });
|
|
377
|
+
}
|
|
378
|
+
: undefined
|
|
379
|
+
});
|
|
380
|
+
const sources = {};
|
|
381
|
+
for (const modulePath of Object.keys(profile.modules)) {
|
|
382
|
+
try {
|
|
383
|
+
sources[modulePath] = fatalDecoder.decode(preflight.assets[urls.keysByPath[modulePath]].bytes);
|
|
384
|
+
}
|
|
385
|
+
catch (cause) {
|
|
386
|
+
throw configurationError(`TinyGo executable module ${modulePath} is not valid UTF-8`, cause);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (typeof Blob !== 'function' ||
|
|
390
|
+
typeof URL?.createObjectURL !== 'function' ||
|
|
391
|
+
typeof URL?.revokeObjectURL !== 'function') {
|
|
392
|
+
throw configurationError('TinyGo executable graph requires Blob module URLs');
|
|
393
|
+
}
|
|
394
|
+
const order = [];
|
|
395
|
+
const visited = new Set();
|
|
396
|
+
const visit = (modulePath) => {
|
|
397
|
+
if (visited.has(modulePath))
|
|
398
|
+
return;
|
|
399
|
+
visited.add(modulePath);
|
|
400
|
+
for (const graphImport of profile.modules[modulePath].imports)
|
|
401
|
+
visit(graphImport.target);
|
|
402
|
+
order.push(modulePath);
|
|
403
|
+
};
|
|
404
|
+
visit(profile.entryPath);
|
|
405
|
+
const moduleUrls = {};
|
|
406
|
+
const ownedUrls = [];
|
|
407
|
+
let disposed = false;
|
|
408
|
+
const dispose = () => {
|
|
409
|
+
if (disposed)
|
|
410
|
+
return;
|
|
411
|
+
disposed = true;
|
|
412
|
+
for (const url of ownedUrls.reverse()) {
|
|
413
|
+
try {
|
|
414
|
+
URL.revokeObjectURL(url);
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
// Blob cleanup must not replace the graph result.
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
try {
|
|
422
|
+
for (const modulePath of order) {
|
|
423
|
+
let source = sources[modulePath];
|
|
424
|
+
for (const graphImport of profile.modules[modulePath].imports) {
|
|
425
|
+
source = replaceUniqueSpecifier(source, graphImport.specifier, moduleUrls[graphImport.target], modulePath);
|
|
426
|
+
}
|
|
427
|
+
const blobUrl = URL.createObjectURL(new Blob([source], { type: 'text/javascript;charset=utf-8' }));
|
|
428
|
+
if (!SAFE_BLOB_URL_PATTERN.test(blobUrl)) {
|
|
429
|
+
try {
|
|
430
|
+
URL.revokeObjectURL(blobUrl);
|
|
431
|
+
}
|
|
432
|
+
catch { }
|
|
433
|
+
throw configurationError('TinyGo executable graph received an unsafe Blob URL');
|
|
434
|
+
}
|
|
435
|
+
moduleUrls[modulePath] = blobUrl;
|
|
436
|
+
ownedUrls.push(blobUrl);
|
|
437
|
+
}
|
|
438
|
+
return Object.freeze({
|
|
439
|
+
entryUrl: moduleUrls[profile.entryPath],
|
|
440
|
+
assetBaseUrl: urls.baseUrl,
|
|
441
|
+
moduleUrls: Object.freeze({ ...moduleUrls }),
|
|
442
|
+
dispose
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
dispose();
|
|
447
|
+
throw error;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type PlaygroundRuntimeAssets } from './assets';
|
|
2
|
+
import { type CompilerDiagnostic, type SandboxExecutionOptions } from './options';
|
|
3
|
+
import type { Sandbox, SandboxProgress } from './sandbox';
|
|
4
|
+
import { type WasmIdleSharedBuffer } from './sharedBuffer';
|
|
5
|
+
type TypeScriptSandboxLanguage = 'JAVASCRIPT' | 'TYPESCRIPT';
|
|
6
|
+
declare class TypeScriptSandbox implements Sandbox {
|
|
7
|
+
private readonly language;
|
|
8
|
+
output: any;
|
|
9
|
+
worker?: Worker;
|
|
10
|
+
buffer: WasmIdleSharedBuffer;
|
|
11
|
+
pendingInput: string[];
|
|
12
|
+
begin: number;
|
|
13
|
+
elapse: number;
|
|
14
|
+
uid: number;
|
|
15
|
+
exit: boolean;
|
|
16
|
+
moduleUrl: string;
|
|
17
|
+
oncompilerdiagnostic?: (diagnostic: CompilerDiagnostic) => void;
|
|
18
|
+
waitingForInput: boolean;
|
|
19
|
+
pendingEof: boolean;
|
|
20
|
+
private activeOperation;
|
|
21
|
+
private disposed;
|
|
22
|
+
private disposePromise;
|
|
23
|
+
private readonly disposeCancellation;
|
|
24
|
+
private readonly workerSession;
|
|
25
|
+
constructor(language?: TypeScriptSandboxLanguage);
|
|
26
|
+
private get compileLanguage();
|
|
27
|
+
private get languageLabel();
|
|
28
|
+
private disposedConfigurationError;
|
|
29
|
+
private requireOperationIdle;
|
|
30
|
+
private beginOperation;
|
|
31
|
+
private isOperationActive;
|
|
32
|
+
private releaseOperation;
|
|
33
|
+
private cleanupOperation;
|
|
34
|
+
private releaseBeforeSession;
|
|
35
|
+
private requireOperationActive;
|
|
36
|
+
private resolveOperationLimits;
|
|
37
|
+
private abortReason;
|
|
38
|
+
private bindPreSessionAbort;
|
|
39
|
+
private bindAbortSignal;
|
|
40
|
+
private bindOperationTimeout;
|
|
41
|
+
private resetExplicitStdinState;
|
|
42
|
+
private resetOwnedBuffers;
|
|
43
|
+
private finishExplicitStdin;
|
|
44
|
+
load(runtimeAssets?: string | PlaygroundRuntimeAssets, _code?: string, _log?: boolean, _args?: string[], options?: SandboxExecutionOptions, progress?: SandboxProgress): Promise<void>;
|
|
45
|
+
write(input: string): void;
|
|
46
|
+
eof(): void;
|
|
47
|
+
private flushPendingInput;
|
|
48
|
+
run(code: string, prepare: boolean, _log?: boolean, _prog?: SandboxProgress, args?: string[], options?: SandboxExecutionOptions): Promise<boolean | string>;
|
|
49
|
+
private cancelOperation;
|
|
50
|
+
kill(): void;
|
|
51
|
+
terminate(reason?: unknown): void;
|
|
52
|
+
clear(): Promise<void>;
|
|
53
|
+
dispose(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export default TypeScriptSandbox;
|