namespace w4c_workflows.Services.Execution;
///
/// A language as exposed by GET /api/languages: identity + whether its
/// runtime is actually executable on this host (availability is probed at
/// startup and cached).
///
public sealed record RuntimeInfo(
string Id,
string DisplayName,
string DefaultFunction,
string Extension,
bool Available);
///
/// Maps each registered language to its . Built on
/// top of (the source of truth for known
/// languages); the executor set is DI-injected so new languages/runtimes plug in
/// without touching this class.
///
public class RuntimeRegistry
{
private readonly IReadOnlyDictionary _executors;
private readonly IReadOnlyList _all;
public RuntimeRegistry(LanguageRegistry languages, IEnumerable executors)
{
_executors = executors.ToDictionary(e => e.Language, StringComparer.Ordinal);
_all = languages.All
.Select(l => new RuntimeInfo(
l.Id,
l.DisplayName,
l.DefaultFunction,
l.Extension,
_executors.TryGetValue(l.Id, out var executor) && executor.IsAvailable()))
.ToList();
}
public IReadOnlyList All => _all;
public IScriptExecutor? Resolve(string language)
=> _executors.TryGetValue(language, out var executor) ? executor : null;
public bool IsAvailable(string language)
=> _executors.TryGetValue(language, out var executor) && executor.IsAvailable();
}