WebAssembly bundle
The compiler and engine the playground runs are published with each release
as cfdl-wasm-<version>.tar.gz, from 0.12.0 on, so an application that runs
models in a page or on a server pins a version instead of building the bundle
from source.
What the archive holds
| Path | What it is |
|---|---|
web/ | the bundle for a page, an ES module: cfdl_wasm.js, cfdl_wasm_bg.wasm, the TypeScript types and a package.json |
node/ | the same bundle for Node, a CommonJS module that loads its own .wasm |
bundle.json | the engine version, the results version, each embedded pack with its version and the SHA-256 of every pack file, the toolchain, and the SHA-256 of every file in the archive |
LICENSE | the license the bundle is published under |
Both builds embed the four packs (CRE, credit, energy, OpCo). The release
checks each embedded pack file against cfdl-packs-<version>.tar.gz byte for
byte, and runs the same models through the bundle and the CLI, requiring the
same model_hash and every ledger hash, before anything is published.
Pin it
Download the archive from
cfdl-dev/cfdl-releases,
check it against the release's SHA256SUMS.txt, and record the version and the
checksum where your application states its dependencies.
release-manifest-<version>.json lists the packs the bundle embeds beside the
packs the release publishes.
Use it
In Node:
const cfdl = require("./vendor/cfdl/node/cfdl_wasm.js");
const compiled = JSON.parse(cfdl.compile(JSON.stringify({ "model.cfdl": source }), "model.cfdl"));
const ran = JSON.parse(cfdl.run(JSON.stringify(compiled.ir), JSON.stringify(runConfig), null));
console.log(ran.results.ledger_hash);In a page, initialize the module once and then call it the same way:
import init, { compile, run } from "./vendor/cfdl/web/cfdl_wasm.js";
await init({ module_or_path: new URL("./vendor/cfdl/web/cfdl_wasm_bg.wasm", import.meta.url) });The web build also runs in Node when it is handed the module's bytes:
initSync({ module: readFileSync("web/cfdl_wasm_bg.wasm") }).
build_info() returns what bundle.json records about the engine and its
packs, so an application can report the engine it is running.