script
Inline or file-backed JavaScript transformations.
The script filter runs a JavaScript function on every record. It
uses Goja, a pure-Go ECMAScript 5.1+
implementation — no eval, no Node.js APIs, no I/O. Just record →
record.
Minimal example
filters:
- type: script
script: |
function transform(record) {
record.processed = true;
return record;
}Options
| property | type | default | description |
|---|---|---|---|
typerequired | "script" | — | Module type discriminator. Must be `script` for this module. |
id | string | — | Unique identifier within the pipeline. |
name | string | — | Human-readable name. |
description | string | — | — |
enabled | boolean | true | Whether module is active. |
tags | array<string> | — | — |
onError | string | "fail" | Default error action. Case-insensitive; normalized to lowercase by the runtime. |
script | string | — | Inline JavaScript source code containing a transform(record) function. |
scriptFile | string | — | Path to JavaScript file containing the transform(record) function. |
Provide exactly one of script or scriptFile — never both. The
schema enforces this.
The transform function
The runtime calls transform(record) once per record. The returned
value must be an object. Returning null, undefined, or a primitive is
an execution error, handled according to onError.
To drop a record from a script, throw — the runtime catches and
applies onError:
filters:
- type: script
onError: skip
script: |
function transform(record) {
if (!record.email) {
throw new Error('missing email');
}
return record;
}File-backed scripts
For non-trivial logic, factor the script out into a .js file:
filters:
- type: script
scriptFile: ./scripts/normalize-customer.jsfunction transform(record) {
if (record.email) {
record.email = record.email.trim().toLowerCase();
}
if (record.country) {
record.country = record.country.toUpperCase();
}
record.normalized_at = new Date().toISOString();
return record;
}What's available
Inside the script:
recordis a plain JavaScript object — read and mutate freely.- Standard ES5+ APIs:
JSON.stringify/parse,Math.*,Date.*, string methods, array methods. console.error,console.warn,console.info,console.log, andconsole.debugare available and routed to the Cannectors logger.- No Node.js APIs (
fs,http,require) and no network or file I/O.
Each record gets a fresh script execution. There's no shared state between records.
The script filter is the most expensive filter per record. Reach for
mapping, condition, set, or remove first — they're orders of
magnitude faster. Use script when the logic genuinely doesn't fit
into those.
Examples
name: script-inline-transform
version: 1.0.0
description: Transform records using inline JavaScript.
tags:
- script
- inline
input:
type: httpPolling
schedule: "0 * * * *"
endpoint: https://source.example.com/api/subscriptions
dataField: subscriptions
filters:
- type: script
onError: skip
script: |
function transform(record) {
record.normalizedStatus = String(record.status || "").toLowerCase();
record.isActive = record.normalizedStatus === "active";
record.planCode = String(record.plan || "unknown").toUpperCase();
return record;
}
output:
type: httpRequest
endpoint: https://destination.example.com/api/subscriptions
method: POST
requestMode: batchname: script-file-transform
version: 1.0.0
description: Transform records with a JavaScript file referenced by scriptFile.
tags:
- script
- script-file
input:
type: httpPolling
schedule: "0 */2 * * *"
endpoint: https://source.example.com/api/customers
dataField: customers
filters:
- type: script
scriptFile: examples/assets/scripts/customer_enrichment.js
output:
type: httpRequest
endpoint: https://destination.example.com/api/customers/enriched
method: POST
requestMode: batch