From 933105f55f0ef08a61c543a1a76e2197b9557958 Mon Sep 17 00:00:00 2001 From: Emile Fokkema Date: Thu, 21 Nov 2024 22:37:58 +0100 Subject: [PATCH 1/3] call Rule.ruleEvent by its correct name --- types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 6dea6b8..0f88c83 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,7 +28,7 @@ export default function engineFactory( export class Engine { constructor(rules?: Array, options?: EngineOptions); - addRule(rule: RuleProperties): this; + addRule(rule: RuleProperties | Rule): this; removeRule(ruleOrName: Rule | string): boolean; updateRule(rule: Rule): void; @@ -171,11 +171,11 @@ export interface RuleResult { ): T extends true ? string : RuleResultSerializable; } -export class Rule implements RuleProperties { +export class Rule { constructor(ruleProps: RuleProperties | string); name: string; conditions: TopLevelCondition; - event: Event; + ruleEvent: Event; priority: number; setConditions(conditions: TopLevelCondition): this; setEvent(event: Event): this; From 16a80a7af4e610b51c8f7d348a0ac56bb2d9beca Mon Sep 17 00:00:00 2001 From: Emile Fokkema <146825801+emilefokkemanavara@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:23:45 +0000 Subject: [PATCH 2/3] let Rule have both event and ruleEvent --- src/rule.js | 1 + test/rule.test.js | 4 ++++ types/index.d.ts | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rule.js b/src/rule.js index 3d52fbf..98007e8 100644 --- a/src/rule.js +++ b/src/rule.js @@ -101,6 +101,7 @@ class Rule extends EventEmitter { this.ruleEvent = { type: event.type } + this.event = this.ruleEvent if (event.params) this.ruleEvent.params = event.params return this } diff --git a/test/rule.test.js b/test/rule.test.js index fc3357b..75a5fee 100644 --- a/test/rule.test.js +++ b/test/rule.test.js @@ -30,6 +30,7 @@ describe('Rule', () => { expect(rule.priority).to.eql(opts.priority) expect(rule.conditions).to.eql(opts.conditions) expect(rule.ruleEvent).to.eql(opts.event) + expect(rule.event).to.eql(opts.event) expect(rule.name).to.eql(opts.name) }) @@ -52,6 +53,7 @@ describe('Rule', () => { expect(rule.priority).to.eql(opts.priority) expect(rule.conditions).to.eql(opts.conditions) expect(rule.ruleEvent).to.eql(opts.event) + expect(rule.event).to.eql(opts.event) expect(rule.name).to.eql(opts.name) }) }) @@ -322,6 +324,7 @@ describe('Rule', () => { expect(hydratedRule.conditions).to.eql(rule.conditions) expect(hydratedRule.priority).to.eql(rule.priority) expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent) + expect(hydratedRule.event).to.eql(rule.event) expect(hydratedRule.name).to.eql(rule.name) }) @@ -333,6 +336,7 @@ describe('Rule', () => { expect(hydratedRule.conditions).to.eql(rule.conditions) expect(hydratedRule.priority).to.eql(rule.priority) expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent) + expect(hydratedRule.event).to.eql(rule.event) expect(hydratedRule.name).to.eql(rule.name) }) }) diff --git a/types/index.d.ts b/types/index.d.ts index 0f88c83..2153f99 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,7 +28,7 @@ export default function engineFactory( export class Engine { constructor(rules?: Array, options?: EngineOptions); - addRule(rule: RuleProperties | Rule): this; + addRule(rule: RuleProperties): this; removeRule(ruleOrName: Rule | string): boolean; updateRule(rule: Rule): void; @@ -171,11 +171,12 @@ export interface RuleResult { ): T extends true ? string : RuleResultSerializable; } -export class Rule { +export class Rule implements RuleProperties { constructor(ruleProps: RuleProperties | string); name: string; conditions: TopLevelCondition; ruleEvent: Event; + event: Event priority: number; setConditions(conditions: TopLevelCondition): this; setEvent(event: Event): this; From 72d7b1aa1c806d1ed96763e6e3cbefec6d917ee6 Mon Sep 17 00:00:00 2001 From: Emile Fokkema <146825801+emilefokkemanavara@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:09:19 +0000 Subject: [PATCH 3/3] deprecate `ruleEvent` property --- types/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/index.d.ts b/types/index.d.ts index 2153f99..aaa22f8 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -175,6 +175,9 @@ export class Rule implements RuleProperties { constructor(ruleProps: RuleProperties | string); name: string; conditions: TopLevelCondition; + /** + * @deprecated Use {@link Rule.event} instead. + */ ruleEvent: Event; event: Event priority: number;