liveBook · Manning

Adapter component

As explained in Server-Side WebAssembly

An adapter component is a WebAssembly component that supplies implementations for another component's imported interfaces and mediates their interaction with the host.

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
A screenshot of a cell phone

AI-generated content may be incorrect.

Shows how WASI-Virt uses an adapter component to restrict or virtualize a component’s capabilities. section 4.4

How Server-Side WebAssembly covers it

How deep it goes
Explains conversion commands, WIT inspection, import translation, and capability composition, but stops short of adapter internals.
Examples
Demonstrates Preview 1-to-Preview 2 adaptation and WASI-Virt configurations that fully restrict or allow stdout.
What it assumes
Assumes a compiled WebAssembly module and basic WASI targets, while introducing component conversion and interface adaptation.
What you can do after
Operate wasm-tools and WASI-Virt to adapt modules, inspect WIT, and configure component capabilities.
How it connects
Connects WebAssembly components with WASI, WIT, component composition, WASI-Virt, and host capabilities.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.