Fix passing around different versions of PackageSpec

The way this is passed has gotten a bit inconsistent; let's just make it
compatible both ways.
This commit is contained in:
Martchus 2022-01-31 20:49:54 +01:00
parent 92f83fadb6
commit 162f56c5e3
4 changed files with 24 additions and 4 deletions

View File

@ -553,8 +553,23 @@ template <>
LIBPKG_EXPORT void pull<LibPkg::PackageSpec>(LibPkg::PackageSpec &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
{
// just deserialize the package (and ignore the ID)
pull(reflectable.pkg, value, errors);
// allow the package being specified with ID or directly
if (!value.IsObject()) {
if (errors) {
errors->reportTypeMismatch<LibPkg::PackageSpec>(value.GetType());
}
return;
}
// find member
const auto obj = value.GetObject();
if (const auto pkg = value.FindMember("pkg"); pkg != value.MemberEnd()) {
pull(reflectable.pkg, pkg->value, errors);
if (const auto id = value.FindMember("id"); id != value.MemberEnd()) {
pull(reflectable.id, id->value, errors);
}
} else {
pull(reflectable.pkg, value, errors);
}
}
} // namespace JsonReflector

View File

@ -513,7 +513,7 @@ REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH(LibPkg::DependencySet);
namespace JsonReflector {
// declare custom (de)serialization for PackageSearchResult
// declare custom (de)serialization for LibPkg::PackageSpec
template <>
LIBPKG_EXPORT void push<LibPkg::PackageSpec>(
const LibPkg::PackageSpec &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator);

View File

@ -781,7 +781,7 @@ function renderBuildPreparationBuildData(buildDataForPackage)
function makeVersionsString(packages)
{
const versions = packages.map(packageObj => packageObj.version);
const versions = packages.map(packageObj => packageObj.pkg ? packageObj.pkg.version : packageObj.version);
if (versions.length === 0) {
return '?';
} else if (versions.length === 1) {

View File

@ -65,6 +65,11 @@ const fieldsWithBasics = ['name', 'version', ...fieldsWithoutBasics];
export function renderPackage(packageObj, withoutBasics)
{
const pkgInfo = packageObj.pkg;
if (pkgInfo) {
pkgInfo.id = packageObj.id;
packageObj = pkgInfo;
}
const table = GenericRendering.renderTableFromJsonObject({
data: packageObj,
displayLabels: withoutBasics ? labelsWithoutBasics : labelsWithBasics,