< Summary

Information
Class: Elsa.Expressions.JavaScript.Endpoints.TypeDefinitions.Request
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Endpoint.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 3
Coverable lines: 3
Total lines: 66
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_WorkflowDefinitionId()100%210%
.ctor()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 />
 22    public Get(ITypeDefinitionService typeDefinitionService, IWorkflowDefinitionService workflowDefinitionService)
 23    {
 24        _typeDefinitionService = typeDefinitionService;
 25        _workflowDefinitionService = workflowDefinitionService;
 26    }
 27
 28    /// <inheritdoc />
 29    public override void Configure()
 30    {
 31        Post("scripting/javascript/type-definitions/{workflowDefinitionId}");
 32        ConfigurePermissions("read:*", "read:javascript-type-definitions");
 33    }
 34
 35    /// <inheritdoc />
 36    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 37    {
 38        var workflowGraph = await GetWorkflowGraphAsync(request.WorkflowDefinitionId, cancellationToken);
 39
 40        if (workflowGraph == null)
 41        {
 42            AddError($"Workflow definition {request.WorkflowDefinitionId} not found");
 43            await Send.ErrorsAsync(cancellation: cancellationToken);
 44            return;
 45        }
 46
 47        var typeDefinitionContext = new TypeDefinitionContext(workflowGraph, request.ActivityTypeName, request.PropertyN
 48        var typeDefinitions = await _typeDefinitionService.GenerateTypeDefinitionsAsync(typeDefinitionContext);
 49        var fileName = $"elsa.{request.WorkflowDefinitionId}.d.ts";
 50        var data = Encoding.UTF8.GetBytes(typeDefinitions);
 51
 52        await Send.BytesAsync(data, fileName, "application/x-typescript", cancellation: cancellationToken);
 53    }
 54
 55    private async Task<WorkflowGraph?> GetWorkflowGraphAsync(string workflowDefinitionId, CancellationToken cancellation
 56    {
 57        return await _workflowDefinitionService.FindWorkflowGraphAsync(workflowDefinitionId, VersionOptions.Latest, canc
 58    }
 59}
 60
 061internal record Request(string WorkflowDefinitionId, string? ActivityTypeName, string? PropertyName)
 62{
 063    public Request() : this(default!, default!, default)
 64    {
 065    }
 66}

Methods/Properties

get_WorkflowDefinitionId()
.ctor()