Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

vrl-wasm

This directory houses the assets for compiling a WebAssembly binary for Vector Remap Language.

Prerequisites

  • Install wasm-pack
  • Install the wasm32-unknown-unknown target for Rust

Build

To build a Wasm binary runnable in the browser:

wasm-pack build --target web

Other targets are available as well.

That outputs a variety of files in pkg.

Using the module from JavaScript

This Wasm module offers just one function, resolve, which takes a single JSON object with two fields:

  • program is the VRL input program (string)
  • event is 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"
  }
}

Testing

To run the tests:

wasm-pack test --node