use crate::registry::Registry;
use crate::tremor_fn;
use halfbrown::hashmap;
use simd_json::prelude::*;
pub fn load(registry: &mut Registry) {
registry
.insert(tremor_fn! (origin::as_uri_string(context) {
if let Some(uri) = context.origin_uri() {
Ok(Value::from(uri.to_string()))
} else {
Ok(Value::null())
}
}))
.insert(tremor_fn! (origin::as_uri_record(context) {
if let Some(uri) = context.origin_uri() {
Ok(Value::from(
hashmap! {
"scheme".into() => Value::from(uri.scheme().to_string()),
"host".into() => Value::from(uri.host().to_string()),
"port".into() => match uri.port() {
Some(n) => Value::from(n),
None => Value::null(),
},
"path".into() => Value::from(uri.path().to_vec()),
}
))
} else {
Ok(Value::null())
}
}))
.insert(tremor_fn! (origin::scheme(context) {
if let Some(uri) = context.origin_uri() {
Ok(Value::String(uri.scheme().to_string().into()))
} else {
Ok(Value::null())
}
}))
.insert(tremor_fn! (origin::host(context) {
if let Some(uri) = context.origin_uri() {
Ok(Value::String(uri.host().to_string().into()))
} else {
Ok(Value::null())
}
}))
.insert(tremor_fn! (origin::port(context) {
if let Some(uri) = context.origin_uri() {
Ok(match uri.port() {
Some(n) => Value::from(n),
None => Value::null(),
})
} else {
Ok(Value::null())
}
}))
.insert(tremor_fn! (origin::path(context) {
if let Some(uri) = context.origin_uri() {
Ok(Value::from(uri.path().to_vec()))
} else {
Ok(Value::null())
}
}));
}