From 966f54d2ecf35bd3a72f4d56ce01475eee5d3df9 Mon Sep 17 00:00:00 2001 From: Joe Wicentowski Date: Fri, 9 Aug 2019 02:27:03 -0400 Subject: [PATCH 1/5] Remove unused module --- modules/index.xql | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 modules/index.xql diff --git a/modules/index.xql b/modules/index.xql deleted file mode 100644 index e15673a..0000000 --- a/modules/index.xql +++ /dev/null @@ -1,9 +0,0 @@ -xquery version "1.0"; - -declare option exist:serialize "method=xhtml media-type=text/html"; - - - -

Demo App

- - \ No newline at end of file From 1dc667788fe301245b97af29198ea88eed1df4fb Mon Sep 17 00:00:00 2001 From: Joe Wicentowski Date: Fri, 9 Aug 2019 02:27:29 -0400 Subject: [PATCH 2/5] Remove unused import --- modules/find.xql | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/find.xql b/modules/find.xql index ffe3d39..e2f01f9 100644 --- a/modules/find.xql +++ b/modules/find.xql @@ -5,7 +5,6 @@ import module namespace response="http://exist-db.org/xquery/response"; import module namespace app="http://exist-db.org/xquery/app" at "app.xql"; import module namespace config="http://exist-db.org/xquery/apps/config" at "config.xqm"; -import module namespace scanrepo="http://exist-db.org/xquery/admin/scanrepo" at "scan.xql"; let $abbrev := request:get-parameter("abbrev", ()) let $name := request:get-parameter("name", ()) From e2a2bd23e5fc4801060cda6dec1cb0f574a6ad69 Mon Sep 17 00:00:00 2001 From: Joe Wicentowski Date: Fri, 9 Aug 2019 02:28:30 -0400 Subject: [PATCH 3/5] Add dependency on new semver library --- expath-pkg.xml.tmpl | 1 + 1 file changed, 1 insertion(+) diff --git a/expath-pkg.xml.tmpl b/expath-pkg.xml.tmpl index f0dc52c..b17223f 100644 --- a/expath-pkg.xml.tmpl +++ b/expath-pkg.xml.tmpl @@ -3,4 +3,5 @@ eXist-db Public Application Repository + From 155753ff337905711e9bddf93388bcb0fe5c2a8e Mon Sep 17 00:00:00 2001 From: Joe Wicentowski Date: Fri, 9 Aug 2019 02:53:28 -0400 Subject: [PATCH 4/5] Use semver library to parse, coerce, sort versions --- modules/list.xql | 15 +++-------- modules/scan.xql | 68 ++++++++++++++++++++++++------------------------ repo.xml | 6 +++++ 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/modules/list.xql b/modules/list.xql index ea8a4d9..d267d07 100644 --- a/modules/list.xql +++ b/modules/list.xql @@ -4,6 +4,7 @@ declare namespace list="http://exist-db.org/apps/public-repo/list"; declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; import module namespace config="http://exist-db.org/xquery/apps/config" at "config.xqm"; +import module namespace semver = "http://exist-db.org/xquery/semver"; declare option output:method "xml"; declare option output:media-type "application/xml"; @@ -18,22 +19,12 @@ declare variable $list:DEFAULT_VERSION := "2.2.0"; declare function list:is-newer-or-same($version1 as xs:string, $version2 as xs:string?) { empty($version2) or - list:check-version($version1, $version2, function($v1, $v2) { $v1 >= $v2 }) + semver:ge($version1, $version2, true()) }; declare function list:is-older-or-same($version1 as xs:string, $version2 as xs:string?) { empty($version2) or - list:check-version($version1, $version2, function($v1, $v2) { $v1 <= $v2 }) -}; - -declare function list:version-to-number($version as xs:string) as xs:int { - let $ana := analyze-string($version, "(\d+)\.(\d+)\.(\d+)-?(.*)") - return - sum(($ana//fn:group[@nr="1"] * 1000000, $ana//fn:group[@nr="2"] * 1000, $ana//fn:group[@nr="3"])) -}; - -declare function list:check-version($version1 as xs:string, $version2 as xs:string, $check as function(*)) { - $check(list:version-to-number($version1), list:version-to-number($version2)) + semver:le($version1, $version2, true()) }; declare function list:get-app($app as element(), $version as xs:string) { diff --git a/modules/scan.xql b/modules/scan.xql index 77503f3..b1a163d 100644 --- a/modules/scan.xql +++ b/modules/scan.xql @@ -1,9 +1,10 @@ -xquery version "3.0"; +xquery version "3.1"; module namespace scanrepo="http://exist-db.org/xquery/admin/scanrepo"; import module namespace config = "http://exist-db.org/xquery/apps/config" at "config.xqm"; import module namespace crypto = "http://expath.org/ns/crypto"; +import module namespace semver = "http://exist-db.org/xquery/semver"; import module namespace util = "http://exist-db.org/xquery/util"; declare namespace repo="http://exist-db.org/xquery/repo"; @@ -11,57 +12,56 @@ declare namespace expath="http://expath.org/ns/pkg"; declare function scanrepo:is-newer-or-same($version1 as xs:string, $version2 as xs:string?) { empty($version2) or - scanrepo:check-version($version1, $version2, function($v1, $v2) { $v1 >= $v2 }) + semver:ge($version1, $version2, true()) }; declare function scanrepo:is-older-or-same($version1 as xs:string, $version2 as xs:string?) { empty($version2) or - scanrepo:check-version($version1, $version2, function($v1, $v2) { $v1 <= $v2 }) -}; - -declare %private function scanrepo:version-to-number($version as xs:string) as xs:int { - let $ana := analyze-string($version, "(\d+)\.(\d+)\.(\d+)-?(.*)") - return - sum(($ana//fn:group[@nr="1"] * 1000000, $ana//fn:group[@nr="2"] * 1000, $ana//fn:group[@nr="3"])) -}; - -declare %private function scanrepo:check-version($version1 as xs:string, $version2 as xs:string, $check as function(*)) { - $check(scanrepo:version-to-number($version1), scanrepo:version-to-number($version2)) + semver:le($version1, $version2, true()) }; declare function scanrepo:process($apps as element(app)*) { for $app in $apps + order by $app/title group by $name := $app/name return - let $newest := scanrepo:find-newest($app, (), ()) + (: Identify newest version of the package; sort previous versions newest to oldest; use SemVer 2.0 rules, coercing where needed :) + let $versions := $app/version + let $version-maps := + $versions ! map:merge(( + map:entry("semver", semver:coerce(.) => semver:serialize()), + map:entry("version", .) + )) + let $sorted-versions := + for $version in $version-maps + order by semver:sort($version?semver) descending + return $version?version/.. + let $newest-version := $sorted-versions => head() + let $older-versions := $sorted-versions => tail() let $abbrevs := distinct-values($app/abbrev) return { - $newest/@*, - $newest/*, - $abbrevs[not(. = $newest/abbrev)] ! element abbrev { attribute type { "legacy" }, . } + $newest-version/@*, + $newest-version/*, + $abbrevs[not(. = $newest-version/abbrev)] ! element abbrev { attribute type { "legacy" }, . } } { - reverse( - for $older in $app[version != $newest/version] - let $xar := concat($config:public, "/", $older/@path) - let $hash := crypto:hash( - util:binary-doc($xar), - "sha256", - "hex" - ) - let $n := tokenize($older/version, "\.") ! xs:int((analyze-string(., "(\d+)")//fn:group)[1]) - order by $n[1], $n[2], $n[3] - return - { - $older/@path, - attribute size { xmldb:size($config:public, $older/@path) }, - attribute sha256 { $hash }, - $older/requires - } + for $older in $older-versions + let $xar := concat($config:public, "/", $older/@path) + let $hash := crypto:hash( + util:binary-doc($xar), + "sha256", + "hex" ) + return + { + $older/@path, + attribute size { xmldb:size($config:public, $older/@path) }, + attribute sha256 { $hash }, + $older/requires + } } diff --git a/repo.xml b/repo.xml index c42ca62..e563596 100644 --- a/repo.xml +++ b/repo.xml @@ -12,6 +12,12 @@ post-install.xql + +
    +
  • New: Full SemVer 2.0 compliance, backward compatible with most previous package version strings
  • +
  • Breaking: New dependency on semver.xq library
  • +
+
  • Fixed: Handling for semantic versioning strings with prerelease and build metadata fragments containing numbers
  • From ebc1247b62d143205455bd9881ce28bf3638b37f Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Fri, 9 Aug 2019 12:43:38 +0100 Subject: [PATCH 5/5] Use released version of Semver --- expath-pkg.xml.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expath-pkg.xml.tmpl b/expath-pkg.xml.tmpl index b17223f..87a3903 100644 --- a/expath-pkg.xml.tmpl +++ b/expath-pkg.xml.tmpl @@ -3,5 +3,5 @@ eXist-db Public Application Repository - +