बिज़नेस रूल्स इंजन
फ्रेमवर्क-स्वतंत्र, प्लगइन-आधारित रूल्स इंजन. AST ही सत्य का एकमात्र स्रोत है: बिल्डर उसे संपादित करता है, एक्ज़ीक्यूटर उसे चलाता है, रेंडरर उसका वर्णन करता है, डीबगर उसे समझाता है. न कोई पेड API, न क्लाउड सेवा, न कोई तीसरा इंजन.
- पैकेज
- 11
- ऑपरेटर
- 27
- फ़ंक्शन
- 23
- रूल प्रकार
- 7
इनसे आयात करता है ADYSRE AST, jsonLogic, json-rules-engine, MongoDB query filters.
यह क्या करता है
A JSON tree
Rules are plain JSON. Storable, diffable, versionable, and readable by anything.
Everything is a plugin
Operators, functions, actions, fields, storage, renderers. Add one without touching the engine.
Runs anywhere
Synchronous, pure, zero dependencies. The same rule evaluates on a server, in a browser or in a test.
Says what it means
Every rule renders as a sentence, generated from the tree and never parsed back into it.
Shows its reasoning
Which row decided the verdict, what the operator received, and what short-circuiting hid.
Edits itself
A visual builder with undo, per-row validation and a live preview, driven entirely by the plugin metadata.
Takes what you have
Converts other rule formats, warning where an equivalent is near rather than exact.
Keeps its history
Versioning, restore and querying behind one contract every adapter is checked against.
आज़माएं
कोई भी शर्त बदलें. वाक्य, नतीजा और व्याख्या साथ-साथ बदलेंगे.
A nested group, a date function, and two outcomes on one rule.
When
Then
Otherwise
In words
MatchedLarge orders from new customers need approval
Why this answer
Why this answer
MatchedTook 0.07msevery condition contributed, so no single one decided
1 branches never ran
- Matchedall of these are true0.05ms
- Matched
greaterThan0.03msThe operator received: 2400, 1000
- Matchedany of these are true0.01ms
- Matched
equals0.01msThe operator received: "new", "new"
- Never ran
before
The rule, as JSON
बिज़नेस रूल्स इंजन का उपयोग
किसी प्रोजेक्ट में रूल जोड़ने के लिए सब कुछ: इंस्टॉल, लिखना, चलाना, समझाना, बढ़ाना और संपादन देना. नीचे हर स्निपेट जैसा है वैसा चलता है.
- 01
इंस्टॉल करें
जो चाहिए वही लें. इंजन और उसकी शब्दावली की कोई रनटाइम डिपेंडेंसी नहीं है; बिल्डर अलग पैकेज है क्योंकि सिर्फ़ रूल चलाने वाले सर्वर को React एडिटर भेजने की ज़रूरत नहीं.
terminal# the engine and its vocabulary pnpm add @adysre/rules-core @adysre/rules-types # the visual builder, when you want one pnpm add @adysre/rules-ui @adysre/rules-react @adysre/rules-theme
- 02
रूल लिखें
रूल सादा JSON है. बिल्डर आईडी और टाइमस्टैम्प संभालते हैं, पर आप ऑब्जेक्ट खुद भी लिख सकते हैं, स्टोर कर सकते हैं और रिव्यू में डिफ़ कर सकते हैं.
rules/large-orders.tsimport { all, condition, field, literal, rule } from '@adysre/rules-core'; // A rule is plain JSON. The builders exist so ids and timestamps are handled // for you, but nothing stops you writing the object by hand. const largeOrders = rule({ name: 'Large orders from new customers need approval', kind: 'validation', when: all([ condition({ left: field('order.total'), operator: 'greaterThan', args: [literal(1000)], }), ]), then: [{ id: 'a_hold', type: 'requireApproval' }], }); - 03
चलाएं
सिंक्रोनस और शुद्ध. रजिस्ट्री खाली शुरू होती है क्योंकि रूल क्या कर सकते हैं यह आपका निर्णय है. नतीजे में वर्डिक्ट, एक्शन और ट्रेस मिलते हैं.
rules/run.tsimport { builtinPlugins, createContext, createRegistry, evaluateRule } from '@adysre/rules-core'; // The registry starts EMPTY: what rules may do is your choice. Pass the // built-ins for the usual twenty-seven operators and twenty-three functions. const registry = createRegistry(builtinPlugins); const outcome = evaluateRule(registry, largeOrders, createContext(order)); outcome.verdict; // 'matched' | 'unmatched' | 'skipped' | 'errored' outcome.actions; // what to do — the engine never does it for you outcome.trace; // every node that ran, and what it concluded - 04
वापस पढ़ें
हर रूल एक वाक्य बनता है, जो ट्री से बनता है और कभी वापस पार्स नहीं होता. पहले संरचना, फिर टेक्स्ट.
rules/explain.tsimport { describeRule } from '@adysre/rules-renderer'; describeRule(largeOrders, { plugins: registry }).text; // When order total is greater than 1,000 // Then require approval // Structure first, text second: `.lines` gives typed segments, so a UI can // highlight the field being edited or colour the condition that decided it. - 05
अपना ऑपरेटर जोड़ें
इंजन जो कुछ करता है वह प्लगइन है. रजिस्टर करें और बिल्डर उसे दिखाएगा, डीबगर समझाएगा, और रूल सादा JSON ही रहेंगे.
rules/registry.tsimport { createRegistry, builtinPlugins, RuleError } from '@adysre/rules-core'; import type { OperatorPlugin } from '@adysre/rules-types'; // Your own operator. The builder picks it up, the debugger explains it, and // your rules stay plain JSON — no change to the engine. const withinBusinessHours: OperatorPlugin = { id: 'withinBusinessHours', labelKey: 'operators.withinBusinessHours', arity: 0, accepts: ['date'], evaluate: (left) => { if (typeof left !== 'string') { // Not `false`: a broken comparison must not look like a failed one. throw new RuleError('type_mismatch', 'withinBusinessHours needs a date.'); } const hour = new Date(left).getHours(); return hour >= 9 && hour < 17; }, }; const registry = createRegistry(builtinPlugins, { operators: [withinBusinessHours] }); - 06
संपादन दें
विज़ुअल बिल्डर पूरी तरह प्लगइन मेटाडेटा से चलता है: arity तय करता है कितने बॉक्स दिखें, accepts तय करता है कौन-से ऑपरेटर मिलें.
app/editor.tsx'use client'; import { RuleBuilder } from '@adysre/rules-ui'; export function Editor({ rule, onChange }) { return ( <RuleBuilder rule={rule} registry={registry} sample={sampleOrder} // runs the rule as you type onChange={onChange} /> ); } - 07
कारण जानें
डीबगर बताता है किस पंक्ति ने नतीजा तय किया, और शॉर्ट-सर्किट बंद करके दोबारा चलाकर छिपी खराबियां सामने लाता है.
rules/debug.tsimport { debugRule } from '@adysre/rules-devtools'; const session = debugRule(registry, largeOrders, createContext(order)); session.decision; // which row decided, or that several did session.comparison.hiddenErrors; // faults a short circuit stepped over - 08
सहेजें
वर्ज़निंग और रीस्टोर के साथ एक स्टोरेज कॉन्ट्रैक्ट. रीस्टोर नया वर्ज़न लिखता है, इतिहास मिटाता नहीं.
rules/storage.tsimport { createMemoryStorage, runStorageConformance } from '@adysre/rules-storage'; const storage = createMemoryStorage(); await storage.save(largeOrders); // version 1 await storage.restore(largeOrders.id, 1); // a NEW version holding version 1 // Writing your own adapter? Check it against the same contract: const results = await runStorageConformance(() => createMyAdapter());
पैकेज
हर पैकेज उसी चरण में आता है जब उसका काम बनता है. जो चाहिए वही इंस्टॉल करें.
- The vocabulary
@adysre/rules-typesType vocabulary for the ADYSRE Business Rules Engine: the rule AST, execution contracts and plugin interfaces.
v0.1.0 - The engine
@adysre/rules-coreFramework-agnostic core of the ADYSRE Business Rules Engine: AST builders, traversal and validation. No runtime dependencies.
v0.1.0 - Importers
@adysre/rules-parserImports rules into the ADYSRE AST from JSON, jsonLogic, json-rules-engine and MongoDB-style queries.
v0.1.0 - Natural language
@adysre/rules-rendererTurns an ADYSRE rule AST into readable language. Generated from the tree, never parsed back into it.
v0.1.0 - Persistence
@adysre/rules-storageWhere rules live: the storage contract, versioning, querying, and a reference adapter every other one has to match.
v0.1.0 - Builder state
@adysre/rules-reactHeadless state for a rule builder: an immutable store with history, plus the React bindings.
v0.1.0 - The visual builder
@adysre/rules-uiThe visual rule builder: React components over @adysre/rules-react, styled with design tokens.
v0.1.0 - The debugger
@adysre/rules-devtoolsThe execution debugger: why a rule answered what it answered, and what short-circuiting hid.
v0.1.0 - Over HTTP
@adysre/rules-nextRules over HTTP: route handlers and server actions on the Web standard, so they run in Next.js and anywhere else.
v0.1.0 - Design tokens
@adysre/rules-themeDesign tokens for the rule builder, and a contrast audit that proves a theme is readable.
v0.1.0 - Sandbox and examples
@adysre/rules-playgroundA runnable sandbox and the worked examples, each verified against the engine that runs it.
v0.1.0
जानने योग्य निर्णय
The AST is the only source of truth
Everything else is a projection of it. Prose is generated from the tree and never parsed back, so the two can never disagree.
An error is not a false
A condition that cannot be evaluated is errored, and so is the rule. A broken comparison never looks like a failed one.
Actions are intent, never performed
The engine reports what should happen and the host decides. That is what lets a rule be run twice, in a preview, or in a test.
The registry cannot be mutated
Extending it returns a new one, so two tenants can hold different capabilities without one leaking into the other.
Every answer carries its reasoning
Each node records what it saw and what it concluded, so somebody can be shown the condition that decided it.
No language to learn
There is no text format to hand-author, so there is no second system to keep in step with the tree.