Use a module in a page
No install. The import map loads atlibs from jsdelivr, and loadModule fetches the module from its
publisher's PDS and checks it against the record.
Save as index.html:
<!DOCTYPE html>
<meta charset="utf-8">
<script type="importmap">
{ "imports": { "atlibs/": "https://cdn.jsdelivr.net/npm/@publicdomainrelay/atlibs@0.5.0/src/" } }
</script>
<output></output>
<script type="module">
import { createPluginContext } from 'atlibs/plugin-context/index.js'
import { hostCall } from 'atlibs/run-module/host-call.js'
import { loadModule, runModule } from 'atlibs/run-module/index.js'
const did = 'did:plc:ocnuqjlzgohypj3zoznermms'
const ctx = createPluginContext({ id: 'demo' })
const hello = await loadModule(ctx, 'bobvmbuilder.bsky.social/hello')
const { result, error } = await runModule(ctx, hello, 'count', { did, collection: 'com.fedfork.exec.wasm.module' }, hostCall({ ctx }))
document.querySelector('output').textContent = JSON.stringify(error ?? result)
</script>
{"collection":"com.fedfork.exec.wasm.module","records":…}
Serve it and open http://127.0.0.1:8000/:
python3 -m http.server 8000 --bind 127.0.0.1 &
curl -s localhost:8000/ | grep -c importmap
1
Signed out, a module makes public reads only. Sign-in: Sign in from a page. A
fuller page (components, a cubit, tests): examples/web/hello, Run modules in a page.
Next: Node