Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
darunrs committed Oct 2, 2023
1 parent 822c698 commit 90589ae
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions indexer/queryapi_coordinator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,40 @@ pub(crate) async fn stats(redis_connection_manager: storage::ConnectionManager)
}
}

pub(crate) fn process_streamer_message(streamer_message: &near_lake_framework::near_indexer_primitives::StreamerMessage) -> Value {
// Serialize the Message object to a JSON string.
pub(crate) fn process_streamer_message(
streamer_message: &near_lake_framework::near_indexer_primitives::StreamerMessage,
) -> Value {
// Serialize the Message object to a JSON string
let json_str = serde_json::to_string(&streamer_message).unwrap();
// Deserialize the JSON string to a Value.

// Deserialize the JSON string to a Value Object
let mut message_value: Value = serde_json::from_str(&json_str).unwrap();
// Convert keys to camelCase.

// Convert keys to Camel Case
to_camel_case_keys(&mut message_value);

return message_value;
}

fn to_camel_case_keys(message_value: &mut Value) {
// Only process if subfield contains objects
match message_value {
Value::Object(map) => {
for key in map.keys().cloned().collect::<Vec<String>>() {
let new_key =
key.split("_").enumerate().map(|(i, str)| {
if i > 0 {
return str[..1].to_uppercase() + &str[1..];
}
return str.to_owned();
}).collect::<Vec<String>>().join("");
// Generate Camel Case Key
let new_key = key
.split("_")
.enumerate()
.map(|(i, str)| {
if i > 0 {
return str[..1].to_uppercase() + &str[1..];
}
return str.to_owned();
})
.collect::<Vec<String>>()
.join("");

// Recursively process inner fields and update map with new key
let mut val = map.remove(&key).unwrap();
to_camel_case_keys(&mut val);
map.insert(new_key, val);
Expand Down

0 comments on commit 90589ae

Please sign in to comment.