parcel 0.2.4
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
audit.h
Go to the documentation of this file.
1#pragma once
2
20#include <parcel/cell.h>
21#include <parcel/common.h>
22#include <parcel/defaults.h>
23#include <parcel/descriptor.h>
24#include <parcel/json.h>
25
26#include <commons/audit_record.hpp>
27#include <commons/identity.hpp>
28#include <commons/json/audit_record.hpp>
29
30#include <cstddef>
31#include <string>
32#include <string_view>
33
34namespace parcel {
35
43class AuditRecordCell : public BaseCell<AuditRecordCell, comms::AuditRecord> {
45
46public:
47 using base_t::base_t;
48 using base_t::operator=;
49
50 static constexpr std::string_view kind_id = "audit_record";
51
52 [[nodiscard]] std::string to_string() const override {
53 return this->value.identity ? comms::to_string(*this->value.identity) : std::string{"—"};
54 }
55
56 static cell_t from_json(json_t const& j, ParcelRegistry const&) {
58 }
59
60 static cell_type_descriptor_t descriptor() {
61 static const auto d = std::make_shared<SimpleCellTypeDescriptor<AuditRecordCell>>(
62 DisplayInfo{.name = "AuditRecord",
63 .description = "Audit-trail entry (who did what, when, from where)"});
64 return d;
65 }
66};
67
75class AuditRecordsCell : public BaseCell<AuditRecordsCell, comms::AuditRecords> {
77
78public:
79 using base_t::base_t;
80 using base_t::operator=;
81
82 static constexpr std::string_view kind_id = "audit_records";
83
84 [[nodiscard]] std::string to_string() const override {
85 return "[" + std::to_string(this->value.size()) + " audit records]";
86 }
87
88 static cell_t from_json(json_t const& j, ParcelRegistry const&) {
90 }
91
92 static cell_type_descriptor_t descriptor() {
93 static const auto d = std::make_shared<SimpleCellTypeDescriptor<AuditRecordsCell>>(
94 DisplayInfo{.name = "AuditRecords",
95 .description = "Capped, insertion-ordered log of audit records"});
96 return d;
97 }
98};
99
112template <CellLike P>
114 : public BaseCell<ChangeAuditRecordCell<P>, comms::ChangeAuditRecord<typename P::storage_t>> {
116
117public:
118 using element_type = P;
119
120 using base_t::base_t;
121 using base_t::operator=;
122
123 static constexpr std::string_view kind_id = prefixed_id_v<"change_audit_record:", P::kind_id>;
124
125 [[nodiscard]] std::string to_string() const override {
126 return this->value.identity ? comms::to_string(*this->value.identity) : std::string{"—"};
127 }
128
129 static cell_t from_json(json_t const& j, ParcelRegistry const&) {
130 return base_t::from_json_strict(j);
131 }
132
133 static cell_type_descriptor_t descriptor() {
134 static const auto d = std::make_shared<SimpleCellTypeDescriptor<ChangeAuditRecordCell>>(
135 DisplayInfo{.name = "ChangeAuditRecord",
136 .description = std::string("Audit-trail change entry (before/after ") +
137 std::string(P::kind_id) + ")"});
138 return d;
139 }
140};
141
151template <CellLike P>
153 : public BaseCell<ChangeAuditRecordsCell<P>, comms::ChangeAuditRecords<typename P::storage_t>> {
154 using base_t =
156
157public:
158 using element_type = P;
159
160 using base_t::base_t;
161 using base_t::operator=;
162
163 static constexpr std::string_view kind_id = prefixed_id_v<"change_audit_records:", P::kind_id>;
164
165 [[nodiscard]] std::string to_string() const override {
166 return "[" + std::to_string(this->value.size()) + " change audit records]";
167 }
168
169 static cell_t from_json(json_t const& j, ParcelRegistry const&) {
170 return base_t::from_json_strict(j);
171 }
172
173 static cell_type_descriptor_t descriptor() {
174 static const auto d =
175 std::make_shared<SimpleCellTypeDescriptor<ChangeAuditRecordsCell>>(DisplayInfo{
176 .name = "ChangeAuditRecords",
177 .description = std::string("Capped log of change audit records (before/after ") +
178 std::string(P::kind_id) + ")"});
179 return d;
180 }
181};
182
183} // namespace parcel
184
Core ICell interface, cell_t handle, BaseCell CRTP base, and CellLike concept.
std::shared_ptr< ICell > cell_t
Shared handle to any ICell-derived value — the canonical cell pointer.
Definition cell.h:68
Cell wrapping comms::AuditRecord.
Definition audit.h:43
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition audit.h:52
Cell wrapping comms::AuditRecords (= comms::AuditLog<comms::AuditRecord>).
Definition audit.h:75
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition audit.h:84
Cell wrapping comms::ChangeAuditRecord<typename P::storage_t>, the before/after change refinement of ...
Definition audit.h:114
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition audit.h:125
Cell wrapping comms::ChangeAuditRecords<typename P::storage_t> (= comms::AuditLog<comms::ChangeAuditR...
Definition audit.h:153
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition audit.h:165
Runtime catalog of cell-type descriptors, keyed by wire kind id.
Definition registry.h:115
The shared vocabulary aliases re-exported from commons and the compile-time kind-id machinery.
constexpr std::string_view prefixed_id_v
Convenience alias yielding the joined std::string_view.
Definition common.h:175
The default_cell_for<T> trait that drives FieldsBuilder field-type inference.
#define PARCEL_DEFAULT_CELL(CellT)
Register a cell type as the default wrapper for its payload type.
Definition defaults.h:269
Runtime cell-type descriptors and the schema-graph mix-ins (IHasFields, ISubTypes).
nlohmann::json typedef shared across cell types.
nlohmann::json json_t
Project-wide alias for nlohmann::json.
Definition json.h:19
CRTP base providing default to_json / clone / kind plumbing on top of a storage type.
Definition cell.h:343
static cell_t from_json_strict(json_t const &j)
Strict shorthand for the recurring cell_from_json + make_shared.
Definition cell.h:571
comms::AuditRecord value
Held value of the cell.
Definition cell.h:348