Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
Loading...
Searching...
No Matches
feed_types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <optional>
6#include <string>
7#include <vector>
8#include <format>
9
10#include <nlohmann/json.hpp>
11
12#include "parser.hpp"
13
14namespace dcn::feed
15{
16 constexpr std::size_t DEFAULT_FEED_LIMIT = 100;
17 constexpr std::size_t MAX_FEED_LIMIT = 256;
18 constexpr std::size_t DEFAULT_STREAM_LIMIT = 500;
19 constexpr std::size_t MAX_STREAM_LIMIT = 2048;
20
21 struct CursorKey
22 {
23 int chain_id = 1;
24 std::string chain_namespace = "local";
25 std::int64_t created_at_ms = 0;
26 std::int64_t block_number = 0;
27 std::int64_t tx_index = 0;
28 std::string feed_id;
29 };
30
31 struct FeedItem
32 {
33 std::string feed_id;
34 std::string event_type;
35 std::string status;
36 bool visible = true;
37 std::string tx_hash;
38 std::int64_t block_number = 0;
39 std::int64_t tx_index = 0;
40 std::int64_t log_index = 0;
41 std::string history_cursor;
42 std::int64_t created_at_ms = 0;
43 std::int64_t updated_at_ms = 0;
45 nlohmann::json payload;
46 };
47
48 struct FeedQuery
49 {
51 std::optional<std::string> before_cursor = std::nullopt;
52 std::optional<std::string> event_type = std::nullopt;
54 };
55
56 struct FeedPage
57 {
58 std::vector<FeedItem> items;
59 std::optional<std::string> next_before_cursor = std::nullopt;
60 bool has_more = false;
61 };
62
64 {
65 std::int64_t since_seq = 0;
66 std::size_t limit = 200;
67 };
68
70 {
71 std::int64_t stream_seq = 0;
72 std::string event_type;
73 std::string status;
74 std::string feed_id;
75 std::string history_cursor;
76 std::int64_t created_at_ms = 0;
77 nlohmann::json payload;
78 };
79
81 {
82 std::vector<StreamDelta> deltas;
83 std::optional<std::int64_t> last_seq = std::nullopt;
84 std::int64_t min_available_seq = 0;
85 std::int64_t replay_floor_seq = 0;
86 bool stale_since_seq = false;
87 bool has_more = false;
88 };
89
91 {
92 public:
93 virtual ~IFeedRepository() = default;
94
95 virtual FeedPage getFeedPage(const FeedQuery & query) const = 0;
96 virtual StreamPage getStreamPage(const StreamQuery & query) const = 0;
97 virtual std::int64_t minAvailableStreamSeq() const = 0;
98 };
99
100 parse::Result<CursorKey> parseHistoryCursor(const std::string & cursor);
101}
102
103template <>
104struct std::formatter<dcn::feed::CursorKey> : std::formatter<std::string> {
105 auto format(const dcn::feed::CursorKey & cursor, format_context& ctx) const {
106 return std::formatter<std::string>::format(
107 std::format("c{}:{}:{}:{}",
108 cursor.created_at_ms,
109 cursor.block_number,
110 cursor.tx_index,
111 cursor.feed_id),
112 ctx);
113 }
114};
Definition feed_types.hpp:91
virtual ~IFeedRepository()=default
virtual StreamPage getStreamPage(const StreamQuery &query) const =0
virtual std::int64_t minAvailableStreamSeq() const =0
virtual FeedPage getFeedPage(const FeedQuery &query) const =0
Definition feed.hpp:17
constexpr std::size_t DEFAULT_FEED_LIMIT
Definition feed_types.hpp:16
constexpr std::size_t MAX_STREAM_LIMIT
Definition feed_types.hpp:19
constexpr std::size_t DEFAULT_STREAM_LIMIT
Definition feed_types.hpp:18
constexpr std::size_t MAX_FEED_LIMIT
Definition feed_types.hpp:17
parse::Result< CursorKey > parseHistoryCursor(const std::string &cursor)
Definition feed_types.cpp:5
std::expected< T, ParseError > Result
Definition parse_error.hpp:26
Definition decentralised_art.hpp:35
Definition feed_types.hpp:22
std::string chain_namespace
Definition feed_types.hpp:24
std::int64_t block_number
Definition feed_types.hpp:26
std::string feed_id
Definition feed_types.hpp:28
int chain_id
Definition feed_types.hpp:23
std::int64_t created_at_ms
Definition feed_types.hpp:25
std::int64_t tx_index
Definition feed_types.hpp:27
Definition feed_types.hpp:32
bool visible
Definition feed_types.hpp:36
std::int64_t tx_index
Definition feed_types.hpp:39
int projector_version
Definition feed_types.hpp:44
nlohmann::json payload
Definition feed_types.hpp:45
std::string status
Definition feed_types.hpp:35
std::int64_t updated_at_ms
Definition feed_types.hpp:43
std::string tx_hash
Definition feed_types.hpp:37
std::string history_cursor
Definition feed_types.hpp:41
std::string event_type
Definition feed_types.hpp:34
std::int64_t log_index
Definition feed_types.hpp:40
std::int64_t block_number
Definition feed_types.hpp:38
std::string feed_id
Definition feed_types.hpp:33
std::int64_t created_at_ms
Definition feed_types.hpp:42
Definition feed_types.hpp:57
std::vector< FeedItem > items
Definition feed_types.hpp:58
std::optional< std::string > next_before_cursor
Definition feed_types.hpp:59
bool has_more
Definition feed_types.hpp:60
Definition feed_types.hpp:49
bool include_unfinalized
Definition feed_types.hpp:53
std::optional< std::string > before_cursor
Definition feed_types.hpp:51
std::optional< std::string > event_type
Definition feed_types.hpp:52
std::size_t limit
Definition feed_types.hpp:50
Definition feed_types.hpp:70
std::int64_t stream_seq
Definition feed_types.hpp:71
nlohmann::json payload
Definition feed_types.hpp:77
std::string history_cursor
Definition feed_types.hpp:75
std::string status
Definition feed_types.hpp:73
std::string feed_id
Definition feed_types.hpp:74
std::string event_type
Definition feed_types.hpp:72
std::int64_t created_at_ms
Definition feed_types.hpp:76
Definition feed_types.hpp:81
std::vector< StreamDelta > deltas
Definition feed_types.hpp:82
std::int64_t replay_floor_seq
Definition feed_types.hpp:85
bool stale_since_seq
Definition feed_types.hpp:86
bool has_more
Definition feed_types.hpp:87
std::int64_t min_available_seq
Definition feed_types.hpp:84
std::optional< std::int64_t > last_seq
Definition feed_types.hpp:83
Definition feed_types.hpp:64
std::size_t limit
Definition feed_types.hpp:66
std::int64_t since_seq
Definition feed_types.hpp:65
auto format(const dcn::feed::CursorKey &cursor, format_context &ctx) const
Definition feed_types.hpp:105