Skip to content

Commit a3f09f6

Browse files
committed
First crack at concepts
1 parent 206d0f3 commit a3f09f6

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

component-model/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
book

component-model/book.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[book]
2+
authors = ["itowlson"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "The WebAssembly Component Model"

component-model/src/SUMMARY.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Summary
2+
3+
- [Concepts](./concepts.md)

component-model/src/concepts.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Concepts
2+
3+
The Component Model is predicated on a small number of fundamental concepts:
4+
5+
## Interfaces
6+
7+
An **interface** describes a single focused, composable contract, through which components can interact with each other and with hosts. Interfaces describe the types and functions used to carry out that interaction.
8+
9+
* A "receive HTTP requests" interface might have only a single "handle request" function, but contain types representing incoming requests, outgoing responses, HTTP methods and headers, and so on.
10+
* A "wall clock" interface might have two functions, one to get the current time and one to get the granularity of the timer. It would also include a type to represent an instant in time.
11+
12+
## Worlds
13+
14+
A **world** is a higher-level contract that describes a component's capabilities and needs. In a sense, a world _defines_ a component - it says what interfaces the component exposes for other code to call, and what interfaces the component depends on - but it defines only the surface of a component, not the internal behaviour.
15+
16+
A world is composed of interfaces, but each interface is _directional_ - it indicates whether the interface is available for outside code to call, or outside code must fulfil the interface for the component to call. These interfaces strictly bounds the component. A component cannot interact with anything outside itself except by having its exports called, or by calling its imports. This provides very strong sandboxing: for example, if a component does not have an import for a secret store, then it _cannot_ access that secret store, even if the store is running in the same process.
17+
18+
For a component to run, its imports must be fulfilled, by a host or by other components. Connecting up one component's imports to another component's matching exports is called _composition_.
19+
20+
* A (trivial) "HTTP proxy" world would export a "receive HTTP requests" interface, and import a "send HTTP requests" interface. A host, or another component, would call the exported "receive" interface, passing an HTTP request; the component would forward it on via the imported "send" interface. To be a _useful_ proxy, the component would also need to import interfaces such as I/O and clock time - without those imports the component could not perform, for example, caching.
21+
22+
## Components
23+
24+
Physically, a **component** is a specially formatted WebAssembly file. Internally, the component could include multiple traditional WebAssembly modules, and sub-components, composed via their imports and exports.
25+
26+
The external interface of a component - its imports and exports - corresponds to a world. The component, however, defines behaviour and internal state.
27+
28+
## Packages
29+
30+
A **package** is a set of one or more WIT (Wasm Interface Type) files containing a related set of interfaces and worlds. WIT is an IDL (interface definition language) for Wasm. Packages provide a way for worlds and interfaces to refer to each other, and thus for an ecosystem of components to share common definitions.
31+
32+
A package is not a world. It's a way of grouping related interfaces and worlds together for ease of discovery and reference, more like a namespace.
33+
34+
* The WebAssembly System Interface (WASI) defines a number of packages, including one named `wasi:clocks`. Our HTTP proxy world could import the `wall-clock` interface from the `wasi:clocks` package, rather than having to define a custom clock interface.

0 commit comments

Comments
 (0)