WebAssembly-based execution engine for machine-readable Dutch law (RegelRecht).
npm install regelrecht-engineimport init, { WasmEngine } from 'regelrecht-engine';
// Initialize WASM module (browser automatically fetches .wasm file)
await init();
// Create engine instance
const engine = new WasmEngine();
// Load a law from YAML
const response = await fetch('/laws/zorgtoeslagwet.yaml');
const yaml = await response.text();
const lawId = engine.loadLaw(yaml); // Returns "zorgtoeslagwet"
// Execute an article output
// NOTE: External dependencies (source.regulation) must be pre-resolved
// and passed as parameters - see Limitations section
const result = engine.execute(
'zorgtoeslagwet',
'heeft_recht_op_zorgtoeslag',
{
BSN: '123456789',
// Pre-resolved external values (workaround for WASM limitation)
vermogen: 50000,
heeft_toeslagpartner: false
},
'2025-01-01' // calculation date
);
console.log(result.outputs.heeft_recht_op_zorgtoeslag); // true or falseimport { initSync, WasmEngine } from 'regelrecht-engine';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
// Node.js requires manual WASM loading
const wasmPath = fileURLToPath(new URL(
'./node_modules/regelrecht-engine/regelrecht_engine_bg.wasm',
import.meta.url
));
const wasmBuffer = readFileSync(wasmPath);
initSync({ module: wasmBuffer });
// Create engine instance
const engine = new WasmEngine();
// Load and execute as shown aboveCreates a new engine instance.
Load a law from a YAML string. Returns the law ID.
- Limits: Max 1 MB YAML, max 100 laws per engine instance
- Throws: If YAML parsing fails, limits exceeded, or law with same ID already loaded (call
unloadLaw()first to replace)
Execute an article's output with the given parameters.
lawId- ID of the loaded lawoutputName- Name of the output to calculateparameters- Object with input parameterscalculationDate- Date string (YYYY-MM-DD)
Returns an object with:
outputs- Calculated output values (plain JavaScript object)resolved_inputs- Input values used in calculationarticle_number- Article that was executedlaw_id- Law IDlaw_uuid- Optional law UUID
List all loaded law IDs (sorted alphabetically).
Get metadata about a loaded law.
Returns:
id- Law IDregulatory_layer- Type of regulation (WET, MINISTERIELE_REGELING, etc.)publication_date- Publication datebwb_id- BWB identifier (optional)url- Official government URL (optional)outputs- Available output names (sorted alphabetically)article_count- Number of articles
Check if a law is loaded.
Remove a loaded law. Returns true if removed.
Get the number of loaded laws.
Get the engine version.
This WASM interface has some limitations compared to the full Rust engine:
- No cross-law resolution: External references (
source.regulation) require a ServiceProvider which is not available in WASM. Workaround: pre-resolve external values and pass them as parameters. - No open term resolution: Open terms (
open_terms/implementsIoC) require a ServiceProvider which is not available in WASM. Workaround: pre-resolve open term values and pass them as parameters.
Full TypeScript definitions are auto-generated by wasm-pack. The package exports:
import init, { WasmEngine } from 'regelrecht-engine';
import type { InitInput, InitOutput } from 'regelrecht-engine';
// Types for results
interface ExecuteResult {
outputs: Record<string, any>;
resolved_inputs: Record<string, any>;
article_number: string;
law_id: string;
law_uuid?: string;
}
interface LawInfo {
id: string;
regulatory_layer: string;
publication_date: string;
bwb_id?: string;
url?: string;
outputs: string[];
article_count: number;
}EUPL-1.2 - See LICENSE for details.