Wit

Config reference

The wit.sources.json schema, the formats a source can return, the built-in env source, and the --allow-exec rules. Source: packages/cli/src/data-sources.ts, packages/runtime/src/data-loader.ts.

wit.sources.json

source
{
  "sources": {
    "sales": {
      "run": ["python3", "scripts/sales.py", "{{region}}"],
      "format": "csv",
      "timeoutMs": 30000
    }
  }
}
result

{ "sources": { "sales": { "run": ["python3", "scripts/sales.py", "{{region}}"], "format": "csv", "timeoutMs": 30000 } } }

Fields
FieldRequiredMeaningDefault
sourcesyesobject of aliases—
ALIAS.runyesnon-empty argv array; the first element is the program—
ALIAS.formatnoone of the seven formats belowjson
ALIAS.timeoutMsnokill the program after this many ms30000
  • Pass it with --sources wit.sources.json to wit build or wit check.
  • run is resolved relative to the sources file, and the program runs in that file's directory.
  • {{name}} in a run token becomes that @load parameter's value; a missing one becomes empty.
  • Output is capped at 16 MB. A non-zero exit, a timeout or a parse failure is E_LOAD_FAILED at the @load.
  • Config errors: expected a top-level "sources" object, source "run" must be a non-empty argv array. JSON only.

Formats

What stdout becomes
FormatValue
jsonparsed JSON; empty output is null
csva collection of records keyed by the first row
tsvthe same with tabs
linesa collection of the non-empty lines
textthe output as one string
svgthe output as one string
htmlthe output as one string

CSV and TSV follow RFC 4180: a quoted field may hold the separator, a doubled quote is a quote, and a quoted field may span lines. Loaded strings are text — never read as Wit markup.

Using a source

@load(as: rows, region: North) sales load@

@table(rows: @rows)
load parameters
FormEffect
body textthe alias to load
from: ALIASthe alias when there is no body
as: NAMEname the resulting data definition; default is the alias
any other KEY: VALUEpassed to the program

@load(from: sales, as: rows, region: North) needs no close. A @load works at the top level, in a node body and in referenced files; it must stand on its own lines, not inside a sentence. Several files may load the same alias — that is one definition, not a duplicate. No alias at all is E_LOAD_FAILED (@load needs an alias).

The env source

Built in; needs no config and no --allow-exec. It returns the process environment merged with the --env dotenv file, as a record.

@load env load@

Built by @env.USER.

The dotenv reader takes KEY=value lines, treats # lines as comments, strips surrounding quotes and skips blank or key-less lines.

Security

Rules
RuleBehaviour
no --allow-execany source other than env fails: running programs is disabled; pass --allow-exec
unknown aliasno source configured for alias NAME
working directorythe sources file's directory
child environmentthe process environment plus --env
parameterssubstituted into run tokens and sent on stdin as JSON

A document can never run a program unless the person building it passes --allow-exec.

See also

CLI · External data · Data model · Errors.