Skip to content

Scripts

A script is a small program HappyView runs when something happens: an XRPC request arrives, a record is created, a label is applied, or a background job is picked up. Without scripts, query endpoints return raw records and procedures proxy simple creates and updates. With them, you decide what an endpoint returns and what happens to each record before it is indexed.

HappyView does not run scripts itself. A script runs inside an interpreter plugin, a WebAssembly plugin that knows one language. Three are published:

Languagescript_typePlugin
Lua 5.4luahappyview-lua
JavaScript (QuickJS-ng)javascripthappyview-javascript
TypeScript (SWC, then QuickJS-ng)typescripthappyview-typescript

A self-hosted instance starts with no interpreter. Until one is installed, no script can be saved or run, and the server logs this at boot:

no interpreter plugin is installed, so no script can be saved or run; install one from the plugins page in the dashboard

Hosts can preinstall interpreters with HAPPYVIEW_DEFAULT_PLUGINS, which installs them in the background on the first boot whose variable lists them. On HappyProto, Lua is preinstalled this way.

You can install more than one interpreter and mix languages on the same instance. Each script stores the language it is written in as its script_type. See Languages for installing interpreters and choosing a language.

A script reaches HappyView only through its two arguments, input and ctx, and through modules it loads:

  • Built-in modules under internal.: logging, time, TIDs and JSON. They come with the interpreter, so nothing extra needs installing.
  • Library plugins under happyview.: records, SQL, HTTP, XRPC, jobs, spaces and more. Each one is a separate plugin you install. A script that loads a library that isn’t installed fails when it loads.

Lua loads modules with require. JavaScript and TypeScript use import.