Skip to content

Instantly share code, notes, and snippets.

@jxub
Created March 3, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jxub/639f9267c2fac3316485ff7194fa915e to your computer and use it in GitHub Desktop.
Save jxub/639f9267c2fac3316485ff7194fa915e to your computer and use it in GitHub Desktop.
Simple typings for the node-rules package (https://github.com/mithunsatheesh/node-rules)
declare module 'node-rules' {
export default class RuleEngine {
constructor(rules?: Rule[] | Rule, options?: object);
register(rule: Rule): any;
sync(): Rule[] | void;
execute(fact: {[x: string]: any}, cb: (data: {result?: any, reason?: any, [x: string]: any}) => void): void;
findRules(filter?: any): Rule[] | void;
turn(state: string, filter: any): Rule[] | void;
prioritize(priority: number, filter: any): Rule[] | void;
toJSON(): string;
fromJSON(rules: string): any;
rule(): Rule | void;
when(condition: any): void;
restart(): any;
stop(): void;
next(): any;
}
export interface Rule {
name: string;
priority?: number;
condition: (R: RuleEngine) => void;
consequence: (R: RuleEngine) => void;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment