Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 1.26 KB

File metadata and controls

62 lines (42 loc) · 1.26 KB

WASM Bindings

QCL can be compiled to WebAssembly via wasm-bindgen.

Prerequisites

cargo install wasm-pack
rustup target add wasm32-unknown-unknown

Build

make wasm
# or directly:
wasm-pack build --target web --release -- --features wasm

Output is generated in the pkg/ directory.

API

eval_json(expression, json_ctx)

Evaluate a QCL expression against a JSON context string. Returns the result as a string.

import init, { eval_json } from "./pkg/qcl.js";

await init();
const result = eval_json('@user.role == "admin"', '{"user": {"role": "admin"}}');
console.log(result); // "true"

eval(expression, ctx)

Evaluate a QCL expression against a JS object. Returns the result as a JS value.

import init, { eval as qclEval } from "./pkg/qcl.js";

await init();
const result = qclEval("@x + 1", { x: 2 });
console.log(result); // 3

Build Targets

wasm-pack supports different targets:

Target Flag Use case
Web (ESM) --target web <script type="module">
Bundler --target bundler Webpack / Vite
Node.js --target nodejs Server-side Node

Example for bundler:

wasm-pack build --target bundler --release -- --features wasm