Skip to content

Commit 4ef4aa9

Browse files
chore: migrate messaging REST API to Opt[T]
Follow-up to the rebase onto master's repo-wide Option[T] -> Opt[T] change (#4035). Converts the code this branch adds to the new convention: - messaging/rest_api/types.nim: MessagingJsonEnvelope fields to Opt[T], Opt.some/Opt.none, and json_serialization/pkg/results instead of json_serialization/std/options. - tests: WakuNodeConf.clusterId is now Opt[uint16]; DTO fields are Opt. `Option[ContentBody]` in the handlers is presto's own API and stays as-is. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cb9c7f6 commit 4ef4aa9

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

logos_delivery/messaging/rest_api/types.nim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import
55
chronicles,
66
results,
77
json_serialization,
8-
json_serialization/std/options,
8+
json_serialization/pkg/results,
99
presto/[route, client, common]
1010
import
1111
logos_delivery/waku/common/base64,
@@ -22,8 +22,8 @@ type MessagingJsonEnvelope* = object
2222
## `payload` / `meta` are base64. Fields mirror `MessageEnvelope` exactly.
2323
payload*: Base64String
2424
contentTopic*: ContentTopic
25-
ephemeral*: Option[bool]
26-
meta*: Option[Base64String]
25+
ephemeral*: Opt[bool]
26+
meta*: Opt[Base64String]
2727

2828
type MessagingPostMessageRequest* = MessagingJsonEnvelope
2929

@@ -66,10 +66,10 @@ proc readValue*(
6666
reader: var JsonReader[RestJson], value: var MessagingJsonEnvelope
6767
) {.raises: [SerializationError, IOError].} =
6868
var
69-
payload = none(Base64String)
70-
contentTopic = none(ContentTopic)
71-
ephemeral = none(bool)
72-
meta = none(Base64String)
69+
payload = Opt.none(Base64String)
70+
contentTopic = Opt.none(ContentTopic)
71+
ephemeral = Opt.none(bool)
72+
meta = Opt.none(Base64String)
7373

7474
var keys = initHashSet[string]()
7575
for fieldName in readObjectFields(reader):
@@ -84,13 +84,13 @@ proc readValue*(
8484

8585
case fieldName
8686
of "payload":
87-
payload = some(reader.readValue(Base64String))
87+
payload = Opt.some(reader.readValue(Base64String))
8888
of "contentTopic":
89-
contentTopic = some(reader.readValue(ContentTopic))
89+
contentTopic = Opt.some(reader.readValue(ContentTopic))
9090
of "ephemeral":
91-
ephemeral = some(reader.readValue(bool))
91+
ephemeral = Opt.some(reader.readValue(bool))
9292
of "meta":
93-
meta = some(reader.readValue(Base64String))
93+
meta = Opt.some(reader.readValue(Base64String))
9494
else:
9595
unrecognizedFieldWarning(value)
9696

@@ -117,7 +117,7 @@ proc writeValue*(
117117
proc readValue*(
118118
reader: var JsonReader[RestJson], value: var MessagingSendResponse
119119
) {.raises: [SerializationError, IOError].} =
120-
var requestId = none(string)
120+
var requestId = Opt.none(string)
121121

122122
var keys = initHashSet[string]()
123123
for fieldName in readObjectFields(reader):
@@ -131,7 +131,7 @@ proc readValue*(
131131

132132
case fieldName
133133
of "requestId":
134-
requestId = some(reader.readValue(string))
134+
requestId = Opt.some(reader.readValue(string))
135135
else:
136136
unrecognizedFieldWarning(value)
137137

@@ -214,15 +214,15 @@ proc readValue*(
214214
reader: var JsonReader[RestJson], value: var SendEventRecord
215215
) {.raises: [SerializationError, IOError].} =
216216
var
217-
kind = none(SendEventKind)
217+
kind = Opt.none(SendEventKind)
218218
messageHash = ""
219219
error = ""
220220
timestamp = int64(0)
221221

222222
for fieldName in readObjectFields(reader):
223223
case fieldName
224224
of "kind":
225-
kind = some(reader.readValue(SendEventKind))
225+
kind = Opt.some(reader.readValue(SendEventKind))
226226
of "messageHash":
227227
messageHash = reader.readValue(string)
228228
of "error":

tests/api/test_entry_layer.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ proc nodeConf(entryLayer: EntryLayer, rest = false): WakuNodeConf =
2727
conf.listenAddress = parseIpAddress("0.0.0.0")
2828
conf.tcpPort = Port(0)
2929
conf.discv5UdpPort = Port(0)
30-
conf.clusterId = some(3'u16)
30+
conf.clusterId = Opt.some(3'u16)
3131
conf.numShardsInNetwork = 1
3232
conf.rest = rest
3333
conf.restAddress = parseIpAddress("127.0.0.1")

tests/api/test_messaging_rest.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ proc restNodeConf(): WakuNodeConf =
3434
conf.listenAddress = parseIpAddress("0.0.0.0")
3535
conf.tcpPort = Port(0)
3636
conf.discv5UdpPort = Port(0)
37-
conf.clusterId = some(3'u16)
37+
conf.clusterId = Opt.some(3'u16)
3838
conf.numShardsInNetwork = 1
3939
conf.rest = true
4040
conf.restAddress = parseIpAddress("127.0.0.1")
@@ -66,8 +66,8 @@ suite "Messaging REST API":
6666
let msg = MessagingJsonEnvelope(
6767
payload: base64.encode("hello rest"),
6868
contentTopic: contentTopic,
69-
ephemeral: none(bool),
70-
meta: none(Base64String),
69+
ephemeral: Opt.none(bool),
70+
meta: Opt.none(Base64String),
7171
)
7272
let sendResp = await client.messagingPostMessagesV1(msg)
7373
check:

0 commit comments

Comments
 (0)