|
| 1 | +/** @file ResolutionCatalog.hpp |
| 2 | + * Immutable in-memory metadata snapshot for deterministic package resolution. |
| 3 | + */ |
| 4 | +#ifndef VIX_CLI_PROJECT_NATIVE_RESOLUTION_CATALOG_HPP |
| 5 | +#define VIX_CLI_PROJECT_NATIVE_RESOLUTION_CATALOG_HPP |
| 6 | + |
| 7 | +#include <optional> |
| 8 | +#include <string> |
| 9 | +#include <vector> |
| 10 | + |
| 11 | +#include <vix/cli/project/native/Resolver.hpp> |
| 12 | + |
| 13 | +namespace vix::cli::project::native |
| 14 | +{ |
| 15 | + enum class ResolutionCatalogErrorCode |
| 16 | + { |
| 17 | + invalid_contract, |
| 18 | + registry_contract_identity_mismatch, |
| 19 | + registry_contract_version_mismatch, |
| 20 | + invalid_git_contract_source, |
| 21 | + invalid_repository_identity, |
| 22 | + invalid_content_digest, |
| 23 | + duplicate_registry_release, |
| 24 | + conflicting_registry_release, |
| 25 | + duplicate_git_revision, |
| 26 | + conflicting_git_revision, |
| 27 | + conflicting_git_commit_metadata |
| 28 | + }; |
| 29 | + |
| 30 | + struct ResolutionCatalogIssue |
| 31 | + { |
| 32 | + ResolutionCatalogErrorCode code{ResolutionCatalogErrorCode::invalid_contract}; |
| 33 | + std::string subject; |
| 34 | + std::string message; |
| 35 | + }; |
| 36 | + |
| 37 | + struct ResolutionCatalogBuildResult; |
| 38 | + |
| 39 | + class ResolutionCatalog final : public ResolutionMetadataProvider |
| 40 | + { |
| 41 | + public: |
| 42 | + [[nodiscard]] std::vector<RegistryCandidate> registry_candidates( |
| 43 | + const RegistryPackageIdentity &identity) const override; |
| 44 | + [[nodiscard]] std::vector<GitResolution> git_resolutions( |
| 45 | + const std::string &normalizedRepository, |
| 46 | + const GitRevisionRequirement &revision) const override; |
| 47 | + |
| 48 | + private: |
| 49 | + friend struct ResolutionCatalogBuildResult; |
| 50 | + friend ResolutionCatalogBuildResult build_resolution_catalog( |
| 51 | + std::vector<RegistryCandidate>, std::vector<GitResolution>); |
| 52 | + |
| 53 | + ResolutionCatalog(std::vector<RegistryCandidate> registry, std::vector<GitResolution> git); |
| 54 | + |
| 55 | + std::vector<RegistryCandidate> registry_; |
| 56 | + std::vector<GitResolution> git_; |
| 57 | + }; |
| 58 | + |
| 59 | + struct ResolutionCatalogBuildResult |
| 60 | + { |
| 61 | + std::optional<ResolutionCatalog> value; |
| 62 | + std::vector<ResolutionCatalogIssue> issues; |
| 63 | + [[nodiscard]] bool valid() const noexcept { return value.has_value() && issues.empty(); } |
| 64 | + }; |
| 65 | + |
| 66 | + // Builds a finalized value snapshot. Duplicate immutable keys and conflicting |
| 67 | + // Git commit metadata are errors; insertion order never selects a winner. |
| 68 | + [[nodiscard]] ResolutionCatalogBuildResult build_resolution_catalog( |
| 69 | + std::vector<RegistryCandidate> registry, |
| 70 | + std::vector<GitResolution> git); |
| 71 | +} // namespace vix::cli::project::native |
| 72 | + |
| 73 | +#endif // VIX_CLI_PROJECT_NATIVE_RESOLUTION_CATALOG_HPP |
0 commit comments