The JS function runtime is documented in index.md; the typed
description of every global is at /docs/runtime/api/ (served live at
GET /runtime.d.ts, over MCP as the resource substrio://runtime/types).
What a function is
Use one JavaScript file per function. The runtime resolves only builtin modules
(substrio:env and the Node subset; see the runtime reference).
Bundle any other dependency into the file. The function runs on JavaScriptCore in a
per-app isolate, with db, substrio, env, fetch, and the web globals in scope.
The runtime recognizes three forms:
export default { async fetch(request, env, ctx) { return Response.json({ ok: true }); } }; // ES module
module.exports = async function (event) { return { ok: true }; }; // CommonJS
(function (event) { return { ok: true }; }) // script
It can be called by an HTTP route, function.invoke, a cron schedule, or a document trigger
(index.md, "Handler shapes").
Where each topic lives
| Topic | Page |
|---|---|
| Forms, handler shapes, limits and their errors, differences from Workers, globals | index.md |
Key-value stores: db.kv |
kv.md |
db.sql, db.prepare, db.transaction, SQL over documents |
sql.md |
| Documents, filters and the chain | collections-and-chains.md |
| Live records and query results | records.md |
substrio.* services |
services.md |
| Durable objects | durable-objects.md |
Failures, console, reading logs |
errors-and-logs.md |
| Async work and concurrency | concurrency.md |
Deploying, invoking and reading source revisions go through the function API: cloud-functions.md and agent function tooling.
Lua scripts
Lua is not available in the current release. It runs redis.call through the
Redis frontend, which the release does not build (SUBSTRIO_BUILD_REDIS). In
the current release, function.eval returns NOT_IMPLEMENTED (HTTP 501), and
substrio.lua.eval throws "Lua scripting is not in this build". In a build
that includes the frontend:
A Lua script runs against the app's default key-value store, Redis style, with
keys and args as arrays of strings. Call it over the API with
function.eval (load: true stores the script and returns its sha, which
later calls send instead of the text), or from a function:
substrio.lua.eval("return redis.call('GET', KEYS[1])", ["greeting"]);
Lua runs under the same key, quota, and deadline checks as other calls.
Boundaries
$whereJS is a query filter that runs JavaScript on each candidate document
after the rest of the filter. A fetch call or another function call is not part of
the database transaction: it does not commit or roll back with a record
mutation.