Arachne 1.0
Arachne - the perpetual stitcher of Wikidata entities.
Loading...
Searching...
No Matches
contracts.hpp
Go to the documentation of this file.
1#ifndef ARACHNE_CONTRACTS_HPP
2#define ARACHNE_CONTRACTS_HPP
3
4#include <nlohmann/json_fwd.hpp>
5
6#include <optional>
7#include <string>
8#include <string_view>
9#include <vector>
10
12
13/** Supported active actor-boundary and product-inbox contracts. */
26
27/** One independently actionable validation failure. */
28struct diagnostic {
29 std::string instance_path;
30 std::string code;
31 std::string message;
32
33 bool operator==(const diagnostic&) const = default;
34};
35
36/** Validation result. An empty diagnostic list means success. */
39
40 [[nodiscard]] bool valid() const noexcept { return diagnostics.empty(); }
41
42 explicit operator bool() const noexcept { return valid(); }
43};
44
45/** Return the canonical wire name, including its major-version suffix. */
47
48/** Parse an exact, currently supported wire name. */
49[[nodiscard]] std::optional<contract_name>
50parse_contract_name(std::string_view name) noexcept;
51
52/** Whether the contract necessarily carries or references artifact bytes. */
53[[nodiscard]] bool is_artifact_bearing(contract_name name) noexcept;
54
55/**
56 * Validate a document after discovering its type from `contract`, or from
57 * `format` for an Arachne product-inbox batch.
58 */
59[[nodiscard]] validation_result validate(const nlohmann::json& document);
60
61/**
62 * Validate a document and require the supplied contract type.
63 */
65validate(contract_name expected, const nlohmann::json& document);
66
67/**
68 * Serialize JSON deterministically: object keys are lexicographically ordered,
69 * arrays retain their declared order, UTF-8 is retained, and no insignificant
70 * whitespace is emitted.
71 *
72 * @throws std::invalid_argument for discarded or non-finite JSON values.
73 */
74[[nodiscard]] std::string canonical_json(const nlohmann::json& document);
75
76} // namespace arachnespace::contracts
77
78#endif
static nlohmann::ordered_json write_plan(const nlohmann::json &materialization, const std::filesystem::path &destination, std::string storage_ref, std::string product_snapshot_id, std::string product_snapshot_sha256, const candidate_configuration &configuration, std::string created_at)
static nlohmann::ordered_json enrichment_fetch_plan(const nlohmann::json &candidate_pool, const nlohmann::json &available_profiles, std::string source_name, std::string locator, std::string created_at)
static nlohmann::ordered_json configuration_values(const candidate_configuration &configuration={})
static nlohmann::ordered_json build(const nlohmann::json &external_graph, const candidate_configuration &configuration={})
std::vector< ranked_candidate > rank_pool(const graph_input &graph, const candidate_configuration &configuration)
void require_only_fields(const nlohmann::json &value, const std::set< std::string_view, std::less<> > &allowed, std::string_view context)
std::string selection_explanation(const ranked_candidate &candidate)
std::uint64_t natural_identifier(std::string_view value)
bool id_less(std::string_view left, std::string_view right)
void collect_profile_features(const nlohmann::json &value, std::string prefix, feature_vector &output)
void validate_configuration(const candidate_configuration &configuration)
std::map< std::string, double, std::less<> > feature_vector
feature_vector centroid(const std::vector< std::size_t > &members, const std::vector< feature_vector > &features)
graph_input parse_graph(const nlohmann::json &document)
void require_stable_id(std::string_view value, std::string_view context)
void group_and_select(std::vector< ranked_candidate > &pool, const graph_input &graph, const candidate_configuration &configuration)
void publish_immutable_file(const std::filesystem::path &destination, std::string_view bytes)
std::string required_string(const nlohmann::json &value, std::string_view field, std::string_view context)
double weighted_jaccard(const feature_vector &left, const feature_vector &right)
std::string sha256(std::span< const std::byte > bytes)
Definition crypto.cpp:209
std::string sha256_file(const std::filesystem::path &path)
Definition crypto.cpp:221
bool is_artifact_bearing(contract_name name) noexcept
validation_result validate(contract_name expected, const nlohmann::json &document)
validation_result validate(const nlohmann::json &document)
std::optional< contract_name > parse_contract_name(std::string_view name) noexcept
std::string_view to_string(contract_name name) noexcept
std::string canonical_json(const nlohmann::json &document)
bool operator==(const diagnostic &) const =default
std::vector< diagnostic > diagnostics
Definition contracts.hpp:38