From 90589ae90bbd60b21eb1a01b77db0d44957e02af Mon Sep 17 00:00:00 2001 From: Darun Seethammagari Date: Mon, 2 Oct 2023 12:11:33 -0700 Subject: [PATCH] Fix formatting --- indexer/queryapi_coordinator/src/utils.rs | 36 +++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/indexer/queryapi_coordinator/src/utils.rs b/indexer/queryapi_coordinator/src/utils.rs index 8ca337e9a..9626c2154 100644 --- a/indexer/queryapi_coordinator/src/utils.rs +++ b/indexer/queryapi_coordinator/src/utils.rs @@ -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::>() { - let new_key = - key.split("_").enumerate().map(|(i, str)| { - if i > 0 { - return str[..1].to_uppercase() + &str[1..]; - } - return str.to_owned(); - }).collect::>().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::>() + .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);