0.1.0 โ€ข Published 2 months ago

@soeasily/rules v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

@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 expr or when/then syntax
  • โœ… 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/rules

or 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

FieldDescription
nameRequired. Unique rule name.
exprJS expression to evaluate (e.g. input.age > 18)
when / thenSimplified condition + action shortcut
eventFallback standard format

Planned: support for lookup, extends, test_cases, settings.


๐Ÿงช Run the Test

npm install
npm run test

๐Ÿ“„ License

MIT โ€” Copyright ยฉ 2025 SoEasily