Skip to content

Logic Nodes

Logic nodes run inline code directly inside Requence. They are useful for:

  • Transforming data between service calls
  • Making routing decisions
  • Filtering or aggregating results

Logic nodes can be written in TypeScript, JavaScript, or Python. The default language is TypeScript, and it is the recommended choice — Requence can fully infer types from TypeScript code, keeping your entire task template type-safe.

Everything is available through the context variable:

  • context.input — the input data arriving at this node, fully typed based on upstream nodes
  • context.getNodeData(alias) — retrieve the output of a previous node by its alias
  • context.getNodeError(alias) — retrieve the error message of a failed node by its alias, or null if it succeeded
  • context.state — a key-value store that persists across invocations of the same node (useful in loops and continuous tasks)
  • context.toOutput(name, value?) — route execution to a specific named output
  • context.overwrite(data) — replaces the entire task data. Useful when there are intermediate values that don’t need to be in the final result.

Logic nodes have an implicit void output — if the node doesn’t return anything, execution continues without modifying the task data. There is no need to explicitly return an empty object.

In addition to context, the following globals are available:

  • fetch — for making HTTP requests
  • console — for logging (log, warn, error)
  • crypto — Web Crypto API
  • setTimeout / setInterval — timers
  • ReadableStream / WritableStream / TransformStream — Web Streams API
  • RequenceFile / RequenceStream — see File Handling
  • createCallback — see Callbacks
  • Max execution time — maximum time in milliseconds the node is allowed to run. Defaults to 1000 ms. When exceeded, the node triggers its on fail output.
  • Concurrency — whether multiple instances of the node can run in parallel. Defaults to on.

When concurrency is enabled, every activation of the logic node spawns a new computation context immediately. When concurrency is turned off, a new context is only spawned after the previous invocation completes. This is useful in continuous task templates and loops.