This directory houses the assets for compiling a WebAssembly binary for Vector Remap Language.
- Install wasm-pack
- Install the
wasm32-unknown-unknowntarget for Rust
To build a Wasm binary runnable in the browser:
wasm-pack build --target webOther targets are available as well.
That outputs a variety of files in pkg.
This Wasm module offers just one function, resolve, which takes a single JSON object with two fields:
programis the VRL input program (string)eventis the VRL event that you want to transform (JSON object)
Here's an example usage of the binary from JavaScript:
import { resolve } from 'vrl-wasm.js';
const program = `.name = "Lee Benson"`;
const event = {
game: "GraphQL"
};
const input = {
program: program,
event: event
};
const res = resolve(input);
const expected = {
// Value returned by the last expression in the program
output: "\"Lee Benson\"",
// The transformed event
result: {
name: "Lee Benson",
game: "GraphQL"
}
}To run the tests:
wasm-pack test --node