//! `software.release.*` record and rkey builders. //! //! Wire shapes and rkeys are centralized here so ingestion never hand-rolls //! JSON or derives rkeys inline. Byte-for-byte behavior is unchanged from the //! original `sync_one` monolith. use serde_json::{Value, json}; use crate::constants::{CHANNEL_TYPE, MANIFEST_TYPE, PROJECT_TYPE, STATUS_TYPE, VERSION_TYPE}; use crate::records::digest_rkey; use crate::release::artifact::Artifact; /// The only channel mode ingested in this wave. pub const LATEST_CHANNEL: &str = "latest"; pub fn project_record(name: &str) -> Value { json!({"$type": PROJECT_TYPE, "name": name}) } pub fn manifest_rkey(project_slug: &str, artifact: &Artifact) -> String { let cid = artifact.cid(); let size = artifact.size.to_string(); digest_rkey(&["manifest", project_slug, &cid, &artifact.url, &size]) } pub fn manifest_record(project_uri: &str, artifact: &Artifact) -> Value { json!({ "$type": MANIFEST_TYPE, "project": project_uri, "artifacts": [{ "$type": "software.release.defs#httpArtifact", "fileName": artifact.file_name, "url": artifact.url, "cid": artifact.cid(), "size": artifact.size, "mimeType": artifact.mime_type, }], }) } pub fn version_rkey(project_slug: &str, version: &str) -> String { format!("{project_slug}:{version}") } pub fn version_record( project_uri: &str, version: &str, manifest_uri: &str, manifest_cid: &str, ) -> Value { json!({ "$type": VERSION_TYPE, "project": project_uri, "version": version, "manifest": {"uri": manifest_uri, "cid": manifest_cid}, }) } pub fn channel_rkey(project_slug: &str, channel: &str) -> String { format!("{project_slug}:{channel}") } pub fn channel_record( project_uri: &str, channel: &str, version_uri: &str, version_cid: &str, ) -> Value { json!({ "$type": CHANNEL_TYPE, "project": project_uri, "name": channel, "version": {"uri": version_uri, "cid": version_cid}, }) } pub fn status_rkey(version_uri: &str, status: &str, reason: &str) -> String { digest_rkey(&["status", version_uri, status, reason]) } pub fn status_record(subject_uri: &str, status: &str, reason: &str) -> Value { let mut record = json!({ "$type": STATUS_TYPE, "subject": subject_uri, "status": status, }); if status == "deprecated" && !reason.is_empty() { record["kind"] = json!("superseded"); record["reason"] = json!(reason); } record }