Dependencies
A dependency is a WebAssembly module the host mounts beside the handlers, from a registry the operator curates.
dependencies: { db: { module: "sqlite3-wasi", version: "3.50", sha256: "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", persistent: true, init: "db/schema.sql", },},import type { AddExpenseHandler } from "../.embabel/realm.d.ts";
export const addExpense: AddExpenseHandler = async (input, ctx) => { await ctx.deps.db.exec("INSERT INTO expenses (amount, note) VALUES (?, ?)", [input.amount, input.note]); const rows = await ctx.deps.db.exec("SELECT sum(amount) AS total FROM expenses"); return { total: rows[0]?.total ?? 0 };};- The key becomes
ctx.deps.<key>: a JavaScript identifier, and notlogorgateway.ctx.depsexists only when the realm declares a dependency. moduleis a registry id ([a-z0-9][a-z0-9-]*),versionan exact version such as3.50(one to three dot-separated numbers), andsha256the digest of the module’s bytes, 64 lowercase hex characters. The host refuses a module the operator has not allowed, and one whose bytes do not hash tosha256. Either refusal takes every handler in the realm dark, including the ones that never touch the dependency. The reference host allowssqlite3-wasiandh3-wasi, at most eight dependencies, and modules up to 32 MiB.- SQLite has one method,
exec(sql, params), which resolves to rows as plain objects. Bind values throughparams(strings, numbers or null). Asqlite3-wasidependency may not declaremethods. - Any other module may declare the
methodsit calls, each withargsand areturnstype fromi32,i64,f32andf64, and the generated types givectx.deps.<key>exactly those methods. Ani64travels as a decimal string, since values such as an H3 cell id do not fit a JavaScript number. A module with no declared methods is typedunknown. The operator’s allowlist decides what a module may really do; a declared method the operator has not allowed refuses at call time. - Without
persistent, state lives for one dispatch and starts empty each time. - With
persistent: true, the host keeps one database for each world, realm and dependency. It restores the database at the start of a dispatch and saves it only when the dispatch succeeds and the output passes validation; a failed or refused dispatch leaves the stored rows as they were. initis a script, relative to the realm with no leading/and no.., run against empty state: once per dispatch for ephemeral state, or once when a persistent database is created. Synth refuses a missing file and copies it into the output. The host copies it from the admitted capture (at most 1 MiB), so editing the file later changes nothing for the admitted version.- The host records the module, version, digest and init script’s hash beside a persistent database. Change any of them and the host reports a mismatch and refuses to reuse the database. It neither wipes nor migrates it, and there is no migration step, so settle the schema before the first install that persists, and ship a changed schema under a new dependency key.
layerstakesname@versionreferences (a registry id and one to three dot-separated numbers), which synth checks and writes, sorted, todependencies/manifest.json. The reference host refuses a realm that declares them, so leave them out.--profile reference-wasmand--profile reference-dockerrefuse them too.

