pub fn thing_to_id_only(mut s: String) -> String {
s = s.split(':').next_back().unwrap_or(&s).to_string();
s = s
.replace(['⟩', '⟨', '›', '‹', '»', '«'], "")
.trim()
.to_string();
s
}
pub fn normalize_record_id_field(table: &str, value: &mut serde_json::Value) {
let Some(obj) = value.as_object_mut() else {
return;
};
let Some(id_val) = obj.get("id").cloned() else {
return;
};
if let Some(id_str) = id_val.as_str() {
let bare = thing_to_id_only(id_str.to_string());
obj.insert(
"id".into(),
serde_json::json!({ "table": table, "id": bare }),
);
}
}
pub fn record_id_json(table: &str, id: &str) -> serde_json::Value {
serde_json::json!({
"table": table,
"id": id,
})
}