You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/plugins.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,3 +33,27 @@ When a plugin is installed, the Server needs to be aware of when the functionali
33
33
34
34
Is run before a Commit is applied.
35
35
Useful for performing authorization or data shape checks.
36
+
37
+
## Wasm class extenders
38
+
39
+
Atomic Server can load class extenders that are compiled to WASM + WASI Preview 2 (aka wasip2).
40
+
Every extender implements the [`class-extender.wit`](../../lib/wit/class-extender.wit) world and exports:
41
+
42
+
-`class-url` – the Subject URL of the class to extend
43
+
-`on-resource-get`
44
+
-`before-commit`
45
+
-`after-commit`
46
+
47
+
Handlers receive JSON-AD payloads that describe the Resource or Commit they should work with and can return an updated JSON-AD document. See the WIT file for the exact record layouts.
48
+
49
+
### Installing a WASM class extender
50
+
51
+
1. Build a component that targets `wasm32-wasip2`. Use `wit-bindgen` or `cargo component` to satisfy the interface defined in `lib/wit/class-extender.wit`.
52
+
2. Copy the resulting `.wasm` file into the `wasm-class-extenders/` directory inside your Atomic data directory (next to the sled store).
53
+
3. Restart `atomic-server` (or recreate the `Db`) so it scans the folder and instantiates your component.
54
+
55
+
All `.wasm` files in that folder are loaded on startup. Errors are logged but do not prevent the server from running, making it safe to iterate on plugins.
56
+
57
+
### Sample Wasm extender
58
+
59
+
See `wasm-plugins/examples/random-folder-extender` for a minimal Rust project that implements the `class-extender` WIT interface. It appends a random suffix to the `name` property of every `https://atomicdata.dev/classes/Folder` resource whenever it is fetched. Build it with `cargo component build --release -p random-folder-extender --target wasm32-wasip2` and copy the resulting `.wasm` into your `wasm-class-extenders/` directory to try it out.
0 commit comments