< Summary

Information
Class: Elsa.Expressions.JavaScript.Endpoints.TypeDefinitions.Get
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Endpoint.cs
Line coverage
35%
Covered lines: 7
Uncovered lines: 13
Coverable lines: 20
Total lines: 66
Line coverage: 35%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%
Configure()100%11100%
HandleAsync()0%620%
GetWorkflowGraphAsync()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Endpoint.cs

#LineLine coverage
 1using System.Text;
 2using Elsa.Abstractions;
 3using Elsa.Common.Models;
 4using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts;
 5using Elsa.Expressions.JavaScript.TypeDefinitions.Models;
 6using Elsa.Workflows.Management;
 7using Elsa.Workflows.Models;
 8using JetBrains.Annotations;
 9
 10namespace Elsa.Expressions.JavaScript.Endpoints.TypeDefinitions;
 11
 12/// <summary>
 13/// Returns a TypeScript definition that is used by the Monaco editor to display intellisense for JavaScript expressions
 14/// </summary>
 15[PublicAPI]
 16internal class Get : ElsaEndpoint<Request>
 17{
 18    private readonly ITypeDefinitionService _typeDefinitionService;
 19    private readonly IWorkflowDefinitionService _workflowDefinitionService;
 20
 21    /// <inheritdoc />
 122    public Get(ITypeDefinitionService typeDefinitionService, IWorkflowDefinitionService workflowDefinitionService)
 23    {
 124        _typeDefinitionService = typeDefinitionService;
 125        _workflowDefinitionService = workflowDefinitionService;
 126    }
 27
 28    /// <inheritdoc />
 29    public override void Configure()
 30    {
 131        Post("scripting/javascript/type-definitions/{workflowDefinitionId}");
 132        ConfigurePermissions("read:*", "read:javascript-type-definitions");
 133    }
 34
 35    /// <inheritdoc />
 36    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 37    {
 038        var workflowGraph = await GetWorkflowGraphAsync(request.WorkflowDefinitionId, cancellationToken);
 39
 040        if (workflowGraph == null)
 41        {
 042            AddError($"Workflow definition {request.WorkflowDefinitionId} not found");
 043            await Send.ErrorsAsync(cancellation: cancellationToken);
 044            return;
 45        }
 46
 047        var typeDefinitionContext = new TypeDefinitionContext(workflowGraph, request.ActivityTypeName, request.PropertyN
 048        var typeDefinitions = await _typeDefinitionService.GenerateTypeDefinitionsAsync(typeDefinitionContext);
 049        var fileName = $"elsa.{request.WorkflowDefinitionId}.d.ts";
 050        var data = Encoding.UTF8.GetBytes(typeDefinitions);
 51
 052        await Send.BytesAsync(data, fileName, "application/x-typescript", cancellation: cancellationToken);
 053    }
 54
 55    private async Task<WorkflowGraph?> GetWorkflowGraphAsync(string workflowDefinitionId, CancellationToken cancellation
 56    {
 057        return await _workflowDefinitionService.FindWorkflowGraphAsync(workflowDefinitionId, VersionOptions.Latest, canc
 058    }
 59}
 60
 61internal record Request(string WorkflowDefinitionId, string? ActivityTypeName, string? PropertyName)
 62{
 63    public Request() : this(default!, default!, default)
 64    {
 65    }
 66}