| | | 1 | | using Elsa.Extensions; |
| | | 2 | | using Elsa.Expressions.JavaScript.Extensions; |
| | | 3 | | using Elsa.Expressions.JavaScript.Options; |
| | | 4 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Abstractions; |
| | | 5 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Models; |
| | | 6 | | using Elsa.Workflows; |
| | | 7 | | using Humanizer; |
| | | 8 | | using JetBrains.Annotations; |
| | | 9 | | using Microsoft.Extensions.Options; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Expressions.JavaScript.Providers; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Produces <see cref="FunctionDefinition"/>s for common functions. |
| | | 15 | | /// </summary> |
| | | 16 | | [UsedImplicitly] |
| | 1 | 17 | | internal class ActivityOutputFunctionsDefinitionProvider(IActivityRegistryLookupService activityRegistryLookup, IOptions |
| | | 18 | | { |
| | | 19 | | protected override async ValueTask<IEnumerable<FunctionDefinition>> GetFunctionDefinitionsAsync(TypeDefinitionContex |
| | | 20 | | { |
| | 0 | 21 | | if(options.Value.DisableWrappers) |
| | 0 | 22 | | return []; |
| | | 23 | | |
| | 0 | 24 | | var nodes = context.WorkflowGraph.Nodes; |
| | 0 | 25 | | var activitiesWithOutputs = nodes.GetActivitiesWithOutputs(activityRegistryLookup).Where(x => x.activity.Name != |
| | 0 | 26 | | var definitions = new List<FunctionDefinition>(); |
| | | 27 | | |
| | 0 | 28 | | await foreach (var (activity, activityDescriptor) in activitiesWithOutputs) |
| | | 29 | | { |
| | 0 | 30 | | definitions.AddRange(from output in activityDescriptor.Outputs.Where(x => x.Name.IsValidVariableName()) |
| | 0 | 31 | | select output.Name.Pascalize() |
| | 0 | 32 | | into outputPascalName |
| | 0 | 33 | | let activityNamePascalName = activity.Name.Pascalize() |
| | 0 | 34 | | select CreateFunctionDefinition(builder => builder.Name($"get{outputPascalName}From{activityNamePascalNa |
| | | 35 | | } |
| | | 36 | | |
| | 0 | 37 | | return definitions; |
| | 0 | 38 | | } |
| | | 39 | | } |