Package Version constraints

This commit is contained in:
2023-04-30 20:25:03 +01:00
parent fa6272ac28
commit cea05fe8ff
14 changed files with 593 additions and 186 deletions

View File

@ -9,19 +9,21 @@ using isnd.Interfaces;
namespace isnd.Data.Catalog
{
public class CatalogEntry : Permalink, IObject// , IPackageDetails
public class PackageDetails : Permalink, IObject
{
/// <summary>
/// Creates a catalog entry
/// </summary>
/// <param name="id">package details url</param>
/// <returns></returns>
public CatalogEntry(string id): base(id)
{
public PackageDetails(PackageVersion pkg, string apiBase, string uri): base(uri)
{
PackageId = pkg.Package.Id;
Version = pkg.FullString;
authors = $"{pkg.Package.Owner.FullName} <${pkg.Package.Owner.Email}>";
packageContent = apiBase + pkg.NugetLink;
}
[JsonProperty("@type")]
public string[] RefType { get; protected set; } = new string[] { "PackageDetails" };
@ -99,5 +101,8 @@ namespace isnd.Data.Catalog
[JsonProperty("version")]
public string Version { get; set; }
[Required,JsonRequired]
[JsonProperty("id")]
public string PackageId { get; set; }
}
}

View File

@ -14,18 +14,17 @@ namespace isnd.Data.Catalog
Items = new List<CatalogPage>();
}
public PackageRegistration(string bid, string id, string apiBase, Packages.Package pkg) : base(bid + $"/{id}/index.json")
public PackageRegistration(string bid, string apiBase, Packages.Package pkg) : base(bid + $"/{pkg.Id}/index.json")
{
Items = new List<CatalogPage>
{
new CatalogPage(bid, id, apiBase, pkg.Versions)
new CatalogPage(bid, pkg.Id, apiBase, pkg.Versions)
};
if (pkg.Versions.Count>0)
{
CommitId = pkg.Versions.Max(v=>v.CommitNId).ToString();
CommitTimeStamp = pkg.Versions.Max(v=>v.LatestCommit.CommitTimeStamp);
}
CommitId = pkg.LatestCommit.CommitId;
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
}
[JsonProperty("count")]

View File

@ -11,9 +11,11 @@ namespace isnd.Data.Catalog
/// </summary>
public class Package
{
public Package(string apiBase, string pkgId, string fullVersionString, CatalogEntry entry)
public Package(string apiBase, string pkgId, string fullVersionString, PackageDetails entry)
{
this.registration = apiBase + ApiConfig.Registration + "/" + pkgId + "/index.json";
this.registration = apiBase + ApiConfig.Registration + "/" + pkgId + "/" + fullVersionString + ".json";
Id = registration;
this.PackageContent = apiBase + ApiConfig.Nuget + "/" + pkgId + "/" + fullVersionString
+ "/" + pkgId + "-" + fullVersionString + "." + Constants.PaquetFileEstension;
Entry = entry;
@ -38,7 +40,7 @@ namespace isnd.Data.Catalog
/// </summary>
/// <value></value>
[JsonProperty("catalogEntry")]
public CatalogEntry Entry { get; set; }
public PackageDetails Entry { get; set; }
/// <summary>
/// The URL to the package content (.nupkg)

View File

@ -20,7 +20,7 @@ namespace isnd.Data.Packages
List<PackageVersion> Versions { get; set; }
long CommitNId { get; set; }
string CommitId { get; }
Commit LatestVersion { get; set; }
Commit LatestCommit { get; set; }
DateTimeOffset CommitTimeStamp { get; set; }
}
@ -61,7 +61,7 @@ namespace isnd.Data.Packages
[ForeignKey("CommitNId")]
public virtual Commit LatestVersion { get; set; }
public virtual Commit LatestCommit { get; set; }
public DateTimeOffset CommitTimeStamp { get; set; }
}

View File

@ -6,11 +6,13 @@ using isnd.Data.Catalog;
using isnd.Data.Packages;
using isnd.Data.Packages.Catalog;
using isnd.Entities;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using NuGet.Versioning;
namespace isnd.Data
{
[PrimaryKey("PackageId", "FullString")]
public class PackageVersion
{
[Required]
@ -37,7 +39,6 @@ namespace isnd.Data
/// <value></value>
[StringLength(256)]
[Required]
[Key]
public string FullString { get; set; }
public bool IsPrerelease { get; set; }
@ -67,14 +68,8 @@ namespace isnd.Data
public Catalog.Package ToPackage(string apiBase)
{
return new Catalog.Package(apiBase ,this.PackageId , FullString,
new CatalogEntry(apiBase + ApiConfig.Registration + "/" + this.PackageId + "/" + FullString + ".json")
{
Version = FullString,
authors = $"{this.Package.Owner.FullName} <${Package.Owner.Email}>",
packageContent = apiBase + this.NugetLink
}
);
return new Catalog.Package(apiBase, this.PackageId , FullString,
new Catalog.PackageDetails(this, apiBase, apiBase + ApiConfig.Registration + "/" + this.PackageId + "/" + FullString + ".json"));
}
public bool IsDeleted => LatestCommit.Action == PackageAction.DeletePackage;
}