Skip to content

Commit

Permalink
standardize store types by using camel case instead of snake case (#2709
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Ivansete-status authored May 17, 2024
1 parent 3faffdb commit 176c98c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 55 deletions.
44 changes: 22 additions & 22 deletions waku/waku_api/rest/legacy_store/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ proc writeValue*(
writer.beginRecord()
writer.writeField("payload", $value.payload)
if value.contentTopic.isSome():
writer.writeField("content_topic", value.contentTopic.get())
writer.writeField("contentTopic", value.contentTopic.get())
if value.version.isSome():
writer.writeField("version", value.version.get())
if value.timestamp.isSome():
Expand Down Expand Up @@ -178,7 +178,7 @@ proc readValue*(
case fieldName
of "payload":
payload = some(reader.readValue(Base64String))
of "content_topic":
of "contentTopic":
contentTopic = some(reader.readValue(ContentTopic))
of "version":
version = some(reader.readValue(uint32))
Expand Down Expand Up @@ -245,9 +245,9 @@ proc writeValue*(
writer: var JsonWriter, value: HistoryCursorRest
) {.gcsafe, raises: [IOError].} =
writer.beginRecord()
writer.writeField("pubsub_topic", value.pubsubTopic)
writer.writeField("sender_time", value.senderTime)
writer.writeField("store_time", value.storeTime)
writer.writeField("pubsubTopic", value.pubsubTopic)
writer.writeField("senderTime", value.senderTime)
writer.writeField("storeTime", value.storeTime)
writer.writeField("digest", value.digest)
writer.endRecord()

Expand All @@ -262,22 +262,22 @@ proc readValue*(

for fieldName in readObjectFields(reader):
case fieldName
of "pubsub_topic":
of "pubsubTopic":
if pubsubTopic.isSome():
reader.raiseUnexpectedField(
"Multiple `pubsub_topic` fields found", "HistoryCursorRest"
"Multiple `pubsubTopic` fields found", "HistoryCursorRest"
)
pubsubTopic = some(reader.readValue(PubsubTopic))
of "sender_time":
of "senderTime":
if senderTime.isSome():
reader.raiseUnexpectedField(
"Multiple `sender_time` fields found", "HistoryCursorRest"
"Multiple `senderTime` fields found", "HistoryCursorRest"
)
senderTime = some(reader.readValue(Timestamp))
of "store_time":
of "storeTime":
if storeTime.isSome():
reader.raiseUnexpectedField(
"Multiple `store_time` fields found", "HistoryCursorRest"
"Multiple `storeTime` fields found", "HistoryCursorRest"
)
storeTime = some(reader.readValue(Timestamp))
of "digest":
Expand All @@ -290,13 +290,13 @@ proc readValue*(
reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName))

if pubsubTopic.isNone():
reader.raiseUnexpectedValue("Field `pubsub_topic` is missing")
reader.raiseUnexpectedValue("Field `pubsubTopic` is missing")

if senderTime.isNone():
reader.raiseUnexpectedValue("Field `sender_time` is missing")
reader.raiseUnexpectedValue("Field `senderTime` is missing")

if storeTime.isNone():
reader.raiseUnexpectedValue("Field `store_time` is missing")
reader.raiseUnexpectedValue("Field `storeTime` is missing")

if digest.isNone():
reader.raiseUnexpectedValue("Field `digest` is missing")
Expand All @@ -320,7 +320,7 @@ proc writeValue*(
if value.cursor.isSome():
writer.writeField("cursor", value.cursor.get())
if value.errorMessage.isSome():
writer.writeField("error_message", value.errorMessage.get())
writer.writeField("errorMessage", value.errorMessage.get())
writer.endRecord()

proc readValue*(
Expand All @@ -345,10 +345,10 @@ proc readValue*(
"Multiple `cursor` fields found", "StoreResponseRest"
)
cursor = some(reader.readValue(HistoryCursorRest))
of "error_message":
of "errorMessage":
if errorMessage.isSome():
reader.raiseUnexpectedField(
"Multiple `error_message` fields found", "StoreResponseRest"
"Multiple `errorMessage` fields found", "StoreResponseRest"
)
errorMessage = some(reader.readValue(string))
else:
Expand All @@ -370,13 +370,13 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} =
writer.beginRecord()
if value.pubsubTopic.isSome():
writer.writeField("pubsub_topic", value.pubsubTopic.get())
writer.writeField("content_topics", value.contentTopics)
writer.writeField("pubsubTopic", value.pubsubTopic.get())
writer.writeField("contentTopics", value.contentTopics)
if value.startTime.isSome():
writer.writeField("start_time", value.startTime.get())
writer.writeField("startTime", value.startTime.get())
if value.endTime.isSome():
writer.writeField("end_time", value.endTime.get())
writer.writeField("page_size", value.pageSize)
writer.writeField("endTime", value.endTime.get())
writer.writeField("pageSize", value.pageSize)
writer.writeField("ascending", value.ascending)
writer.endRecord()

Expand Down
64 changes: 31 additions & 33 deletions waku/waku_api/rest/store/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ proc writeValue*(
writer.beginRecord()

writer.writeField("payload", base64.encode(msg.payload))
writer.writeField("content_topic", msg.contentTopic)
writer.writeField("contentTopic", msg.contentTopic)

if msg.meta.len > 0:
writer.writeField("meta", base64.encode(msg.meta))
Expand Down Expand Up @@ -114,7 +114,7 @@ proc readValue*(
let base64String = reader.readValue(Base64String)
payload = base64.decode(base64String).valueOr:
reader.raiseUnexpectedField("Failed decoding data", "payload")
of "content_topic":
of "contentTopic":
contentTopic = reader.readValue(ContentTopic)
of "version":
version = reader.readValue(uint32)
Expand Down Expand Up @@ -185,7 +185,7 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} =
writer.beginRecord()

writer.writeField("message_hash", value.messageHash)
writer.writeField("messageHash", value.messageHash)

if value.message.isSome():
writer.writeField("message", value.message.get())
Expand All @@ -201,10 +201,10 @@ proc readValue*(

for fieldName in readObjectFields(reader):
case fieldName
of "message_hash":
of "messageHash":
if messageHash.isSome():
reader.raiseUnexpectedField(
"Multiple `message_hash` fields found", "WakuMessageKeyValue"
"Multiple `messageHash` fields found", "WakuMessageKeyValue"
)
messageHash = some(reader.readValue(WakuMessageHash))
of "message":
Expand All @@ -217,7 +217,7 @@ proc readValue*(
reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName))

if messageHash.isNone():
reader.raiseUnexpectedValue("Field `message_hash` is missing")
reader.raiseUnexpectedValue("Field `messageHash` is missing")

value = WakuMessageKeyValue(messageHash: messageHash.get(), message: message)

Expand All @@ -228,15 +228,13 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} =
writer.beginRecord()

writer.writeField("request_id", value.requestId)

writer.writeField("status_code", value.statusCode)
writer.writeField("status_desc", value.statusDesc)

writer.writeField("requestId", value.requestId)
writer.writeField("statusCode", value.statusCode)
writer.writeField("statusDesc", value.statusDesc)
writer.writeField("messages", value.messages)

if value.paginationCursor.isSome():
writer.writeField("pagination_cursor", value.paginationCursor.get())
writer.writeField("paginationCursor", value.paginationCursor.get())

writer.endRecord()

Expand All @@ -252,22 +250,22 @@ proc readValue*(

for fieldName in readObjectFields(reader):
case fieldName
of "request_id":
of "requestId":
if requestId.isSome():
reader.raiseUnexpectedField(
"Multiple `request_id` fields found", "StoreQueryResponse"
"Multiple `requestId` fields found", "StoreQueryResponse"
)
requestId = some(reader.readValue(string))
of "status_code":
of "statusCode":
if code.isSome():
reader.raiseUnexpectedField(
"Multiple `status_code` fields found", "StoreQueryResponse"
"Multiple `statusCode` fields found", "StoreQueryResponse"
)
code = some(reader.readValue(uint32))
of "status_desc":
of "statusDesc":
if desc.isSome():
reader.raiseUnexpectedField(
"Multiple `status_desc` fields found", "StoreQueryResponse"
"Multiple `statusDesc` fields found", "StoreQueryResponse"
)
desc = some(reader.readValue(string))
of "messages":
Expand All @@ -276,23 +274,23 @@ proc readValue*(
"Multiple `messages` fields found", "StoreQueryResponse"
)
messages = some(reader.readValue(seq[WakuMessageKeyValue]))
of "pagination_cursor":
of "paginationCursor":
if cursor.isSome():
reader.raiseUnexpectedField(
"Multiple `pagination_cursor` fields found", "StoreQueryResponse"
"Multiple `paginationCursor` fields found", "StoreQueryResponse"
)
cursor = some(reader.readValue(WakuMessageHash))
else:
reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName))

if requestId.isNone():
reader.raiseUnexpectedValue("Field `request_id` is missing")
reader.raiseUnexpectedValue("Field `requestId` is missing")

if code.isNone():
reader.raiseUnexpectedValue("Field `status_code` is missing")
reader.raiseUnexpectedValue("Field `statusCode` is missing")

if desc.isNone():
reader.raiseUnexpectedValue("Field `status_desc` is missing")
reader.raiseUnexpectedValue("Field `statusDesc` is missing")

if messages.isNone():
reader.raiseUnexpectedValue("Field `messages` is missing")
Expand All @@ -312,28 +310,28 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} =
writer.beginRecord()

writer.writeField("request_id", req.requestId)
writer.writeField("include_data", req.includeData)
writer.writeField("requestId", req.requestId)
writer.writeField("includeData", req.includeData)

if req.pubsubTopic.isSome():
writer.writeField("pubsub_topic", req.pubsubTopic.get())
writer.writeField("pubsubTopic", req.pubsubTopic.get())

writer.writeField("content_topics", req.contentTopics)
writer.writeField("contentTopics", req.contentTopics)

if req.startTime.isSome():
writer.writeField("start_time", req.startTime.get())
writer.writeField("startTime", req.startTime.get())

if req.endTime.isSome():
writer.writeField("end_time", req.endTime.get())
writer.writeField("endTime", req.endTime.get())

writer.writeField("message_hashes", req.messageHashes)
writer.writeField("messageHashes", req.messageHashes)

if req.paginationCursor.isSome():
writer.writeField("pagination_cursor", req.paginationCursor.get())
writer.writeField("paginationCursor", req.paginationCursor.get())

writer.writeField("pagination_forward", req.paginationForward)
writer.writeField("paginationForward", req.paginationForward)

if req.paginationLimit.isSome():
writer.writeField("pagination_limit", req.paginationLimit.get())
writer.writeField("paginationLimit", req.paginationLimit.get())

writer.endRecord()

0 comments on commit 176c98c

Please sign in to comment.