Function Extensions

Function Extensions are powerful tools that you attach directly to a function's output to provide additional, often simpler, capabilities for on-the-fly data processing. They allow you to modify, filter, record, or handle errors without needing a separate function block.

Working with Extensions

The following actions apply to all extension types, allowing you to build complex processing pipelines directly on a function's output.

  • Adding an Extension: To add an extension, click the + icon on a function's output and select the desired type from the menu. You can add multiple parallel extensions to the same output to perform independent actions on the same data.

  • Chaining Extensions: To create a multi-step process, you can add an extension to the output of another extension. This allows you to, for example, filter data first and then modify the result.

  • Deleting an Extension: To remove an extension, right-click on it and select Delete from the context menu.

The four extension types
One function with three extensions

Modifier

The Modifier is a simple but powerful tool for on-the-fly data modification and transformation. It takes the output from a function and allows you to apply a JSONata or JavaScript expression to change its structure or value before passing it to the next step in your flow.

A Modifier can use either JSONata or a JavaScript expression to perform transformations. By default, it is set to JSONata. You can switch between types at any time by right-clicking the modifier and selecting Jsonata or Expression.

JSONata Modifier

JSONata is a lightweight query and transformation language designed for JSON data.

  • To refer to the value from the preceding output, use the $ sign.

  • For JSONata functions, however, the previous value is automatically considered as an argument, eliminating the need to explicitly fill it into the brackets.

  • For a complete guide, refer to the official JSONata documentation.

Examples

1. Wrap a value in an object: This expression takes the incoming value ($) and wraps it inside a JSON object with a key named payload.

{ "payload": $ }

2. Select a nested value: This expression selects the location value from a nested incoming object. If the input is an object like { "user": { "name": "John", "location": "Berlin" } }, this expression will output the string "Berlin".

user.location

Visual Examples

$ sign as reference for context
JSONata function in the modifier
Object filtering with JSONata

JavaScript Expression Modifier

This allows you to use any standard JavaScript expression that evaluates to a new value.

Examples

1. Concatenate a string: This expression takes the incoming string (x) and adds a prefix to it.

'Hello, ' + x

2. Perform a conditional check: This ternary expression checks if the incoming number (x) is greater than 100 and returns a corresponding string.

x > 100 ? 'High' : 'Normal'

Visual Examples

Array filter expression in JavaScript

Filter

The Filter acts as a conditional gate for your data flow, allowing you to branch logic based on conditions. It is the primary method for implementing if/else scenarios in your flows.

The Filter evaluates a JavaScript expression you provide, which must return true or false. The input value from the previous output is available as the variable x. If the result is true, the data is passed on; if false, the data flow is halted at this point. At the same time, the true and false states of the filter can be used to trigger separate logic paths.

Examples

1. Check a numeric value This expression checks if the temperature value in an incoming object (x) exceeds a threshold of 90.

x.temperature > 90

2. Check text content This expression checks if an incoming message (x) contains the word "Error".

x.includes('Error')

Visual Example

A function with four filters.

Recorder

The Recorder captures a function's output and stores it as time-series data in the internal InfluxDB. This allows you to store a data stream, visualize it within your applications, or analyze it as required. It records data during both build-time (in test mode) and the app's runtime.

The Recorder has two settings:

  • Measurement Name: You must provide a unique name for the measurement in the recorder's text box.

  • Retention Policy: Right-click the circle icon (which defaults to 'F' for Forever) to set how long the recorded data should be stored. Options range from one hour to a year, or forever.

Error Handler

The Error Handler allows you to gracefully manage potential errors thrown by a function. It provides a separate output that will only activate if the function it's attached to fails or throws an exception.

This enables you to build a safe, separate logic path to handle error conditions, such as logging the error details to a database or displaying a user-friendly error message on the UI.

Error simulator function with captured error message and JSONata modification.

Last updated