@o3r/rules-engine
Version:
This module provides a rule engine that can be executed on your Otter application to customize your application (translations, placeholders and configs) based on a json file generated by your CMS.
85 lines • 3.35 kB
TypeScript
import { logging } from '@angular-devkit/core';
import * as ts from 'typescript';
import { Action, MetadataFact, MetadataOperator } from './rules-engine.extractor.interfaces';
/**
* Extracts rules engine facts and operator from code
*/
export declare class RulesEngineExtractor {
private readonly basePath;
private readonly logger;
/** Interface of a Fact definition */
static readonly FACT_DEFINITIONS_INTERFACE = "FactDefinitions";
/** Interface of an operator definition */
static readonly OPERATOR_DEFINITIONS_INTERFACES: string[];
/** Interface of an action definition */
static readonly OPERATOR_ACTIONS_INTERFACE = "RulesEngineAction";
/** Reserved fact names that will be filtered out of metadata */
static readonly RESERVED_FACT_NAMES: string[];
/** TSConfig to parse the code */
private readonly tsconfig;
/** Instance of the comment parser */
private readonly commentParser;
constructor(tsconfigPath: string, basePath: string, logger: logging.LoggerApi);
/**
* Extract type definition of a type reference into schema file
* @param type Name of the type to extract
* @param sourceFile path to the code source file
*/
private extractTypeRef;
/**
* Extract the type node used to generate the type metadata.
* In the case of an array, it will look for the child node with the relevant information
* @param typeNode
* @private
*/
private extractTypeNode;
/**
* Return the list of types matching the type node. If the type is not supported, it will be replaced with an unknown entry
* @param type
* @param source
* @private
*/
private extractSimpleTypesData;
/**
* Return the nbValue number associated to the simple type.
* If it is an array, it will be -1
* If it is an unknown type (or any), it will return 0
* If it is any other type of object it will return 1
* @param type
* @private
*/
private getTypeNbValue;
/**
* Construct a metadata object that will describe the operator hand type as a list of types and a nbValue describing
* the structure of the operand
* nbValue reflects whether the operand support a single object (1), an array (-1), both (0) or a n-tuple (n)
* @param type
* @param source
* @param nbValue
* @private
*/
private extractComplexTypeData;
/**
* Extract facts from source code
* @param sourceFile path to the code source file
* @param schemaFolderFullPath full path to the schema folder
* @param schemaFolderRelativePath path to the schema folder from the metadata file
*/
extractFacts(sourceFile: string, schemaFolderFullPath: string, schemaFolderRelativePath: string): Promise<MetadataFact[]>;
/**
* Check if typescript type node is a native type or a list of native element
* @param type
*/
isNativeType(type: ts.TypeNode): boolean;
/**
* Extract operators from source code
* @param sourceFile path to the code source file
*/
extractOperators(sourceFile: string): MetadataOperator[];
/**
* Not used for the moment, kept for later updates
* @param sourceFile
*/
extractActions(sourceFile: string): Action[];
}
//# sourceMappingURL=rules-engine.extractor.d.ts.map