@@ -20,8 +20,11 @@ type RuleActions = {
2020 actions : Action [ ] ;
2121} ;
2222
23- export type FactMap = Record < string , Condition > ;
24- export type Condition = {
23+ interface FactMap {
24+ [ fact : string ] : Evaluator ;
25+ }
26+
27+ export type Evaluator = {
2528 params ?: Record < string , any > ;
2629 path ?: string ;
2730 is : Record < string , any > ;
@@ -110,6 +113,21 @@ type ActionExecutionError = {
110113 error : Error ;
111114} ;
112115
116+ type FactMapResult = {
117+ [ key : string ] : {
118+ result : boolean ;
119+ value : any ;
120+ resolved : any ;
121+ } ;
122+ } ;
123+
124+ type RuleResult = {
125+ actions ?: Record < string , Action [ ] > ;
126+ results ?: Record < string , Record < string , FactMapResult > > ;
127+ } ;
128+
129+ type EngineResults = Record < string , RuleResult > ;
130+
113131export type DebugEvent =
114132 | StartingFactMapEvent
115133 | StartingFactEvent
@@ -127,6 +145,7 @@ export type StartEvent = {
127145} ;
128146export type CompleteEvent = {
129147 context : Context ;
148+ results : EngineResults ;
130149} ;
131150
132151export type DebugSubscriber = ( event : DebugEvent ) => void ;
@@ -158,7 +177,7 @@ export interface RulesEngine {
158177 setRules ( rules : Patch < Rules > ) : void ;
159178 setActions ( actions : Patch < Actions > ) : void ;
160179 setFacts ( facts : Patch < Facts > ) : void ;
161- run ( context ?: Context ) : Promise < void > ;
180+ run ( context ?: Context ) : Promise < EngineResults > ;
162181 on ( event : 'debug' , subscriber : DebugSubscriber ) : Unsubscribe ;
163182 on ( event : 'start' , subscriber : StartSubscriber ) : Unsubscribe ;
164183 on ( event : 'complete' , subscriber : CompleteSubscriber ) : Unsubscribe ;
0 commit comments