An adapter component wraps or composes with a WebAssembly module to translate imported interfaces into component-model interfaces. It can satisfy the module’s WASI imports internally and expose only the host capabilities that remain necessary. section 4.3 section 4.4
Use an adapter component when:
- Migrating legacy or third-party modules without source access. section 4.3
- Adapting a module whose language does not directly support the targeted component-model APIs. section 4.3
- Gradually migrating a large codebase while translating Preview 1 WASI imports into Preview 2 component imports. section 4.3
- Restricting capabilities by allowing selected interfaces, denying others, or virtualizing resources such as read-only filesystems. section 4.4
Adapting a Preview 1 module
Compile the module for wasm32-wasip1, obtain the wasi_snapshot_preview1 reactor adapter, and run wasm-tools component new with --adapt. The resulting component exposes Preview 2 imports such as wasi:cli/environment and wasi:filesystem/types. Inspect the result with wasm-tools component wit. section 4.3
Figure 4.8 Utilizing WASI-Virt to restrict capabilities of a Wasm component
Shows how WASI-Virt uses an adapter component to restrict or virtualize a component’s capabilities. section 4.4
