| | | 1 | | using Elsa.Expressions.JavaScript.Contracts; |
| | | 2 | | using Elsa.Expressions.JavaScript.Helpers; |
| | | 3 | | using Elsa.Expressions.JavaScript.Options; |
| | | 4 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Abstractions; |
| | | 5 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Models; |
| | | 6 | | using Elsa.Workflows.Activities; |
| | | 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 InputFunctionsDefinitionProvider(ITypeAliasRegistry typeAliasRegistry, IOptions<JintOptions> options) : F |
| | | 18 | | { |
| | | 19 | | protected override ValueTask<IEnumerable<FunctionDefinition>> GetFunctionDefinitionsAsync(TypeDefinitionContext cont |
| | | 20 | | { |
| | 0 | 21 | | if(options.Value.DisableWrappers) |
| | 0 | 22 | | return ValueTask.FromResult<IEnumerable<FunctionDefinition>>([]); |
| | | 23 | | |
| | 0 | 24 | | var workflow = context.WorkflowGraph.Workflow; |
| | 0 | 25 | | return ValueTask.FromResult(GetFunctionDefinitionsAsync(workflow)); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | private IEnumerable<FunctionDefinition> GetFunctionDefinitionsAsync(Workflow workflow) |
| | | 29 | | { |
| | | 30 | | // Input argument getters. |
| | 0 | 31 | | foreach (var input in workflow.Inputs.Where(x => VariableNameValidator.IsValidVariableName(x.Name))) |
| | | 32 | | { |
| | 0 | 33 | | var pascalName = input.Name.Pascalize(); |
| | 0 | 34 | | var variableType = input.Type; |
| | 0 | 35 | | var typeAlias = typeAliasRegistry.TryGetAlias(variableType, out var alias) ? alias : "any"; |
| | | 36 | | |
| | | 37 | | // get{Input}. |
| | 0 | 38 | | yield return CreateFunctionDefinition(builder => builder.Name($"get{pascalName}").ReturnType(typeAlias)); |
| | | 39 | | } |
| | 0 | 40 | | } |
| | | 41 | | } |