Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter versions by prerelease and snapshot in request query str #112

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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