0.1.0 โข Published 5 months ago
@soeasily/rules v0.1.0
@soeasily/rules
A lightweight, AI-friendly rule engine for evaluating and validating SoEasily DSL rules in Node.js or TypeScript.
Write simple, JSON-based rules like:
"when": "user.age >= 18", then: { type: 'approve' }
โจ Features
- โ
Evaluate rules with simple
exprorwhen/thensyntax - โ Validate rules using the official JSON Schema
- ๐ง Typed with TypeScript
- ๐งช Includes a test harness
- โก Fast and dependency-light (uses Ajv only)
๐ฆ Install
npm install @soeasily/rulesor with yarn:
yarn add @soeasily/rules๐ง Usage
Evaluate a Rule
import { evaluateRule } from '@soeasily/rules';
const rule = {
name: 'is_adult',
expr: 'input.age >= 18',
event: { type: 'allow' }
};
const input = { age: 20 };
const result = evaluateRule(rule, input);
// result: { matched: true, event: { type: 'allow' } }Validate a Rule
import { validateRule } from '@soeasily/rules';
const rule = {
name: 'missing_expr'
};
const validation = validateRule(rule);
// validation: { valid: true/false, errors: [...] }๐ Supported DSL Fields
| Field | Description |
|---|---|
name | Required. Unique rule name. |
expr | JS expression to evaluate (e.g. input.age > 18) |
when / then | Simplified condition + action shortcut |
event | Fallback standard format |
Planned: support for lookup, extends, test_cases, settings.
๐งช Run the Test
npm install
npm run test๐ License
MIT โ Copyright ยฉ 2025 SoEasily
0.1.0
5 months ago