2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Expressions.Contracts;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Expressions.Models;
|
2023-11-14 19:44:42 +00:00
|
|
|
using Elsa.Extensions;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.JavaScript.Expressions;
|
2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Workflows.Core.Contracts;
|
2023-11-14 19:44:42 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2022-01-11 12:28:21 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
namespace Elsa.JavaScript.Providers;
|
2022-01-11 12:28:21 +00:00
|
|
|
|
2023-11-14 19:44:42 +00:00
|
|
|
internal class JavaScriptExpressionDescriptorProvider : IExpressionDescriptorProvider
|
2022-01-11 12:28:21 +00:00
|
|
|
{
|
2023-11-14 19:44:42 +00:00
|
|
|
private const string TypeName = "JavaScript";
|
2022-01-11 12:28:21 +00:00
|
|
|
|
2023-11-14 19:44:42 +00:00
|
|
|
public ValueTask<IEnumerable<ExpressionDescriptor>> GetDescriptorsAsync(CancellationToken cancellationToken = default)
|
2022-01-11 12:28:21 +00:00
|
|
|
{
|
|
|
|
|
var javaScript = CreateJavaScriptDescriptor();
|
|
|
|
|
|
2023-11-14 19:44:42 +00:00
|
|
|
return ValueTask.FromResult<IEnumerable<ExpressionDescriptor>>(new[] { javaScript });
|
2022-01-11 12:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
2023-11-14 19:44:42 +00:00
|
|
|
private static ExpressionDescriptor CreateJavaScriptDescriptor() => new()
|
2022-01-12 10:43:46 +00:00
|
|
|
{
|
2023-11-14 19:44:42 +00:00
|
|
|
Type = TypeName,
|
|
|
|
|
DisplayName = "JavaScript",
|
|
|
|
|
Properties = new { MonacoLanguage = "javascript" }.ToDictionary(),
|
|
|
|
|
HandlerFactory = ActivatorUtilities.GetServiceOrCreateInstance<JavaScriptExpressionHandler>
|
2022-01-12 10:43:46 +00:00
|
|
|
};
|
2022-01-11 12:28:21 +00:00
|
|
|
}
|