JavaScript
10x JavaScript files provide control over the behavior of different components of a pipeline such as inputs, objects and outputs.
To load a JavaScript file at startup:
- Specify its path via a YAML config +include directive.
- Place it within a config folder.
- Pull it from a GitHub config repo.
- Specify its path as a command-line argument:
Activation
JavaScript .js files placed in included folders or GitHub repos must open with // @loader: tenx in the following manner to be loaded by the 10x Engine:
// @loader: tenx
import {TenXObject, TenXEnv, TenXInput, TenXLookup} from '@tenx/tenx';
export class PolicyRegulatorInput extends TenXInput {
...
}
Loading Behavior
JavaScript files must compile successfully for the 10x CLI to start. If a JS file fails to load (e.g., due to syntax errors or unresolved imports), the engine will report the error and the CLI will not proceed with execution.
Loading can be performed recursively when specifying folder arguments.
Handling Compile Errors
If there is a compilation error in a loaded JS file (e.g., missing closing parenthesis in line 13 below), the 10x CLI will fail to start and display a detailed error message. This includes:
- The path of the problematic file
- A snippet of the file's content with line numbers
- Specific parse error details, including line/column numbers and expected syntax
- The number of problems found
- The launch arguments for context
Example Output:
could not parse script ~/config/modules/pipelines/run/modules/output/event/file/output.js:
01: // @loader: tenx
02:
03: //import {TenXOutput, TenXEnv, TenXConsole, TenXArray, TenXString} from '@tenx/tenx';
04:
05: class FileOutput extends TenXOutput {
06:
07: static get shouldLoad() {
08: return !TenXEnv.get("quiet", false);
09: }
10:
11: void constructor() {
12:
13: if (this.outputFilePath {
14:
15: var fieldStr = "";
16:
17: var fieldSize = TenXArray.length(this.outputFileFields);
18:
19: if (fieldSize > 1) {
20:
21: fieldStr = "TenXObject fields: '" + this.outputFileFields + "'";
22:
23: } else if (fieldSize == 1) {
24:
25: fieldStr = "TenXObject field: '" + this.outputFileFields + "'";
26:
27: } else if (this.outputFileWriteTemplates) {
28:
29: fieldStr = "TenXTemplates";
30: }
31:
32: TenXConsole.log("📝 Writing " + fieldStr + " → " + TenXString.match(this.outputFilePath, "[^/\\\\]+\\.[^/\\\\]+$"));
33: }
34: }
35: }
found 2 problems:
(line 13,col 10) Parse error. Found "{", expected one of "!=" "%" "%=" "&" "&&" "&=" "(" ")" "*" "*=" "+" "+=" "-" "-=" "->" "/" "/=" "::" "<" "<<=" "<=" "=" "==" ">" ">=" ">>=" ">>>=" "?" "^" "^=" "instanceof" "|" "|=" "||" in: outputFilePath {
var fieldStr = "";
(line 34,col 1) Parse error. Found "}", expected one of ";" "@" "\u001a" "abstract" "class" "default" "enum" "final" "import" "interface" "module" "native" "open" "private" "protected" "public" "static" "strictfp" "synchronized" "transient" "transitive" "volatile" <EOF> in: }
}