2025-05-20 11:38:24 +00:00
|
|
|
using Elsa.Caching.Features;
|
2026-05-31 09:09:39 +00:00
|
|
|
using Elsa.Expressions.Options;
|
2025-05-20 11:38:24 +00:00
|
|
|
using Elsa.Common.Features;
|
|
|
|
|
using Elsa.Expressions.Features;
|
|
|
|
|
using Elsa.Extensions;
|
|
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Attributes;
|
|
|
|
|
using Elsa.Features.Services;
|
2025-05-20 11:52:19 +00:00
|
|
|
using Elsa.Expressions.JavaScript.Activities;
|
|
|
|
|
using Elsa.Expressions.JavaScript.Contracts;
|
|
|
|
|
using Elsa.Expressions.JavaScript.Extensions;
|
|
|
|
|
using Elsa.Expressions.JavaScript.HostedServices;
|
|
|
|
|
using Elsa.Expressions.JavaScript.Options;
|
|
|
|
|
using Elsa.Expressions.JavaScript.Providers;
|
|
|
|
|
using Elsa.Expressions.JavaScript.Services;
|
|
|
|
|
using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts;
|
|
|
|
|
using Elsa.Expressions.JavaScript.TypeDefinitions.Services;
|
2025-05-20 11:38:24 +00:00
|
|
|
using Elsa.Workflows;
|
2026-05-31 09:09:39 +00:00
|
|
|
using Elsa.Workflows.Options;
|
2025-05-20 11:38:24 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-05-31 09:09:39 +00:00
|
|
|
using Elsa.Common.Serialization;
|
2025-05-20 11:38:24 +00:00
|
|
|
|
2025-05-20 11:52:19 +00:00
|
|
|
namespace Elsa.Expressions.JavaScript.Features;
|
2025-05-20 11:38:24 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Installs JavaScript integration.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DependsOn(typeof(MediatorFeature))]
|
|
|
|
|
[DependsOn(typeof(ExpressionsFeature))]
|
|
|
|
|
[DependsOn(typeof(MemoryCacheFeature))]
|
|
|
|
|
public class JavaScriptFeature : FeatureBase
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public JavaScriptFeature(IModule module) : base(module)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the Jint options.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Action<JintOptions> JintOptions { get; set; } = _ => { };
|
|
|
|
|
|
|
|
|
|
public JavaScriptFeature ConfigureJintOptions(Action<JintOptions> configure)
|
|
|
|
|
{
|
|
|
|
|
JintOptions += configure;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void ConfigureHostedServices()
|
|
|
|
|
{
|
|
|
|
|
ConfigureHostedService<RegisterVariableTypesWithJavaScriptHostedService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Configure()
|
|
|
|
|
{
|
|
|
|
|
Module.AddFastEndpointsAssembly<JavaScriptFeature>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Apply()
|
|
|
|
|
{
|
|
|
|
|
Services.Configure(JintOptions);
|
2026-05-31 09:09:39 +00:00
|
|
|
Services.Configure<ExpressionOptions>(JavaScriptExceptionTypeAliasRegistrar.Register);
|
|
|
|
|
Services.Configure<SerializationTypeOptions>(JavaScriptExceptionTypeAliasRegistrar.Register);
|
2025-05-20 11:38:24 +00:00
|
|
|
|
|
|
|
|
// JavaScript services.
|
|
|
|
|
Services
|
|
|
|
|
.AddScoped<IJavaScriptEvaluator, JintJavaScriptEvaluator>()
|
|
|
|
|
.AddScoped<ITypeDefinitionService, TypeDefinitionService>()
|
|
|
|
|
.AddExpressionDescriptorProvider<JavaScriptExpressionDescriptorProvider>()
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
// Type definition services.
|
|
|
|
|
Services
|
|
|
|
|
.AddScoped<ITypeDefinitionService, TypeDefinitionService>()
|
|
|
|
|
.AddScoped<ITypeDescriber, TypeDescriber>()
|
|
|
|
|
.AddScoped<ITypeDefinitionDocumentRenderer, TypeDefinitionDocumentRenderer>()
|
2026-05-31 09:09:39 +00:00
|
|
|
.AddSingleton<ITypeAliasRegistry, Services.TypeAliasRegistry>()
|
2025-05-20 11:38:24 +00:00
|
|
|
.AddFunctionDefinitionProvider<CommonFunctionsDefinitionProvider>()
|
|
|
|
|
.AddFunctionDefinitionProvider<ActivityOutputFunctionsDefinitionProvider>()
|
|
|
|
|
.AddFunctionDefinitionProvider<RunJavaScriptFunctionsDefinitionProvider>()
|
|
|
|
|
.AddTypeDefinitionProvider<CommonTypeDefinitionProvider>()
|
|
|
|
|
.AddTypeDefinitionProvider<VariableTypeDefinitionProvider>()
|
|
|
|
|
.AddTypeDefinitionProvider<WorkflowVariablesTypeDefinitionProvider>()
|
|
|
|
|
.AddVariableDefinitionProvider<WorkflowVariablesVariableProvider>()
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
// Handlers.
|
|
|
|
|
Services.AddNotificationHandlersFrom<JavaScriptFeature>();
|
|
|
|
|
|
|
|
|
|
// Activities.
|
|
|
|
|
Module.UseWorkflowManagement(management => management.AddActivity<RunJavaScript>());
|
|
|
|
|
|
|
|
|
|
// Type Script definitions.
|
|
|
|
|
Services.AddFunctionDefinitionProvider<InputFunctionsDefinitionProvider>();
|
|
|
|
|
|
|
|
|
|
// UI property handlers.
|
|
|
|
|
Services.AddScoped<IPropertyUIHandler, RunJavaScriptOptionsProvider>();
|
|
|
|
|
}
|
2026-05-31 09:09:39 +00:00
|
|
|
}
|