WebAssembly Demo

The tflo-wasm crate compiles the temporal event processing engine to WebAssembly, letting you run SMA, RSI, deviation bands, cross detection, and CEL rules entirely in the browser. No server, no network, no API keys.

Try the Live Playground

Package

The wasm bindings live in the tflo-wasm crate. tflo is experimental and pre-1.0, so the package is not yet published — build it locally with wasm-pack against the repository:

wasm-pack build tflo-wasm --target web

Quick Start

import init, { computeSma } from "tflo-wasm";

await init();

const ticks = [
  { ts: 0, value: 10 },
  { ts: 1, value: 20 },
  { ts: 2, value: 30 },
];

const sma = computeSma(ticks, { period: 3 });
// → [null, null, 20]

Architecture

+--------------+    +----------------------+    +------------------+
|  TypeScript  | ==> |  JSON-in/JSON-out    | ==> |  tflo-core       |
|  Your code   |     |  tflo-wasm bridge    |     |  (CompiledGraph) |
|              | <== |  (wasm-bindgen FFI)  | <== |  (event engine)  |
+--------------+    +----------------------+    +------------------+

The design is intentionally simple: no complex TypeScript types cross the wasm boundary. wasm-bindgen handles all serialization and memory management.

Functions

computeSma

Simple Moving Average over a count-based window.

computeSma(ticks, { period: 20 }) → (number | null)[]

computeRsi

Relative Strength Index (Wilder's smoothing).

computeRsi(ticks, { period: 14 }) → (number | null)[]

computeBollinger

Bollinger Bands with configurable multiplier.

computeBollinger(ticks, { period: 20, multiplier: 2 })
→ ({ middle, upper, lower } | null)[]

detectCross

Detect threshold crossings.

detectCross(ticks, { threshold: 70, direction: "above" })
→ { value: number, direction: "above" | "below" }[]

evaluateRules

Evaluate CEL rules against data items.

evaluateRules(rules, items)
→ { item_id: string, matched_rules: string[] }[]

Performance

Every computation runs through the same CompiledGraph engine used by the Rust crate — the wasm target just swaps the host environment.

Pattern matching in the browser

The sibling tflo-cep-wasm crate exposes tflo-cep's closure-based event-pattern matching to JavaScript. Build patterns with the same six-method API as the Rust crate (when / then / notThen / within / emit) using plain JS callbacks — the shared engine::Runtime handles the matching, so feature additions land on both surfaces simultaneously.

For an end-to-end browser SDK with a capture layer (IntersectionObserver viewport tracking, throttled DOM listeners), pluggable sinks (Console, Edge, GA4, custom), and a consent gate, see the companion @tflo/browser-events package — documented on the browser analytics page. Total bundle: ~41 KB optimized .wasm + ~10 KB TypeScript glue (~25 KB gzip).

Try it now: Head to the Interactive Playground or read the event patterns docs.