An Extism host for MoonBit: a WASM engine layer, the Extism kernel and a plugin API
| Family | Policy choices | Default |
|---|---|---|
| config_get | Deny, Empty, Values(map) | Empty: handle 0 |
| var_get, var_set | Deny, Empty (get gives 0, set is denied), Session(limit) | Empty |
| log_*, get_log_level | Discard, Sink(level, sink) | Discard; the level is 2147483647 |
| http_request, http_status_code, http_headers | Deny, Handler(handler) | Deny |
///|
test "a manifest, a policy and a call" {
let policy = @extism.Policy::default().config(Values({ "mode": "strict" }))
let plugin = @extism.Plugin::load(
@extism.Manifest::new(@fixtures.plugin())
.policy(policy)
.register(
@extism.HostFunction::new(
@extism.Namespace::parse("extism:host/user"),
@extism.FunctionName::parse("lookup"),
@engine.Signature::new([I64], [I64]),
(context, args) => {
guard args is [I64(offset)] else {
raise @engine.HostError("bad arguments")
}
let input = context.read(@extism.Handle::parse(offset)) catch {
_ => raise @engine.HostError("no input")
}
let output = context.allocate(input) catch {
_ => raise @engine.HostError("no room")
}
[I64(output.offset())]
},
),
),
)
assert_eq(plugin.call(@extism.ExportName::parse("config"), b""), b"strict")
assert_eq(plugin.call(@extism.ExportName::parse("lookup"), b"same"), b"same")
}
///|
test "a plugin with the WASI sandbox" {
let printed = []
let sandbox = @wasi.Sandbox::new().stdout(bytes => {
printed.push(bytes.to_owned())
})
let plugin = @extism.Plugin::load(
@extism.Manifest::new(@fixtures.wasi_plugin()).wasi(sandbox),
)
assert_eq(plugin.call(@extism.ExportName::parse("print"), b""), b"")
assert_eq(printed, [b"hello"])
}pub(all) suberror CallError {
Plugin(Int, String)
Exit(Int)
Denied(DeniedCall)
HostFunction(String, String)
MemoryLimit(MemoryKind)
Limit(String)
Engine(CallError)
Initialization(CallError)
UnknownExport(String)
} derive(Debug)pub(all) suberror LoadError {
UnlinkedImport(String, String)
WrongSignature(String, String)
Engine(EngineError)
} derive(Debug)pub struct CallContext {
// private fields
}pub struct HostFunction {
// private fields
}fn HostFunction::new(namespace_ : Namespace, name : FunctionName, signature : Signature, function : (CallContext, Array[Value]) -> Array[Value] raise HostError) -> HostFunctionpub(all) struct HttpRequest {
method_ : String
url : String
headers : Map[String, String]
body : Bytes
}pub struct Limits {
// private fields
}pub struct Manifest {
// private fields
}pub struct Plugin {
// private fields
}pub struct Policy {
// private fields
}Install
Download zipAn Extism host for MoonBit: a WASM engine layer, the Extism kernel and a plugin API