Licence
Apache-2.0
Version
0.3.0
Deps
0
Size
229 kB
Vulns
0
Weekly
0
pin-derive-wasm
Host-agnostic ESM bindings for the pin-derive wasm core. The package bundles
pin_derive_wasm.wasm and exposes a tiny API: instantiate the engine from wasm
bytes, then solve the same JSON specs used by the TypeScript, Rust, and Python
runtimes.
Install
Once published:
npm install pin-derive-wasm
For development from this repository:
cd rust/js
pnpm run test
Usage
Browser or bundler
import { load, wasmUrl } from "pin-derive-wasm";
const wasmBytes = await fetch(wasmUrl).then((response) => response.arrayBuffer());
const engine = await load(wasmBytes);
const snapshot = engine.solve({
cells: [
{ id: "profit", init: { lo: 0, hi: null } },
{ id: "price", init: { lo: 0, hi: null } },
{ id: "margin", init: { lo: 0, hi: null } },
],
relations: [
{ type: "product", z: "profit", x: "price", y: "margin" },
],
pins: [
{ cell: "price", value: { lo: 50, hi: 50 } },
{ cell: "margin", value: { lo: 0.2, hi: 0.2 } },
],
});
Node
import { readFile } from "node:fs/promises";
import { load, wasmUrl } from "pin-derive-wasm";
const engine = await load(await readFile(wasmUrl));
const snapshot = engine.solve({ /* spec */ });
Bundled wasm
The npm package includes pin_derive_wasm.wasm as package data. Release CI
rebuilds the wasm artifact, copies it into this package directory, and then packs
or publishes, so consumers do not need a Rust toolchain.
Full project
See the main repository README for the engine model, TypeScript API, Rust port, Python package, and interactive docs site: https://github.com/nightwork-dev/pin-derive.