Skip to content

Commit

Permalink
Merge pull request #112 from isc-shuliu/fix-filter-prerelease-snapshots
Browse files Browse the repository at this point in the history
feat: filter versions by prerelease and snapshot in request query str
  • Loading branch information
nsolov authored Sep 3, 2024
2 parents 091f22b + 76b78e7 commit 5617543
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Name>zpm-registry</Name>
<ExternalName>ZPM Registry</ExternalName>
<Description>Registry server for ZPM</Description>
<Version>1.2.9</Version>
<Version>1.3.0</Version>
<Packaging>module</Packaging>
<Dependencies>
<ModuleReference>
Expand Down
34 changes: 29 additions & 5 deletions src/cls/ZPM/Package.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -158,20 +169,33 @@ 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
Return version
} 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 {
Expand Down
4 changes: 3 additions & 1 deletion src/cls/ZPM/Registry.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 5617543

Please sign in to comment.