| | | 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 JetBrains.Annotations; |
| | | 7 | | using Microsoft.Extensions.Options; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Expressions.JavaScript.Providers; |
| | | 10 | | |
| | | 11 | | [UsedImplicitly] |
| | 1 | 12 | | internal class WorkflowVariablesTypeDefinitionProvider(IOptions<JintOptions> options) : TypeDefinitionProvider |
| | | 13 | | { |
| | | 14 | | protected override IEnumerable<TypeDefinition> GetTypeDefinitions(TypeDefinitionContext context) |
| | | 15 | | { |
| | 0 | 16 | | if(options.Value.DisableWrappers) |
| | 0 | 17 | | yield break; |
| | | 18 | | |
| | 0 | 19 | | var variables = context.WorkflowGraph.Workflow.Variables; |
| | | 20 | | |
| | 0 | 21 | | var workflowTypeDefinition = new TypeDefinition |
| | 0 | 22 | | { |
| | 0 | 23 | | Name = "WorkflowVariables", |
| | 0 | 24 | | DeclarationKeyword = "class" |
| | 0 | 25 | | }; |
| | | 26 | | |
| | 0 | 27 | | foreach (var variable in variables.Where(x => x.Name.IsValidVariableName())) |
| | | 28 | | { |
| | 0 | 29 | | var variableType = variable.GetVariableType(); |
| | 0 | 30 | | workflowTypeDefinition.Properties.Add(new PropertyDefinition |
| | 0 | 31 | | { |
| | 0 | 32 | | Name = variable.Name, |
| | 0 | 33 | | Type = variableType.Name |
| | 0 | 34 | | }); |
| | | 35 | | } |
| | | 36 | | |
| | 0 | 37 | | yield return workflowTypeDefinition; |
| | 0 | 38 | | } |
| | | 39 | | } |