mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
22 lines
701 B
TypeScript
22 lines
701 B
TypeScript
import { Tournament } from '@n8n/tournament';
|
|
|
|
import { PrototypeSanitizer } from './ExpressionSandboxing';
|
|
|
|
type Evaluator = (expr: string, data: unknown) => string | null | (() => unknown);
|
|
type ErrorHandler = (error: Error) => void;
|
|
|
|
const errorHandler: ErrorHandler = () => {};
|
|
const tournamentEvaluator = new Tournament(errorHandler, undefined, undefined, {
|
|
before: [],
|
|
after: [PrototypeSanitizer],
|
|
});
|
|
const evaluator: Evaluator = tournamentEvaluator.execute.bind(tournamentEvaluator);
|
|
|
|
export const setErrorHandler = (handler: ErrorHandler) => {
|
|
tournamentEvaluator.errorHandler = handler;
|
|
};
|
|
|
|
export const evaluateExpression: Evaluator = (expr, data) => {
|
|
return evaluator(expr, data);
|
|
};
|