A valid package index page
This commit is contained in:
parent
88c8480911
commit
58f77a06ea
15 changed files with 210 additions and 153 deletions
|
|
@ -1,27 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class RegistrationPageIndexQuery : RegistrationPageIndex
|
||||
{
|
||||
|
||||
public RegistrationPageIndexQuery() : base("")
|
||||
{
|
||||
}
|
||||
public RegistrationPageIndexQuery(string bid, IEnumerable<RegistrationLeaf> leaves) : base(bid, leaves)
|
||||
{
|
||||
}
|
||||
|
||||
[JsonProperty("query")]
|
||||
public string Query { get; set; }
|
||||
|
||||
[JsonProperty("prerelease")]
|
||||
public bool Prerelease { get; set; }
|
||||
|
||||
public int Skip { get; set; }
|
||||
|
||||
public int Take { get; set; } = 25;
|
||||
public int TotalHits { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,62 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using isnd.Data.Packages;
|
||||
using Newtonsoft.Json;
|
||||
using NuGet.Versioning;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class RegistrationPage
|
||||
public class RegistrationPage
|
||||
{
|
||||
[JsonProperty("@id")]
|
||||
[JsonRequired]
|
||||
public string Id { get; }
|
||||
public RegistrationPage (string id)
|
||||
public string Id { get; protected set;}
|
||||
|
||||
private List<PackageVersion> items;
|
||||
|
||||
protected string Bid { get ; private set; }
|
||||
public string DlBase { get; }
|
||||
|
||||
public RegistrationPage (string bid, string dlBase)
|
||||
{
|
||||
Id = id;
|
||||
Items = new List<RegistrationLeaf>();
|
||||
Bid = bid;
|
||||
DlBase = dlBase;
|
||||
this.items = new List<PackageVersion>();
|
||||
}
|
||||
|
||||
public RegistrationPage (string bid, string pkgid, string dlBase, IEnumerable<PackageVersion> items)
|
||||
{
|
||||
Bid = bid;
|
||||
Parent = Bid + "/index.json";
|
||||
DlBase = dlBase;
|
||||
this.items = new List<PackageVersion>(items);
|
||||
SetPackageId(pkgid);
|
||||
UpdateCompact();
|
||||
}
|
||||
|
||||
protected void SetPackageId(string pkgid)
|
||||
{
|
||||
this.Id = Bid + "/" + pkgid + "/index.json";
|
||||
}
|
||||
|
||||
private void UpdateCompact()
|
||||
{
|
||||
NuGetVersion upper = new NuGetVersion(0,0,0);
|
||||
|
||||
// Assert.True(items.All(p=>p.Id == id));
|
||||
|
||||
foreach (var p in items)
|
||||
{
|
||||
if (upper < p.NugetVersion) upper = p.NugetVersion;
|
||||
}
|
||||
Upper = upper.ToFullString();
|
||||
NuGetVersion lower = upper;
|
||||
foreach (var p in items)
|
||||
{
|
||||
if (lower > p.NugetVersion) lower = p.NugetVersion;
|
||||
}
|
||||
Lower = lower.ToFullString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -21,19 +65,26 @@ namespace isnd.Data.Catalog
|
|||
/// <value></value>
|
||||
[JsonProperty("items")]
|
||||
|
||||
public List<RegistrationLeaf> Items { get; set; }
|
||||
public RegistrationLeaf[] Items { get => items.Select((p) => p.ToLeave(Bid, DlBase)).ToArray(); }
|
||||
|
||||
public void AddVersionRange(IEnumerable<PackageVersion> vitems)
|
||||
{
|
||||
if (vitems.Count() == 0) return;
|
||||
items.AddRange(vitems);
|
||||
UpdateCompact();
|
||||
}
|
||||
/// <summary>
|
||||
/// The highest SemVer 2.0.0 version in the page (inclusive)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("upper"), JsonRequired]
|
||||
public Version Upper { get; set; }
|
||||
public string Upper { get; private set; }
|
||||
/// <summary>
|
||||
/// The lowest SemVer 2.0.0 version in the page (inclusive)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("lower"), JsonRequired]
|
||||
public Version Lower { get; set; }
|
||||
public string Lower { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL to the registration index
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using isnd.Data.Packages;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
|
|
@ -10,30 +12,24 @@ namespace isnd.Data.Catalog
|
|||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("@id")]
|
||||
public string Id { get; set; }
|
||||
public RegistrationPageIndex(string id)
|
||||
public string Id { get; protected set; }
|
||||
|
||||
public RegistrationPageIndex(string bid, string id)
|
||||
{
|
||||
Id = id;
|
||||
Id = bid + "/" + id + "/index.json";
|
||||
Items = new List<RegistrationPage>();
|
||||
}
|
||||
|
||||
public RegistrationPageIndex(IEnumerable<RegistrationPage> pages)
|
||||
{
|
||||
Items = new List<RegistrationPage>(pages);
|
||||
}
|
||||
|
||||
public RegistrationPageIndex(string id, IEnumerable<RegistrationLeaf> leaves) : this(id)
|
||||
public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable<Package> pkgs) : this(bid, id)
|
||||
{
|
||||
// leaves;
|
||||
this.Items = new List<RegistrationPage>
|
||||
(
|
||||
|
||||
|
||||
)
|
||||
{
|
||||
|
||||
|
||||
};
|
||||
(pkgs.GroupBy(l => l.Id)
|
||||
.Select(lg => new RegistrationPage
|
||||
(bid, lg.Key, dlBase, lg.ToArray()
|
||||
.Select(p => p.Versions).Aggregate
|
||||
((l, m) => { l.AddRange(m); return l.ToList(); })
|
||||
)));
|
||||
}
|
||||
|
||||
[JsonProperty("count")]
|
||||
|
|
|
|||
28
src/isnd/Data/Catalog/RegistrationPageIndexQuery.cs
Normal file
28
src/isnd/Data/Catalog/RegistrationPageIndexQuery.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections.Generic;
|
||||
using isnd.Data.Packages;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class RegistrationPageIndexQuery
|
||||
{
|
||||
|
||||
public RegistrationPageIndexQuery()
|
||||
{
|
||||
}
|
||||
|
||||
[JsonProperty("query")]
|
||||
public string Query { get; set; }
|
||||
|
||||
[JsonProperty("prerelease")]
|
||||
public bool Prerelease { get; set; } = true;
|
||||
[JsonProperty("skip")]
|
||||
|
||||
public int Skip { get; set; } = 0;
|
||||
[JsonProperty("take")]
|
||||
|
||||
public int Take { get; set; } = 25;
|
||||
[JsonProperty("totalHits")]
|
||||
public int TotalHits { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using isn.abst;
|
||||
using isnd.Data.Catalog;
|
||||
using isnd.Data.Packages;
|
||||
using isnd.Data.Packages.Catalog;
|
||||
using Newtonsoft.Json;
|
||||
|
|
@ -28,6 +29,11 @@ namespace isnd.Data
|
|||
|
||||
public int Revision { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Full version string
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[StringLength(256)]
|
||||
[Required][Key]
|
||||
public string FullString { get; set; }
|
||||
|
|
@ -48,13 +54,30 @@ namespace isnd.Data
|
|||
public string CommitId { get => CommitNId.ToString(); }
|
||||
|
||||
public virtual Commit LatestCommit {get; set; }
|
||||
public string NugetLink => $"/{Constants.PaquetFileEstension}/{PackageId}/{FullString}/{PackageId}-{FullString}."
|
||||
public string NugetLink => $"{Constants.PaquetFileEstension}/{PackageId}/{FullString}/{PackageId}-{FullString}."
|
||||
+ Constants.PaquetFileEstension;
|
||||
public string NuspecLink => $"/{Constants.SpecFileEstension}/{PackageId}/{FullString}/{PackageId}-{FullString}."
|
||||
public string NuspecLink => $"{Constants.SpecFileEstension}/{PackageId}/{FullString}/{PackageId}-{FullString}."
|
||||
+ Constants.SpecFileEstension;
|
||||
|
||||
public string SementicVersionString { get => $"{Major}.{Minor}.{Patch}"; }
|
||||
public NuGetVersion NugetVersion { get => new NuGetVersion(FullString); }
|
||||
|
||||
public RegistrationLeaf ToLeave(string bid, string dlbase)
|
||||
{
|
||||
string leaveid = bid + "/" + this.PackageId + "/" + FullString + ".json";
|
||||
return new RegistrationLeaf
|
||||
{
|
||||
Id = leaveid,
|
||||
PackageContent = dlbase + NugetLink,
|
||||
Entry = new CatalogEntry
|
||||
{
|
||||
Id = leaveid,
|
||||
idp = PackageId,
|
||||
version = FullString,
|
||||
authors = $"{this.Package.Owner.FullName} <${Package.Owner.Email}>"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue