@swimlane/turbine-transformations
v2.1.1
Published
Turbine Transformations
Downloads
428
Maintainers
Readme
Turbine Transformations
Transformation functions for use within Turbine.
Install
npm i @swimlane/turbine-transformations
Building
npm run build
Testing
npm run test
Usage
In order to utilize the transformation functions, you will first need to instantiate an evaluator. The only evaluators that are currently supported are a Native evaluator and a JSONata evaluator. The JSONata evaluator allows the transformation functions to be invoked from within JSONata expressions and the Native evaluator allows the transformation functions to be invoked directly (i.e. no intermediate expression language) via the same abstraction (i.e. the TransformationEvaluator abstraction).
Due to a limitation with JSONata, functions can only be accessed via their namespaced-concatenated names. That is,
by concatenating the function's namespace with the function's capitalized name. For example: date.adjust
-> dateAdjust
.
JSONata
const evaluator = new JSONataEvaluator();
const context: TransformationContext<JSONataInput> = {
input: {
expression: `$dateAdjust(date, 5, 'days')`,
data: {
date: new Date(Date.now()).toISOString()
}
}
};
const result = await evaluator.evaluate(context) as string;
Native
const evaluator = new NativeEvaluator();
const context: TransformationContext<NativeInput> = {
input: {
function: 'dateAdjust',
arguments: [new Date(Date.now()).toISOString(), 5, 'days']
}
};
const result = await evaluator.evaluate(context) as string;