@dendrite-lang/core
v0.8.2
Published
A declarative dataflow language with incremental reactive evaluation, embeddable in TypeScript.
Downloads
1,563
Maintainers
Readme
@dendrite-lang/core
A declarative dataflow language you embed in a TypeScript application.
A program is a set of named values and outputs. Your application declares what programs may read and must produce, pushes values in, and acts on what comes out. When an input changes, only what depends on it recomputes. Programs are type-checked before they run, and every program terminates.
📖 Documentation · 🧪 Playground
Install
npm install @dendrite-lang/coreESM and CommonJS, with types. One runtime dependency, zod.
A program, running
import {
createEnvironment,
createStdlib,
Policy,
serialiseSource,
Type,
} from "@dendrite-lang/core";
const env = createEnvironment(createStdlib());
// Your contract: what every program on this runtime may read and must produce.
const runtime = env.createRuntime({
layers: [
{
id: "host",
policy: Policy.host,
ports: {
inputs: [{ name: "temperature", type: Type.number, default: 20 }],
outputs: [{ name: "alert", type: Type.boolean, mode: "required" }],
},
},
],
});
// One program, running.
const instance = env.createInstance(runtime, {
program: serialiseSource("output alert = $temperature > 25"),
});
instance.outputs.subscribe(({ outputs, stale }) => console.log(outputs?.get("alert"), { stale }));
runtime.setInputs({ temperature: 30 }); // trueWhat is in the box
- The language: a parser, an analyser that resolves types and checks every op call, and a pull-based evaluator that recomputes only what an input change reaches.
- A standard library of logic, control, array, arithmetic, list, conversion and string ops,
with symbols as sugar over them.
createStdlib({ segments: ["logic", "arithmetic"] })takes part of it. - Port layers: a language declares no inputs or outputs; your application does, in layers whose order is authority.
- An instance to hold: five observables and five commands. A program that stops compiling keeps its last good outputs, marked stale rather than hidden.
- Extension: register your own types, ops, evaluators and operators.
- Every diagnostic documented:
diagnosticsis the registry of all of them, each with a program that triggers it.
Where to go next
- Installation and Embedding core for hosting programs.
- Extending the language for your own types and ops.
- Learn for what programs look like.
Pre-1.0: the API can still change between minor versions.
Related packages
@dendrite-lang/editor: a code editor over a running program, with React components.@dendrite-lang/link: a program driven across a channel, served on one side and edited on the other.
