| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Expressions.Contracts; |
| | | 3 | | using Elsa.Expressions.Models; |
| | | 4 | | using Elsa.Models; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Api.Endpoints.Scripting.ExpressionDescriptors.List; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Returns a TypeScript definition that is used by the Monaco editor to display intellisense for JavaScript expressions |
| | | 11 | | /// </summary> |
| | | 12 | | [UsedImplicitly] |
| | 1 | 13 | | internal class List(IExpressionDescriptorRegistry expressionDescriptorRegistry) : ElsaEndpointWithoutRequest<ListRespons |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public override void Configure() |
| | | 17 | | { |
| | 1 | 18 | | Get("/descriptors/expression-descriptors"); |
| | 1 | 19 | | ConfigurePermissions("read:*", "read:expression-descriptors"); |
| | 1 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override Task HandleAsync(CancellationToken cancellationToken) |
| | | 24 | | { |
| | 0 | 25 | | var descriptors = expressionDescriptorRegistry.ListAll().ToList(); |
| | 0 | 26 | | var models = Map(descriptors).ToList(); |
| | 0 | 27 | | var response = new ListResponse<ExpressionDescriptorModel>(models); |
| | 0 | 28 | | return Send.OkAsync(response, cancellationToken); |
| | | 29 | | } |
| | | 30 | | |
| | 0 | 31 | | private static IEnumerable<ExpressionDescriptorModel> Map(List<ExpressionDescriptor> descriptors) => descriptors.Sel |
| | | 32 | | |
| | | 33 | | private static ExpressionDescriptorModel Map(ExpressionDescriptor descriptor) |
| | | 34 | | { |
| | 0 | 35 | | var properties = descriptor.Properties; |
| | 0 | 36 | | return new ExpressionDescriptorModel( |
| | 0 | 37 | | descriptor.Type, |
| | 0 | 38 | | descriptor.DisplayName, |
| | 0 | 39 | | descriptor.IsSerializable, |
| | 0 | 40 | | descriptor.IsBrowsable, |
| | 0 | 41 | | properties); |
| | | 42 | | } |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | internal record ExpressionDescriptorModel(string Type, string DisplayName, bool IsSerializable, bool IsBrowsable, IDicti |