UNPKG

kangaroo-expression

Version:

Secure expression evaluator with AST-based execution - A fast, safe, and powerful JavaScript-like expression language

61 lines 2.38 kB
import type { Node } from 'acorn'; import type { ExpressionContext, EvaluationResult, FunctionRegistry } from '@/types'; export interface ExecutionOptions { timeout?: number; maxStackDepth?: number; collectMetrics?: boolean; enableDebugging?: boolean; errorHandler?: (error: Error, node: Node, context: ExpressionContext) => any | undefined; } export interface ArrayOperations { filter(array: any[], callbackNode: Node, context: ExpressionContext): any[]; map(array: any[], callbackNode: Node, context: ExpressionContext): any[]; find(array: any[], callbackNode: Node, context: ExpressionContext): any; some(array: any[], callbackNode: Node, context: ExpressionContext): boolean; every(array: any[], callbackNode: Node, context: ExpressionContext): boolean; reduce(array: any[], callbackNode: Node, initialValue: any, context: ExpressionContext): any; } export declare class ASTExecutor { private functionRegistry; private arrayOperations; private executionStack; private startTime; private options; private propertyCache; private cacheSize; private readonly maxCacheSize; private stats; constructor(functionRegistry: FunctionRegistry, options?: ExecutionOptions); setArrayOperations(arrayOperations: ArrayOperations): void; execute(node: Node, context?: ExpressionContext, options?: ExecutionOptions): EvaluationResult; getStats(): typeof this.stats; resetStats(): void; clearCache(): void; private executeNode; private executeLiteral; private executeIdentifier; private executeMemberExpression; private executeCallExpression; private executeBinaryExpression; private executeLogicalExpression; private executeConditionalExpression; private executeUnaryExpression; private executeArrayExpression; private executeObjectExpression; private executeFunction; private executeMethod; private executeCallbackMethod; private validateFunctionCall; private safePropertyAccess; private isCallbackMethod; private getMethodName; private getFullMethodName; private checkTimeout; private checkStackDepth; private categorizeError; private calculateNodeComplexity; private extractAccessedVariables; private extractCalledFunctions; private setCached; } //# sourceMappingURL=executor.d.ts.map