@hlang-org/runtime

中文文档
1.0.7发布于 2026/11/01MITTypeScriptCommonJS

A FBP-Inspired language for universal applications.

原始使用文档
文档目录7 节
  1. Install
  2. Example
  3. Nodes
  4. Ports
  5. Flows
  6. Related packages
  7. License

hlang runtime

@hlang-org/runtime

The hlang runtime: flow-based programming on RxJS streams. Build programs from Readable, Transform, and Writable nodes connected through named ports.

npm license

Install

npm install @hlang-org/runtime

The same build is published as @hlang-tech/runtime. The package is CommonJS with type declarations. ES modules can import its named exports.

Example

const { Flow, ReadableNode, TransformNode, WriteableNode, Port } = require('@hlang-org/runtime');

class Numbers extends ReadableNode {
  constructor(opts) {
    super(opts);
    Port.O('out').attach(this);
  }
  _read($o) {
    [1, 2, 3].forEach((n) => $o('out').send(n));
  }
}

class Double extends TransformNode {
  constructor(opts) {
    super(opts);
    Port.I('in').attach(this);
    Port.O('out').attach(this);
  }
  _transform($i, $o) {
    $i('in').receive((n) => $o('out').send(n * 2));
  }
}

class Log extends WriteableNode {
  constructor(opts) {
    super(opts);
    Port.I('in').attach(this);
  }
  _write($i) {
    $i('in').receive((n) => console.log(n));
  }
}

const numbers = new Numbers();
const double = new Double();
const log = new Log();

numbers.O('out').connect(double.I('in'));
double.O('out').connect(log.I('in'));

new Flow().run(numbers); // 2, 4, 6

Nodes

ClassKindPortsImplement
ReadableNodeR, a sourceoutputs, plus @node/error_read($o)
TransformNodeTinputs and outputs, plus @node/error_transform($i, $o)
WriteableNodeW, a sinkinputs only, no error port_write($i)

Create ports in the constructor with Port.I(name).attach(this) and Port.O(name).attach(this). A node can have any number of named ports. The constructor argument is stored as this.opts. The interpreter and the compiler pass { nodeId, flowId, env, middleware, config, signal }, and node parameters are in this.opts.config.params.

The runtime calls _read, _transform, or _write once per flow. $i(name) and $o(name) return the node's input and output ports. Inside a node, this.I(name), this.O(name), and this.E() (the error port) return the same ports.

Readable and Transform nodes have throw(error), which sends error on @node/error.

Ports

A port wraps an RxJS Subject.

MethodEffect
send(message)Emits message (next).
receive(listener)Subscribes listener. Returns the RxJS Subscription.
pipe(...operators)Applies RxJS operators to what the port emits. Returns { receive }.
connect(input)Connects this output port to an input port. Throws unless the direction is output to input.

Ports are multicast: one output can feed several inputs, and an input can receive from several outputs.

Flows

new Flow().run(readable) collects the nodes reachable from the Readable root through its connections. It starts the Writable nodes first, then the Transform nodes, then the Readable root, so every subscriber exists before data is sent. Run each Readable root of a graph. run throws if its argument is not a Readable node.

Transform nodes can form cycles, so a graph can contain feedback loops. Bound a feedback loop, for example with take or a counter, so it ends.

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

License

MIT

版本与发布记录

@hlang-org/runtime 共发布 8 个版本,首次发布于 2024/07/31;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.7latest2026/11/012 天前
1.0.62026/11/012 天前
1.0.52025/05/221.5 年前
1.0.42024/08/282 年前
1.0.32024/08/182 年前
1.0.22024/07/312 年前

关于 @hlang-org/runtime 的常见问题

@hlang-org/runtime 是什么?

一种受fbp启发的通用应用程序语言。

如何安装 @hlang-org/runtime?

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

@hlang-org/runtime 支持 TypeScript 吗?

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

@hlang-org/runtime 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@hlang-org/runtime 需要什么版本的 Node.js?

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

@hlang-org/runtime 可以商用吗?

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

@hlang-org/runtime 还在维护吗?

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