patchbayDecodeCatalogOutputProjections function

Map<String, PatchbayOutputProjection> patchbayDecodeCatalogOutputProjections(
  1. Map<String, Object?> catalog
)

Decodes every outputProjection a catalog document carries, so one malformed declaration fails the catalog as a whole.

The proposal's reason for the all-or-nothing rule: a provider that ships a declaration no client can agree on must not be able to make each client guess a different projection of the same command. Callers translate the FormatException into their own typed catalog failure.

Implementation

Map<String, PatchbayOutputProjection> patchbayDecodeCatalogOutputProjections(
  Map<String, Object?> catalog,
) {
  final Object? rows = catalog['commands'];
  if (rows is! List<Object?>) return const <String, PatchbayOutputProjection>{};
  final Map<String, PatchbayOutputProjection> decoded =
      <String, PatchbayOutputProjection>{};
  for (final Object? row in rows) {
    if (row is! Map<Object?, Object?>) continue;
    final Object? name = row['name'];
    final String command = name is String ? name : '<unnamed>';
    final PatchbayOutputProjection? projection;
    try {
      projection = PatchbayOutputProjection.fromCatalogRow(row);
    } on FormatException catch (failure) {
      throw FormatException('$command: ${failure.message}');
    }
    if (projection != null && name is String) decoded[name] = projection;
  }
  return decoded;
}