import '../../../core/api_gateway.dart'; import 'artifact_record.dart'; /// Parses one step's recorded artifact list. An absent, null or malformed list /// yields no records; the capture state (and its unavailable wording) is /// reported by `artifact_capture.dart`, never treated as an empty capture here. List artifactsOf(JsonMap step) { final value = step['artifacts']; if (value is! List) return const []; return [ for (final item in value) if (item is Map) ArtifactRecord.fromJson(Map.from(item)), ]; } /// The html names a visit's session-export repairs produced. Set repairArtifactNames(JsonMap step) { final value = step['session_export_repairs']; if (value is! List) return const {}; return { for (final entry in value) if (entry is Map && entry['html'] is String && '${entry['html']}'.trim().isNotEmpty) '${entry['html']}', }; } /// The artifacts of one visit as presented: the recorded files with the retired /// markdown session export filtered out. Duplicate names are kept because an /// artifact's identity is its recorded url, not its name. List presentedArtifacts(Iterable artifacts) { return [ for (final artifact in artifacts) if (!artifact.isLegacySessionMarkdown) artifact, ]; } /// A visit's stage-produced artifacts: everything except the turn-owned files /// and repaired session exports. Order is preserved. List stageArtifactsFrom( Iterable artifacts, { Set repairs = const {}, }) { return [ for (final artifact in presentedArtifacts(artifacts)) if (!artifact.isSystem && !repairs.contains(artifact.name)) artifact, ]; } /// A visit's system files and repaired exports, in recorded order. List systemArtifactsFrom( Iterable artifacts, { Set repairs = const {}, }) { return [ for (final artifact in presentedArtifacts(artifacts)) if (artifact.isSystem || repairs.contains(artifact.name)) artifact, ]; } /// Convenience for callers holding a raw step rather than parsed records. List stageArtifacts(JsonMap step) => stageArtifactsFrom(artifactsOf(step), repairs: repairArtifactNames(step)); List systemArtifacts(JsonMap step) => systemArtifactsFrom(artifactsOf(step), repairs: repairArtifactNames(step));