From 663c16814cc7d360dd2c7ff5dfb336cff9122029 Mon Sep 17 00:00:00 2001 From: Paxton Hare Date: Mon, 21 Mar 2016 10:30:58 -0400 Subject: [PATCH 1/2] fixed #140 - vet plugins not working correctly --- .../root/com.marklogic.hub/lib/flow-lib.xqy | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy b/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy index 19175db315..34b6632d03 100644 --- a/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy +++ b/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy @@ -612,16 +612,32 @@ declare function flow:validate-entities() let $_ := for $plugin in $flow/hub:plugins/hub:plugin let $destination := $plugin/@dest + let $module-uri := $plugin/@module + let $module-name := hul:get-module-name($module-uri) + let $filename as xs:string := hul:get-file-from-uri($module-uri) + let $type := flow:get-type($filename) + let $ns := + if ($type eq $flow:TYPE-JAVASCRIPT) then () + else + $flow:PLUGIN-NS || fn:lower-case($module-name) + let $func-name := + if ($type eq $flow:TYPE-JAVASCRIPT) then + "create" || functx:capitalize-first($destination) + else + "create-" || $destination return try { - flow:run-plugin( - $plugin, - $data-format, - "123", - (), - (), - (), - $options) + if ($type eq $flow:TYPE-XQUERY) then + xdmp:eval( + 'import module namespace x = "' || $ns || '" at "' || $module-uri || '"; ' || + '()', + map:new(map:entry("staticCheck", fn:true())) + ) + else + xdmp:javascript-eval( + 'var x = require("' || $module-uri || '");', + map:new(map:entry("staticCheck", fn:true())) + ) } catch($ex) { json:array-push($errors, flow:make-error-json($ex)) From fb26b5b51169444f0bb8dd220a0d4d7e426282ff Mon Sep 17 00:00:00 2001 From: Paxton Hare Date: Mon, 21 Mar 2016 10:40:13 -0400 Subject: [PATCH 2/2] added comment --- .../ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy b/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy index 34b6632d03..d93c3963ff 100644 --- a/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy +++ b/marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy @@ -626,6 +626,15 @@ declare function flow:validate-entities() else "create-" || $destination return + (: + : Note that we are static checking the files. + : This is because there is no reasonable way to actually + : call the plugins and pass in data that will work for all plugins. + : + : The disadvantage to static checking is that we will not catch typos + : like ctsdoc <- (missing period) because Javascript is dynamically + : typed. Static checking will only catch syntax errors in sjs. + :) try { if ($type eq $flow:TYPE-XQUERY) then xdmp:eval(