import { IInputProvider, IOutputProvider, ICorpusRuleGroup, IClosure, ILogger } from './types'; export interface IRuleHarvesterProviders { inputs: IInputProvider[]; outputs: IOutputProvider[]; corpus: ICorpusRuleGroup[]; closures: IClosure[]; logger?: ILogger; } export interface IRuleHarvesterConfig { providers: IRuleHarvesterProviders; extraContext?: object | null; closureHandlerWrapper?: (facts: any, context: any, handler: (facts: any, context: any) => any | Promise) => any | Promise; fieldDereferenceChar?: string; } export * from './types'; export * from './generators'; export { default as CoreClosures } from './core/closures/index'; export { default as CoreConditionals } from './core/closures/conditionals'; export { default as CoreTransformations } from './core/closures/transformations'; export { default as CoreErrorHandling } from './core/closures/error-handling'; export { default as CoreErrorHandlingHttp } from './core/closures/error-handling-http'; export { default as CoreInputAmqp, ICoreInputAmqpProviderOptions, } from './core/inputs/amqp-input'; export { default as CoreInputHttp, ICoreInputHttpProviderOptions, CoreInputHttpResponseType, } from './core/inputs/http-input'; export { default as CoreInputUdp, ICoreInputUdpProviderOptions, } from './core/inputs/udp-input'; export { default as CoreInputScheduler, ICoreInputSchedulerProviderOptions, } from './core/inputs/scheduler-input'; export { default as CoreOutputAmqp } from './core/outputs/amqp-output'; export { default as CoreOutputAmqpRpc } from './core/outputs/amqp-rpc-output'; export * from './core/types/amqp-types'; export * from './core/types/http-types'; export * from './core/types/udp-types'; export * from './core/types/scheduler-types'; export default class RuleHarvester { providers: IRuleHarvesterProviders; config: IRuleHarvesterConfig; engine: any; logger?: ILogger; fieldDereferenceChar: string; ruleGroups: string[]; extraContext?: object | null; forbiddenExtraContext: string[]; /***************************** * Dereference parameters logic *******************************/ /** * dereferenceString * Pulls a property from facts determined by the path in param. * @param facts * @param param */ dereferenceString(facts: any, param: string): any; /** * dereferenceArray * Pulls an array from facts determined by the path in parameters. * @param facts * @param parameters */ dereferenceArray(facts: any, parameters: any[]): any[]; /** * dereferenceSingleValue * // TODO: Add a good comment about dereferenceSingleValue * @param facts * @param originalValue */ dereferenceSingleValue(facts: any, originalValue: any): any; /** * dereferenceObject * Used to dereference fields within an object. A field is de-referenced if the key begins with a "^" * Call dereferenceSingleValue which does the following * - If values are string then get path from facts object * - If value is an object then call this recursively * - If value is an array then call dereferenceArray * - dereferenceArray uses the leading character of the value to determine if something should be de-referenced or not */ dereferenceObject(facts: any, parameters: any): any; /** * defaultClosureHandlerWrapper * This wraps the closure handler so that we log errors well * * @param name * @param handler * @param options */ defaultClosureHandlerWrapper(name: string, handler: (facts: any, context: any) => any | Promise, options?: any): (facts: any, context: any) => any | Promise; /** * closureHandlerWrapper * This function is a wrapper to allow us to override the context of closure functions. * it wraps the closure handler to supply extra context if the handler is defined. * * @param closure - The defined closure function * @return returns a wrapped closure function **/ private closureHandlerWrapper; /** * Constructor * This function configures the engine. * 1. Setup class variables * @params config: IRuleHarvesterConfig * @returns - None **/ constructor(config: IRuleHarvesterConfig); /** * Setup * This function configures the engine. * 1. Instantiates the engine * 2. Sets up the engine corpus (definitions) * 3. Sets of the closers (Available function closures for the corpus to work from) * @returns - None **/ setup(): void; /** * start the Rules Harvester. * Does this by... * 1. Does this by registering an input handler for each rule input * 2. Run setup input provider to initialize the rules engine * NOTE: Setup is purposely run after registerInput because the input provider should be able to modify the corpus * or configuration during setup * * @params - None * @returns void **/ start(): void; /** * applyRule - Applies the rule to the rules engine * If input is not null then .. * 1. Process rules using the rules engine * 2. Send the resulting facts to the output providers **/ applyRule(input: any, thisRunContext?: any, ruleGroupOverrides?: string[] | undefined): Promise; }