convertReportsFrom function
The reports a --report file holds, each as ConvertReport.toJson
wrote it: from the enveloped document, or from the bare list the file
was before 1.0.
Throws a DocumentFormatException for another format's document, a
newer version, or a document with no list of reports.
Implementation
List<Map<String, Object?>> convertReportsFrom(Object? json) {
final list = switch (json) {
final List<Object?> bare => bare,
final Map<String, Object?> document => switch (convertReportFormat.read(
document,
refuse: DocumentFormatException.new,
)['reports']) {
final List<Object?> reports => reports,
_ => throw const DocumentFormatException(
'a convert report with no "reports" list',
),
},
_ => throw const DocumentFormatException(
'a convert report is a JSON object with "reports"',
),
};
return <Map<String, Object?>>[
for (final each in list)
if (each is Map<String, Object?>)
each
else
throw DocumentFormatException('a convert report entry is $each'),
];
}