@hlang-org/ir

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

The hlang intermediate representation: IGraph types, validation, and the execution plan shared by the interpreter and the compiler.

原始使用文档
文档目录5 节
  1. Install
  2. IGraph
  3. planGraph
  4. Exports
  5. License

hlang ir

@hlang-org/ir

The hlang intermediate representation. IGraph is the JSON form of an hlang program. planGraph validates a graph and lowers it to an execution plan. The interpreter and the compiler both start from this plan, so they apply the same rules.

npm license

Install

npm install @hlang-org/ir

The same build is published as @hlang-tech/ir. No runtime dependencies. ESM and CommonJS builds with type declarations.

IGraph

import type { IGraph } from '@hlang-org/ir';

const graph: IGraph = {
  nodeList: [
    { nodeId: 'a', code: 'numbers', name: 'Numbers', type: 'R', bizData: { params: { count: 3 } } },
    { nodeId: 'b', code: 'log', name: 'Log', type: 'W' },
  ],
  connections: [
    { Output: { nodeId: 'a', portConf: { id: 'out' } }, Input: { nodeId: 'b', portConf: { id: 'in' } } },
  ],
};
  • type is the node kind: 'R' (Readable), 'T' (Transform), or 'W' (Writable).
  • code selects the node implementation. A backend maps it to a class or a module.
  • bizData is passed to the node constructor as config; parameters are in bizData.params.
  • In a connection, Output is the upstream output port and Input is the downstream input port. A missing port id defaults to Output and Input. The legacy spelling portConfig.id is also read.

planGraph

import { planGraph, GraphError } from '@hlang-org/ir';

const plan = planGraph(graph);
// {
//   nodes: [{ nodeId: 'a', code: 'numbers', kind: 'R', config: { params: { count: 3 } } }, ...],
//   connections: [{ source: { nodeId: 'a', portId: 'out' }, target: { nodeId: 'b', portId: 'in' } }],
//   roots: ['a'],
// }

The plan keeps graph order. config is a copy of bizData with params defaulted to {}.

planGraph throws a GraphError with one of these codes:

codeCause
duplicate-node-idTwo nodes share a nodeId.
invalid-node-kindA node type is not R, T, or W.
unknown-nodeA connection references a node that is not in nodeList.
invalid-connectionA Writable node is a source, a Readable node is a target, or @node/error is a target.
no-readable-rootThe graph has no Readable node to run.

Transform-to-Transform cycles are valid.

Exports

  • Types: IGraph, INodeInfo, IConnection, IConnectionEndpoint, IBizData, IPortInfo, IPackageInfo, ParamBag, ParamValue, IParamObject, NodeKind, ExecutionPlan, PlannedNode, PlannedConnection, PlannedEndpoint, GraphErrorCode.
  • Values: planGraph, GraphError, ERROR_PORT_NAME ('@node/error').

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

License

MIT

版本与发布记录

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

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

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

@hlang-org/ir 是什么?

hlang中间表示:图形类型、验证以及解释器和编译器共享的执行计划。

如何安装 @hlang-org/ir?

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

@hlang-org/ir 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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