wave-binder
v0.0.2
Published
Wave Binder - A simple state manager for javascript
Maintainers
Readme
Wave Binder
TypeScript library for state management with a focus in orchestrating interdependent parameters (nodes), with native support for data retriving from REST API
What It’s For
Wave Binder solves scenarios where one field depends on another:
region -> province -> municipality- dynamic lists of repeated elements
- complex objects with nested fields
- value calculation via custom function or backend call
The model is reactive: when a node changes, dependent nodes update automatically.
Requirements
- Node.js 18+ recommended
- npm
Installation & Build (library)
From the repo root:
cd wvb
npm install
npm run buildCompiled output in wvb/lib/.
Key Concepts
1) Node (ProtoNode)
Each node has:
name: logical namepath: data pathtype:SINGLE | MULTI | LIST | COMPLEXdep: dependencies on other nodesla: loading action (how to compute/load the value)- optional
defaultValue
2) Loading Action (la)
USER_SELECTION: value chosen by the userGET | POST | PUT | DELETE | PATCH: loading via HTTPCUSTOM_FUNCTION: calculation via registered custom function
3) Node Types
SINGLE: single valueMULTI: value selected from a list of choicesLIST: dynamic list of child nodesCOMPLEX: object with child fields
Usage Flow (important)
Initialization
Initialization starts asynchronous validations in the background.
import { WaveBinder } from "wave-binder";
const wb = new WaveBinder(license, protoNodes, services, customFunctions);
wb.tangleNodes();Main APIs (WaveBinder)
isReady(): boolean: ready/not-ready statetangleNodes(): connects dependenciesgetNodes(): returns internal nodesgetNodeByName(name): find node by namegetNodeByNameAndType(name, type): find node by name + typegetNodeChoicesByName(name): choices of aMULTInodegetDataPool(): synthetic snapshot of valuesgetNodesInfo(logDepth?): values + event logsaddCustomFunction(fn, name): register runtime custom functionnukeNodes(): full teardown of nodes + stop periodic license checks
HTTP Services Configuration
Pass a Map<string, HttpServiceSetting>:
const services = new Map();
services.set("RETRIEVE_DATA", {
target: "http://localhost:3000/retrieve",
secure: false,
authorization: "Bearer token"
});Notes:
- if
authorizationis set and noAuthorizationheader is already present in the node, it is added automatically - HTTP config logs redact sensitive headers (
Authorization, token, cookie, api-key)
Custom Functions (security)
Only trusted functions via reference are allowed:
const customFunctions = [
{ name: "sum", implementation: (a: number, b: number) => a + b }
];Optional: you can receive a read-only snapshot of the node as the last argument:
{ name: "sumWithCtx", implementation: (a, b, snapshot) => {
// snapshot frozen at invocation time
// snapshot.node: { name, type, path, value, iteration }
// snapshot.depValuesByParameter: dependency values by parameterName
return a + b;
}}Recent Breaking Changes
- Asynchronous bootstrap available in background
- String-based custom functions disabled
- Stricter backend/custom function error handling (fallback to
null) - More aggressive node teardown on license invalidation
Troubleshooting
Error: "WaveBinder is not ready..."
The runtime state has been invalidated. Check license/connectivity and reinitialize the binder.
Empty nodes after startup
License is invalid or heartbeat failed. Check:
- signature payload
- expiration date
- license server reachability
CORS blocked on license server
Configure ALLOWED_ORIGINS with the calling origin.
HTTPS required on license server
Configure a TLS reverse proxy or set REQUIRE_HTTPS=false only for local development.
