@plurnk/plurnk-execs-wasm 0.1.0 → 0.1.1
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 +14 -7
- package/dist/Wasm.d.ts +2 -2
- package/dist/Wasm.d.ts.map +1 -1
- package/dist/Wasm.js +35 -6
- package/dist/Wasm.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,12 +6,19 @@ A `@plurnk/plurnk-execs-*` sibling built on the [plurnk-execs](https://github.co
|
|
|
6
6
|
|
|
7
7
|
## Runtime tags
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|---|---|---|
|
|
11
|
-
| `wat` | 🧩 | WebAssembly **Text** (S-expression module) — the model-facing form |
|
|
12
|
-
| `wasm` | 🧩 | base64-encoded **binary** module (pre-compiled) |
|
|
9
|
+
The module comes from the **EXEC body** (inline) or, when a `(target)` path is given, from a **file** — mirroring `sqlite`'s target-as-path:
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
| Tag | Glyph | `(target)` = file path | no target (body) |
|
|
12
|
+
|---|---|---|---|
|
|
13
|
+
| `wat` | 🧩 | read `.wat` file → compile | WebAssembly **Text** → compile |
|
|
14
|
+
| `wasm` | 🧩 | read `.wasm` file → bytes | base64-encoded **binary** |
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
<<EXEC[wat]:(module (func (export "main") (result i32) (i32.const 42))):EXEC # inline text
|
|
18
|
+
<<EXEC[wasm](./build/mod.wasm)::EXEC # built module from disk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`wat` is assembled to wasm via [wabt](https://github.com/AssemblyScript/wabt.js); `wasm` is the raw binary. (`.wast` — the spec test-suite superset with `assert_*` commands — is deliberately *not* supported; this executes a module, not a test script.)
|
|
15
22
|
|
|
16
23
|
## Execution model
|
|
17
24
|
|
|
@@ -23,9 +30,9 @@ Both forms instantiate in a sandbox whose only import is `env.log` (capture). Th
|
|
|
23
30
|
|
|
24
31
|
to the `results` channel (`application/json`). A module that imports `(import "env" "log" (func $log (param i32)))` can emit intermediate values.
|
|
25
32
|
|
|
26
|
-
- **`effect
|
|
33
|
+
- **`effect`** — inline body → `pure` (sandboxed; **auto-runs inline**, never proposal-gated). File-path target → `read` (it touches the filesystem, even though execution stays sandboxed). Target-classified, never command-inspected.
|
|
27
34
|
- **`probe`** — always available (`WebAssembly` builtin + bundled `wabt`).
|
|
28
|
-
- **Errors** emit a `TelemetryEvent` (`source: "exec:wat"`/`"exec:wasm"`): `wat_parse_error`, `wasm_invalid`, `wasm_trap`, `wabt_init_failed`.
|
|
35
|
+
- **Errors** emit a `TelemetryEvent` (`source: "exec:wat"`/`"exec:wasm"`): `wat_parse_error`, `wasm_invalid`, `wasm_trap`, `wasm_read_failed`, `wabt_init_failed`.
|
|
29
36
|
|
|
30
37
|
## Tests
|
|
31
38
|
|
package/dist/Wasm.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { BaseExecutor } from "@plurnk/plurnk-execs";
|
|
|
2
2
|
import type { ChannelDecl, Effect, ExecArgs, ExecResult, RuntimeAvailability } from "@plurnk/plurnk-execs";
|
|
3
3
|
export default class Wasm extends BaseExecutor {
|
|
4
4
|
get channels(): Readonly<Record<string, ChannelDecl>>;
|
|
5
|
-
effect(
|
|
5
|
+
effect(target: string | null): Effect;
|
|
6
6
|
probe(): Promise<RuntimeAvailability>;
|
|
7
|
-
run({ runtime, command, write, setState, emit }: ExecArgs): Promise<ExecResult>;
|
|
7
|
+
run({ runtime, command, cwd, write, setState, emit }: ExecArgs): Promise<ExecResult>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=Wasm.d.ts.map
|
package/dist/Wasm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wasm.d.ts","sourceRoot":"","sources":["../src/Wasm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Wasm.d.ts","sourceRoot":"","sources":["../src/Wasm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AA+B3G,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC1C,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAEpD;IAKQ,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM;IAI/B,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAI9C,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAkE7F"}
|
package/dist/Wasm.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
1
2
|
import wabtInit from "wabt";
|
|
2
3
|
import { BaseExecutor } from "@plurnk/plurnk-execs";
|
|
3
4
|
let wabtPromise;
|
|
@@ -18,21 +19,39 @@ export default class Wasm extends BaseExecutor {
|
|
|
18
19
|
get channels() {
|
|
19
20
|
return { results: { mimetype: "application/json" } };
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// Inline body is sandboxed → `pure` (auto-run). A file-path target reads the
|
|
23
|
+
// host filesystem → `read` (execution stays sandboxed; the FS read is the
|
|
24
|
+
// only host interaction). Target-classified, never command-inspected.
|
|
25
|
+
effect(target) {
|
|
26
|
+
return target ? "read" : "pure";
|
|
23
27
|
}
|
|
24
28
|
async probe() {
|
|
25
29
|
return { available: true, detail: "WebAssembly + wabt" };
|
|
26
30
|
}
|
|
27
|
-
async run({ runtime, command, write, setState, emit }) {
|
|
31
|
+
async run({ runtime, command, cwd, write, setState, emit }) {
|
|
28
32
|
const fail = (kind, message) => {
|
|
29
33
|
emit({ source: `exec:${runtime}`, kind, message });
|
|
30
34
|
setState("results", "errored");
|
|
31
35
|
return { status: 500 };
|
|
32
36
|
};
|
|
33
|
-
//
|
|
37
|
+
// The EXEC target slot, when set, is a module file path; otherwise the
|
|
38
|
+
// module rides the body (WAT text / base64). Mirrors sqlite's target.
|
|
39
|
+
const path = cwd && cwd.length > 0 ? cwd : null;
|
|
40
|
+
// 1. Obtain the module bytes — from the file-path target, else the body.
|
|
34
41
|
let bytes;
|
|
35
42
|
if (runtime === "wat") {
|
|
43
|
+
let watText;
|
|
44
|
+
if (path !== null) {
|
|
45
|
+
try {
|
|
46
|
+
watText = await readFile(path, "utf8");
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
return fail("wasm_read_failed", `cannot read '${path}': ${err.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
watText = command;
|
|
54
|
+
}
|
|
36
55
|
let wabt;
|
|
37
56
|
try {
|
|
38
57
|
wabt = await getWabt();
|
|
@@ -42,7 +61,7 @@ export default class Wasm extends BaseExecutor {
|
|
|
42
61
|
}
|
|
43
62
|
let mod;
|
|
44
63
|
try {
|
|
45
|
-
mod = wabt.parseWat("module.wat",
|
|
64
|
+
mod = wabt.parseWat(path ?? "module.wat", watText);
|
|
46
65
|
bytes = mod.toBinary({}).buffer;
|
|
47
66
|
}
|
|
48
67
|
catch (err) {
|
|
@@ -53,7 +72,17 @@ export default class Wasm extends BaseExecutor {
|
|
|
53
72
|
}
|
|
54
73
|
}
|
|
55
74
|
else if (runtime === "wasm") {
|
|
56
|
-
|
|
75
|
+
if (path !== null) {
|
|
76
|
+
try {
|
|
77
|
+
bytes = await readFile(path);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
return fail("wasm_read_failed", `cannot read '${path}': ${err.message}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
bytes = Uint8Array.from(Buffer.from(command.trim(), "base64"));
|
|
85
|
+
}
|
|
57
86
|
}
|
|
58
87
|
else {
|
|
59
88
|
throw new Error(`plurnk-execs-wasm received unclaimed runtime tag '${runtime}'`);
|
package/dist/Wasm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wasm.js","sourceRoot":"","sources":["../src/Wasm.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAcpD,IAAI,WAAsC,CAAC;AAC3C,MAAM,OAAO,GAAG,GAAkB,EAAE,CAAC,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC,CAAC;AAElE,0EAA0E;AAC1E,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAC3D,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAE3D,2EAA2E;AAC3E,4CAA4C;AAC5C,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAExC,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,2BAA2B;AAC3B,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC1C,IAAI,QAAQ;QACR,OAAO,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,EAAE,CAAC;IACzD,CAAC;
|
|
1
|
+
{"version":3,"file":"Wasm.js","sourceRoot":"","sources":["../src/Wasm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,QAAQ,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,YAAY,E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AAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC;QACnF,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACzG,IAAI,QAAQ,GAAY,IAAI,CAAC;QAC7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC;gBAAC,QAAQ,GAAI,OAAO,CAAC,KAAK,CAAmB,EAAE,CAAC;YAAC,CAAC;YACvD,OAAO,GAAG,EAAE,CAAC;gBAAC,OAAO,IAAI,CAAC,WAAW,EAAE,GAAG,KAAK,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;YAAC,CAAC;QACpF,CAAC;QAED,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;QAClF,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC9B,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC3B,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plurnk/plurnk-execs-wasm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "WebAssembly runtime executor for plurnk-service's exec scheme — in-process sandboxed execution of WAT (text) and wasm (binary) modules.",
|
|
5
5
|
"keywords": ["plurnk", "exec", "runtime", "executor", "webassembly", "wasm", "wat", "sandbox"],
|
|
6
6
|
"homepage": "https://github.com/plurnk/plurnk-execs-wasm#readme",
|