standardize store types by using camel case instead of snake case (#2709)

This commit is contained in:
Ivan FB 2024-05-17 16:56:54 +02:00 committed by GitHub
parent 3faffdbcaa
commit 176c98c589
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 55 deletions

View File

@ -142,7 +142,7 @@ proc writeValue*(
writer.beginRecord() writer.beginRecord()
writer.writeField("payload", $value.payload) writer.writeField("payload", $value.payload)
if value.contentTopic.isSome(): if value.contentTopic.isSome():
writer.writeField("content_topic", value.contentTopic.get()) writer.writeField("contentTopic", value.contentTopic.get())
if value.version.isSome(): if value.version.isSome():
writer.writeField("version", value.version.get()) writer.writeField("version", value.version.get())
if value.timestamp.isSome(): if value.timestamp.isSome():
@ -178,7 +178,7 @@ proc readValue*(
case fieldName case fieldName
of "payload": of "payload":
payload = some(reader.readValue(Base64String)) payload = some(reader.readValue(Base64String))
of "content_topic": of "contentTopic":
contentTopic = some(reader.readValue(ContentTopic)) contentTopic = some(reader.readValue(ContentTopic))
of "version": of "version":
version = some(reader.readValue(uint32)) version = some(reader.readValue(uint32))
@ -245,9 +245,9 @@ proc writeValue*(
writer: var JsonWriter, value: HistoryCursorRest writer: var JsonWriter, value: HistoryCursorRest
) {.gcsafe, raises: [IOError].} = ) {.gcsafe, raises: [IOError].} =
writer.beginRecord() writer.beginRecord()
writer.writeField("pubsub_topic", value.pubsubTopic) writer.writeField("pubsubTopic", value.pubsubTopic)
writer.writeField("sender_time", value.senderTime) writer.writeField("senderTime", value.senderTime)
writer.writeField("store_time", value.storeTime) writer.writeField("storeTime", value.storeTime)
writer.writeField("digest", value.digest) writer.writeField("digest", value.digest)
writer.endRecord() writer.endRecord()
@ -262,22 +262,22 @@ proc readValue*(
for fieldName in readObjectFields(reader): for fieldName in readObjectFields(reader):
case fieldName case fieldName
of "pubsub_topic": of "pubsubTopic":
if pubsubTopic.isSome(): if pubsubTopic.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `pubsub_topic` fields found", "HistoryCursorRest" "Multiple `pubsubTopic` fields found", "HistoryCursorRest"
) )
pubsubTopic = some(reader.readValue(PubsubTopic)) pubsubTopic = some(reader.readValue(PubsubTopic))
of "sender_time": of "senderTime":
if senderTime.isSome(): if senderTime.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `sender_time` fields found", "HistoryCursorRest" "Multiple `senderTime` fields found", "HistoryCursorRest"
) )
senderTime = some(reader.readValue(Timestamp)) senderTime = some(reader.readValue(Timestamp))
of "store_time": of "storeTime":
if storeTime.isSome(): if storeTime.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `store_time` fields found", "HistoryCursorRest" "Multiple `storeTime` fields found", "HistoryCursorRest"
) )
storeTime = some(reader.readValue(Timestamp)) storeTime = some(reader.readValue(Timestamp))
of "digest": of "digest":
@ -290,13 +290,13 @@ proc readValue*(
reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName)) reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName))
if pubsubTopic.isNone(): if pubsubTopic.isNone():
reader.raiseUnexpectedValue("Field `pubsub_topic` is missing") reader.raiseUnexpectedValue("Field `pubsubTopic` is missing")
if senderTime.isNone(): if senderTime.isNone():
reader.raiseUnexpectedValue("Field `sender_time` is missing") reader.raiseUnexpectedValue("Field `senderTime` is missing")
if storeTime.isNone(): if storeTime.isNone():
reader.raiseUnexpectedValue("Field `store_time` is missing") reader.raiseUnexpectedValue("Field `storeTime` is missing")
if digest.isNone(): if digest.isNone():
reader.raiseUnexpectedValue("Field `digest` is missing") reader.raiseUnexpectedValue("Field `digest` is missing")
@ -320,7 +320,7 @@ proc writeValue*(
if value.cursor.isSome(): if value.cursor.isSome():
writer.writeField("cursor", value.cursor.get()) writer.writeField("cursor", value.cursor.get())
if value.errorMessage.isSome(): if value.errorMessage.isSome():
writer.writeField("error_message", value.errorMessage.get()) writer.writeField("errorMessage", value.errorMessage.get())
writer.endRecord() writer.endRecord()
proc readValue*( proc readValue*(
@ -345,10 +345,10 @@ proc readValue*(
"Multiple `cursor` fields found", "StoreResponseRest" "Multiple `cursor` fields found", "StoreResponseRest"
) )
cursor = some(reader.readValue(HistoryCursorRest)) cursor = some(reader.readValue(HistoryCursorRest))
of "error_message": of "errorMessage":
if errorMessage.isSome(): if errorMessage.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `error_message` fields found", "StoreResponseRest" "Multiple `errorMessage` fields found", "StoreResponseRest"
) )
errorMessage = some(reader.readValue(string)) errorMessage = some(reader.readValue(string))
else: else:
@ -370,13 +370,13 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} = ) {.gcsafe, raises: [IOError].} =
writer.beginRecord() writer.beginRecord()
if value.pubsubTopic.isSome(): if value.pubsubTopic.isSome():
writer.writeField("pubsub_topic", value.pubsubTopic.get()) writer.writeField("pubsubTopic", value.pubsubTopic.get())
writer.writeField("content_topics", value.contentTopics) writer.writeField("contentTopics", value.contentTopics)
if value.startTime.isSome(): if value.startTime.isSome():
writer.writeField("start_time", value.startTime.get()) writer.writeField("startTime", value.startTime.get())
if value.endTime.isSome(): if value.endTime.isSome():
writer.writeField("end_time", value.endTime.get()) writer.writeField("endTime", value.endTime.get())
writer.writeField("page_size", value.pageSize) writer.writeField("pageSize", value.pageSize)
writer.writeField("ascending", value.ascending) writer.writeField("ascending", value.ascending)
writer.endRecord() writer.endRecord()

View File

@ -72,7 +72,7 @@ proc writeValue*(
writer.beginRecord() writer.beginRecord()
writer.writeField("payload", base64.encode(msg.payload)) writer.writeField("payload", base64.encode(msg.payload))
writer.writeField("content_topic", msg.contentTopic) writer.writeField("contentTopic", msg.contentTopic)
if msg.meta.len > 0: if msg.meta.len > 0:
writer.writeField("meta", base64.encode(msg.meta)) writer.writeField("meta", base64.encode(msg.meta))
@ -114,7 +114,7 @@ proc readValue*(
let base64String = reader.readValue(Base64String) let base64String = reader.readValue(Base64String)
payload = base64.decode(base64String).valueOr: payload = base64.decode(base64String).valueOr:
reader.raiseUnexpectedField("Failed decoding data", "payload") reader.raiseUnexpectedField("Failed decoding data", "payload")
of "content_topic": of "contentTopic":
contentTopic = reader.readValue(ContentTopic) contentTopic = reader.readValue(ContentTopic)
of "version": of "version":
version = reader.readValue(uint32) version = reader.readValue(uint32)
@ -185,7 +185,7 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} = ) {.gcsafe, raises: [IOError].} =
writer.beginRecord() writer.beginRecord()
writer.writeField("message_hash", value.messageHash) writer.writeField("messageHash", value.messageHash)
if value.message.isSome(): if value.message.isSome():
writer.writeField("message", value.message.get()) writer.writeField("message", value.message.get())
@ -201,10 +201,10 @@ proc readValue*(
for fieldName in readObjectFields(reader): for fieldName in readObjectFields(reader):
case fieldName case fieldName
of "message_hash": of "messageHash":
if messageHash.isSome(): if messageHash.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `message_hash` fields found", "WakuMessageKeyValue" "Multiple `messageHash` fields found", "WakuMessageKeyValue"
) )
messageHash = some(reader.readValue(WakuMessageHash)) messageHash = some(reader.readValue(WakuMessageHash))
of "message": of "message":
@ -217,7 +217,7 @@ proc readValue*(
reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName)) reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName))
if messageHash.isNone(): if messageHash.isNone():
reader.raiseUnexpectedValue("Field `message_hash` is missing") reader.raiseUnexpectedValue("Field `messageHash` is missing")
value = WakuMessageKeyValue(messageHash: messageHash.get(), message: message) value = WakuMessageKeyValue(messageHash: messageHash.get(), message: message)
@ -228,15 +228,13 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} = ) {.gcsafe, raises: [IOError].} =
writer.beginRecord() writer.beginRecord()
writer.writeField("request_id", value.requestId) writer.writeField("requestId", value.requestId)
writer.writeField("statusCode", value.statusCode)
writer.writeField("status_code", value.statusCode) writer.writeField("statusDesc", value.statusDesc)
writer.writeField("status_desc", value.statusDesc)
writer.writeField("messages", value.messages) writer.writeField("messages", value.messages)
if value.paginationCursor.isSome(): if value.paginationCursor.isSome():
writer.writeField("pagination_cursor", value.paginationCursor.get()) writer.writeField("paginationCursor", value.paginationCursor.get())
writer.endRecord() writer.endRecord()
@ -252,22 +250,22 @@ proc readValue*(
for fieldName in readObjectFields(reader): for fieldName in readObjectFields(reader):
case fieldName case fieldName
of "request_id": of "requestId":
if requestId.isSome(): if requestId.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `request_id` fields found", "StoreQueryResponse" "Multiple `requestId` fields found", "StoreQueryResponse"
) )
requestId = some(reader.readValue(string)) requestId = some(reader.readValue(string))
of "status_code": of "statusCode":
if code.isSome(): if code.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `status_code` fields found", "StoreQueryResponse" "Multiple `statusCode` fields found", "StoreQueryResponse"
) )
code = some(reader.readValue(uint32)) code = some(reader.readValue(uint32))
of "status_desc": of "statusDesc":
if desc.isSome(): if desc.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `status_desc` fields found", "StoreQueryResponse" "Multiple `statusDesc` fields found", "StoreQueryResponse"
) )
desc = some(reader.readValue(string)) desc = some(reader.readValue(string))
of "messages": of "messages":
@ -276,23 +274,23 @@ proc readValue*(
"Multiple `messages` fields found", "StoreQueryResponse" "Multiple `messages` fields found", "StoreQueryResponse"
) )
messages = some(reader.readValue(seq[WakuMessageKeyValue])) messages = some(reader.readValue(seq[WakuMessageKeyValue]))
of "pagination_cursor": of "paginationCursor":
if cursor.isSome(): if cursor.isSome():
reader.raiseUnexpectedField( reader.raiseUnexpectedField(
"Multiple `pagination_cursor` fields found", "StoreQueryResponse" "Multiple `paginationCursor` fields found", "StoreQueryResponse"
) )
cursor = some(reader.readValue(WakuMessageHash)) cursor = some(reader.readValue(WakuMessageHash))
else: else:
reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName)) reader.raiseUnexpectedField("Unrecognided field", cstring(fieldName))
if requestId.isNone(): if requestId.isNone():
reader.raiseUnexpectedValue("Field `request_id` is missing") reader.raiseUnexpectedValue("Field `requestId` is missing")
if code.isNone(): if code.isNone():
reader.raiseUnexpectedValue("Field `status_code` is missing") reader.raiseUnexpectedValue("Field `statusCode` is missing")
if desc.isNone(): if desc.isNone():
reader.raiseUnexpectedValue("Field `status_desc` is missing") reader.raiseUnexpectedValue("Field `statusDesc` is missing")
if messages.isNone(): if messages.isNone():
reader.raiseUnexpectedValue("Field `messages` is missing") reader.raiseUnexpectedValue("Field `messages` is missing")
@ -312,28 +310,28 @@ proc writeValue*(
) {.gcsafe, raises: [IOError].} = ) {.gcsafe, raises: [IOError].} =
writer.beginRecord() writer.beginRecord()
writer.writeField("request_id", req.requestId) writer.writeField("requestId", req.requestId)
writer.writeField("include_data", req.includeData) writer.writeField("includeData", req.includeData)
if req.pubsubTopic.isSome(): 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(): if req.startTime.isSome():
writer.writeField("start_time", req.startTime.get()) writer.writeField("startTime", req.startTime.get())
if req.endTime.isSome(): 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(): 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(): if req.paginationLimit.isSome():
writer.writeField("pagination_limit", req.paginationLimit.get()) writer.writeField("paginationLimit", req.paginationLimit.get())
writer.endRecord() writer.endRecord()