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
{
"sources": {
"sales": {
"run": ["python3", "scripts/sales.py", "{{region}}"],
"format": "csv",
"timeoutMs": 30000
}
}
}{ "sources": { "sales": { "run": ["python3", "scripts/sales.py", "{{region}}"], "format": "csv", "timeoutMs": 30000 } } }
| Field | Required | Meaning | Default |
|---|---|---|---|
| sources | yes | object of aliases | — |
| ALIAS.run | yes | non-empty argv array; the first element is the program | — |
| ALIAS.format | no | one of the seven formats below | json |
| ALIAS.timeoutMs | no | kill the program after this many ms | 30000 |
- Pass it with
--sources wit.sources.jsontowit buildorwit check. runis resolved relative to the sources file, and the program runs in that file's directory.{{name}}in aruntoken becomes that@loadparameter'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_FAILEDat the@load. - Config errors:
expected a top-level "sources" object,source "run" must be a non-empty argv array. JSON only.
Formats
| Format | Value |
|---|---|
| json | parsed JSON; empty output is null |
| csv | a collection of records keyed by the first row |
| tsv | the same with tabs |
| lines | a collection of the non-empty lines |
| text | the output as one string |
| svg | the output as one string |
| html | the 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)
| Form | Effect |
|---|---|
| body text | the alias to load |
| from: ALIAS | the alias when there is no body |
| as: NAME | name the resulting data definition; default is the alias |
| any other KEY: VALUE | passed 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
| Rule | Behaviour |
|---|---|
| no --allow-exec | any source other than env fails: running programs is disabled; pass --allow-exec |
| unknown alias | no source configured for alias NAME |
| working directory | the sources file's directory |
| child environment | the process environment plus --env |
| parameters | substituted 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.