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