@hlang-tech/interpreter

中文文档
1.0.1发布于 2026/11/01MITTypeScriptESM + CJS

In-process interpreter for hlang: evaluates an IGraph program into a live RxJS object graph, with no code generation.

原始使用文档
文档目录9 节
  1. Install
  2. Usage
  3. What interpret does
  4. API
  5. interpret(graph, deps, options?)
  6. Execution handle
  7. Stop signal
  8. NodeRegistry
  9. License

hlang interpreter

@hlang-tech/interpreter

Runs an hlang program (IGraph) in the current process. It builds the nodes, connects their ports, and runs the flow, with no code generation and no file access. It works in Node.js and in browsers.

npm license

Install

npm install @hlang-tech/interpreter @hlang-tech/runtime

The same build is published as @hlang-org/interpreter. ESM and CommonJS builds with type declarations.

Usage

import { Flow } from '@hlang-tech/runtime';
import { interpret, NodeRegistry } from '@hlang-tech/interpreter';

const registry = new NodeRegistry()
  .register('numbers', Numbers) // classes that extend the runtime's node classes
  .register('double', Double)
  .register('log', Log);

const handle = interpret(graph, { registry, createFlow: () => new Flow() }, { env: 'prod' });

handle.onError(({ nodeId, error }) => console.error(nodeId, error));
handle.onActivity(({ nodeId, portId }) => highlight(nodeId, portId));

// Later: stop long-running nodes and release subscriptions.
handle.dispose();

What interpret does

  1. Validates the graph with planGraph from @hlang-tech/ir. Invalid graphs throw a GraphError.
  2. Constructs every node with new NodeClass({ nodeId, flowId, env, middleware, config, signal }). config is the node's bizData.
  3. Subscribes the @node/error port of every Readable and Transform node.
  4. Connects each connection as source.O(port).connect(target.I(port)).
  5. Runs every Readable root with a new Flow.

@hlang-tech/compiler emits the same steps as an ES module.

API

interpret(graph, deps, options?)

ArgumentDescription
deps.registryA NodeRegistry that maps each node code to a node class.
deps.createFlowReturns a new runtime Flow.
options.flowIdFlow id passed to every node. Generated when omitted.
options.envEnvironment label passed to every node. Default 'prod'.
options.middlewareObject passed to every node, for services such as a logger.

It throws if a node code is not registered.

Execution handle

MemberDescription
flowIdThe flow id of this run.
rootsThe Readable root nodes.
getNode(nodeId)The constructed node, or undefined.
onError(listener)Errors sent on any @node/error port. Errors sent while the flow starts are buffered, so a listener added after interpret returns still receives them. Returns a disposable.
onActivity(listener)Fires when data passes a connection, for both the source port and the target node. Returns a disposable.
dispose()Stops the run: emits the stop signal, calls onStop callbacks, and unsubscribes the interpreter's observers.

Stop signal

Every node receives signal in its constructor options. Bind long-running work to it:

interval(1000).pipe(takeUntil(this.opts.signal.observable)).subscribe(tick);
this.opts.signal.onStop(() => socket.close());

NodeRegistry

register(code, NodeClass) (chainable; the last registration wins), get(code), has(code), codes().

The package also re-exports planGraph, GraphError, and the IGraph types from @hlang-tech/ir.

Source and documentation: github.com/hlang-tech/hlang.

License

MIT

版本与发布记录

@hlang-tech/interpreter 共发布 3 个版本,首次发布于 2026/11/01;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.0.1latest2026/11/012 天前
1.0.02026/11/012 天前
0.0.0-stage2026/11/012 天前

关于 @hlang-tech/interpreter 的常见问题

@hlang-tech/interpreter 是什么?

hlang:的进程内解释器将一个IGraph程序计算为一个实时的RxJS对象图,不需要生成代码。

如何安装 @hlang-tech/interpreter?

在项目目录运行 npm install @hlang-tech/interpreter,或使用 pnpm add / yarn add / bun add。

@hlang-tech/interpreter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@hlang-tech/interpreter 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@hlang-tech/interpreter 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@hlang-tech/interpreter 可以商用吗?

@hlang-tech/interpreter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@hlang-tech/interpreter 还在维护吗?

最新版本 1.0.1 发布于 2026/11/01(2 天前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/11/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。