| | | 1 | | using Elsa.Caching.Features; |
| | | 2 | | using Elsa.Common.Features; |
| | | 3 | | using Elsa.Expressions.Features; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using Elsa.Features.Abstractions; |
| | | 6 | | using Elsa.Features.Attributes; |
| | | 7 | | using Elsa.Features.Services; |
| | | 8 | | using Elsa.Expressions.JavaScript.Activities; |
| | | 9 | | using Elsa.Expressions.JavaScript.Contracts; |
| | | 10 | | using Elsa.Expressions.JavaScript.Extensions; |
| | | 11 | | using Elsa.Expressions.JavaScript.HostedServices; |
| | | 12 | | using Elsa.Expressions.JavaScript.Options; |
| | | 13 | | using Elsa.Expressions.JavaScript.Providers; |
| | | 14 | | using Elsa.Expressions.JavaScript.Services; |
| | | 15 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts; |
| | | 16 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Services; |
| | | 17 | | using Elsa.Workflows; |
| | | 18 | | using Microsoft.Extensions.DependencyInjection; |
| | | 19 | | |
| | | 20 | | namespace Elsa.Expressions.JavaScript.Features; |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Installs JavaScript integration. |
| | | 24 | | /// </summary> |
| | | 25 | | [DependsOn(typeof(MediatorFeature))] |
| | | 26 | | [DependsOn(typeof(ExpressionsFeature))] |
| | | 27 | | [DependsOn(typeof(MemoryCacheFeature))] |
| | | 28 | | public class JavaScriptFeature : FeatureBase |
| | | 29 | | { |
| | | 30 | | /// <inheritdoc /> |
| | 235 | 31 | | public JavaScriptFeature(IModule module) : base(module) |
| | | 32 | | { |
| | 235 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Configures the Jint options. |
| | | 37 | | /// </summary> |
| | 575 | 38 | | private Action<JintOptions> JintOptions { get; set; } = _ => { }; |
| | | 39 | | |
| | | 40 | | public JavaScriptFeature ConfigureJintOptions(Action<JintOptions> configure) |
| | | 41 | | { |
| | 2 | 42 | | JintOptions += configure; |
| | 2 | 43 | | return this; |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <inheritdoc /> |
| | | 47 | | public override void ConfigureHostedServices() |
| | | 48 | | { |
| | 235 | 49 | | ConfigureHostedService<RegisterVariableTypesWithJavaScriptHostedService>(); |
| | 235 | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | public override void Configure() |
| | | 54 | | { |
| | 235 | 55 | | Module.AddFastEndpointsAssembly<JavaScriptFeature>(); |
| | 235 | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <inheritdoc /> |
| | | 59 | | public override void Apply() |
| | | 60 | | { |
| | 235 | 61 | | Services.Configure(JintOptions); |
| | | 62 | | |
| | | 63 | | // JavaScript services. |
| | 235 | 64 | | Services |
| | 235 | 65 | | .AddScoped<IJavaScriptEvaluator, JintJavaScriptEvaluator>() |
| | 235 | 66 | | .AddScoped<ITypeDefinitionService, TypeDefinitionService>() |
| | 235 | 67 | | .AddExpressionDescriptorProvider<JavaScriptExpressionDescriptorProvider>() |
| | 235 | 68 | | ; |
| | | 69 | | |
| | | 70 | | // Type definition services. |
| | 235 | 71 | | Services |
| | 235 | 72 | | .AddScoped<ITypeDefinitionService, TypeDefinitionService>() |
| | 235 | 73 | | .AddScoped<ITypeDescriber, TypeDescriber>() |
| | 235 | 74 | | .AddScoped<ITypeDefinitionDocumentRenderer, TypeDefinitionDocumentRenderer>() |
| | 235 | 75 | | .AddSingleton<ITypeAliasRegistry, TypeAliasRegistry>() |
| | 235 | 76 | | .AddFunctionDefinitionProvider<CommonFunctionsDefinitionProvider>() |
| | 235 | 77 | | .AddFunctionDefinitionProvider<ActivityOutputFunctionsDefinitionProvider>() |
| | 235 | 78 | | .AddFunctionDefinitionProvider<RunJavaScriptFunctionsDefinitionProvider>() |
| | 235 | 79 | | .AddTypeDefinitionProvider<CommonTypeDefinitionProvider>() |
| | 235 | 80 | | .AddTypeDefinitionProvider<VariableTypeDefinitionProvider>() |
| | 235 | 81 | | .AddTypeDefinitionProvider<WorkflowVariablesTypeDefinitionProvider>() |
| | 235 | 82 | | .AddVariableDefinitionProvider<WorkflowVariablesVariableProvider>() |
| | 235 | 83 | | ; |
| | | 84 | | |
| | | 85 | | // Handlers. |
| | 235 | 86 | | Services.AddNotificationHandlersFrom<JavaScriptFeature>(); |
| | | 87 | | |
| | | 88 | | // Activities. |
| | 470 | 89 | | Module.UseWorkflowManagement(management => management.AddActivity<RunJavaScript>()); |
| | | 90 | | |
| | | 91 | | // Type Script definitions. |
| | 235 | 92 | | Services.AddFunctionDefinitionProvider<InputFunctionsDefinitionProvider>(); |
| | | 93 | | |
| | | 94 | | // UI property handlers. |
| | 235 | 95 | | Services.AddScoped<IPropertyUIHandler, RunJavaScriptOptionsProvider>(); |
| | 235 | 96 | | } |
| | | 97 | | } |