WorkspaceEvidenceConfig.fromMap constructor
Implementation
factory WorkspaceEvidenceConfig.fromMap(Map<Object?, Object?> value) {
for (final key in ['output', 'records', 'observations']) {
final raw = value[key];
if (raw != null && (raw is! String || raw.trim().isEmpty)) {
throw FormatException('evidence.$key must be a non-empty string');
}
}
final rawInclude = value['includeSourceCode'];
if (rawInclude != null && rawInclude is! bool) {
throw const FormatException('evidence.includeSourceCode must be boolean');
}
const allowedModes = {
'record',
'scenario-record',
'control-backed',
'attestation',
};
final types = <String, String>{};
final rawTypes = value['types'];
if (rawTypes != null) {
if (rawTypes is! Map) {
throw const FormatException('evidence.types must be a mapping');
}
for (final entry in rawTypes.entries) {
final mode = entry.value is Map ? (entry.value as Map)['mode'] : null;
if (entry.key is! String ||
mode is! String ||
!allowedModes.contains(mode)) {
throw FormatException(
'evidence type ${entry.key} has an unsupported mode',
);
}
types[entry.key as String] = mode;
}
}
return WorkspaceEvidenceConfig(
output: value['output'] as String?,
records: value['records'] as String?,
observations: value['observations'] as String?,
includeSourceCode: rawInclude as bool?,
types: Map.unmodifiable(types),
extensions: Map.unmodifiable({
for (final entry in value.entries)
if (entry.key is String && !_knownKeys.contains(entry.key))
entry.key as String: _freeze(entry.value),
}),
);
}