@gorules/zen-engine

中文文档
2.1.11发布于 2026/11/12MITTypeScriptCommonJS近 30 天下载 63万

Open-source Business Rules Engine for Node.js, powered by Rust

原始使用文档
文档目录14 节
  1. Rules that read like sentences
  2. Rules as graphs, or as documents
  3. What's new in 2.0
  4. Installation
  5. Quickstart
  6. Loaders
  7. Other platforms
  8. The GoRules platform
  9. AI that builds rules, and stays reviewable
  10. Promote like a release, run like a binary
  11. Prove it before it ships
  12. Support matrix
  13. Contribution
  14. License

Node.js Rules Engine

Business logic humans can read and machines can run. One copy of your rules: the owner reads it, every system runs it.

License: MIT npm

GoRules ZEN Engine

ZEN Engine is a cross-platform, open-source Business Rules Engine (BRE) written in Rust with native Node.js bindings, alongside Python, Go, Java, Kotlin and .NET. Decisions evaluate in microseconds, run identically on every platform, and are stored as portable JSON. Loading the JSON is up to you: file system, database or service call.

Try it in the free Online Editor with a built-in simulator, or embed the open-source React JDM Editor in your own product. Learn more about the Node.js rules engine on the GoRules website.

Rules that read like sentences

Conditions are written the way the business says them, in the ZEN Expression Language. The developer view is one toggle away, and the two can never drift apart: there is only one source of truth, and this engine runs it.

Readable rules

Rules as graphs, or as documents

Model a decision on a visual canvas of decision tables, switches, expressions, functions and reusable sub-decisions. Or write it as a policy document with prose, typed data models and tables. Both compile to the same engine and return the same answers.

Graphs and documents

To go deeper, see the Node.js SDK documentation, the decision graph guide and the ZEN Expression Language reference.

What's new in 2.0

Version 2.0 is the first stable release of the new engine line:

  • Policy documents: model decisions as readable documents with typed data models, expressions, decision tables, match blocks and assertions. Policies compile to the same engine as graphs and return the same answers.
  • Workspace analysis: static type checking across policies and graphs. Type flow, exhaustiveness checking, write-conflict detection and precise diagnostics, all available before anything runs.
  • Per-column collect: decision table output columns can collect across all matching rows (tags[]) while the rest of the table stays first-match.
  • Pre-compiled engine: decisions are parsed and compiled once at load; evaluation is allocation-light and repeat-safe.
  • Hardened runtime: out-of-range numbers, arithmetic overflow and malformed inputs return errors or nulls instead of crashing the process.
  • Unified bindings: configurable loaders, batch evaluation and consistent error envelopes across Node.js, Python, Go and FFI consumers.

Installation

npm i @gorules/zen-engine

Prebuilt binaries ship for Linux (gnu and musl), macOS, Windows and WASM (WASI); no Rust toolchain required.

Quickstart

import { ZenEngine } from '@gorules/zen-engine';
import fs from 'fs/promises';

const content = await fs.readFile('./jdm_graph.json');
const engine = new ZenEngine();

const decision = engine.createDecision(content);
const result = await decision.evaluate({ input: 15 });
console.log(result);

Loaders

For more advanced use cases where you want to load multiple decisions and reuse them across evaluations you can build loaders. When engine.evaluate is invoked it calls the loader with a key, expecting the content of the JDM decision graph in return.

import { ZenEngine } from '@gorules/zen-engine';
import fs from 'fs/promises';
import path from 'path';

const loader = async (key: string) => fs.readFile(path.join(import.meta.dirname, 'jdm_directory', key));

const engine = new ZenEngine({ loader });
const result = await engine.evaluate('jdm_graph1.json', { input: 5 });
console.log(result);

The same pattern works for loading from a REST API, S3, a database, or anywhere else. Full guides, including multi-decision graphs and batch evaluation, are in the Node.js SDK documentation.

Other platforms

The GoRules platform

The engine is open at the core; GoRules is the platform around it. Managed cloud, self-hosted, or embedded with no network hop. SOC 2 Type II.

AI that builds rules, and stays reviewable

An AI copilot and MCP server that edits rules, runs tests and explains decisions. It never deploys. Releases stay with your reviewers.

GoRules AI

Promote like a release, run like a binary

A release moves from testing to staging to production untouched. Approvals, instant rollback, and a paper trail for every change.

Governance

Prove it before it ships

Scenario suites run on every change, coverage is measured against decision paths, and every answer comes with a replayable trace.

Testing

Support matrix

ArchNode.js
linux-x64-gnu:heavy_check_mark:
linux-arm64-gnu:heavy_check_mark:
darwin-x64:heavy_check_mark:
darwin-arm64:heavy_check_mark:
win32-x64-msvc:heavy_check_mark:
linux-x64-musl:heavy_check_mark:
linux-arm64-musl:heavy_check_mark:
wasm32 (WASI):heavy_check_mark:

Contribution

The JDM standard is growing and we need to keep tight control over its development and roadmap, as a number of companies use GoRules ZEN Engine and GoRules BRMS. For this reason we can't accept code contributions at this moment, apart from help with documentation and additional tests.

License

MIT License

版本与发布记录

@gorules/zen-engine 共发布 128 个版本,首次发布于 2023/04/03;过去 12 个月发布了 42 个版本。

版本发布日期距今
2.1.11latest2026/11/124 天前
2.1.102026/11/106 天前
2.1.92026/10/2226 天前
2.1.82026/10/2127 天前
2.1.72026/10/141 个月前
2.1.62026/10/131 个月前

其他发布通道:beta → 1.0.0-beta.14。

关于 @gorules/zen-engine 的常见问题

@gorules/zen-engine 是什么?

Open-source Business Rules Engine for Node.js, powered by Rust

如何安装 @gorules/zen-engine?

在项目目录运行 npm install @gorules/zen-engine,或使用 pnpm add / yarn add / bun add。

@gorules/zen-engine 支持 TypeScript 吗?

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

@gorules/zen-engine 支持 ESM 还是 CommonJS?

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

@gorules/zen-engine 需要什么版本的 Node.js?

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

@gorules/zen-engine 可以商用吗?

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

@gorules/zen-engine 的下载量有多少?

根据 npm 官方下载统计,@gorules/zen-engine 在 2026/10/17 – 2026/11/15 这 30 天内被下载 630,226 次,日均约 21,008 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gorules/zen-engine 还在维护吗?

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