parseMetadata function
Parses the metadata JSON object that accompanies a migration. The main purpose of this function is to decode the array of base64-encoded operations.
Implementation
MetaData parseMetadata(Map<String, Object?> data) {
try {
final dataProtocol = data['protocol_version']! as String;
if (dataProtocol != protocolVersion) {
throw Exception(
'Protocol version mismatch for migration. Expected: $protocolVersion. Got: $dataProtocol',
);
}
final dataFormat = data['format']! as String;
final dataOps =
(data['ops']! as List<dynamic>).cast<String>().map(decode).toList();
final dataVersion = data['version']! as String;
// Now decode the `SatOpMigrate` operations inside the `ops` array
final decoded = MetaData(
format: dataFormat,
ops: dataOps,
protocolVersion: dataProtocol,
version: dataVersion,
);
return decoded;
} catch (e) {
throw Exception('Failed to parse migration data, due to:\n$e');
}
}