From 53c9f5750bc91e96fdf0b08f05130a5faf97f1a0 Mon Sep 17 00:00:00 2001 From: Shuheng Liu Date: Thu, 29 Aug 2024 13:51:11 -0400 Subject: [PATCH 1/2] feat: filter versions by prerelease and snapshot in request query str --- src/cls/ZPM/Package.cls | 34 +++++++++++++++++++++++++++++----- src/cls/ZPM/Registry.cls | 4 +++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/cls/ZPM/Package.cls b/src/cls/ZPM/Package.cls index 268769f..3517964 100644 --- a/src/cls/ZPM/Package.cls +++ b/src/cls/ZPM/Package.cls @@ -140,7 +140,18 @@ Method versionsGet() As %ListOfDataTypes Set tList = ##class(%ListOfDataTypes).%New() Set name = ..name - &sql(SELECT %DLIST(version) INTO :versions FROM Package WHERE name = :name) + Set tPrerelease = $Select($Data(%request) # 2: %request.Get("includePrerelease", 0), 1: 1) + Set tSnapshot = $Select($Data(%request) # 2: %request.Get("includeSnapshots", 0), 1: 1) + &sql( + SELECT %DLIST(version) INTO :versions + FROM Package + WHERE name = :name + AND ( + versionPrerelease IS NULL + OR (:tSnapshot = 1 AND LOWER(versionPrerelease) = 'snapshot') + OR (:tPrerelease = 1 AND LOWER(versionPrerelease) <> 'snapshot') + ) + ) If (SQLCODE=0) { Set ptr = 0 While $ListNext(versions, ptr, version) { @@ -158,12 +169,19 @@ Method versionsGet() As %ListOfDataTypes Return tList } -ClassMethod VersionFind(pkg As %String = "", version As %String = "") As %String +ClassMethod VersionFind(pkg As %String = "", version As %String = "", pPrerelease As %Boolean = 1, pSnapshot As %Boolean = 1) As %String { If (version = "") || (version = "latest") || (version = "*") { // package was published directly in this registry - return the last version - &sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package WHERE Name = :pkg AND UpLink IS NULL - ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC + &sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package + WHERE Name = :pkg + AND UpLink IS NULL + AND ( + versionPrerelease IS NULL + OR (:pSnapshot = 1 AND LOWER(versionPrerelease) = 'snapshot') + OR (:pPrerelease = 1 AND LOWER(versionPrerelease) <> 'snapshot') + ) + ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC ) If SQLCODE=0 { // found @@ -171,7 +189,13 @@ ClassMethod VersionFind(pkg As %String = "", version As %String = "") As %String } Else { // find the latest version in UpLinks Do ##class(ZPM.UpLink).LoadPackageFromAllUpLinks(pkg, "latest") - &sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package WHERE Name = :pkg + &sql(SELECT TOP 1 Version INTO :version FROM ZPM.Package + WHERE Name = :pkg + AND ( + versionPrerelease IS NULL + OR (:pSnapshot = 1 AND LOWER(versionPrerelease) = 'snapshot') + OR (:pPrerelease = 1 AND LOWER(versionPrerelease) <> 'snapshot') + ) ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC ) If SQLCODE=0 { diff --git a/src/cls/ZPM/Registry.cls b/src/cls/ZPM/Registry.cls index 29747fb..1c1b591 100644 --- a/src/cls/ZPM/Registry.cls +++ b/src/cls/ZPM/Registry.cls @@ -117,8 +117,10 @@ ClassMethod Package(pkg As %String = "", version As %String = "", platformVersio If (version="") { $$$ThrowOnError(##class(ZPM.UpLink).FindPackageInAllUpLinks(pkg)) } + Set tIncludePrerelease = %request.Get("includePrerelease", 0) + Set tIncludeSnapshots = %request.Get("includeSnapshots", 0) - Set version = ##class(ZPM.Package).VersionFind(pkg, version) + Set version = ##class(ZPM.Package).VersionFind(pkg, version, tIncludePrerelease, tIncludeSnapshots) If (version = "") { Return ..ReportHttpStatusCode(..#HTTP404NOTFOUND) } From 76b78e7eccfcd58d6b81384cc852c8c845270ee8 Mon Sep 17 00:00:00 2001 From: Shuheng Liu Date: Thu, 29 Aug 2024 13:59:17 -0400 Subject: [PATCH 2/2] chore: bump minor version --- module.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module.xml b/module.xml index a05e5a2..4413df0 100644 --- a/module.xml +++ b/module.xml @@ -5,7 +5,7 @@ zpm-registry ZPM Registry Registry server for ZPM - 1.2.9 + 1.3.0 module