@hlang-org/runtime

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

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

中文使用文档
文档目录7 节
  1. 安装
  2. 例子
  3. 节点
  4. 港口
  5. 流
  6. 相关的包
  7. 许可证

hlang runtime

@hlang-org运行时

hlang运行时:基于流的RxJS流编程。从通过指定端口连接的可读、转换和可写节点构建程序。

npm license

安装

npm install @hlang-org/runtime

相同的构建发布为 @hlang-tech/runtime。包是带有类型声明的CommonJS。ES模块可以导入其命名的导出。

例子

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

节点

类种类港口实现
ReadableNodeR是源输出,加上 @node/error_read($o)
TransformNodeT输入和输出,加上 @node/error_transform($i, $o)
WriteableNodeW,水槽只有输入,没有错误端口_write($i)

在构造函数中创建端口 Port.I(name).attach(this) 和 Port.O(name).attach(this)。一个节点可以有任意数量的命名端口。构造函数参数存储为 this.opts。解释器和编译器通过 { nodeId, flowId, env, middleware, config, signal },节点参数为 this.opts.config.params.

运行时调用 _read, _transform,或者 _write 每个流一次。 $i(name) 和 $o(name) 返回节点的输入和输出端口。在节点内部, this.I(name), this.O(name), this.E() (错误端口)返回相同的端口。

可读和转换节点 throw(error),它发送 error 在 @node/error.

港口

一个端口封装了一个RxJS Subject.

方法效果
send(message)发出 message (next)。
receive(listener)订阅 listener。返回RxJS Subscription.
pipe(...operators)对端口发出的内容应用RxJS操作符。返回 { receive }.
connect(input)将此输出端口连接到输入端口。抛出,除非方向是输出到输入。

端口是多播的:一个输出可以提供多个输入,一个输入可以从多个输出接收。

流

new Flow().run(readable) 收集可读根通过其连接可访问的节点。它首先启动可写节点,然后是转换节点,然后是可读根,因此在发送数据之前每个订阅者都存在。运行一个图的每个可读根。 run 如果其参数不是可读节点则抛出。

变换节点可以形成循环,因此图可以包含反馈循环。绑定一个反馈循环,例如用 take 或者计数器,这样就结束了。

来源、问题和文档: github.com/hlang-tech/hlang.

许可证

麻省理工学院

版本与发布记录

@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 和提交记录判断。