fixing bug

fixing bug

module namespace page = 'http://basex.org/modules/web-page';

(:Import other namespaces.  :)
import module namespace csd_webconf =  "https://github.com/openhie/openinfoman/csd_webconf";
import module namespace csd_webui =  "https://github.com/openhie/openinfoman/csd_webui";
import module namespace csr_proc = "https://github.com/openhie/openinfoman/csr_proc";
import module namespace csd_dm = "https://github.com/openhie/openinfoman/csd_dm";
import module namespace csd_mcs = "https://github.com/openhie/openinfoman/csd_mcs";
import module namespace functx = "http://www.functx.com";

declare namespace csd = "urn:ihe:iti:csd:2013";

declare function page:is_hfr($search_name) {
  let $function := csr_proc:get_function_definition($search_name)
  let $ufunction := csr_proc:get_updating_function_definition($search_name)
  let $ext := $function//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter' and @type='hfr']
  let $uext := $ufunction//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter' and @type='hfr']
  return (count($uext) + count($ext) > 0)
};

declare function page:get_actions($search_name) {
  let $function := csr_proc:get_function_definition($search_name)
  let $ufunction := csr_proc:get_updating_function_definition($search_name)
  return
    (
    for $act in $function//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter:hfr:action']/@type
    return string($act)
    ,for $act in $ufunction//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter:hfr:action']/@type
    return string($act)
  )
};

declare
  %rest:path("/CSD/csr/{$doc_name}/careServicesRequest/{$search_name}/adapter/hfr")
  %output:method("xhtml")
  function page:show_endpoints($search_name,$doc_name)
{
    if (not(page:is_hfr($search_name)) )
      then ('Not a HFR Compatible stored function'    )
    else
      let $actions := page:get_actions($search_name)
      let $contents :=

HFR Operations on {$doc_name}

        {
          if ($actions = 'upload')
	  then

Upload Organizational Hierarchy

	     {
	       let $function := csr_proc:get_updating_function_definition($search_name)
	       let $oid := string($function/csd:extension[@urn='urn:openhie.org:openinfoman:adapter:hfr:action:upload:oid']/@type)
	       let $url := concat($csd_webconf:baseurl, "CSD/csr/" , $doc_name , "/careServicesRequest/",$search_name, "/adapter/hfr/upload")
	       return
	         <form action="{$url}" method="POST" enctype="multipart/form-data">
		   HFR Organizational Hierarchy File
		   <input type='file' name='csv'/>

		   Root OID for SVS list ID
		   <input type='text' size='60' value="{$oid}" name='oid'/>

		   <input type='submit' value='Upload'/>
		 </form>
	     }

	  else ()
	}

      return csd_webui:wrapper($contents)
};

declare updating
  %rest:path("/CSD/csr/{$doc_name}/careServicesRequest/{$search_name}/adapter/hfr/upload")
  %rest:POST
  %rest:form-param("csv", "{$csv}")
  %rest:form-param("oid", "{$oid}",'')
  function page:update_doc($search_name,$doc_name,$csv,$oid)
{
  if (not(page:is_hfr($search_name)) ) then
    db:output(<restxq:redirect>{$csd_webconf:baseurl}CSD/bad</restxq:redirect>)
  else
    let $function := csr_proc:get_updating_function_definition($search_name)

    let $d_oid := string($function/csd:extension[@urn='urn:openhie.org:openinfoman:adapter:dhis2:action:uploadDXF:oid']/@type)

    let $s_oid := if ($oid = '') then $d_oid else $oid

    let $name :=  map:keys($csv)[1]
    let $content := convert:binary-to-string($csv($name))

    let $careServicesRequest :=
      <csd:careServicesRequest>
       <csd:function urn="{$search_name}" resource="{$doc_name}" base_url="{$csd_webconf:baseurl}">
         <csd:requestParams >
           <csv>{$content}</csv>
           <oid>{$s_oid}</oid>
         </csd:requestParams>
       </csd:function>
      </csd:careServicesRequest>
    return
       (
        csr_proc:process_updating_CSR_results($csd_webconf:db, $careServicesRequest)
        ,db:output(<restxq:redirect>{$csd_webconf:baseurl}CSD</restxq:redirect>)
       )

};

module namespace page = 'http://basex.org/modules/web-page';

(:Import other namespaces.  :)
import module namespace csd_webconf =  "https://github.com/openhie/openinfoman/csd_webconf";
import module namespace csr_proc = "https://github.com/openhie/openinfoman/csr_proc";
import module namespace csd_dm = "https://github.com/openhie/openinfoman/csd_dm";
import module namespace csd_mcs = "https://github.com/openhie/openinfoman/csd_mcs";
import module namespace functx = "http://www.functx.com";

declare namespace csd = "urn:ihe:iti:csd:2013";

declare function page:is_hfr($search_name) {
  let $function := csr_proc:get_function_definition($csd_webconf:db,$search_name)
  let $ufunction := csr_proc:get_updating_function_definition($csd_webconf:db,$search_name)
  let $ext := $function//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter' and @type='hfr']
  let $uext := $ufunction//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter' and @type='hfr']
  return (count($uext) + count($ext) > 0)
};

declare function page:get_actions($search_name) {
  let $function := csr_proc:get_function_definition($csd_webconf:db,$search_name)
  let $ufunction := csr_proc:get_updating_function_definition($csd_webconf:db,$search_name)
  return
    (
    for $act in $function//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter:hfr:action']/@type
    return string($act)
    ,for $act in $ufunction//csd:extension[  @urn='urn:openhie.org:openinfoman:adapter:hfr:action']/@type
    return string($act)
  )
};

declare
  %rest:path("/CSD/csr/{$doc_name}/careServicesRequest/{$search_name}/adapter/hfr")
  %output:method("xhtml")
  function page:show_endpoints($search_name,$doc_name)
{
    if (not(page:is_hfr($search_name)) )
      then ('Not a HFR Compatible stored function'    )
    else
      let $actions := page:get_actions($search_name)
      let $contents :=

HFR Operations on {$doc_name}

        {
          if ($actions = 'upload')
	  then

Upload Organizational Hierarchy

	     {
	       let $function := csr_proc:get_updating_function_definition($csd_webconf:db,$search_name)
	       let $oid := string($function/csd:extension[@urn='urn:openhie.org:openinfoman:adapter:hfr:action:upload:oid']/@type)
	       let $url := concat($csd_webconf:baseurl, "CSD/csr/" , $doc_name , "/careServicesRequest/",$search_name, "/adapter/hfr/upload")
	       return
	         <form action="{$url}" method="POST" enctype="multipart/form-data">
		   HFR Organizational Hierarchy File
		   <input type='file' name='csv'/>

		   Root OID for SVS list ID
		   <input type='text' size='60' value="{$oid}" name='oid'/>

		   <input type='submit' value='Upload'/>
		 </form>
	     }

	  else ()
	}

      return csd_webconf:wrapper($contents)
};

declare updating
  %rest:path("/CSD/csr/{$doc_name}/careServicesRequest/{$search_name}/adapter/hfr/upload")
  %rest:POST
  %rest:form-param("csv", "{$csv}")
  %rest:form-param("oid", "{$oid}",'')
  function page:update_doc($search_name,$doc_name,$csv,$oid)
{
  if (not(page:is_hfr($search_name)) ) then
    db:output(<restxq:redirect>{$csd_webconf:baseurl}CSD/bad</restxq:redirect>)
  else
    let $function := csr_proc:get_updating_function_definition($csd_webconf:db,$search_name)

    let $d_oid := string($function/csd:extension[@urn='urn:openhie.org:openinfoman:adapter:dhis2:action:uploadDXF:oid']/@type)

    let $s_oid := if ($oid = '') then $d_oid else $oid

    let $name :=  map:keys($csv)[1]
    let $content := convert:binary-to-string($csv($name))

    let $careServicesRequest :=
      <csd:careServicesRequest>
       <csd:function urn="{$search_name}" resource="{$doc_name}" base_url="{$csd_webconf:baseurl}">
         <csd:requestParams >
           <csv>{$content}</csv>
           <oid>{$s_oid}</oid>
         </csd:requestParams>
       </csd:function>
      </csd:careServicesRequest>
    return
       (
        csr_proc:process_updating_CSR_results($csd_webconf:db, $careServicesRequest)
        ,db:output(<restxq:redirect>{$csd_webconf:baseurl}CSD</restxq:redirect>)
       )

};


[bugfix] ensure that the advanced search tab is selected after clicking on a facet

svn path=/trunk/eXist/; revision=12901

xquery version "1.0";

(:~
    Returns the list of distinct authors, dates etc. occurring in the result set.
    The query is called via AJAX when the user expands one of the headings in the
    "filter" box.
:)
import module namespace names="http://exist-db.org/xquery/biblio/names"
    at "names.xql";

declare namespace mods="http://www.loc.gov/mods/v3";

declare variable $local:MAX_RESULTS := 1000;
declare variable $local:MAX_RESULTS_NAMES := 2000;
declare variable $local:MAX_TERMS := 30;

declare function local:key($key, $options) {

{$key} ({$options[1]})

};

declare function local:keywords($results as element()*) {
    let $max :=
        if (count($results) ge $local:MAX_RESULTS) then
            $local:MAX_TERMS
        else
            () (: unlimited :)
    let $prefixParam := request:get-parameter("prefix", "")
    let $prefix := if (empty($max)) then "" else $prefixParam
    let $callback := util:function(xs:QName("local:key"), 2)
    return

        { util:index-keys($results//mods:titleInfo, $prefix, $callback, $max, "lucene-index") }

};

let $type := request:get-parameter("type", ())
let $cached := session:get-attribute("mods:cached")
return
    if ($type eq 'author') then

        {
            let $names := $cached//mods:name
            return
                if (count($names) gt $local:MAX_RESULTS_NAMES) then

Too many names. Please restrict the result set.

                else
                    let $authors :=
                        for $author in $names
                        return names:format-name($author)
                    let $distinct := distinct-values($authors)
                    for $name in $distinct
                    order by $name
                    return

{$name}

        }

    else if ($type eq 'date') then

        {
            let $dates := $cached/mods:originInfo
            return
                if (count($dates) gt $local:MAX_RESULTS_NAMES) then

Too many dates. Please restrict the result set.

                else
                    let $dates :=
                        for $info in $cached/mods:originInfo
                        return
                            ($info/mods:dateCreated | $info/mods:dateIssued)[1]
                    for $date in distinct-values($dates)
                    order by $date descending
                    return

{$date}

         }

    else if ($type eq 'keywords') then
        local:keywords($cached)
    else
        ()


[biblio] Made header/footer text consistent with the MODS demo project.

svn path=/trunk/eXist/; revision=12136

xquery version "1.0";

module namespace style = "http://exist-db.org/mods-style";

declare namespace request="http://exist-db.org/xquery/request";
declare namespace xf="http://www.w3.org/2002/xforms";
declare namespace xrx="http://code.google.com/p/xrx";

declare variable $style:site-home := '/';
declare variable $style:web-path-to-site := '/db/org/library';
declare variable $style:web-path-to-app := style:substring-before-last-slash(style:substring-before-last-slash(substring-after(request:get-uri(), '/rest')));
declare variable $style:db-path-to-site  := concat('xmldb:exist://',  $style:web-path-to-site);
declare variable $style:db-path-to-app  := concat('xmldb:exist://', $style:web-path-to-app) ;
declare variable $style:db-path-to-app-data := concat($style:db-path-to-app, '/data');

declare variable $style:site-resources := concat(request:get-context-path(), '/rest', $style:web-path-to-site, '/resources');
declare variable $style:site-images := concat($style:site-resources, '/images');
declare variable $style:site-css := concat($style:site-resources, '/css');
declare variable $style:site-info-file := concat($style:web-path-to-site, '/site-info.xml');
declare variable $style:site-info := doc($style:site-info-file);
declare variable $style:form-debug-default := true();

declare function style:substring-before-last-slash($arg as xs:string?)  as xs:string {

   if (matches($arg, '/'))
   then replace($arg,
            concat('^(.*)', '/','.*'),
            '$1')
   else ''
 } ;

declare function style:assemble-page($title as xs:string*, $breadcrumbs as node()*,
                                     $style as element()*, $content as node()+)
as element() {
    (
    util:declare-option('exist:serialize', 'method=xhtml media-type=text/html indent=yes')
    ,

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>{ $title }</title>
            { style:css('xhtml') }
            { $style }

                { style:header() }
                { $breadcrumbs }

{$title}

                   { $content }

                { style:footer() }

     )
};

declare function style:assemble-page($title as xs:string, $content as node()+)
as element() {
    style:assemble-page($title, style:breadcrumbs(), (), $content)
};

declare function style:assemble-page($title as xs:string, $style as node(), $content as node()+)
as element() {
    style:assemble-page($title, style:breadcrumbs(), $style, $content)
};

declare function style:breadcrumbs() as node() {

};

declare function style:assemble-form($model as node(), $content as node()+)
as node()+ {
    style:assemble-form((), (), $model, $content, true())
};

(:~
    An alternate version of style:assemble-form(), allowing debug mode.

    @param $model an XForms model node
    @param $content nodes for the body of the page
    @param $debug boolean to activate XSLTForms debug mode
    @return properly serialized XHTML+XForms page
:)
declare function style:assemble-form($model as node(), $content as node()+, $debug as xs:boolean)
as node()+ {
    style:assemble-form((), (), $model, $content, $debug)
};

(:~
    A helper function for style:assemble-form(), with all optional parameters.

    @param $dummy-attributes an optional sequence of attributes to add to the HTML element
    @param $style an optional style node containing CDATA-encased CSS definitions
    @param $model an XForms model node
    @param $content nodes for the body of the page
    @return properly serialized XHTML+XForms page
:)
declare function style:assemble-form($title as xs:string, $dummy-attributes as attribute()*, $style as element(style)*,
                                     $model as element(xf:model), $content as node()+)
as node()+ {
    style:assemble-form($dummy-attributes, $style, $model, $content, $style:form-debug-default)
};

(:~
    A helper function for style:assemble-form(), with all optional parameters.

    @param $title the text node containing the title of the page
    @param $breadcrumbs the element node containing the breadcrumbs
    @param $style an optional style node containing CDATA-encased CSS definitions
    @param $model an XForms model node
    @param $content nodes for the body of the page
    @param $dummy-attributes an optional sequence of attributes to add to the HTML element
    @param $debug boolean to activate XSLTForms debug mode
    @return properly serialized XHTML+XForms page
:)
declare function style:assemble-form(
        $title as xs:string,
        $dummy-attributes as attribute()*,
        $style as node()*,
        $model as node(),
        $content as node()+,
        $debug as xs:boolean)
as node()+ {
    util:declare-option('exist:serialize', 'method=xhtml media-type=text/xml indent=yes process-xsl-pi=no')
    ,
    processing-instruction xml-stylesheet {concat('type="text/xsl" href="', request:get-context-path(), '/rest', '/db/xforms/xsltforms/xsltforms.xsl"')}
    ,
    if ($debug) then
        processing-instruction xsltforms-options {'debug="yes"'}
    else ()
    ,
    { $dummy-attributes }

            <title>{ $title }</title>
            <link rel="stylesheet" type="text/css" href="edit.css"/>
            { style:css('xforms') }
            { $style }
            { $model }

                { style:header() }

{$title}

                    { $content }

                { style:footer() }

};

declare function style:css($page-type as xs:string)
as node()+ {
    if ($page-type eq 'xhtml') then
        (

        <link rel="stylesheet" href="{$style:site-css}/blueprint/screen.css" type="text/css" media="screen, projection" />,
        <link rel="stylesheet" href="{$style:site-css}/blueprint/print.css" type="text/css" media="print" />,,
        <link rel="stylesheet" href="{$style:site-css}/styles.css" type="text/css" media="screen, projection" />

    )
    else if ($page-type eq 'xforms') then
        <link rel="stylesheet" href="{$style:site-css}/xforms.css.xq" type="text/css" />
    else ()
};

declare function style:header() as node()+  {

            Demo of MODS Editor

};

declare function style:footer()
as node()*  {
    let $footer-message := $style:site-info//xrx:site-footer-message/node()
    return

                    Demo of MODS Editor

};

xquery version "1.0";

module namespace style = "http://exist-db.org/mods-style";

declare namespace request="http://exist-db.org/xquery/request";
declare namespace xf="http://www.w3.org/2002/xforms";
declare namespace xrx="http://code.google.com/p/xrx";

declare variable $style:site-home := '/';
declare variable $style:web-path-to-site := '/db/org/library';
declare variable $style:web-path-to-app := style:substring-before-last-slash(style:substring-before-last-slash(substring-after(request:get-uri(), '/rest')));
declare variable $style:db-path-to-site  := concat('xmldb:exist://',  $style:web-path-to-site);
declare variable $style:db-path-to-app  := concat('xmldb:exist://', $style:web-path-to-app) ;
declare variable $style:db-path-to-app-data := concat($style:db-path-to-app, '/data');

declare variable $style:site-resources := concat(request:get-context-path(), '/rest', $style:web-path-to-site, '/resources');
declare variable $style:site-images := concat($style:site-resources, '/images');
declare variable $style:site-css := concat($style:site-resources, '/css');
declare variable $style:site-info-file := concat($style:web-path-to-site, '/site-info.xml');
declare variable $style:site-info := doc($style:site-info-file);
declare variable $style:form-debug-default := true();

declare function style:substring-before-last-slash($arg as xs:string?)  as xs:string {

   if (matches($arg, '/'))
   then replace($arg,
            concat('^(.*)', '/','.*'),
            '$1')
   else ''
 } ;

declare function style:assemble-page($title as xs:string*, $breadcrumbs as node()*,
                                     $style as element()*, $content as node()+)
as element() {
    (
    util:declare-option('exist:serialize', 'method=xhtml media-type=text/html indent=yes')
    ,

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>{ $title }</title>
            { style:css('xhtml') }
            { $style }

                { style:header() }
                { $breadcrumbs }

{$title}

                   { $content }

                { style:footer() }

     )
};

declare function style:assemble-page($title as xs:string, $content as node()+)
as element() {
    style:assemble-page($title, style:breadcrumbs(), (), $content)
};

declare function style:assemble-page($title as xs:string, $style as node(), $content as node()+)
as element() {
    style:assemble-page($title, style:breadcrumbs(), $style, $content)
};

declare function style:breadcrumbs() as node() {

};

declare function style:assemble-form($model as node(), $content as node()+)
as node()+ {
    style:assemble-form((), (), $model, $content, true())
};

(:~
    An alternate version of style:assemble-form(), allowing debug mode.

    @param $model an XForms model node
    @param $content nodes for the body of the page
    @param $debug boolean to activate XSLTForms debug mode
    @return properly serialized XHTML+XForms page
:)
declare function style:assemble-form($model as node(), $content as node()+, $debug as xs:boolean)
as node()+ {
    style:assemble-form((), (), $model, $content, $debug)
};

(:~
    A helper function for style:assemble-form(), with all optional parameters.

    @param $dummy-attributes an optional sequence of attributes to add to the HTML element
    @param $style an optional style node containing CDATA-encased CSS definitions
    @param $model an XForms model node
    @param $content nodes for the body of the page
    @return properly serialized XHTML+XForms page
:)
declare function style:assemble-form($title as xs:string, $dummy-attributes as attribute()*, $style as element(style)*,
                                     $model as element(xf:model), $content as node()+)
as node()+ {
    style:assemble-form($dummy-attributes, $style, $model, $content, $style:form-debug-default)
};

(:~
    A helper function for style:assemble-form(), with all optional parameters.

    @param $title the text node containing the title of the page
    @param $breadcrumbs the element node containing the breadcrumbs
    @param $style an optional style node containing CDATA-encased CSS definitions
    @param $model an XForms model node
    @param $content nodes for the body of the page
    @param $dummy-attributes an optional sequence of attributes to add to the HTML element
    @param $debug boolean to activate XSLTForms debug mode
    @return properly serialized XHTML+XForms page
:)
declare function style:assemble-form(
        $title as xs:string,
        $dummy-attributes as attribute()*,
        $style as node()*,
        $model as node(),
        $content as node()+,
        $debug as xs:boolean)
as node()+ {
    util:declare-option('exist:serialize', 'method=xhtml media-type=text/xml indent=yes process-xsl-pi=no')
    ,
    processing-instruction xml-stylesheet {concat('type="text/xsl" href="', request:get-context-path(), '/rest', '/db/xforms/xsltforms/xsltforms.xsl"')}
    ,
    if ($debug) then
        processing-instruction xsltforms-options {'debug="yes"'}
    else ()
    ,
    { $dummy-attributes }

            <title>{ $title }</title>
            <link rel="stylesheet" type="text/css" href="edit.css"/>
            { style:css('xforms') }
            { $style }
            { $model }

                { style:header() }

{$title}

                    { $content }

                { style:footer() }

};

declare function style:css($page-type as xs:string)
as node()+ {
    if ($page-type eq 'xhtml') then
        (

        <link rel="stylesheet" href="{$style:site-css}/blueprint/screen.css" type="text/css" media="screen, projection" />,
        <link rel="stylesheet" href="{$style:site-css}/blueprint/print.css" type="text/css" media="print" />,,
        <link rel="stylesheet" href="{$style:site-css}/styles.css" type="text/css" media="screen, projection" />

    )
    else if ($page-type eq 'xforms') then
        <link rel="stylesheet" href="{$style:site-css}/xforms.css.xq" type="text/css" />
    else ()
};

declare function style:header() as node()+  {

            Library Managment System XRX Demo Copyright Dan McCreary & Associates, All Rights Reserved.

};

declare function style:footer()
as node()*  {
    let $footer-message := $style:site-info//xrx:site-footer-message/node()
    return

                    Library Managment System XRX Demo Copyright Dan McCreary & Associates, All Rights Reserved.

};


[bugfix] Fix the incorrect path to the test document in positional-nested.xql

xquery version "3.1";

module namespace npt="http://exist-db.org/test/nested-positional-predicate";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare variable $npt:TEST_COLLECTION_NAME := "test-positional-nested";
declare variable $npt:TEST_COLLECTION_URI := "/db/" || $npt:TEST_COLLECTION_NAME;
declare variable $npt:TEST_DOC_NAME := "test.xml";
declare variable $npt:TEST_DOC_URI := $npt:TEST_COLLECTION_URI || "/" || $npt:TEST_DOC_NAME;

declare variable $npt:DATA :=
    document {
        <xml>

                B1

                B2
                <c>correct</c>

                B3
                <c>wrong</c>

        </xml>
    };

declare
    %test:setUp
function npt:setup() {
    xmldb:create-collection("/db", $npt:TEST_COLLECTION_NAME),
    xmldb:store($npt:TEST_COLLECTION_URI, $npt:TEST_DOC_NAME, $npt:DATA)
};

declare
    %test:tearDown
function npt:cleanup() {
    xmldb:remove($npt:TEST_COLLECTION_URI)
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-memory() {
    $npt:DATA//c[../preceding-sibling::a]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-database() {
    doc($npt:TEST_DOC_URI)//c[../preceding-sibling::a]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-memory-predicate() {
    $npt:DATA//c[../preceding-sibling::a[1]]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-database-predicate() {
    doc($npt:TEST_DOC_URI)//c[../preceding-sibling::a[1]]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-memory-position() {
    $npt:DATA//c[../preceding-sibling::a[position() eq 1]]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-database-position() {
    doc($npt:TEST_DOC_URI)//c[../preceding-sibling::a[position() eq 1]]
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-memory-predicate-and-path() {
    $npt:DATA//c[../preceding-sibling::a[1]/b = 'B1']
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-database-predicate-and-path() {
    doc($npt:TEST_DOC_URI)//c[../preceding-sibling::a[1]/b = 'B1']
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-memory-position-and-path() {
    $npt:DATA//c[../preceding-sibling::a[position() eq 1]/b = 'B1']
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-database-position-and-path() {
    doc($npt:TEST_DOC_URI)//c[../preceding-sibling::a[position() eq 1]/b = 'B1']
};

xquery version "3.1";

module namespace npt="http://exist-db.org/test/nested-positional-predicate";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare variable $npt:DATA :=
    document {
        <xml>

                B1

                B2
                <c>correct</c>

                B3
                <c>wrong</c>

        </xml>
    };

declare
    %test:setUp
function npt:setup() {
    xmldb:create-collection("/db", "test"),
    xmldb:store("/db/test", "test.xml", $npt:DATA)
};

declare
    %test:tearDown
function npt:cleanup() {
    xmldb:remove("/db/test")
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-memory() {
    $npt:DATA//c[../preceding-sibling::a]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-database() {
    doc("/db/test.xml")//c[../preceding-sibling::a]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-memory-predicate() {
    $npt:DATA//c[../preceding-sibling::a[1]]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-database-predicate() {
    doc("/db/test.xml")//c[../preceding-sibling::a[1]]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-memory-position() {
    $npt:DATA//c[../preceding-sibling::a[position() eq 1]]
};

declare
    %test:assertEquals("<c>correct</c><c>wrong</c>")
function npt:in-database-position() {
    doc("/db/test.xml")//c[../preceding-sibling::a[position() eq 1]]
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-memory-predicate-and-path() {
    $npt:DATA//c[../preceding-sibling::a[1]/b = 'B1']
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-database-predicate-and-path() {
    doc("/db/test.xml")//c[../preceding-sibling::a[1]/b = 'B1']
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-memory-position-and-path() {
    $npt:DATA//c[../preceding-sibling::a[position() eq 1]/b = 'B1']
};

declare
    %test:assertEquals("<c>correct</c>")
function npt:in-database-position-and-path() {
    doc("/db/test.xml")//c[../preceding-sibling::a[position() eq 1]/b = 'B1']
};


Final tests. All pass!

Final tests. All pass!

(:
 : @author James Wright
 : Tests for xq-promise library
 :)
module namespace test = 'http://basex.org/modules/xqunit-tests';
import module namespace promise = 'org.jw.basex.async.xq-promise';

declare %unit:test function test:promise() {
   let $work := function ($name) {
     'Hello ' || $name || '!'
   }
   let $promise := promise:defer($work, 'world')
   return
      unit:assert-equals($promise(()), 'Hello world!')
 };

declare %unit:test function test:callbacks-add() {
  for $type in ('then', 'done', 'always')
  return
    let $path := file:temp-dir() || $type || '.txt'
    let $callback := file:write-text($path, ?)
    let $work := promise:defer(trace(?, 'Hello world!'), $type)
    let $promise := $work(map { $type: $callback })
    return
      ($promise(()), file:exists($path), file:delete($path))
};

declare %unit:test function test:callbacks-fail() {
  let $path := file:temp-dir() || 'fail.txt'
  let $callback := function () { file:write-text($path, 'Failed!') }
  let $work := promise:defer(function () { fn:error('Failed!') })
  let $promise := $work(map { 'fail': $callback })
  return
    ($promise(()), file:exists($path), file:delete($path))
};

declare %unit:test function test:callbacks-fail-fix-value() {
  let $callback := function () { 'Hello world!' }
  let $work := promise:defer(function () { fn:error('Failed!') })
  let $promise := $work(map { 'fail': $callback })
  return
    unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:callbacks-fail-fatal() {
  let $callback := function () { fn:error('Callback Failed!') }
  let $work := promise:defer(function () { fn:error('Failed!') })
  let $promise := $work(map { 'fail': $callback })
  let $result :=
    try {
      unit:assert-equals($promise(()), 'Hello world!')
    } catch * { ('Failed!') }
  return
   unit:assert-equals($result, 'Failed!')
};

declare %unit:test function test:callback-then() {
  let $greet := function ($name) { 'Hello ' || $name || '!'}
  let $promise :=
      promise:defer(trace(?), 'world', map {
          'then': $greet
      })
  return
    unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:multiple-callbacks() {
  let $greet := function ($name) { 'Hello ' || $name }
  let $get-end := function ($name) { $name || '!' }
  let $promise :=
      promise:defer(trace(?), 'world', map {
          'then': ($get-end, $greet)
      })
  return
    unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:callbacks-attached-after() {
  let $greet := function ($name) { 'Hello ' || $name }
  let $get-end := function ($name) { $name || '!' }
  let $work := promise:defer(trace(?), 'world')
  let $get := $work(map { 'then': $get-end })
  let $promise := $get(map { 'then': $greet })
  return
    unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:when-with-same-arity() {
  let $greet := function ($greeting, $name) { trace($greeting || ' ' || $name || '!', 'Arity test: ')}
  let $promise :=
    promise:when((
      promise:defer(trace(?), 'Hello'),
      promise:defer(trace(?), 'world')),
      map { 'then': $greet }
  )
  return
   unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:when-with-diff-arity() {
  let $greet := function ($args) { $args?1 || ' ' || $args?2 || '!'}
  let $promise :=
    promise:when(
      (
        promise:defer(trace(?), 'Hello'),
        promise:defer(trace(?), 'world')
      ),
      map { 'then': $greet }
    )
  return
   unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:fork-join() {
  let $work := function ($input) { element text {$input} }
  let $promises :=
    for $i in (1 to 1000) return
      promise:defer($work, $i)
  return
    let $out := promise:fork-join($promises)
    let $sum := sum($out)
    return
      unit:assert-equals($sum, 500500)
};

declare %unit:test function test:fork-join-shared-resource() {
  let $shared := array { for $i in (1 to 1000) return map { 'value': $i } }
  let $work := function ($input) {
    let $value := $shared?*[?value = $input]
    return
      element text {json:serialize($value)}
  }
  let $promises := for $i in (1 to 1000)
                   return promise:defer($work, $i)
  return
    let $out := promise:fork-join($promises, 100)
    let $sum := sum((($out ! promise:defer(parse-json(?), .))
       => promise:fork-join(100))?value)
    return
      unit:assert-equals($sum, 500500)
};

(:
 : @author James Wright
 : Tests for xq-promise library
 :)
module namespace test = 'http://basex.org/modules/xqunit-tests';
import module namespace promise = 'org.jw.basex.async.xq-promise';

declare %unit:test function test:promise() {
   let $work := function ($name) {
     'Hello ' || $name || '!'
   }
   let $promise := promise:defer($work, 'world')
   return
      unit:assert-equals($promise(()), 'Hello world!')
 };

declare %unit:test function test:callbacks-add() {
  for $type in ('then', 'done', 'always')
  return
    let $path := file:temp-dir() || $type || '.txt'
    let $callback := file:write-text($path, ?)
    let $work := promise:defer(trace(?, 'Hello world!'))
    let $promise := $work(map { $type: $callback })
    return
      ($promise(()), file:exists($path), file:delete($path))
};

declare %unit:test function test:callbacks-fail() {
  let $path := file:temp-dir() 'fail.txt'
  let $callback := file:write-text($path, ?)
  let $work := promise:defer(function () { fn:error('Failed!') })
  let $promise := $work(map { 'fail': $callback })
  return
    ($promise(()), file:exists($path), file:delete($path))
};

declare %unit:test function test:callbacks-fail-fix-value() {
  let $callback := function () { 'Hello world!' }
  let $work := promise:defer(function () { fn:error('Failed!') })
  let $promise := $work(map { 'fail': $callback })
  return
    unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:callbacks-fail-fatal() {
  let $callback := function () { fn:error('Callback Failed!') }
  let $work := promise:defer(function () { fn:error('Failed!') })
  let $promise := $work(map { 'fail': $callback })
  let $result :=
    try {
      unit:assert-equals($promise(()), 'Hello world!')
    } catch * { ('Failed!') }
  return
   unit:assert-equals($result, 'Failed!')
}

declare %unit:test function test:callback-then() {
  let $greet := function ($res) { 'Hello ' || $name || '!'}
  let $promise :=
      promise:defer(trace(?), 'world', map {
          'then': $greet
      })
  return
    unit:assert-equals($promise(()), 'Hello world!')
};

declare %unit:test function test:multiple-callbacks() {
  let $greet := function ($res) { 'Hello ' || $name }
  let $get-end := function ($name) { $name || '!' }
  let $promise :=
      promise:defer(trace(?), 'world', map {
          'then': ($get-end, $greet)
      })
  return
    unit:assert-equals($promise(()), 'Hello world!')
}

declare %unit:test function test:callbacks-attached-after() {
  let $greet := function ($res) { 'Hello ' || $name }
  let $get-end := function ($name) { $name || '!' }
  let $work := promise:defer(trace(?), 'world')
  let $get := $work(map { 'then': $get-end })
  let $promise := $get(map { 'then': $greet })
  return
    unit:assert-equals($promise(()), 'Hello world!')
}

declare %unit:test function test:when-with-same-arity() {
  let $greet := function ($greeting, $name) { $greeting || ' ' || $name || '!'}
  let $promise :=
    promise:when((
      promise:defer(trace(?), 'Hello'),
      promise:defer(trace(?), 'world'),
      map { 'then': $greet }
  ))
  return
   unit:assert-equals($promise(()), 'Hello world!')
}

declare %unit:test function test:when-with-diff-arity() {
  let $greet := function ($args) { $args?1 || ' ' || $args?2 || '!'}
  let $promise :=
    promise:when((
      promise:defer(trace(?), 'Hello'),
      promise:defer(trace(?), 'world'),
      map { 'then': $greet }
  ))
  return
   unit:assert-equals($promise(()), 'Hello world!')
}

declare %unit:test function test:fork-join() {
  let $work := function ($input) { element {text} {$input} }
  let $promises :=
    for $i in (1 to 1000) return
      promise:defer($work, $i)
  return
    let $out := promise:fork-join($promises, map {
    let $sum := sum($out)
    return
      unit:assert-equals($sum, 500500)
}

declare %unit:test function test:fork-join-shared-resource() {
  let $shared := map ( for $i in 1000 return map { 'value':$i })
  let $work := function ($input) {
    let $value := $shared?*[. = $input]
    return
      element {text} {json:serialize($input)}
  }
  let $promises := for $i in (1 to 1000)
                   return promise:defer($work, $i)
  return
    let $out := promise:fork-join($promises)
    let $sum := sum(($nodes ! json:parse(.))?value)
    return
      unit:assert-equals($sum, 500500)
}


Use replace rather than add to avoid duplicate files

(: =====================================================

   Load DITA map and dependencies to BaseX

   Author: W. Eliot Kimber

   ===================================================== :)

(: import module namespace db="http://basex.org/modules/db"; :)

declare variable $db external;
(: The directory load from: :)
declare variable $dir external;
(: The collection to load into: :)
declare variable $collection external;
(: URI of entity resolution catalog to use for DTD resolution: :)
declare variable $catalogURI external;

declare variable $xmlLoadOptions as element() :=
<options>
  <catfile value='{$catalogURI}'/>
  <dtd value='true'/>
  <chop value='false'/>
  <skipcorrupt value='true'/>
  <createfilter value="*.xml,*.dita,*.ditamap,*.ditaval"/>
</options>;

for $file in (file:list($dir, false(), '*.xml,*.dita,*.ditamap,*.ditaval'))
    let $fullDir :=  concat($dir, '/', $file)
    return if (file:is-file($file)) then db:replace($db, $file, $fullDir, $xmlLoadOptions) else (),

for $file in (file:list($dir, true()))
    let $fullDir :=  concat($dir, '/', $file)
    (:return if (file:is-dir($fullDir)) then <cmd>{(concat('db:replace("',$db,'","', $fullDir, '","',$file, '",'), $xmlLoadOptions,')')}</cmd> else () :)
    return if (file:is-dir($fullDir)) then db:replace($db, $file, $fullDir, $xmlLoadOptions) else ()

(: ==================== End of Module ================================= :)

(: =====================================================

   Load DITA map and dependencies to BaseX

   Author: W. Eliot Kimber

   ===================================================== :)

(: import module namespace db="http://basex.org/modules/db"; :)

declare variable $db external;
(: The directory load from: :)
declare variable $dir external;
(: The collection to load into: :)
declare variable $collection external;
(: URI of entity resolution catalog to use for DTD resolution: :)
declare variable $catalogURI external;

declare variable $xmlLoadOptions as element() :=
<options>
  <catfile value='{$catalogURI}'/>
  <dtd value='true'/>
  <chop value='false'/>
  <skipcorrupt value='true'/>
  <createfilter value="*.xml,*.dita,*.ditamap,*.ditaval"/>
</options>;

for $file in (file:list($dir, true()))
    let $fullDir :=  concat($dir, '/', $file)
    (:return if (file:is-dir($fullDir)) then <cmd>{(concat('db:add("',$db,'","', $fullDir, '","',$file, '",'), $xmlLoadOptions,')')}</cmd> else () :)
    return if (file:is-dir($fullDir)) then db:add($db, $fullDir, $file, $xmlLoadOptions) else ()

(: ==================== End of Module ================================= :)


Rework BaseX Database Module function annotations and argument comments.

xquery version "3.0";
(:~
: BaseX Database Module functions
:
: @see http://docs.basex.org/wiki/Database_Module
:)
module namespace db = "http://basex.org/modules/db";

import module namespace a = "http://reecedunn.co.uk/xquery/annotations" at "res://reecedunn.co.uk/xquery/annotations.xqy";

declare %a:since("basex", "7.0") function db:system() as element(system) external;
declare %a:since("basex", "9.0") function db:option($name as xs:string) as xs:string external;
declare %a:since("basex", "7.0") function db:info($db as xs:string) as element(database) external;
declare %a:since("basex", "8.6") function db:property($db as xs:string, $name as xs:string) as xs:anyAtomicType external;
declare %a:since("basex", "7.0") function db:list() as xs:string* external;
declare %a:since("basex", "7.0") function db:list($db as xs:string) as xs:string* external;
declare %a:since("basex", "7.0") function db:list($db as xs:string, $path as xs:string) as xs:string* external;
declare %a:since("basex", "7.1") function db:list-details() as element(database)* external;
declare %a:since("basex", "7.1") function db:list-details($db as xs:string) as element(resource)* external;
declare %a:since("basex", "7.1") function db:list-details($db as xs:string, $path as xs:string) as element(resource)* external;
declare %a:since("basex", "7.0") function db:backups() as element(backup)* external;
declare %a:since("basex", "7.0") function db:backups($db as xs:string) as element(backup)* external;
declare %a:since("basex", "7.0") function db:open($db as xs:string) as document-node()* external;
declare %a:since("basex", "7.0") function db:open($db as xs:string, $path as xs:string) as document-node()* external;
declare %a:since("basex", "7.0") function db:open-pre($db as xs:string, $pre as xs:integer) as node() external;
declare %a:since("basex", "7.0") function db:open-id($db as xs:string, $id as xs:integer) as node() external;
declare %a:since("basex", "7.0") function db:node-pre($nodes as node()*) as xs:integer* external;
declare %a:since("basex", "7.0") function db:node-id($nodes as node()*) as xs:integer* external;
declare %a:since("basex", "7.0") function db:retrieve($db as xs:string, $path as xs:string) as xs:base64Binary external;
declare %a:since("basex", "7.0") function db:retrieve($db as xs:string, $path as xs:string) as xs:base64Binary external;
declare %a:since("basex", "7.0") function db:text($db as xs:string, $strings as xs:string*) as text()* external;
declare %a:since("basex", "7.2.1") function db:text-range($db as xs:string, $min as xs:string, $max as xs:string) as text()* external;
declare %a:since("basex", "7.0") function db:attribute($db as xs:string, $strings as xs:string*) as attribute()* external;
declare %a:since("basex", "7.0") function db:attribute($db as xs:string, $strings as xs:strings*, $name as xs:string) as attribute()* external;
declare %a:since("basex", "7.2.1") function db:attribute-range($db as xs:string, $min as xs:string, $max as xs:string) as attribute()* external;
declare %a:since("basex", "7.0") function db:attribute-range($db as xs:string, $min as xs:string, $max as xs:string, $name as xs:string) as attribute()* external;
declare %a:since("basex", "8.4") function db:token($db as xs:string, $tokens as xs:string*) as attribute()* external;
declare %a:since("basex", "8.4") function db:token($db as xs:string, $tokens as xs:string*, $name as xs:string) as attribute()* external;
declare %a:since("basex", "7.5") function db:create($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.5") function db:create($db as xs:string, $inputs as item()* (: $inputs [7.5] as item() [7.6] as item()* :)) as empty-sequence() external;
declare %a:since("basex", "7.5") function db:create($db as xs:string, $inputs as item()* (: $inputs [7.5] as item() [7.6] as item()*):), $paths as xs:string* (: $paths [7.5] as xs:string [7.6] as xs:string* :)) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:create($db as xs:string, $inputs as item()* (: $inputs [7.5] as item() [7.6] as item()*):), $paths as xs:string* (: $paths [7.5] as xs:string [7.6] as xs:string* :), $options as map(*)? (: $options [7.7] as item() [8.2.1] as map(xs:string, xs:string) [8.2.3] as map(*) [8.6.7] as map(*)? :)) as empty-sequence() external;
declare %a:since("basex", "7.5") function db:drop($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:add($db as xs:string, $input as item() (: [7.5] :)) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:add($db as xs:string, $input as item() (: [7.5] :), $path as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:add($db as xs:string, $input as item() (: [7.5] :), $path as xs:string, $options as map(*)? (: $options [7.9] as item() [8.2.1] as map(xs:string, xs:string) [8.2.3] as map(*) [8.6.7] as map(*)? :)) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:delete($db as xs:string, $path as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:copy($db as xs:string, $name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:alter($db as xs:string, $name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:create-backup($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:drop-backup($name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:restore($name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:optimize($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:optimize($db as xs:string, $all as xs:boolean) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:optimize($db as xs:string, $all as xs:boolean, $options as map(*)? (: $options [7.7] as item() [8.2.1] as map(xs:string, xs:string) [8.2.3] as map(*) [8.6.7] as map(*)? :))  as empty-sequence() external;
declare %a:since("basex", "7.0") function db:rename($db as xs:string, $source as xs:string, $target as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:replace($db as xs:string, $path as xs:string, $input as item()) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:replace($db as xs:string, $path as xs:string, $input as item(), $options as map(*)? (: $options [7.9] as item() [8.2.1] as map(xs:string, xs:string) [8.2.3] as map(*) [8.6.7] as map(*)? :)) as empty-sequence() external;
declare %a:since("basex", "7.0") function db:store($db as xs:string, $path as xs:string, $input as item()) as empty-sequence() external;
declare %a:since("basex", "7.3") function db:flush($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.7") function db:name($node as node()) as xs:string external;
declare %a:since("basex", "7.7") function db:path($node as node()) as xs:string external;
declare %a:since("basex", "7.0") function db:exists($db as xs:string) as xs:boolean external;
declare %a:since("basex", "7.0") function db:exists($db as xs:string, $path as xs:string) as xs:boolean external;
declare %a:since("basex", "7.0") function db:is-raw($db as xs:string, $path as xs:string) as xs:boolean external;
declare %a:since("basex", "7.0") function db:is-xml($db as xs:string, $path as xs:string) as xs:boolean external;
declare %a:since("basex", "7.1") function db:content-type($db as xs:string, $path as xs:string) as xs:string external;
declare %a:since("basex", "7.2.1") %a:until("basex", "9.0") %a:see-also("basex", "9.0", "update:output") function db:output() external;
declare %a:since("basex", "8.2") %a:until("basex", "9.0") %a:see-also("basex", "9.0", "update:cache") function db:output-cache() external;
declare %a:since("basex", "7.7") function db:export($db as xs:string, $path as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.7") function db:export($db as xs:string, $path as xs:string, $params as item()) as empty-sequence() external;
declare %a:since("basex", "7.0") %a:until("basex", "8.2") function db:event($name as xs:string, $query as item()) as empty-sequence() external;
declare %a:since("basex", "7.0") %a:until("basex", "7.8") function db:fulltext($db as item(), $terms as xs:string) as text()* external;

xquery version "3.0";
(:~
: BaseX Database Module functions
:
: @see http://docs.basex.org/wiki/Database_Module
:)
module namespace db = "http://basex.org/modules/db";

import module namespace a = "http://reecedunn.co.uk/xquery/annotations" at "res://reecedunn.co.uk/xquery/annotations.xqy";

declare %a:since("basex", "7.8") function db:system() as element(system) external;
declare %a:since("basex", "9.0") function db:option($name as xs:string) as xs:string external;
declare %a:since("basex", "7.8") function db:info($db as xs:string) as element(database) external;
declare %a:since("basex", "8.6") function db:property($db as xs:string, $name as xs:string) as xs:anyAtomicType external;
declare %a:since("basex", "7.8") function db:list() as xs:string* external;
declare %a:since("basex", "7.8") function db:list($db as xs:string) as xs:string* external;
declare %a:since("basex", "7.8") function db:list($db as xs:string, $path as xs:string) as xs:string* external;
declare %a:since("basex", "7.8") function db:list-details() as element(database)* external;
declare %a:since("basex", "7.8") function db:list-details($db as xs:string) as element(resource)* external;
declare %a:since("basex", "7.8") function db:list-details($db as xs:string, $path as xs:string) as element(resource)* external;
declare %a:since("basex", "7.8") function db:backups() as element(backup)* external;
declare %a:since("basex", "7.8") function db:backups($db as xs:string) as element(backup)* external;
declare %a:since("basex", "7.8") function db:open($db as xs:string) as document-node()* external;
declare %a:since("basex", "7.8") function db:open($db as xs:string, $path as xs:string) as document-node()* external;
declare %a:since("basex", "7.8") function db:open-pre($db as xs:string, $pre as xs:integer) as node() external;
declare %a:since("basex", "7.8") function db:open-id($db as xs:string, $id as xs:integer) as node() external;
declare %a:since("basex", "7.8") function db:node-pre($nodes as node()*) as xs:integer* external;
declare %a:since("basex", "7.8") function db:node-id($nodes as node()*) as xs:integer* external;
declare %a:since("basex", "7.8") function db:retrieve($db as xs:string, $path as xs:string) as xs:base64Binary external;
declare %a:since("basex", "7.8") function db:retrieve($db as xs:string, $path as xs:string) as xs:base64Binary external;
declare %a:since("basex", "7.8") function db:text($db as xs:string, $strings as xs:string*) as text()* external;
declare %a:since("basex", "7.8") function db:text-range($db as xs:string, $min as xs:string, $max as xs:string) as text()* external;
declare %a:since("basex", "7.8") function db:attribute($db as xs:string, $strings as xs:string*) as attribute()* external;
declare %a:since("basex", "7.8") function db:attribute($db as xs:string, $strings as xs:strings*, $name as xs:string) as attribute()* external;
declare %a:since("basex", "7.8") function db:attribute-range($db as xs:string, $min as xs:string, $max as xs:string) as attribute()* external;
declare %a:since("basex", "7.8") function db:attribute-range($db as xs:string, $min as xs:string, $max as xs:string, $name as xs:string) as attribute()* external;
declare %a:since("basex", "8.4") function db:token($db as xs:string, $tokens as xs:string*) as attribute()* external;
declare %a:since("basex", "8.4") function db:token($db as xs:string, $tokens as xs:string*, $name as xs:string) as attribute()* external;
declare %a:since("basex", "7.8") function db:create($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:create($db as xs:string, $inputs as item()*) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:create($db as xs:string, $inputs as item()*, $paths as xs:string*) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:create($db as xs:string, $inputs as item()*, $paths as xs:string*, $options as map(*)? (: $options [7.8] as item() [8.2.1] as map(xs:string, xs:string) [8.2.3] as map(*) [8.6.7] as map(*)? :)) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:drop($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:add($db as xs:string, $input as item()) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:add($db as xs:string, $input as item(), $path as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:add($db as xs:string, $input as item(), $path as xs:string, $options as map(*)?) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:delete($db as xs:string, $path as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:copy($db as xs:string, $name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:alter($db as xs:string, $name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:create-backup($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:drop-backup($name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8.2") function db:restore($name as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:optimize($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:optimize($db as xs:string, $all as xs:boolean) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:optimize($db as xs:string, $all as xs:boolean, $options as map(*)?) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:rename($db as xs:string, $source as xs:string, $target as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:replace($db as xs:string, $path as xs:string, $input as item()) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:replace($db as xs:string, $path as xs:string, $input as item(), $options as map(*)?) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:store($db as xs:string, $path as xs:string, $input as item()) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:flush($db as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:name($node as node()) as xs:string external;
declare %a:since("basex", "7.8") function db:path($node as node()) as xs:string external;
declare %a:since("basex", "7.8") function db:exists($db as xs:string) as xs:boolean external;
declare %a:since("basex", "7.8") function db:exists($db as xs:string, $path as xs:string) as xs:boolean external;
declare %a:since("basex", "7.8") function db:is-raw($db as xs:string, $path as xs:string) as xs:boolean external;
declare %a:since("basex", "7.8") function db:is-xml($db as xs:string, $path as xs:string) as xs:boolean external;
declare %a:since("basex", "7.8") function db:content-type($db as xs:string, $path as xs:string) as xs:string external;
declare %a:since("basex", "7.8") %a:until("basex", "9.0") %a:see-also("basex", "9.0", "update:output") function db:output() external;
declare %a:since("basex", "8.2") %a:until("basex", "9.0") %a:see-also("basex", "9.0", "update:cache") function db:output-cache() external;
declare %a:since("basex", "7.8") function db:export($db as xs:string, $path as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.8") function db:export($db as xs:string, $path as xs:string, $params as item()) as empty-sequence() external;
declare %a:since("basex", "7.8") %a:until("basex", "8.2") function db:event($name as xs:string, $query as item()) as empty-sequence() external;