trigger_system 1.0.0 → 1.0.2

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.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Base Engine Interface - Define la interfaz común para todos los motores
3
+ * Platform-agnostic y extensible
4
+ */
5
+ import type { TriggerRule, TriggerContext, TriggerResult, RuleEngineConfig } from "../types";
6
+ export type EngineActionHandler = (params: any, context: TriggerContext) => Promise<any> | any;
7
+ /**
8
+ * Interfaz base que deben implementar todos los motores
9
+ */
10
+ export interface ITriggerEngine {
11
+ readonly rules: TriggerRule[];
12
+ processEvent(context: TriggerContext): Promise<TriggerResult[]>;
13
+ processEvent(eventType: string, data?: Record<string, any>, globals?: Record<string, any>): Promise<TriggerResult[]>;
14
+ registerAction(type: string, handler: EngineActionHandler): void;
15
+ updateRules(newRules: TriggerRule[]): void;
16
+ getRules(): TriggerRule[];
17
+ readonly config?: RuleEngineConfig;
18
+ }
19
+ //# sourceMappingURL=base-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-engine.d.ts","sourceRoot":"","sources":["../../src/core/base-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,aAAa,EAIb,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAE/F;;GAEG;AACH,MAAM,WAAW,cAAc;IAE7B,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC;IAG9B,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAChE,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAGrH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAGjE,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC3C,QAAQ,IAAI,WAAW,EAAE,CAAC;IAG1B,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;CACpC"}
@@ -22,7 +22,7 @@ export declare class ExpressionEngine {
22
22
  * Obtiene un valor anidado de un objeto usando notación de puntos
23
23
  * Ejemplo: getNestedValue("data.user.profile.name", context)
24
24
  */
25
- static getNestedValue(path: string, context: TriggerContext): any;
25
+ static getNestedValue(path: string, context: TriggerContext): Record<string, any> | undefined;
26
26
  /**
27
27
  * Ejecuta una expresión matemática específica (como "1 + 2")
28
28
  */
@@ -1 +1 @@
1
- {"version":3,"file":"expression-engine.d.ts","sourceRoot":"","sources":["../../src/core/expression-engine.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,gBAAgB;IAC3B;;;OAGG;IAEH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,GAAG;IAoBjE;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM;IAoBrE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAUrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IA2BjC;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,GAAG;IAcjE;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM;CA+CzE"}
1
+ {"version":3,"file":"expression-engine.d.ts","sourceRoot":"","sources":["../../src/core/expression-engine.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,gBAAgB;IAC3B;;;OAGG;IAEH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,GAAG;IAoBjE;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM;IAoBrE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAUrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IA2BjC;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc;IAc3D;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM;CA+CzE"}
@@ -2,9 +2,14 @@ export * from "./expression-engine";
2
2
  export * from "./event-queue";
3
3
  export * from "./persistence";
4
4
  export * from "./persistence-browser";
5
+ export type { ITriggerEngine, EngineActionHandler } from "./base-engine";
6
+ export { TriggerEngine } from "./trigger-engine";
7
+ export { RuleEngine } from "./rule-engine-new";
5
8
  export * from "./action-registry";
6
9
  export * from "./context-adapter";
10
+ export * from "./state-manager";
11
+ export { TriggerEngine as Engine } from "./trigger-engine";
12
+ export { RuleEngine as AdvancedRuleEngine } from "./rule-engine-new";
7
13
  export * from "./rule-engine";
8
14
  export * from "./engine";
9
- export * from "./state-manager";
10
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,uBAAuB,CAAC;AAGtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,uBAAuB,CAAC;AAGtC,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGrE,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * RuleEngine - Extensión de TriggerEngine con características avanzadas
3
+ * Agrega observabilidad, estado persistente, y ActionRegistry integrado
4
+ */
5
+ import type { TriggerContext, TriggerResult, RuleEngineConfig } from "../types";
6
+ import { TriggerEngine } from "./trigger-engine";
7
+ export declare class RuleEngine extends TriggerEngine {
8
+ private actionRegistry;
9
+ private stateManager;
10
+ constructor(config: RuleEngineConfig);
11
+ /**
12
+ * Procesa un evento con contexto completo (sobrescribe el método padre)
13
+ * Agrega observabilidad y manejo de estado
14
+ */
15
+ processEvent(context: TriggerContext): Promise<TriggerResult[]>;
16
+ /**
17
+ * Método convenience para procesar eventos simples
18
+ * Usa el método renombrado del padre
19
+ */
20
+ processEventSimple(eventType: string, data?: Record<string, any>, globals?: Record<string, any>): Promise<TriggerResult[]>;
21
+ /**
22
+ * Ejecuta acciones usando el ActionRegistry
23
+ */
24
+ private executeRuleActionsWithRegistry;
25
+ /**
26
+ * Ejecuta una acción individual usando el ActionRegistry
27
+ */
28
+ private executeSingleActionWithRegistry;
29
+ /**
30
+ * Actualiza el tiempo de última ejecución de una regla
31
+ */
32
+ private updateLastExecution;
33
+ /**
34
+ * Sobrescribe getStateContext para usar StateManager
35
+ */
36
+ protected getStateContext(): Record<string, any>;
37
+ /**
38
+ * Sobrescribe shouldEvaluateAll para usar la configuración
39
+ */
40
+ protected shouldEvaluateAll(): boolean;
41
+ /**
42
+ * Sobrescribe executeRuleActions para usar el registry
43
+ */
44
+ protected executeRuleActions(actionConfig: any, context: TriggerContext): Promise<TriggerResult['executedActions']>;
45
+ /**
46
+ * Sobrescribe executeSingleAction para usar el registry
47
+ */
48
+ protected executeSingleAction(action: any, context: TriggerContext): Promise<TriggerResult['executedActions'][0]>;
49
+ }
50
+ export { RuleEngine as AdvancedEngine };
51
+ //# sourceMappingURL=rule-engine-new.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-engine-new.d.ts","sourceRoot":"","sources":["../../src/core/rule-engine-new.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAEV,cAAc,EACd,aAAa,EACb,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAKjD,qBAAa,UAAW,SAAQ,aAAa;IAC3C,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,YAAY,CAAe;gBAEvB,MAAM,EAAE,gBAAgB;IASpC;;;OAGG;IACY,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAmE9E;;;OAGG;IACY,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAWjJ;;OAEG;YACW,8BAA8B;IA2C5C;;OAEG;YACW,+BAA+B;IAsD7C;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAK3B;;OAEG;cACgB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAIzD;;OAEG;cACgB,iBAAiB,IAAI,OAAO;IAI/C;;OAEG;cACsB,kBAAkB,CACzC,YAAY,EAAE,GAAG,EACjB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAI5C;;OAEG;cACsB,mBAAmB,CAC1C,MAAM,EAAE,GAAG,EACX,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;CAGhD;AAGD,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * TriggerEngine - Motor base platform-agnostic
3
+ * Proporciona funcionalidad básica de procesamiento de reglas
4
+ * Puede ser extendido para agregar características adicionales
5
+ */
6
+ import type { TriggerRule, TriggerContext, TriggerResult, Action, ActionGroup, RuleCondition, RuleEngineConfig } from "../types";
7
+ export type EngineActionHandler = (params: any, context: TriggerContext) => Promise<any> | any;
8
+ export declare class TriggerEngine {
9
+ protected _rules: TriggerRule[];
10
+ protected actionHandlers: Map<string, EngineActionHandler>;
11
+ protected lastExecution: Map<string, number>;
12
+ protected _config?: RuleEngineConfig;
13
+ /**
14
+ * Constructor base - puede recibir reglas directamente o config
15
+ */
16
+ constructor(rulesOrConfig?: TriggerRule[] | RuleEngineConfig);
17
+ /**
18
+ * Ordena reglas por prioridad (mayor primero)
19
+ */
20
+ protected sortRules(): void;
21
+ /**
22
+ * Registra un handler para un tipo de acción específico
23
+ */
24
+ registerAction(type: string, handler: EngineActionHandler): void;
25
+ /**
26
+ * Procesa un evento con contexto completo
27
+ */
28
+ processEvent(context: TriggerContext): Promise<TriggerResult[]>;
29
+ /**
30
+ * Método convenience para procesar eventos simples
31
+ * Renombrado para evitar conflicto con processEvent(context)
32
+ */
33
+ processEventSimple(eventType: string, data?: Record<string, any>, globals?: Record<string, any>): Promise<TriggerResult[]>;
34
+ /**
35
+ * Actualiza las reglas del motor
36
+ */
37
+ updateRules(newRules: TriggerRule[]): void;
38
+ /**
39
+ * Obtiene todas las reglas actuales
40
+ */
41
+ getRules(): TriggerRule[];
42
+ /**
43
+ * Verifica si una regla está en cooldown
44
+ */
45
+ protected checkCooldown(ruleId: string, cooldown: number): boolean;
46
+ /**
47
+ * Determina si se deben evaluar todas las reglas o solo la primera coincidente
48
+ */
49
+ protected shouldEvaluateAll(): boolean;
50
+ /**
51
+ * Obtiene el contexto de estado (puede ser sobrescrito por subclases)
52
+ */
53
+ protected getStateContext?(): Record<string, any>;
54
+ /**
55
+ * Evalúa condiciones de una regla
56
+ */
57
+ protected evaluateConditions(condition: RuleCondition | RuleCondition[] | undefined, context: TriggerContext): boolean;
58
+ /**
59
+ * Evalúa una condición individual
60
+ */
61
+ protected evaluateSingleCondition(cond: RuleCondition, context: TriggerContext): boolean;
62
+ /**
63
+ * Ejecuta las acciones de una regla
64
+ */
65
+ protected executeRuleActions(actionConfig: Action | Action[] | ActionGroup, context: TriggerContext): Promise<TriggerResult['executedActions']>;
66
+ /**
67
+ * Ejecuta una acción individual
68
+ */
69
+ protected executeSingleAction(action: Action, context: TriggerContext): Promise<TriggerResult['executedActions'][0]>;
70
+ /**
71
+ * Interpola parámetros con variables del contexto
72
+ */
73
+ protected interpolateParams(params: Record<string, any>, context: TriggerContext): Record<string, any>;
74
+ /**
75
+ * Interpolación recursiva para objetos anidados
76
+ */
77
+ protected interpolateDeep(obj: any, context: TriggerContext): any;
78
+ get rules(): TriggerRule[];
79
+ get config(): RuleEngineConfig | undefined;
80
+ set rules(newRules: TriggerRule[]);
81
+ }
82
+ export type { TriggerEngine as BaseEngine };
83
+ //# sourceMappingURL=trigger-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-engine.d.ts","sourceRoot":"","sources":["../../src/core/trigger-engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,MAAM,EACN,WAAW,EACX,aAAa,EAGb,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAMlB,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAE/F,qBAAa,aAAa;IACxB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,CAAM;IACrC,SAAS,CAAC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAa;IACvE,SAAS,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IACzD,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAErC;;OAEG;gBACS,aAAa,GAAE,WAAW,EAAE,GAAG,gBAAqB;IAYhE;;OAEG;IACH,SAAS,CAAC,SAAS,IAAI,IAAI;IAI3B;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAIhE;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAoCrE;;;OAGG;IACG,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,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