ScriptEval
The Do It All Swiss Army Knife Valve
The Do It All Swiss Army Knife Valve
Valve for evaluating scripts using the Java Scripting API (javax.script) and GraalJS/GraalVM.
Type of script supported (JavaScript/ECMA, Python, Ruby etc) is depending on the script engine used. By default this valve (and the examples) uses the graal.js
engine with support for JavaScript.
For more information, see:
Valve name: ScriptEval
Name | Description | Default value | Mandatory | Expanded |
---|---|---|---|---|
During script evaluation the following objects are available in the script context:
Name | Description |
---|---|
Pipe request parameters are accessed using the request
object in script context:
Pipe state can be accessed using the state
script context object. Properties stored in state are available to all valves in a pipe and also included in the pipe response.
The current session can be accessed using the session
script context object.
Session has two reserved properties that can not be modified:
id
trace_id
Items is an API that provides access to the current item set. Using this API items can be created, loaded by id, removed and iterated.
Item objects returned by this api has an id
property (reserved and read only) and an arbitrary number of other properties.
Note: Item properties are always of type string
Logging in scripts can be done using the standard console object:
or using the Fortified Logging API Logger object also supporting "printf" formatting:
Bad script syntax result in a syntax error in the log (WARN
) and a flow failure.
A syntax error typically looks like this and contains a location, description and the bad line:
To access java types in script use:
or (backwards-compatible syntax):
For more information regarding script interoperability with java, see: https://www.graalvm.org/reference-manual/js/JavaInteroperability/
Script engine log can be configured using the following system property:
engine
The script engine to use.
"graal.js"
source
The script to evaluate (Mandatory unless config.path is configured)
path
Path to script to evaluate.
request
The current request. Object is read-only and can not be modified.
state
Object representing the current pipe state.
session
Object representing the current session
items
Object providing access to the current set of items.
log
The current valve logger.
context
The raw pipe context. Use only if objects above are not sufficient. Type: foss.pipes.valves.item.api.PipeContextItem