using w4c_workflows.Models.Nodes; namespace w4c_workflows.Services.Nodes; /// /// Maps a blueprint type id to the that can run it. /// Blueprints may exist without an executor (catalogue-only, e.g. a connector /// that is listed but not installed); the compiler and API decide how to surface /// that, the registry only answers whether a runner exists. /// public class NodeExecutorRegistry { private readonly IReadOnlyDictionary _executors; public NodeExecutorRegistry(IEnumerable executors) { var map = new Dictionary(StringComparer.Ordinal); foreach (var executor in executors) { if (string.IsNullOrWhiteSpace(executor.Type)) throw new InvalidOperationException("a node executor is missing its type id"); if (!map.TryAdd(executor.Type, executor)) throw new InvalidOperationException($"duplicate node executor for type '{executor.Type}'"); } _executors = map; } public IReadOnlyCollection Types => (IReadOnlyCollection)_executors.Keys; public INodeExecutor? Resolve(string type) => _executors.TryGetValue(type, out var executor) ? executor : null; public bool CanRun(string type) => _executors.ContainsKey(type); public bool CanRun(NodeBlueprint blueprint) => CanRun(blueprint.Type); }