@o3r/rules-engine 12.2.0-rc.4 → 12.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,7 @@ export declare class EngineDebugger {
|
|
|
19
19
|
private registeredRulesets;
|
|
20
20
|
private readonly debugEventsSubject$;
|
|
21
21
|
private performanceMeasures$;
|
|
22
|
+
private readonly requestFactsSnapshot;
|
|
22
23
|
/** Stream emitting a debug event when is fired; timeline is kept */
|
|
23
24
|
readonly debugEvents$: Observable<DebugEvent>;
|
|
24
25
|
/** Retrieved the rules engine plugged to the debugger */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.debug.d.ts","sourceRoot":"","sources":["../../../src/engine/debug/engine.debug.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"engine.debug.d.ts","sourceRoot":"","sources":["../../../src/engine/debug/engine.debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAGX,MAAM,MAAM,CAAC;AAUd,OAAO,KAAK,EACV,WAAW,EACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAEL,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EAGrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,KAAK,EACN,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACR,MAAM,cAAc,CAAC;AAMtB,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,oBAAoB,CAAC,CAAc;IAE3C,OAAO,CAAC,kBAAkB,CAAsC;IAGhE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA0D;IAE9F,OAAO,CAAC,oBAAoB,C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;;;;;;;OAQG;IACI,6BAA6B,CAClC,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,MAAM,EAAE,EAC3B,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACxC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EACjE,eAAe,EAAE,cAAc,EAAE;IAMnC;;;;OAIG;IACI,8BAA8B,CACnC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC;IAK7B;;;OAGG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE;kBACvB,MAAM;eAAS,GAAG;;CAS9C"}
|
|
@@ -4,7 +4,7 @@ import * as i1 from '@angular/forms';
|
|
|
4
4
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
5
5
|
import * as i1$1 from '@angular/common';
|
|
6
6
|
import { CommonModule, JsonPipe } from '@angular/common';
|
|
7
|
-
import { Subject, of, from, ReplaySubject, Observable, combineLatest, BehaviorSubject, merge, firstValueFrom, fromEvent } from 'rxjs';
|
|
7
|
+
import { Subject, of, from, ReplaySubject, Observable, debounceTime, combineLatest, BehaviorSubject, merge, firstValueFrom, fromEvent } from 'rxjs';
|
|
8
8
|
import { switchMap, delay, startWith, mergeMap, map, catchError, withLatestFrom, concatMap, tap, share, shareReplay, pairwise, distinctUntilChanged, takeUntil, filter, scan } from 'rxjs/operators';
|
|
9
9
|
import * as i1$3 from '@ngrx/store';
|
|
10
10
|
import { createAction, props, on, createReducer, StoreModule, createFeatureSelector, createSelector, select } from '@ngrx/store';
|
|
@@ -725,27 +725,43 @@ class EngineDebugger {
|
|
|
725
725
|
*/
|
|
726
726
|
constructor(options) {
|
|
727
727
|
this.registeredRulesets = [];
|
|
728
|
+
this.requestFactsSnapshot = new Subject();
|
|
728
729
|
this.debugEventsSubject$ = new ReplaySubject(options?.eventsStackLimit);
|
|
729
730
|
this.initializePerformanceObserver();
|
|
730
|
-
this.debugEvents$ =
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
debugEvent
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
731
|
+
this.debugEvents$ = new Observable((subscriber) => {
|
|
732
|
+
const factsSnapshotSubscription = this.requestFactsSnapshot.pipe(debounceTime(1000), switchMap(async () => {
|
|
733
|
+
const timestamp = Date.now();
|
|
734
|
+
const facts = await this.getFactsSnapshot(this.registeredRuleEngine.getRegisteredFactsNames());
|
|
735
|
+
this.debugEventsSubject$.next(() => ({
|
|
736
|
+
timestamp,
|
|
737
|
+
type: 'AvailableFactsSnapshot',
|
|
738
|
+
facts
|
|
739
|
+
}));
|
|
740
|
+
})).subscribe();
|
|
741
|
+
const debugEventsSubscription = this.debugEventsSubject$.pipe(withLatestFrom(this.performanceMeasures$), concatMap(async ([eventFunc, performanceMeasures]) => {
|
|
742
|
+
const debugEvent = await eventFunc();
|
|
743
|
+
if (debugEvent.type === 'RulesetExecution' || debugEvent.type === 'RulesetExecutionError') {
|
|
744
|
+
let rulesetDuration = 0;
|
|
745
|
+
debugEvent.rulesEvaluations.forEach((rule) => {
|
|
746
|
+
const mark = `rules-engine:${this.registeredRuleEngine?.rulesEngineInstanceName || ''}:${debugEvent.rulesetName}:${rule.rule.name}`;
|
|
747
|
+
const measures = performanceMeasures.filter((m) => m.name === mark);
|
|
748
|
+
const duration = measures.at(-1)?.duration || 0;
|
|
749
|
+
rule.duration = duration;
|
|
750
|
+
rulesetDuration += duration;
|
|
751
|
+
});
|
|
752
|
+
debugEvent.duration = rulesetDuration;
|
|
753
|
+
}
|
|
754
|
+
return debugEvent;
|
|
755
|
+
}), tap((debugEvent) => {
|
|
756
|
+
if (debugEvent.type === 'RulesetExecution') {
|
|
757
|
+
this.rulesEngine?.logger?.debug?.(`${debugEvent.rulesetName} has been triggered and resulted in ${JSON.stringify(debugEvent.outputActions)}`);
|
|
758
|
+
}
|
|
759
|
+
})).subscribe(subscriber);
|
|
760
|
+
return () => {
|
|
761
|
+
factsSnapshotSubscription.unsubscribe();
|
|
762
|
+
debugEventsSubscription.unsubscribe();
|
|
763
|
+
};
|
|
764
|
+
}).pipe(share());
|
|
749
765
|
}
|
|
750
766
|
initializePerformanceObserver() {
|
|
751
767
|
this.performanceMeasures$ = new Observable((subscriber) => {
|
|
@@ -893,15 +909,7 @@ class EngineDebugger {
|
|
|
893
909
|
* @param factValue$
|
|
894
910
|
*/
|
|
895
911
|
addAvailableFactsSnapshotEvent(_id, factValue$) {
|
|
896
|
-
factValue$.subscribe(
|
|
897
|
-
const timestamp = Date.now();
|
|
898
|
-
const facts = await this.getFactsSnapshot(this.registeredRuleEngine.getRegisteredFactsNames());
|
|
899
|
-
this.debugEventsSubject$.next(() => ({
|
|
900
|
-
timestamp,
|
|
901
|
-
type: 'AvailableFactsSnapshot',
|
|
902
|
-
facts
|
|
903
|
-
}));
|
|
904
|
-
});
|
|
912
|
+
factValue$.subscribe(() => this.requestFactsSnapshot.next());
|
|
905
913
|
}
|
|
906
914
|
/**
|
|
907
915
|
* Returns a list of fact name and value pairs
|