Update Elsa API Client with ActivityDescriptors API

This commit is contained in:
Sipke Schoorstra 2023-06-10 15:33:32 +02:00
parent de9b3e866b
commit 144d9d0aa4
14 changed files with 312 additions and 2 deletions

View file

@ -1,4 +1,5 @@
using Elsa.Api.Client.Resources.WorkflowDefinitions.Contracts;
using Elsa.Api.Client.Resources.ActivityDescriptors.Contracts;
using Elsa.Api.Client.Resources.WorkflowDefinitions.Contracts;
using Elsa.Api.Client.Resources.WorkflowInstances.Contracts;
namespace Elsa.Api.Client.Contracts;
@ -13,6 +14,11 @@ public interface IElsaClient
/// </summary>
IWorkflowDefinitionsApi WorkflowDefinitions { get; }
/// <summary>
/// Gets the activity descriptors API.
/// </summary>
IActivityDescriptorsApi ActivityDescriptors { get; }
/// <summary>
/// Gets the workflow instances API.
/// </summary>

View file

@ -1,5 +1,6 @@
using Elsa.Api.Client.Contracts;
using Elsa.Api.Client.Options;
using Elsa.Api.Client.Resources.ActivityDescriptors.Contracts;
using Elsa.Api.Client.Resources.Identity.Contracts;
using Elsa.Api.Client.Resources.WorkflowDefinitions.Contracts;
using Elsa.Api.Client.Services;
@ -26,6 +27,7 @@ public static class DependencyInjectionExtensions
var settings = new RefitSettings();
services.AddElsaApiClient<IWorkflowDefinitionsApi>(settings);
services.AddElsaApiClient<IActivityDescriptorsApi>(settings);
services.AddElsaApiClient<ILoginApi>(settings);
return services;
}

View file

@ -0,0 +1,19 @@
using Elsa.Api.Client.Resources.ActivityDescriptors.Models;
using Refit;
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Contracts;
/// <summary>
/// Represents a client for the workflow definitions API.
/// </summary>
public interface IActivityDescriptorsApi
{
/// <summary>
/// Lists activity descriptors.
/// </summary>
/// <param name="request">The request containing options for listing activity descriptors.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The response containing the activity descriptors.</returns>
[Get("/descriptors/activities")]
Task<ListActivityDescriptorsResponse> ListAsync([Query]ListActivityDescriptorsRequest request, CancellationToken cancellationToken = default);
}

View file

@ -0,0 +1,77 @@
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// A descriptor of an activity type.
/// </summary>
public record ActivityDescriptor
{
/// <summary>
/// The fully qualified name of the activity type.
/// </summary>
public string TypeName { get; init; } = default!;
/// <summary>
/// The namespace of the activity type.
/// </summary>
public string Namespace { get; init; } = default!;
/// <summary>
/// The name of the activity type.
/// </summary>
public string Name { get; init; } = default!;
/// <summary>
/// The version of the activity type.
/// </summary>
public int Version { get; init; }
/// <summary>
/// The category of the activity type.
/// </summary>
public string Category { get; init; } = default!;
/// <summary>
/// The display name of the activity type.
/// </summary>
public string? DisplayName { get; init; }
/// <summary>
/// The description of the activity type.
/// </summary>
public string? Description { get; init; }
/// <summary>
/// The input properties of the activity type.
/// </summary>
public ICollection<InputDescriptor> Inputs { get; init; } = new List<InputDescriptor>();
/// <summary>
/// The output properties of the activity type.
/// </summary>
public ICollection<OutputDescriptor> Outputs { get; init; } = new List<OutputDescriptor>();
/// <summary>
/// The kind of activity.
/// </summary>
public ActivityKind Kind { get; set; } = ActivityKind.Action;
/// <summary>
/// The ports of the activity type.
/// </summary>
public ICollection<Port> Ports { get; init; } = new List<Port>();
/// <summary>
/// The custom properties of the activity type.
/// </summary>
public IDictionary<string, object> CustomProperties { get; set; } = new Dictionary<string, object>();
/// <summary>
/// A value indicating whether this activity is a container of child activities.
/// </summary>
public bool IsContainer { get; set; }
/// <summary>
/// Whether this activity type is selectable from activity pickers.
/// </summary>
public bool IsBrowsable { get; set; }
}

View file

@ -0,0 +1,27 @@
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// Represents the kind of an activity, which affects how it is executed.
/// </summary>
public enum ActivityKind
{
/// <summary>
/// Always run synchronously.
/// </summary>
Action,
/// <summary>
/// Can be used to trigger new workflows.
/// </summary>
Trigger,
/// <summary>
/// Always run asynchronously.
/// </summary>
Job,
/// <summary>
/// Run synchronously by default (like <see cref="Action"/>, but can be configured to run asynchronously (like <see cref="Job"/>).
/// </summary>
Task
}

View file

@ -0,0 +1,57 @@
using JetBrains.Annotations;
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// A descriptor of an activity's input property.
/// </summary>
[PublicAPI]
public class InputDescriptor : PropertyDescriptor
{
/// <inheritdoc />
public InputDescriptor()
{
}
/// <summary>
/// True if the property is wrapped with an <c>"Input{T}"</c> type, false otherwise.
/// </summary>
public bool IsWrapped { get; set; }
/// <summary>
/// A string value that hints at what UI control might be used to render in a UI tool.
/// </summary>
public string UIHint { get; set; } = default!;
/// <summary>
/// An arbitrary options object that can be used by some UI tool.
/// </summary>
public object? Options { get; set; }
/// <summary>
/// The category to whcih this input belongs. Can be used by UI to e.g. render different inputs in different tabs.
/// </summary>
public string? Category { get; set; }
/// <summary>
/// The default value.
/// </summary>
public object? DefaultValue { get; set; }
/// <summary>
/// The default syntax.
/// </summary>
public string? DefaultSyntax { get; set; }
//public ICollection<string> SupportedSyntaxes { get; set; } = new List<string>();
/// <summary>
/// True if the input is readonly, false otherwise.
/// </summary>
public bool? IsReadOnly { get; set; }
/// <summary>
/// The storage driver type to use for persistence.
/// If no driver is specified, the referenced memory block will remain in memory for as long as the expression execution context exists.
/// </summary>
public string? StorageDriverType { get; set; }
}

View file

@ -0,0 +1,6 @@
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// Represents a request to list activity descriptors.
/// </summary>
public record ListActivityDescriptorsRequest;

View file

@ -0,0 +1,8 @@
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// Represents a response from listing activity descriptors.
/// </summary>
/// <param name="Items">The activity descriptors.</param>
/// <param name="Count">The total number of activity descriptors.</param>
public record ListActivityDescriptorsResponse(ICollection<ActivityDescriptor> Items, int Count);

View file

@ -0,0 +1,11 @@
using JetBrains.Annotations;
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// A descriptor of an activity's output property.
/// </summary>
[PublicAPI]
public class OutputDescriptor : PropertyDescriptor
{
}

View file

@ -0,0 +1,27 @@
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// Represents a port on an activity.
/// </summary>
public class Port
{
/// <summary>
/// Gets or sets the name of the port.
/// </summary>
public string Name { get; set; } = default!;
/// <summary>
/// Gets or sets the display name of the port.
/// </summary>
public string? DisplayName { get; set; }
/// <summary>
/// Gets or sets the type of the port.
/// </summary>
public PortType Type { get; set; }
/// <summary>
/// Gets or sets the visibility of the port.
/// </summary>
public bool IsBrowsable { get; set; } = true;
}

View file

@ -0,0 +1,17 @@
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// The type of a port.
/// </summary>
public enum PortType
{
/// <summary>
/// A port that is embedded in the activity.
/// </summary>
Embedded,
/// <summary>
/// A flow port.
/// </summary>
Flow
}

View file

@ -0,0 +1,47 @@
using System.Text.Json.Serialization;
using JetBrains.Annotations;
namespace Elsa.Api.Client.Resources.ActivityDescriptors.Models;
/// <summary>
/// A base type for <see cref="InputDescriptor"/> and <see cref="OutputDescriptor"/>.
/// </summary>
[PublicAPI]
public abstract class PropertyDescriptor
{
/// <summary>
/// The name.
/// </summary>
public string Name { get; set; } = default!;
/// <summary>
/// The .NET type.
/// </summary>
[JsonPropertyName("typeName")]
public string TypeName { get; set; } = default!;
/// <summary>
/// The user friendly name of the input. Used by UI tools.
/// </summary>
public string? DisplayName { get; set; }
/// <summary>
/// The user friendly description of the input. Used by UI tools.
/// </summary>
public string? Description { get; set; }
/// <summary>
/// The order in which this input should be displayed by UI tools.
/// </summary>
public float Order { get; set; }
/// <summary>
/// True if this input should be displayed by UI tools, false otherwise.
/// </summary>
public bool? IsBrowsable { get; set; }
/// <summary>
/// True if this input property is synthetic, which means it does not exist physically on the activity's .NET type.
/// </summary>
public bool IsSynthetic { get; set; }
}

View file

@ -1,4 +1,5 @@
using Elsa.Api.Client.Contracts;
using Elsa.Api.Client.Resources.ActivityDescriptors.Contracts;
using Elsa.Api.Client.Resources.WorkflowDefinitions.Contracts;
using Elsa.Api.Client.Resources.WorkflowInstances.Contracts;
@ -10,15 +11,19 @@ public class ElsaClient : IElsaClient
/// <summary>
/// Initializes a new instance of the <see cref="ElsaClient"/> class.
/// </summary>
public ElsaClient(IWorkflowDefinitionsApi workflowDefinitions, IWorkflowInstancesApi workflowInstances)
public ElsaClient(IWorkflowDefinitionsApi workflowDefinitions, IWorkflowInstancesApi workflowInstances, IActivityDescriptorsApi activityDescriptors)
{
WorkflowDefinitions = workflowDefinitions;
WorkflowInstances = workflowInstances;
ActivityDescriptors = activityDescriptors;
}
/// <inheritdoc />
public IWorkflowDefinitionsApi WorkflowDefinitions { get; }
/// <inheritdoc />
public IActivityDescriptorsApi ActivityDescriptors { get; }
/// <inheritdoc />
public IWorkflowInstancesApi WorkflowInstances { get; }
}

View file

@ -12,4 +12,5 @@ internal class Response
}
public ICollection<ActivityDescriptor> Items { get; set; }
public int Count => Items.Count;
}