Tera
tera
is a lean secure capability-based runtime for JavaScript. It is primarily designed for multi-tenant serverless environment but has uses in other contexts.
tera
provides a small set of permission-enabled system APIs that you can get started with but you can also create your own permission types and bindings.
There is currently no plan to strictly support web-compatible APIs or out-of-the-box typescript compilation. If need those functionalities, take a look at deno.
tera
is heavily inspired by deno runtime and it will include a non-web webassembly runtime like wasmtime in the future for better security guarantees, no cold start and improved wasm performance.
Information provided here is for folks working on this package. If your goal is to get started with the Gigamono framework, check the Gigamono repo on how to do that.
Content
Usage
You need to add tokio to your dependencies.
extern crate tera;
use tera::{
permissions::{
fs::{PathString, FS},
Permissions,
},
Runtime,
};
use tokio::fs;
use utilities::result::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Create allowed resources
let allow_list = [PathString("./examples/txt".into())];
// Create permissions object.
let permissions = Permissions::builder()
.add_permissions(&[
(FS::Open, &allow_list),
(FS::Read, &allow_list)
])
.build();
// Start a new js runtime.
let mut runtime = Runtime::default_main(permissions).await?;
// Get code and main module filename.
let main_module_filename = "./examples/js/read_text_file.js";
let main_module_code = fs::read_to_string(main_module_filename).await?;
// Execute the main module code.
runtime
.execute_module(main_module_filename, main_module_code)
.await
}