elsa-core/src/modules/Elsa.JavaScript/Contracts/IJavaScriptEvaluator.cs
Sipke Schoorstra 1e1abfa100 Add support for list/array conversion in JavaScript evaluator
A StringObjectDictionaryConverter has been added, which converts all IList fields of an object to array fields. This enhances the interaction of JS expressions with list types, allowing common Array methods to be applied directly. Furthermore, defaults have been added to the ExpressionEvaluatorOptions parameters to improve usability. Lastly, adjustments were made to ensure variables are correctly set while evaluating expressions.
2024-01-30 21:22:32 +01:00

30 lines
1.2 KiB
C#

using Elsa.Expressions.Models;
using JetBrains.Annotations;
using Jint;
namespace Elsa.JavaScript.Contracts;
/// <summary>
/// Evaluates JavaScript expressions.
/// </summary>
[PublicAPI]
public interface IJavaScriptEvaluator
{
/// <summary>
/// Evaluates a JavaScript expression.
/// </summary>
/// <param name="expression">The expression to evaluate.</param>
/// <param name="returnType">The type of the return value.</param>
/// <param name="context">The context in which the expression is evaluated.</param>
/// <param name="options">The options to use when evaluating the expression.</param>
/// <param name="configureEngine">An optional callback that can be used to configure the JavaScript engine.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The result of the evaluation.</returns>
Task<object?> EvaluateAsync(
string expression,
Type returnType,
ExpressionExecutionContext context,
ExpressionEvaluatorOptions? options = default,
Action<Engine>? configureEngine = default,
CancellationToken cancellationToken = default);
}