Skip to content

Extensions

An extension adds a class to Novis. The code of the class is written in another language, such as Rust or C, and compiled to WebAssembly. Your program calls the class like any other class, and the compiler checks every call.

Write an extension when you need a library that exists in another language and Novis does not have. A Markdown parser, a file format or a special algorithm are good examples. Look in the Core reference first. Most of what a web server or a command line tool needs is already there.

If the code is easy to write in Novis, write it in Novis. An extension is for code that already exists somewhere else.

  • An extension runs in a sandbox. It has its own memory, and it cannot read or change the memory of your program.
  • It cannot open a file or connect to a host. An extension can ask for both in its manifest. The person who runs the server decides what each extension gets.
  • Only the configuration file nvs.toml can load an extension. Each entry has the sha256 of the file, so a changed file does not load.
  • Each request gets a new copy of the extension. Nothing that one request stores in it is there in the next request.
  • A tainted value stays tainted. If you pass text from a form to an extension, the result is tainted too. A secret value cannot be passed to an extension at all.

A call to an extension takes about 10 nanoseconds longer than a call to a built-in function. The first call in a request also creates the new copy of the extension. That takes about 8 to 23 microseconds.

The values are copied into the extension and back. A bytes value (a byte string) is copied once into the extension and once back. So a large file or an image costs about the time to copy its bytes.

Write functions that do a lot of work in one call: give the whole document, and get the whole result. A function that is called once for each character of a text is slow.

Novis has a template for Rust and one for C. nvs ext new --lang rust or nvs ext new --lang c creates a project that builds and runs as it is.

Other languages work too, if their compiler writes WebAssembly for the target wasm32-wasip2. A language that brings its own runtime makes a much bigger file. The tools for JavaScript, for example, put a whole JavaScript engine into the file.

Write an extension in Rust builds an extension from an empty folder. It converts Markdown to HTML with a Rust library, and a web page uses it at the end.

The reference pages list every option: