Skip to main content

Mountain/IPC/UriComponents/
Normalize.rs

1
2//! Normalise an `extensionLocation` (or any similar) field that arrives
3//! as either a URL string, a pre-built `UriComponents` object (possibly
4//! already tagged), or is missing / null. The output is always a
5//! tagged object with the five URI fields.
6
7use serde_json::Value;
8
9use crate::IPC::UriComponents::{FromFilePath, FromUrl, StampMidUri};
10
11pub fn Fn(Raw:Option<&Value>) -> Value {
12	match Raw {
13		Some(Value::Object(Map)) if Map.contains_key("scheme") => StampMidUri::Fn(Value::Object(Map.clone())),
14
15		Some(Value::String(Url)) => FromUrl::Fn(Url),
16
17		// {"value": "url_string"} - legacy cache loader format where the URI
18		// was mistakenly wrapped in the Identifier shape. Unwrap and parse as URL.
19		Some(Value::Object(Map)) if Map.contains_key("value") => {
20			if let Some(Value::String(Url)) = Map.get("value") {
21				FromUrl::Fn(Url)
22			} else {
23				FromFilePath::Fn("/extensions/unknown")
24			}
25		},
26
27		_ => FromFilePath::Fn("/extensions/unknown"),
28	}
29}