# alternera_plugin_wasm_framework v0.9.1 - API Reference

## Modules

- [Alternera.PluginWasmFramework.Application](Alternera.PluginWasmFramework.Application.md): Starts `Slots`, the node's limit on guests running at once,
`UploadedModules`, the node's cache of uploaded modules, and
`Runtime.Port.Pool`, the processes of the port runtime. The package is a
dependency of every language plugin, so all three are up before a
language step runs.
- [Alternera.PluginWasmFramework.Frame](Alternera.PluginWasmFramework.Frame.md): The frames of guest interface version 0 (`c_src/alternera_guest.h`), the
host's side. A field is a 32-bit little-endian length and that many
bytes.
- [Alternera.PluginWasmFramework.HostCalls](Alternera.PluginWasmFramework.HostCalls.md): The host functions a language step's guest calls through
`alternera.host_call`, served in the process that runs the step
(`Runtime.call/5`), each through the plugin SDK only:
`Plugin.Provisional.Store`, `Plugin.Provisional.Reads` (over
`Plugin.Host`) and `Plugin.Provisional.Calls`.
- [Alternera.PluginWasmFramework.Language](Alternera.PluginWasmFramework.Language.md): What every language step shares, the way `PluginHosts.Step` is shared by
the plugin hosts' steps: a language plugin holds a `%Language{}` naming
itself and its module, and delegates its callbacks here.
- [Alternera.PluginWasmFramework.MemoryLimit](Alternera.PluginWasmFramework.MemoryLimit.md): A language step's "Memory limit" setting: how much memory the script's
guest may use in one call. Guest memory is outside every BEAM limit, so
the step says it, where whoever edits the pipeline sees it, and it
travels with the step in exports and releases.
- [Alternera.PluginWasmFramework.ModuleFile](Alternera.PluginWasmFramework.ModuleFile.md): Reads the outline of a WebAssembly core module from its bytes, without
compiling it: its imports, exports, memories, whether it has a start
function, and its custom sections. The runtime binding does not expose
custom sections, and an uploaded module must be judged before anything
of it runs, so the walk is ours: the module header, then each section's
id and LEB128 length, reading only the sections it needs.
- [Alternera.PluginWasmFramework.Modules](Alternera.PluginWasmFramework.Modules.md): The node's compiled language modules, one per module digest (SHA-256 of
the `.wasm` bytes), kept in `:persistent_term`: compiling an interpreter
takes 150 to 500 ms, so it happens once per node, when the language
plugin's package starts (`load/2` from its application's `start/2`),
not on the first request. A call finds its module by digest
(`fetch/1`); a module not loaded yet is compiled then, once.
- [Alternera.PluginWasmFramework.Runtime](Alternera.PluginWasmFramework.Runtime.md): The WebAssembly runtime a language step runs its module on, as a
behaviour, so the binding underneath can be replaced without touching
anything above it. Nothing outside an implementation names the binding,
its engine, epochs or fuel: callers speak in `t:limits/0` and
`t:host/0`.
- [Alternera.PluginWasmFramework.Runtime.Port](Alternera.PluginWasmFramework.Runtime.Port.md): `PluginWasmFramework.Runtime` in OS processes: the package's own host
program, `alternera_wasm_host` (`native/alternera_wasm_host/`, Wasmtime
51.0.0, the version wasmex 0.18.1 carries), run as Erlang ports by
`Runtime.Port.Pool`. A fault, a hang or a compiler bug costs one OS
process, never the node.
- [Alternera.PluginWasmFramework.Runtime.Port.Binary](Alternera.PluginWasmFramework.Runtime.Port.Binary.md): The host program of `Runtime.Port`, `alternera_wasm_host`, built from
the package's `native/alternera_wasm_host/` crate: where it is, what
it is started with, and whether it can run here.
- [Alternera.PluginWasmFramework.Runtime.Port.Compiler](Alternera.PluginWasmFramework.Runtime.Port.Compiler.md): Compiles a module for `Runtime.Port` in a host process of its own
(`alternera_wasm_host compile IN OUT`), never in a serving one: a
compile then has a time limit (the process is killed past
`compile_timeout_ms/0`), a fault of the compiler on a hostile module
costs that process, and no serving process stalls behind a compile.
- [Alternera.PluginWasmFramework.Runtime.Port.Pool](Alternera.PluginWasmFramework.Runtime.Port.Pool.md): The node's `alternera_wasm_host serve` processes for `Runtime.Port`,
each an Erlang port running one call at a time.
- [Alternera.PluginWasmFramework.Runtime.Port.Protocol](Alternera.PluginWasmFramework.Runtime.Port.Protocol.md): The frames between the node and `alternera_wasm_host serve`, over the
port with `{:packet, 4}`. A frame is one tag byte and fixed
little-endian fields, then bytes to its end. The framework's own frames
(`PluginWasmFramework.Frame`) travel inside as bytes.
- [Alternera.PluginWasmFramework.Runtime.Wasmex](Alternera.PluginWasmFramework.Runtime.Wasmex.md): `PluginWasmFramework.Runtime` on wasmex 0.18.1, a precompiled NIF over
Wasmtime. Experimental: the binding is chosen for good at the gate after
the first language plugin, with numbers from the Observatory.
- [Alternera.PluginWasmFramework.Slots](Alternera.PluginWasmFramework.Slots.md): The node's limit on guests running at once, shared fairly between
tenants. How many may run is the configured runtime's
(`Runtime.max_running/0`): `Runtime.Wasmex` lets one fewer run than its
threads, so one always stays free for its epoch tick (a guest keeps its
thread until the tick, and the tick is a task on the same threads: on a
two-thread node two endless scripts at once stopped every language step);
`Runtime.Port` lets as many run as the node has processors, since each
guest is an OS process of its own with its ticker on its own thread.
- [Alternera.PluginWasmFramework.StepEditor](Alternera.PluginWasmFramework.StepEditor.md): The step editor every language step shares, laid out as Script's
editor is, so what a user knows of it carries over. A language plugin's
editor is a thin LiveComponent that hands its `%Language{}` and its
callbacks here, as Camel's hands its `%PluginHosts.StepEditor{}` to the
plugin hosts' editor
- [Alternera.PluginWasmFramework.Test](Alternera.PluginWasmFramework.Test.md): The contract a language plugin keeps, as ExUnit tests, the way the SDK's
`plugin_contract/2` checks a plugin. The plugin gives, in its own
language, the source for each named scenario; the kit runs each through
the step with the SDK's test host (`Plugin.Test`) and checks the result.
- [Alternera.PluginWasmFramework.Upload](Alternera.PluginWasmFramework.Upload.md): Takes a compiled module a user uploads into a step: checks it, compiles
it and stores it (`Plugin.Provisional.Files`), so a broken module is
refused in the editor, never on the first request.
- [Alternera.PluginWasmFramework.UploadedModules](Alternera.PluginWasmFramework.UploadedModules.md): The node's compiled uploaded modules: modules a user uploaded into a
step, as opposed to the shipped languages' (`Modules`, kept for good in
`:persistent_term`). Uploads come and go, so they live in an ETS table
bounded by the size of their files (`:uploaded_cache_bytes` in the
framework's application env, 256 MiB by default), the least recently
used going first when a new one does not fit. A module evicted is
compiled again from storage on its next use.
- [Alternera.PluginWasmFramework.Uses](Alternera.PluginWasmFramework.Uses.md): The named parameters an uploaded module declares, and how a step's
bindings turn them into the tenant's own stores, pipelines, variables
and secrets.

## Mix Tasks

- [mix alternera.wasm_host](Mix.Tasks.Alternera.WasmHost.md): Puts `alternera_wasm_host`, the host program of
`PluginWasmFramework.Runtime.Port`, at
`priv/native/<target>/alternera_wasm_host` in the framework package.

