Skip to content

JavaScript Transform

Runs a bounded JavaScript transform over automation data.

@lainstack/js/transform · Data

JavaScript Transform runs a short script over named inputs and returns the outputs you declare. Choose it to reshape, compute or filter data that no built-in block covers, for example mapping a list into a list of records or summing a field.

Choose a built-in block first when one fits:

  • @lainstack/flow/set-value builds a typed value from literals and references, without code.
  • @lainstack/data/apply-shape checks an existing value against a shape and does not change it.
  • @lainstack/data/parse-json parses JSON text.

Traps:

  • The script sees only its named inputs. Map every value it needs into inputs. An input cannot be unset or an optional reference.
  • The output is one record under result, with one field per declared output. Downstream blocks read paths such as result.total. Every top-level output must be required, and there must be at least one.
  • rejectUndeclaredFields is always true, so a field outside the output schema fails the step.
  • automation.block.availableReferences builds paths from the block type’s output schema and any pinned sample. That schema declares no fields below result, so those paths show origin “sample” and appear only after a sample is pinned. See guide references.

Before writing or changing the script, read guide javascript.transform.

Setting Key Type Details
Named inputs (required) inputs Value Named Value Inputs become frozen JavaScript variables.
Script (required) script Text Declare each output with const or let. The preview below shows its fields. At most 50,000 characters.
Output schema (required) outputSchema Value
Timeout timeoutMs Number Maximum script execution duration in milliseconds.