Transformation functions for use within Turbine.
npm i @swimlane/turbine-transformations
npm run build
npm run test
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
.
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;
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;