forked from
slices.network/slices
Highly ambitious ATProtocol AppView service and sdks
1//! DataLoader utilities for extracting references from records
2
3use serde_json::Value;
4
5/// Extract URI from a strongRef value
6/// strongRef format: { "$type": "com.atproto.repo.strongRef", "uri": "at://...", "cid": "..." }
7pub fn extract_uri_from_strong_ref(value: &Value) -> Option<String> {
8 if let Some(obj) = value.as_object() {
9 // Check if this is a strongRef
10 if let Some(type_val) = obj.get("$type") {
11 if type_val.as_str() == Some("com.atproto.repo.strongRef") {
12 return obj
13 .get("uri")
14 .and_then(|u| u.as_str())
15 .map(|s| s.to_string());
16 }
17 }
18
19 // Also support direct uri field (some lexicons might use this)
20 if let Some(uri) = obj.get("uri") {
21 if let Some(uri_str) = uri.as_str() {
22 if uri_str.starts_with("at://") {
23 return Some(uri_str.to_string());
24 }
25 }
26 }
27 }
28
29 None
30}