| | | 1 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts; |
| | | 2 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Expressions.JavaScript.TypeDefinitions.Services; |
| | | 5 | | |
| | | 6 | | /// <inheritdoc /> |
| | 1 | 7 | | public class TypeDefinitionService( |
| | 1 | 8 | | IEnumerable<ITypeDefinitionProvider> typeDefinitionProviders, |
| | 1 | 9 | | IEnumerable<IFunctionDefinitionProvider> functionDefinitionProviders, |
| | 1 | 10 | | IEnumerable<IVariableDefinitionProvider> variableDefinitionProviders, |
| | 1 | 11 | | ITypeDefinitionDocumentRenderer typeDefinitionDocumentRenderer) |
| | | 12 | | : ITypeDefinitionService |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public async Task<string> GenerateTypeDefinitionsAsync(TypeDefinitionContext context) |
| | | 16 | | { |
| | 0 | 17 | | var typeDefinitions = await GetTypeDefinitionsAsync(context).ToListAsync(context.CancellationToken); |
| | 0 | 18 | | var functionDefinitions = await GetFunctionDefinitionsAsync(context).ToListAsync(context.CancellationToken); |
| | 0 | 19 | | var variableDefinitions = await GetVariableDefinitionsAsync(context).ToListAsync(context.CancellationToken); |
| | | 20 | | |
| | 0 | 21 | | var document = new TypeDefinitionsDocument |
| | 0 | 22 | | { |
| | 0 | 23 | | Functions = functionDefinitions, |
| | 0 | 24 | | Types = typeDefinitions, |
| | 0 | 25 | | Variables = variableDefinitions |
| | 0 | 26 | | }; |
| | | 27 | | |
| | 0 | 28 | | return typeDefinitionDocumentRenderer.Render(document); |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | private async IAsyncEnumerable<FunctionDefinition> GetFunctionDefinitionsAsync(TypeDefinitionContext context) |
| | | 32 | | { |
| | 0 | 33 | | foreach (var provider in functionDefinitionProviders) |
| | | 34 | | { |
| | 0 | 35 | | var definitions = await provider.GetFunctionDefinitionsAsync(context); |
| | | 36 | | |
| | 0 | 37 | | foreach (var definition in definitions) |
| | 0 | 38 | | yield return definition; |
| | | 39 | | } |
| | 0 | 40 | | } |
| | | 41 | | |
| | | 42 | | private async IAsyncEnumerable<TypeDefinition> GetTypeDefinitionsAsync(TypeDefinitionContext context) |
| | | 43 | | { |
| | 0 | 44 | | foreach (var provider in typeDefinitionProviders) |
| | | 45 | | { |
| | 0 | 46 | | var definitions = await provider.GetTypeDefinitionsAsync(context); |
| | | 47 | | |
| | 0 | 48 | | foreach (var definition in definitions) |
| | 0 | 49 | | yield return definition; |
| | | 50 | | } |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | private async IAsyncEnumerable<VariableDefinition> GetVariableDefinitionsAsync(TypeDefinitionContext context) |
| | | 54 | | { |
| | 0 | 55 | | foreach (var provider in variableDefinitionProviders) |
| | | 56 | | { |
| | 0 | 57 | | var definitions = await provider.GetVariableDefinitionsAsync(context); |
| | | 58 | | |
| | 0 | 59 | | foreach (var definition in definitions) |
| | 0 | 60 | | yield return definition; |
| | | 61 | | } |
| | 0 | 62 | | } |
| | | 63 | | } |