@pattern-js/runtime-node
v0.2.2
Published
Pattern runtime adapter for Node — HTTP/WS host, worker-thread pool, connection registry, sqlite trace sink.
Readme
@pattern-js/runtime-node
The Node runtime adapter for Pattern. Thin by design — it binds
external sources to boundary triggers and provides isolation. All platform code
lives here so @pattern-js/core stays runtime-neutral.
npm install @pattern-js/core @pattern-js/runtime-nodeProject loader (recommended)
import { loadProject } from "@pattern-js/runtime-node";
const { engine, start } = await loadProject(); // reads pattern.config.json
const { ports } = await start(); // derives routes from workflowsloadProject installs mods, loads workflow .json files, and returns a ready
HTTP host. See projects & mods.
Hosts
Routing is declarative: the HTTP host derives routes from the
boundary.http.request nodes of registered workflows (method/path/port/cors/
body+query JSON-Schema all in config). No programmatic route table.
import { Engine } from "@pattern-js/core";
import { createHttpHost } from "@pattern-js/runtime-node";
const engine = new Engine();
engine.registerWorkflow(api); // route declared inside the workflow
const host = createHttpHost(engine, { defaultPort: 3000 });
const { ports } = await host.start(); // re-derives live as workflows change| Host | Binds | Out-gate |
|------|-------|----------|
| createHttpHost | boundary.http.request (declarative routes) | boundary.http.response (buffered/sse/chunked) |
| createWsHost | boundary.ws.message / open / close | boundary.ws.send |
| runCli | boundary.cli | boundary.cli.exit |
| createScheduleHost | boundary.schedule (interval or 5-field cron) | result discarded/traced |
Isolation: worker-thread pool
A RunTransport that runs each workflow on a node:worker_threads worker — a
drop-in for the in-process transport. Streamed out-gate results are reconstructed
on the host; cancellation crosses the seam.
import { WorkerPoolTransport } from "@pattern-js/runtime-node";
const engine = new Engine({ transport: new WorkerPoolTransport({ size: 4 }) });Also here
NodeConnectionRegistry—ConnectionRegistrybound to live WebSocket sockets (rooms, broadcast, streamed sends).- Trace sinks —
jsonlTraceSink(path)andsqliteTraceSink(path)for persistence (core only emits). loadMods(engine, specifiers)— load external plugin mods by module specifier.patternCLI —pattern graph|validate|dev.
CLI
pattern graph workflow.json # render the graph in the terminal
pattern validate workflow.json # located, human-readable validation errors
pattern dev [entry] # run an entry with file-watch hot-reload