1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! `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
}