< Summary

Information
Class: Elsa.Expressions.JavaScript.Providers.InputFunctionsDefinitionProvider
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Providers/InputFunctionsDefinitionProvider.cs
Line coverage
9%
Covered lines: 1
Uncovered lines: 10
Coverable lines: 11
Total lines: 41
Line coverage: 9%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetFunctionDefinitionsAsync(...)0%620%
GetFunctionDefinitionsAsync()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Providers/InputFunctionsDefinitionProvider.cs

#LineLine coverage
 1using Elsa.Expressions.JavaScript.Contracts;
 2using Elsa.Expressions.JavaScript.Helpers;
 3using Elsa.Expressions.JavaScript.Options;
 4using Elsa.Expressions.JavaScript.TypeDefinitions.Abstractions;
 5using Elsa.Expressions.JavaScript.TypeDefinitions.Models;
 6using Elsa.Workflows.Activities;
 7using Humanizer;
 8using JetBrains.Annotations;
 9using Microsoft.Extensions.Options;
 10
 11namespace Elsa.Expressions.JavaScript.Providers;
 12
 13/// <summary>
 14/// Produces <see cref="FunctionDefinition"/>s for common functions.
 15/// </summary>
 16[UsedImplicitly]
 117internal class InputFunctionsDefinitionProvider(ITypeAliasRegistry typeAliasRegistry, IOptions<JintOptions> options) : F
 18{
 19    protected override ValueTask<IEnumerable<FunctionDefinition>> GetFunctionDefinitionsAsync(TypeDefinitionContext cont
 20    {
 021        if(options.Value.DisableWrappers)
 022            return ValueTask.FromResult<IEnumerable<FunctionDefinition>>([]);
 23
 024        var workflow = context.WorkflowGraph.Workflow;
 025        return ValueTask.FromResult(GetFunctionDefinitionsAsync(workflow));
 26    }
 27
 28    private IEnumerable<FunctionDefinition> GetFunctionDefinitionsAsync(Workflow workflow)
 29    {
 30        // Input argument getters.
 031        foreach (var input in workflow.Inputs.Where(x => VariableNameValidator.IsValidVariableName(x.Name)))
 32        {
 033            var pascalName = input.Name.Pascalize();
 034            var variableType = input.Type;
 035            var typeAlias = typeAliasRegistry.TryGetAlias(variableType, out var alias) ? alias : "any";
 36
 37            // get{Input}.
 038            yield return CreateFunctionDefinition(builder => builder.Name($"get{pascalName}").ReturnType(typeAlias));
 39        }
 040    }
 41}