Re: [basex-talk] mapping functions

2023-08-15 Thread gerrit . imsieke
You can import the library module in the evaluated expression. Example: 
https://github.com/transpect/control-backend/blob/main/webapp/control-backend.xqm#L60

Gerrit


Sent from MailDroid

-Original Message-
From: Graydon Saunders 
To: BaseX 
Sent: Wed, 16 Aug 2023 4:42
Subject: [basex-talk] mapping functions

Hello --

I have various databases that will be run through the same code after their
contents is regularized.  So the only different function is the one used
for regularization.

This can be handled by writing a wrapper function and passing in a label to
say which function to use, but I was wondering if there's a way to do it in
the configuration map directly.  The configuration map exists as a text
file and gets run through xquery:eval() at the start of the process.

declare namespace abc='http://some/uri';
'regularizationFunction': map {
 'typeOne': abc:regularizationOne#1,
 'typeTwo': abc:regularizationTwo#1
}

doesn't work, because the abc functions aren't known at evaluation time.
These functions are defined in the library module that's evaluating the
configuration file but xquery:eval() doesn't know that.  I don't see a way
to use bindings to get around this.

Is there a way to map a locally-defined function reference so xquery:eval()
will recognize it?

thanks!
Graydon

-- 
Graydon Saunders  | graydon...@fastmail.com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")


[basex-talk] mapping functions

2023-08-15 Thread Graydon Saunders
Hello --

I have various databases that will be run through the same code after their
contents is regularized.  So the only different function is the one used
for regularization.

This can be handled by writing a wrapper function and passing in a label to
say which function to use, but I was wondering if there's a way to do it in
the configuration map directly.  The configuration map exists as a text
file and gets run through xquery:eval() at the start of the process.

declare namespace abc='http://some/uri';
'regularizationFunction': map {
 'typeOne': abc:regularizationOne#1,
 'typeTwo': abc:regularizationTwo#1
}

doesn't work, because the abc functions aren't known at evaluation time.
These functions are defined in the library module that's evaluating the
configuration file but xquery:eval() doesn't know that.  I don't see a way
to use bindings to get around this.

Is there a way to map a locally-defined function reference so xquery:eval()
will recognize it?

thanks!
Graydon

-- 
Graydon Saunders  | graydon...@fastmail.com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")


[basex-talk] Use Bash to construct multi-file form submission

2023-08-15 Thread Eliot Kimber
This is not strictly a BaseX question but it is in the context of communicating 
with a BaseX-implemented REST service and I’m hoping someone in this community 
can answer my question as I’ve not found a solution the interwebs.

I’ve implemented a POST method that expects a multi-part form request with 
multiple files that then loads those files into a database. The files are all 
related such that I want something close to an atomic commit for the set of 
files. Thus the multi-file form approach.


The REST method works and I can use from the command line using curl, i.e:

curl --location http://localhost:9984/now/rest/validation/reports?debug=false \
--form 
'files=@"/Users/eliot.kimber/git-basex/product-content-analytics/validation-reports/vancouver/bundle-strategic-portfolio-mgmt_errors_vancouver_2023-08-14T22~11~28Z_1ae692f8_1692054936.xml"'
 \
--form 
'files=@"/Users/eliot.kimber/git-basex/product-content-analytics/validation-reports/vancouver/bundle-tech-technology-industry_errors_vancouver_2023-08-14T22~11~28Z_1ae692f8_1692054971.xml"'

What I haven’t been able to figure out is how to construct the equivalent curl 
command in a bash script, where the script gets a list of flies to load and 
then constructs the –form parameters.

Everything I’ve tried results in a “Warning: Trailing data after quoted form 
parameter” message or some more utter failure.

It must be some subtlety of how to escape the quotes—my googling around 
produces lots of stack overflow discussions of how to manage the escapes, but 
nothing I’ve tried has so far worked.

My bash approach is simply:


curlcmd=”curl --location …”
for file in ${files[@]}; do
   curlcmd+=” --form ‘files=@\”${file}\”’
done

And then execute the resulting string:

bash -c $curlcmd

I have a separate script that successfully constructs a curl call to a 
companion end point that takes one file:



curl \
"--location" 
"${serverUrl}:${serverPort}/now/rest/validation/report/${fileName}?debug=${debug}"
 \
"--header" "Content-Type: text/xml" \
"--data-binary" "@${filePath}"

And I’m currently just calling this for each file, which is OK.

But I’d really like to be able to send a set of files as a single REST call.

Thanks,

Eliot
_
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com
LinkedIn | 
Twitter | 
YouTube | 
Facebook