# @plastic-io/plastic-io

> JavaScript graph programming lanague.

Latest version **2.4.0** (published 2026-09-22) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @plastic-io/plastic-io
pnpm add @plastic-io/plastic-io
yarn add @plastic-io/plastic-io
bun add @plastic-io/plastic-io
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2026-09-22 |
| First published | 2020-02-13 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 156.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | TonyGermaneri@gmail.com |
| Maintainers | tgermaneri |

## Links

- npm: https://www.npmjs.com/package/@plastic-io/plastic-io
- Repository: https://github.com/plastic-io/plastic-io
- Homepage: https://github.com/plastic-io/plastic-io#readme
- Issues: https://github.com/plastic-io/plastic-io/issues
- npm.io page: https://npm.io/package/@plastic-io/plastic-io

## Dependencies (3)

- [meriyah](https://npm.io/package/meriyah.md) ^1.9.12
- [escodegen](https://npm.io/package/escodegen.md) ^1.14.1
- [@types/escodegen](https://npm.io/package/@types/escodegen.md) 0.0.6

## Recent versions

- 2.4.0 (latest) — 2026-09-22
- 2.3.1 — 2026-09-22
- 2.3.0 — 2026-09-22
- 2.2.0 — 2026-09-21
- 2.1.0 — 2026-09-21
- 2.0.4 — 2024-03-24
- 2.0.3 — 2024-02-09
- 2.0.2 — 2024-01-06
- 2.0.1 — 2022-11-27
- 2.0.0 — 2022-11-27
- 1.0.18 — 2020-05-31
- 1.0.17 — 2020-05-30
- 1.0.16 — 2020-05-29
- 1.0.15 — 2020-05-26
- 1.0.14 — 2020-05-20
- … 14 more at https://npm.io/package/@plastic-io/plastic-io/versions

## README

# plastic-io

## Executions, budgets and cancellation (2.1)

`url()` now resolves when the execution has ended: every set function and
every connector delivery it started has settled, or its budget ran out, or it
was cancelled.  `invoke()` returns the handle behind that promise.

```javascript
const handle = scheduler.invoke("index", value, "field", undefined, {
    budget: {wallMs: 5000, hops: 10000, fanOut: 1000, depth: 256},
});
handle.cancel("user pressed stop");        // cooperative: refused at the next hop
const result = await handle.done;          // never rejects
// result: {state: "completed" | "failed" | "cancelled" | "abandoned", reason, hops, errors, duration, budget}
```

* Every event carries `executionId`, `seq`, and for edge-level events `spanId`
  and `parentSpanId`, so a run can be reconstructed from its events.
* `end` fires once per execution, last.  `endedge` fires when the node's set
  function has finished, so `afterSet` now precedes it.  `afterSet` carries
  `err` when the set function failed.
* Running out of budget emits one `error` with `code: "BUDGET_EXCEEDED"` and
  cancels the execution (`reason: "budget:<dimension>"`).  A cancellation that
  cannot drain within `graceMs` (250 ms) ends as `abandoned`.
* A node that emits on an edge after its execution has ended (a UI event, a
  timer) starts a new execution with `trigger: "edge"` and
  `parentExecutionId` on its `begin` event.
* Node code receives a `host` binding: `host.executionId`, `host.cancelled`,
  `host.signal` (an AbortSignal for fetch), `host.throwIfCancelled()`,
  `host.emit(kind, data)` (an `observation` event, counted against the
  budget), `host.now()`, `host.random()`, plus whatever the embedder adds
  through `new Scheduler(graph, context, state, logger, {host})`.
* Set functions are compiled from their source as written (`AsyncFunction`),
  so top-level `await` and modern syntax work; `{compile: "meriyah"}` keeps the
  2.0 parse-and-regenerate path.  Compiled functions are cached per scheduler.
* `onInput` / `onOutput` hooks validate values entering and leaving nodes;
  a thrown error is a `CONTRACT_VIOLATION` warning, or an error that drops the
  delivery with `{contractMode: "reject"}`.
* A connector into another graph loads that graph for itself; 2.0 redirected
  the node's remaining connectors into it.
* `scheduler.cancelAll(reason)` ends every open execution, for embedders that
  replace the graph while it runs.

## Graph scheduling engine.

![CI/CD](https://github.com/plastic-io/plastic-io/workflows/CI/CD/badge.svg?event=push)

This program can execute graphs written in the application/json+plastic-io schema.

[Documentation](https://plastic-io.github.io/plastic-io/)

[Test Coverage](https://plastic-io.github.io/plastic-io/coverage/lcov-report/)

[Repo](https://github.com/plastic-io/plastic-io)


## Major engine features

* Just in time loading and compiling of:
    - graph
    - nodes
    - embedded graphs
    - ES6 code
* Event emitter shows detailed graph execution data
* Graphs can be published, linked and embedded in other graphs
* Nodes can be published and linked
* Graphs support templating engines to create UIs using various frameworks (e.g.: Vue, React)

## Basic Usage

```
    // load the lib
    import {Scheduler} from "plastic-io";
    // instantiate the scheduler
    const scheduler = new Scheduler(myGraphJson);
    scheduler.url("url-of-a-node", "some value");
```

For more useage see [Scheduler](https://plastic-io.github.io/plastic-io/classes/_scheduler_.scheduler.html)

To create, run and debug graphs, use the plastic-io/graph-editor and the plastic-io/graph-server

---
_Source: https://npm.io/package/@plastic-io/plastic-io · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
