/* * @Author: 陶秋峰 * @Date: 2015-10-15 17:00:14 * @Last Modified by: 陶秋峰 * @Last Modified time: 2015-10-20 11:38:36 * @CopyRight */ declare module 'nools' { module e{ interface FlowContainer { compile(source: string, options: { name?: string; define?: any; // define?: { (cls: string): any }; scope?: any; }, callback?: Function): FlowContainer; compile(source: string, callback?: Function): FlowContainer; getFlow(name: string): FlowContainer; flow(s: string, rule?: Function): FlowContainer; hasFlow(name: string): boolean; deleteFlow(name: string): FlowContainer; deleteFlows(...name: string[]): FlowContainer; name:string; } interface FlowContainer { rule(name: string, conditions: any[], then: Function); addDefined(name: string, cls: any): any; getDefined(name: string): any; getSession(...facts: any[]): Session; conflictResolution(strategies: string[]); } interface AVLTree{ // todo } interface Agenda{ agendaGroupStack: string[]; addAgendaGroup(groupName: string): void; getAgendaGroup(groupName: string): AVLTree; setFocus(agendaGroup: string): Agenda; getFocused(): string; getFocusedAgenda(): AVLTree; register(node): void; isEmpty(): boolean; fireNext(): boolean | promise; pop(): AVLTree; peek(): AVLTree; modify(node, context): void; retract(node, retract): void; insert(node, insert): void; dispose(): void; } interface Session { agenda: Agenda; assert(fact: any): any; retract(fact: any): any; modify(fact: any, cb?: Function): any; focus(fact: any): Session; halt(fact: any): Session; print(): void; on(evt: string, callback: Function): Session; /** * fire the rules * @param {Function} callback [description] */ match(callback?: Function): promise; matchUntilHalt(callback?: Function): promise; containsRule(name: string): boolean; rule(rule): void; getFacts(type): any[]; getFact(type): any; dispose(): void; } interface promise{ addCallback(cb: Function | promise): promise; addErrback(cb: Function | promise): promise; callback(args?: any): promise; errback(args?: any): promise; resolve(err?: any, args?: any): promise; classic(cb: Function): promise; callback(args?: any): promise; then(callback?: Function, err_callback?: Function): promise; both(callback?: Function): promise; promise(): promise; } } var e: e.FlowContainer; export = e; } /* Pattern(optional) - The pattern that should evaluate to a boolean, the alias that was used should be used to reference the object in the pattern. Strings should be in single quotes, regular expressions are allowed. Any previously defined alias/reference can be used within the pattern. Available operators are. &&, AND, and ||, OR, or >, <, >=, <=, gt, lt, gte, lte ==, ===, !=, !==, =~, !=~, eq, seq, neq, sneq, like, notLike +, -, *, /, % - (unary minus) . (member operator) in (check inclusion in an array) notIn (check that something is not in an array) Defined helper functions now - the current date Date(year?, month?, day?, hour?, minute?, second?, ms?) - creates a new Date object lengthOf(arr, length) - checks the length of an array isTrue(something) - check if something === true isFalse(something) - check if something === false isRegExp(something) - check if something is a RegExp isArray(something) - check if something is an Array isNumber(something) - check if something is an Number isHash(something) - check if something is strictly an Object isObject(something) - check if something is any type of Object isDate(something) - check if something is a Date isBoolean(something) - check if something is a Boolean isString(something) - check if something is a String isUndefined(something) - check if something is a undefined isDefined(something) - check if something is Defined isUndefinedOrNull(something) - check if something is a undefined or null isPromiseLike(something) - check if something is a "promise" like (containing then, addCallback, addErrback) isFunction(something) - check if something is a Function isNull(something) - check if something is null isNotNull(something) - check if something is not null dateCmp(dt1, dt2) - compares two dates return 1, -1, or 0 (years|months|days|hours|minutes|seconds)(Ago|FromNow)(interval) - adds/subtracts the date unit from the current time */