Skip to content

Commit

Permalink
Merge pull request eXist-db#68 from joewiz/fix/adopt-xq31-fn-sigs
Browse files Browse the repository at this point in the history
adopt xquery 3.1 function signatures
  • Loading branch information
duncdrum authored Jan 21, 2019
2 parents 9d2886d + 74c4c19 commit 332506d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 44 deletions.
19 changes: 10 additions & 9 deletions modules/restxq.xql
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ declare %private function restxq:post($anno as element(annotation), $method as x
if ($var) then
let $accessor := function() { request:get-data() }
return
map:new(($params, map:entry($var, $accessor)))
map:merge(($params, map:entry($var, $accessor)))
else
$params
};
Expand Down Expand Up @@ -232,7 +232,7 @@ declare %private function restxq:query-param($anno as element(annotation), $para
let $default := if ($anno/value[3]) then $anno/value[3]/string() else ()
let $param := request:get-parameter($paramName, $default)
return
map:new(($params, map:entry($var, $param)))
map:merge(($params, map:entry($var, $param)))
};

(:~
Expand All @@ -243,7 +243,7 @@ declare %private function restxq:header-param($anno as element(annotation), $par
let $var := restxq:extract-variable($anno/value[2]/string())
let $header := request:get-header($headerName)
return
map:new(($params, map:entry($var, $header)))
map:merge(($params, map:entry($var, $header)))
};

(:~
Expand Down Expand Up @@ -271,13 +271,14 @@ declare %private function restxq:match-path($params as map(*), $input as xs:stri
let $groups := analyze-string($input, $groupsRegex)//fn:group/string()
let $analyzed := analyze-string($template, "\{\$[^\}]+\}")
return
map:new((
map:merge((
$params,
map-pairs(function($group, $varExpr) {
let $var := replace($varExpr, "\{\$([^\}]+)\}", "$1")
return
map:entry($var, $group)
}, $groups, $analyzed//fn:match)
for-each-pair($groups, $analyzed//fn:match,
function($group, $varExpr) {
let $var := replace($varExpr, "\{\$([^\}]+)\}", "$1")
return
map:entry($var, $group)
})
))
else
()
Expand Down
10 changes: 5 additions & 5 deletions modules/templates.xql
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ declare variable $templates:root-collection :=
:)
declare function templates:apply($content as node()+, $resolver as function(xs:string, xs:int) as item()?, $model as map(*)?,
$configuration as map(*)?) {
let $model := if ($model) then $model else map:new()
let $model := if ($model) then $model else map {}
let $configuration :=
if (exists($configuration)) then
map:new(($configuration, map { "resolve" := $resolver }))
map:merge(($configuration, map { "resolve" := $resolver }))
else
map { "resolve" := $resolver }
let $model := map:new(($model, map:entry($templates:CONFIGURATION, $configuration)))
let $model := map:merge(($model, map:entry($templates:CONFIGURATION, $configuration)))
for $root in $content
return
templates:process($root, $model)
Expand Down Expand Up @@ -174,7 +174,7 @@ declare %private function templates:process-output($node as element(), $model as
declare %private function templates:process-output($node as element(), $model as map(*), $output as item()*) {
typeswitch($output)
case map(*) return
templates:process($node/node(), map:new(($model, $output)))
templates:process($node/node(), map:merge(($model, $output)))
default return
$output
};
Expand Down Expand Up @@ -246,7 +246,7 @@ declare %private function templates:resolve($arity as xs:int, $func as xs:string
};

declare %private function templates:parse-parameters($paramStr as xs:string?) as map(xs:string, xs:string) {
map:new(
map:merge(
for $param in tokenize($paramStr, "&")
let $key := substring-before($param, "=")
let $value := substring-after($param, "=")
Expand Down
9 changes: 5 additions & 4 deletions plugins/browsing/service.xql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xquery version "3.0";
xquery version "3.1";

module namespace service="http://exist-db.org/apps/dashboard/service";

Expand Down Expand Up @@ -347,7 +347,8 @@ function service:change-properties($resources as xs:string, $owner as xs:string?
(: return:)
(: <result>:)
(: {:)
(: map-pairs(function($name, $file) {:)
(: for-each-pair($names, $files, :)
(: function($name, $file) {:)
(: let $stored := xmldb:store($collection, xmldb:encode-uri($name), $file):)
(: let $log := util:log("DEBUG", ("Uploaded: ", $stored)):)
(: return:)
Expand All @@ -356,7 +357,7 @@ function service:change-properties($resources as xs:string, $owner as xs:string?
(: <size>xmldb:size($collection, $name)</size>:)
(: <type>xmldb:get-mime-type($stored)</type>:)
(: </json:value>:)
(: }, $names, $files):)
(: }):)
(: }:)
(: </result>:)
(:};:)
Expand Down Expand Up @@ -442,7 +443,7 @@ declare %private function service:canWriteResource($collection as xs:string, $re
};

declare %private function service:merge-properties($maps as map(*)) {
map:new(
map:merge(
for $key in map:keys($maps[1])
let $values := distinct-values(for $map in $maps return $map($key))
return
Expand Down
25 changes: 13 additions & 12 deletions plugins/browsing/upload.xql
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ let $files := request:get-uploaded-file-data("uploadedfiles[]")
return
<response>
{
map-pairs(function($name, $file) {
try {
let $stored := xmldb:store($collection, xmldb:encode-uri($name), $file)
return
for-each-pair($names, $files,
function($name, $file) {
try {
let $stored := xmldb:store($collection, xmldb:encode-uri($name), $file)
return
<json:value json:array="true">
<file>{$stored}</file>
<type>{xmldb:get-mime-type($stored)}</type>
</json:value>
} catch * {
<json:value json:array="true">
<file>{$stored}</file>
<type>{xmldb:get-mime-type($stored)}</type>
<error>{$err:description}</error>
</json:value>
} catch * {
<json:value json:array="true">
<error>{$err:description}</error>
</json:value>
}
}, $names, $files)
}
})
}
</response>
29 changes: 15 additions & 14 deletions plugins/packageManager/packages.xql
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,22 @@ declare %private function packages:public-repo-contents($installed as element(ap
if ($status != 200) then
response:set-status-code($status)
else
map(function($app as element(app)) {
(: Ignore apps which are already installed :)
if ($app/abbrev = $installed/abbrev) then
if (packages:is-newer($app/version/string(), $installed[abbrev = $app/abbrev]/version)) then
element { node-name($app) } {
attribute available { $app/version/string() },
attribute installed { $installed[abbrev = $app/abbrev]/version/string() },
$app/@*,
$app/*
}
for-each($data[2]//app,
function($app as element(app)) {
(: Ignore apps which are already installed :)
if ($app/abbrev = $installed/abbrev) then
if (packages:is-newer($app/version/string(), $installed[abbrev = $app/abbrev]/version)) then
element { node-name($app) } {
attribute available { $app/version/string() },
attribute installed { $installed[abbrev = $app/abbrev]/version/string() },
$app/@*,
$app/*
}
else
()
else
()
else
$app
}, $data[2]//app)
$app
})
} catch * {
util:log("ERROR", "Error while retrieving app packages: " || $err:description)
}
Expand Down

0 comments on commit 332506d

Please sign in to comment.