public async Task <StringBuilder> GenerateTypeScriptDefinitionsAsync(
            StringBuilder builder,
            ICollection <string> declaredTypes,
            WorkflowDefinition?workflowDefinition = default,
            IntellisenseContext?context           = default,
            CancellationToken cancellationToken   = default)
        {
            var providerContext = new TypeDefinitionContext(workflowDefinition, context);
            var types           = await CollectTypesAsync(providerContext, cancellationToken);

            providerContext.GetTypeScriptType = ((provider, type) => GetTypeScriptType(providerContext, type, types, provider));

            // Render type declarations for anything except those listed in TypeConverters.
            foreach (var type in types)
            {
                var shouldRenderDeclaration = ShouldRenderTypeDeclaration(providerContext, type);
                if (shouldRenderDeclaration)
                {
                    RenderTypeDeclaration(providerContext, type, types, builder);
                }
            }

            string GetTypeScriptTypeInternal(Type type) => GetTypeScriptType(providerContext, type, types);

            var renderingTypeScriptDefinitions = new RenderingTypeScriptDefinitions(workflowDefinition, GetTypeScriptTypeInternal, context, declaredTypes, builder);
            await _mediator.Publish(renderingTypeScriptDefinitions, cancellationToken);

            return(builder);
        }
        public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context)
        {
            var workflowDefinition = context.WorkflowDefinition;

            if (workflowDefinition != null)
            {
                // For each HTTP Endpoint activity, determine its TargetType. If configured, register it.
                var httpEndpointActivities = workflowDefinition.Activities.Where(x => x.Type == nameof(HttpEndpoint)).ToList();

                foreach (var activityDefinition in httpEndpointActivities)
                {
                    var targetTypeName = activityDefinition.Properties.First(x => x.Name == nameof(HttpEndpoint.TargetType)).Expressions.Values.FirstOrDefault();

                    if (string.IsNullOrWhiteSpace(targetTypeName))
                    {
                        continue;
                    }

                    var type = Type.GetType(targetTypeName);

                    if (type != null)
                    {
                        yield return(type);
                    }
                }
            }

            yield return(typeof(HttpRequestModel));

            yield return(typeof(HttpResponseHeaders));

            yield return(typeof(HttpResponseModel));
        }
Example #3
0
        public override string GetTypeDefinition(TypeDefinitionContext context, Type type)
        {
            var providers      = _serviceProvider.GetServices <ITypeDefinitionProvider>().Where(x => x is not EnumerableTypeDefinitionProvider).ToList();
            var elementType    = type.IsArray ? type.GetElementType() ! : type.GetGenericArguments().FirstOrDefault();
            var typeScriptType = elementType != null?providers.FirstOrDefault(x => x.SupportsType(context, elementType))?.GetTypeDefinition(context, elementType) : null;

            return(typeScriptType == null ? "[]" : $"Array<{typeScriptType}>");
        }
        public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context)
        {
            var workflowDefinition = context.WorkflowDefinition;
            var contextType        = workflowDefinition?.ContextOptions?.ContextType;

            if (contextType != null)
            {
                yield return(contextType);
            }
        }
Example #5
0
        private string GetTypeScriptType(TypeDefinitionContext context, Type type, ISet <Type> collectedTypes)
        {
            if (type.IsNullableType())
            {
                type = type.GetTypeOfNullable();
            }

            var provider       = _providers.FirstOrDefault(x => x.SupportsType(context, type));
            var typeScriptType = provider != null?provider.GetTypeDefinition(context, type) : collectedTypes.Contains(type) ? type.Name : "any";

            return(GetSafeSymbol(typeScriptType));
        }
        public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context)
        {
            var workflowDefinition = context.WorkflowDefinition;

            if (workflowDefinition == null)
            {
                yield break;
            }

            foreach (var variable in workflowDefinition.Variables !.Data.Values)
            {
                yield return(variable?.GetType() ?? typeof(object));
            }
        }
Example #7
0
 public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context) => new[]
 {
     typeof(Instant),
     typeof(Duration),
     typeof(Period),
     typeof(LocalDate),
     typeof(LocalTime),
     typeof(LocalDateTime),
     typeof(Guid),
     typeof(CultureInfo),
     typeof(ActivityExecutionContext),
     typeof(WorkflowExecutionContext),
     typeof(WorkflowInstance),
 };
Example #8
0
        private void RenderTypeDeclaration(TypeDefinitionContext context, string symbol, Type type, ISet <Type> collectedTypes, StringBuilder output)
        {
            var typeName   = GetSafeSymbol(type.Name);
            var properties = type.GetProperties();
            var methods    = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static).Where(x => !x.IsSpecialName).ToList();

            output.AppendLine($"declare {symbol} {typeName} {{");

            foreach (var property in properties)
            {
                var typeScriptType = GetTypeScriptType(context, property.PropertyType, collectedTypes);
                var propertyName   = property.PropertyType.IsNullableType() ? $"{property.Name}?" : property.Name;
                output.AppendLine($"{propertyName}: {typeScriptType};");
            }

            foreach (var method in methods)
            {
                if (method.Name.StartsWith("<"))
                {
                    continue;
                }

                if (symbol == "interface" && method.IsStatic)
                {
                    continue;
                }

                if (method.IsStatic)
                {
                    output.Append("static ");
                }

                output.Append($"{method.Name}(");

                var arguments = method.GetParameters().Select(x => $"{x.Name}:{GetTypeScriptType(context, x.ParameterType, collectedTypes)}");
                output.Append(string.Join(", ", arguments));
                output.Append(")");

                var returnType = method.ReturnType;
                if (returnType != typeof(void))
                {
                    output.AppendFormat(":{0}", GetTypeScriptType(context, returnType, collectedTypes));
                }

                output.AppendLine(";");
            }

            output.AppendLine("}");
        }
        private async Task <ISet <Type> > CollectTypesAsync(TypeDefinitionContext context, CancellationToken cancellationToken = default)
        {
            var collectedTypes = new HashSet <Type>();

            foreach (var provider in _providers)
            {
                var providedTypes = await provider.CollectTypesAsync(context, cancellationToken);

                foreach (var providedType in providedTypes)
                {
                    CollectType(providedType, collectedTypes);
                }
            }

            return(collectedTypes);
        }
        public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context)
        {
            return(new[]
            {
                typeof(TelnyxWebhook),

                typeof(CallAnsweredPayload),
                typeof(CallBridgedPayload),
                typeof(CallDtmfReceivedPayload),
                typeof(CallGatherEndedPayload),
                typeof(CallHangupPayload),
                typeof(CallInitiatedPayload),
                typeof(CallPayload),
                typeof(CallPlayback),
                typeof(CallPlaybackEndedPayload),
                typeof(CallPlaybackStartedPayload),
                typeof(CallRecordingSaved),
                typeof(CallRecordingUrls),
                typeof(CallSpeakEnded),
                typeof(CallSpeakStarted),
            });
        }
 public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context)
 {
     return(new[] { typeof(EmailAttachment) });
 }
 public virtual ValueTask <IEnumerable <Type> > CollectTypesAsync(TypeDefinitionContext context, CancellationToken cancellationToken = default) => new(CollectTypes(context));
 public virtual string GetTypeDefinition(TypeDefinitionContext context, Type type) => "any";
 public virtual bool ShouldRenderType(TypeDefinitionContext context, Type type) => false;
 public virtual bool SupportsType(TypeDefinitionContext context, Type type) => false;
 public override string GetTypeDefinition(TypeDefinitionContext context, Type type) => TypeMap[type];
 public override bool SupportsType(TypeDefinitionContext context, Type type) => TypeMap.ContainsKey(type);
 private void RenderTypeDeclaration(TypeDefinitionContext context, Type type, ISet <Type> collectedTypes, StringBuilder output)
 {
     var symbol = type switch
     {
         { IsInterface : true } => "interface",
Example #19
0
 private void RenderTypeDeclaration(TypeDefinitionContext context, Type type, ISet <Type> collectedTypes, StringBuilder output) => RenderTypeDeclaration(context, "interface", type, collectedTypes, output);
Example #20
0
 public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context)
 {
     return(new[] { typeof(FirstMessage), typeof(SecondMessage) });
 }
        public override ValueTask <IEnumerable <Type> > CollectTypesAsync(TypeDefinitionContext context, CancellationToken cancellationToken = default)
        {
            var types = new[] { typeof(User), typeof(RegistrationModel), typeof(DocumentFile), typeof(Document), typeof(FileModel), typeof(NewDocumentReceived) };

            return(new ValueTask <IEnumerable <Type> >(types));
        }
Example #22
0
        private bool ShouldRenderTypeDeclaration(TypeDefinitionContext context, Type type)
        {
            var provider = _providers.FirstOrDefault(x => x.SupportsType(context, type));

            return(provider == null);
        }
Example #23
0
 public override bool SupportsType(TypeDefinitionContext context, Type type) => type.IsEnum;
Example #24
0
 public override string GetTypeDefinition(TypeDefinitionContext context, Type type) => "[]";
Example #25
0
 public override bool SupportsType(TypeDefinitionContext context, Type type) => typeof(IEnumerable).IsAssignableFrom(type);
 public override IEnumerable <Type> CollectTypes(TypeDefinitionContext context)
 {
     return(new[] { typeof(HttpRequestModel), typeof(HttpResponseHeaders), typeof(HttpResponseModel) });
 }