JAVASCRIPT
The JavaScript Step allows you to run arbitrary JavaScript code in order to perform minor data processing tasks such as filtering or manipulating data from other Steps in the Process. If you have complex logic to be implemented, please consider using a Workers, which can run independently as a service.
The code to execute is defined via the input.script
field in the Step Context. This snippet is expected to be an
anonymous function that receives two arguments: steps
and context
. The object returned from this function will be
stored in the output.result
field in the Step Context after execution.
Snippets provided to this Step may use the console.log()
statement to persist execution information in the Step
Context. Note that it is not currently feasible to use 3rd party libraries other than those in the default Node runtime.
If you have a custom cluster, we can enable any arbitrary libraries you want, please reach out to us for support on how
to do this. If your use-case requires 3rd party support, a Workers might be a good solution.
Video Overview
Example Walkthrough
Please find below an example of how this Step might be used to filter the results of the user_fetcher
step ref:
// steps is an object containing references to all other steps in the current process.
// context the ProcessContext attached to this Process
(steps, context) => {
// ProcessContext input is provided during Process invocation
const location = context.input.locationId;
// Other Step Contexts can be accessed using the `steps` argument
const data = steps.user_fetcher_ref.output.response;
// Manipulate the data
const filteredData = data.filter(it => it.locationId === locationId);
return {
id: locationId,
locations: filteredData
}
}
Input
Field | Description | Mandatory | JSON Example |
---|---|---|---|
script | The anonymous function to execute as part of this Step. | ✔ | (steps, context) => { return 'hello' } |
Output
Field | Description |
---|---|
result | The object that was returned by the function provided in input.script . |
logs | An array of log objects, each containing the ms elapsed since execution started and the log message. |
error | An error message in case of an unsuccessful execution. |
Unmeshed runs the scripts using a highly performant JavaScript engine. It achieves 10x the speed of GraalVM under load.