2024-06-28 10:34:57 +00:00
|
|
|
{.push raises: [].}
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-10-10 12:40:09 +00:00
|
|
|
import std/options, results
|
2024-03-15 23:08:47 +00:00
|
|
|
import ../waku_core, ../common/paging
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Public API types
|
|
|
|
|
|
|
|
type
|
2024-07-12 16:19:12 +00:00
|
|
|
ArchiveCursor* = WakuMessageHash
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
ArchiveQuery* = object
|
2024-07-12 16:19:12 +00:00
|
|
|
includeData*: bool
|
2022-11-22 18:40:24 +00:00
|
|
|
pubsubTopic*: Option[PubsubTopic]
|
|
|
|
contentTopics*: seq[ContentTopic]
|
|
|
|
cursor*: Option[ArchiveCursor]
|
|
|
|
startTime*: Option[Timestamp]
|
|
|
|
endTime*: Option[Timestamp]
|
2024-03-12 11:51:03 +00:00
|
|
|
hashes*: seq[WakuMessageHash]
|
2022-11-22 18:40:24 +00:00
|
|
|
pageSize*: uint
|
2023-12-19 14:10:27 +00:00
|
|
|
direction*: PagingDirection
|
2024-08-29 20:56:14 +00:00
|
|
|
requestId*: string
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
ArchiveResponse* = object
|
2024-03-12 11:51:03 +00:00
|
|
|
hashes*: seq[WakuMessageHash]
|
2022-11-22 18:40:24 +00:00
|
|
|
messages*: seq[WakuMessage]
|
2024-05-08 19:35:56 +00:00
|
|
|
topics*: seq[PubsubTopic]
|
2022-11-22 18:40:24 +00:00
|
|
|
cursor*: Option[ArchiveCursor]
|
|
|
|
|
|
|
|
ArchiveErrorKind* {.pure.} = enum
|
|
|
|
UNKNOWN = uint32(0)
|
|
|
|
DRIVER_ERROR = uint32(1)
|
|
|
|
INVALID_QUERY = uint32(2)
|
|
|
|
|
|
|
|
ArchiveError* = object
|
|
|
|
case kind*: ArchiveErrorKind
|
|
|
|
of DRIVER_ERROR, INVALID_QUERY:
|
|
|
|
# TODO: Add an enum to be able to distinguish between error causes
|
|
|
|
cause*: string
|
|
|
|
else:
|
|
|
|
discard
|
|
|
|
|
|
|
|
ArchiveResult* = Result[ArchiveResponse, ArchiveError]
|
|
|
|
|
|
|
|
proc `$`*(err: ArchiveError): string =
|
2024-03-15 23:08:47 +00:00
|
|
|
case err.kind
|
2022-11-22 18:40:24 +00:00
|
|
|
of ArchiveErrorKind.DRIVER_ERROR:
|
|
|
|
"DIRVER_ERROR: " & err.cause
|
|
|
|
of ArchiveErrorKind.INVALID_QUERY:
|
|
|
|
"INVALID_QUERY: " & err.cause
|
|
|
|
of ArchiveErrorKind.UNKNOWN:
|
|
|
|
"UNKNOWN"
|
2023-01-11 11:19:59 +00:00
|
|
|
|
|
|
|
proc invalidQuery*(T: type ArchiveError, cause: string): T =
|
|
|
|
ArchiveError(kind: ArchiveErrorKind.INVALID_QUERY, cause: cause)
|