< Summary

Information
Class: Elsa.Expressions.JavaScript.Providers.CommonFunctionsDefinitionProvider
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Providers/CommonFunctionsDefinitionProvider.cs
Line coverage
0%
Covered lines: 1
Uncovered lines: 110
Coverable lines: 111
Total lines: 167
Line coverage: 0.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%
GetFunctionDefinitions()0%4260%

File(s)

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

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Expressions.JavaScript.Contracts;
 3using Elsa.Expressions.JavaScript.Extensions;
 4using Elsa.Expressions.JavaScript.Options;
 5using Elsa.Expressions.JavaScript.TypeDefinitions.Abstractions;
 6using Elsa.Expressions.JavaScript.TypeDefinitions.Models;
 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 CommonFunctionsDefinitionProvider(ITypeAliasRegistry typeAliasRegistry, IOptions<JintOptions> options) : 
 18{
 19    protected override IEnumerable<FunctionDefinition> GetFunctionDefinitions(TypeDefinitionContext context)
 20    {
 021        yield return CreateFunctionDefinition(builder => builder
 022            .Name("getWorkflowDefinitionId")
 023            .ReturnType("string"));
 24
 025        yield return CreateFunctionDefinition(builder => builder
 026            .Name("getWorkflowDefinitionVersionId")
 027            .ReturnType("string"));
 28
 029        yield return CreateFunctionDefinition(builder => builder
 030            .Name("getWorkflowDefinitionVersion")
 031            .ReturnType("number"));
 32
 033        yield return CreateFunctionDefinition(builder => builder
 034            .Name("getWorkflowInstanceId")
 035            .ReturnType("string"));
 36
 037        yield return CreateFunctionDefinition(builder => builder
 038            .Name("getCorrelationId")
 039            .ReturnType("string"));
 40
 041        yield return CreateFunctionDefinition(builder => builder
 042            .Name("setCorrelationId")
 043            .Parameter("value", "string"));
 44
 045        yield return CreateFunctionDefinition(builder => builder
 046            .Name("getWorkflowInstanceName")
 047            .ReturnType("string"));
 48
 049        yield return CreateFunctionDefinition(builder => builder
 050            .Name("setWorkflowInstanceName")
 051            .Parameter("value", "string"));
 52
 053        yield return CreateFunctionDefinition(builder => builder
 054            .Name("setVariable")
 055            .Parameter("name", "string")
 056            .Parameter("value", "any"));
 57
 058        yield return CreateFunctionDefinition(builder => builder
 059            .Name("getVariable")
 060            .Parameter("name", "string")
 061            .ReturnType("any"));
 62
 063        yield return CreateFunctionDefinition(builder => builder
 064            .Name("getInput")
 065            .Parameter("name", "string")
 066            .ReturnType("any"));
 67
 068        yield return CreateFunctionDefinition(builder => builder
 069            .Name("getOutputFrom")
 070            .Parameter("activityId", "string")
 071            .Parameter("outputName", "string", true)
 072            .ReturnType("any"));
 73
 074        yield return CreateFunctionDefinition(builder => builder
 075            .Name("getLastResult")
 076            .ReturnType("any"));
 77
 078        yield return CreateFunctionDefinition(builder => builder
 079            .Name("isNullOrWhiteSpace")
 080            .Parameter("value", "string")
 081            .ReturnType("boolean"));
 82
 083        yield return CreateFunctionDefinition(builder => builder
 084            .Name("isNullOrEmpty")
 085            .Parameter("value", "string")
 086            .ReturnType("boolean"));
 87
 088        yield return CreateFunctionDefinition(builder => builder
 089            .Name("parseGuid")
 090            .Parameter("value", "string")
 091            .ReturnType("Guid"));
 92
 093        yield return CreateFunctionDefinition(builder => builder
 094            .Name("getShortGuid")
 095            .ReturnType("string"));
 96
 097        yield return CreateFunctionDefinition(builder => builder
 098            .Name("getGuid")
 099            .ReturnType("Guid"));
 100
 0101        yield return CreateFunctionDefinition(builder => builder
 0102            .Name("getGuidString")
 0103            .ReturnType("string"));
 104
 0105        yield return CreateFunctionDefinition(builder => builder
 0106            .Name("toJson")
 0107            .Parameter("value", "any")
 0108            .ReturnType("string"));
 109
 0110        yield return CreateFunctionDefinition(builder => builder
 0111            .Name("bytesToString")
 0112            .Parameter("value", "Byte[]")
 0113            .ReturnType("string"));
 114
 0115        yield return CreateFunctionDefinition(builder => builder
 0116            .Name("bytesFromString")
 0117            .Parameter("value", "string")
 0118            .ReturnType("Byte[]"));
 119
 0120        yield return CreateFunctionDefinition(builder => builder
 0121            .Name("bytesToBase64")
 0122            .Parameter("value", "Byte[]")
 0123            .ReturnType("string"));
 124
 0125        yield return CreateFunctionDefinition(builder => builder
 0126            .Name("bytesFromBase64")
 0127            .Parameter("value", "string")
 0128            .ReturnType("Byte[]"));
 129
 0130        yield return CreateFunctionDefinition(builder => builder
 0131            .Name("stringFromBase64")
 0132            .Parameter("value", "string")
 0133            .ReturnType("string"));
 134
 0135        yield return CreateFunctionDefinition(builder => builder
 0136            .Name("stringToBase64")
 0137            .Parameter("value", "string")
 0138            .ReturnType("string"));
 139
 0140        yield return CreateFunctionDefinition(builder => builder
 0141            .Name("streamToBytes")
 0142            .Parameter("value", "Stream")
 0143            .ReturnType("Byte[]"));
 144
 0145        yield return CreateFunctionDefinition(builder => builder
 0146            .Name("streamToBase64")
 0147            .Parameter("value", "Stream")
 0148            .ReturnType("string"));
 149
 0150        if (!options.Value.DisableWrappers)
 151        {
 152            // Variable getter and setters.
 0153            foreach (var variable in context.WorkflowGraph.Workflow.Variables.Where(x => x.Name.IsValidVariableName()))
 154            {
 0155                var pascalName = variable.Name.Pascalize();
 0156                var variableType = variable.GetVariableType();
 0157                var typeAlias = typeAliasRegistry.TryGetAlias(variableType, out var alias) ? alias : "any";
 158
 159                // get{Variable}.
 0160                yield return CreateFunctionDefinition(builder => builder.Name($"get{pascalName}").ReturnType(typeAlias))
 161
 162                // set{Variable}.
 0163                yield return CreateFunctionDefinition(builder => builder.Name($"set{pascalName}").Parameter("value", typ
 0164            }
 165        }
 0166    }
 167}