Templates: reference for AI agents
This page is a compact, generated summary of the templates: grammar of the omni-edge configuration, for tools and AI agents.
The templates page explains the same grammar for people, with procedures.
Rules
templates:is a map from a template name to a template. A template is a body or a list of template names (a module).- An
instances:entry- expand: <block>generates entries. The expander replaces it before the gateway loads the configuration. - A block iterates one time,
repeat: <n>times, or one time for each record ofover:(a list of maps, or{ file: <csv> }). - In a block,
use: <template>orlayout: [<entry>…]selects what each iteration makes. A layout entry is a name,{ use, repeat?, with? }or{ expand }. ${expr}is jsonata, evaluated against the scope. A whole-field expression keeps its type; text around it gives text.- The scope of a template: its params and
parent. Other names are errors. - Params come from the block's
with:, the record and the layout entry'swith:. A param withinherit: truetakes the enclosing call's value; thendefault; else error. counters: { name: { start, step, format: "00", in: [...] } }on a block;counter: { name: param }on a template takes the next value.${name.count}and${name.last}read it later in the same block.index: n(0, 1, 2…) orindex: { name, start, step, format, in }gives each iteration a value.when: ${expr}on an entry keeps it only when the expression is true.reverse: trueon a block: its counters give their values from the other end; the entry order does not change.- Blocked functions:
$now,$millis,$random,$eval. - After expansion: a duplicate browse path or node id is an error; a
$Nameanchor on a non-unique browseName is an error.
Keys
| Key | In | Type | Meaning |
|---|---|---|---|
params | template | object | The params of the template, by name. A template sees only its params and parent. |
counter | template | object | { asd: n }: each use takes the next value of the counter asd as the param n. A block that contains the use must declare the counter. |
repeat | template | object | Repeat the body of the template. { count, index }. |
instances | template | array | The instances that each use adds. An - expand: entry here is a nested block. |
mapping | template | array | The mapping entries that each use adds, at the end of mapping:. |
initializers | template | array | The initializers that each use adds, at the end of initializers:. |
expand | template | ExpandBlock | A block that runs after the entries of the template. Use it to make children. |
parent | expand block | string | The parent of the entries. Templates read it as ${parent}. Without it, the block uses the parent of the enclosing block. |
with | expand block | object | Values that are the same for all iterations. The block gives them to each template that declares a param with that name. |
counters | expand block | object | The counters of the block, by name. A counter lives in this block and in the blocks in it. |
use | expand block | string | The template that each iteration uses. |
layout | expand block | array | The templates that each iteration uses, in order. An entry is a name, { use, repeat, with } or { expand }. |
repeat | expand block | number or string | The number of iterations. An expression can give it. |
index | expand block | TemplateIndex | The value of each iteration. n gives 0, 1, 2. A map gives a counter with a name: { name: n, start: 1, format: "000" }. |
over | expand block | array or object | One iteration for each record. A list of maps, or a CSV table { file }. |
reverse | expand block | boolean or string | The counters of the block give their values from the other end. The order of the entries does not change. |
instances | expand block | array | Instances that each iteration adds, without a template. |
mapping | expand block | array | Mapping entries that each iteration adds, without a template. |
initializers | expand block | array | Initializers that each iteration adds, without a template. |
start | counter | number | The first value. The default is 0. |
step | counter | number | The increase between two values. The default is 1. |
format | counter | string | A run of "0". The value becomes text, with zeros on the left to this width: "00" gives 01, 02. |
in | counter | array | The values, in order. Do not use it with start or step. |
type | param | "string", "number", "boolean" | The type of the value. A value of another type is an error. |
default | param | any | The value when the block gives no value. Without a default, the param is required. |
enum | param | array | The only values that the param accepts. |
inherit | param | boolean | When the block gives no value, take the value of the same name from the enclosing template call. |
file | table (over:) | string | The CSV table, relative to the configuration file. Its first line names the columns. |
delimiter | table (over:) | ",", ";" | The separator of the cells. Without it, the expander finds it from the first line. |
decimalSeparator | table (over:) | ".", "," | The decimal separator of the numbers. The default is ".". The expander never guesses it. |
Golden samples
Each sample is a configuration and its exact expanded result, checked by the tests of @sterfive/instance-templates.
golden/01-one-template: This sample shows the smallest template.golden/02-repeat-with-index: This sample showsrepeat:andindex:.golden/03-counter-with-format: This sample shows a counter with a format.golden/04-module-in-a-repeat: This sample shows a module.golden/05-nested-blocks: This sample shows nested blocks.golden/06-records: This sample showsover:with a list of records.golden/07-csv-table: This sample showsover:with a CSV table.golden/08-optional-equipment: This sample showswhen:.golden/09-mapping-and-initializers: This sample shows a template that addsmapping:andinitializers:entries.golden/10-station: This sample shows a complete station: two platforms, their doors and one variable for each automatic door.golden/11-overrides: This sample showsoverrides:.
Diagnostic codes
| Code | Meaning | Fix |
|---|---|---|
| TPL-E001 | use: names a template that templates: does not define. | Correct the name, or add the template. |
| TPL-E002 | An expression reads a name that is not in its scope. A template sees only its params and parent. | Declare the value as a param, and give it in with: or in the record. |
| TPL-E003 | A param without a default gets no value. | Give the value in with: or in the record, or give the param a default. |
| TPL-E004 | The same name comes from the with: of the block and from a record. | Give the value one time only. |
| TPL-E005 | A template uses itself, directly or through other templates. | Remove the loop. |
| TPL-E006 | A value does not have the type of its param, or is not in its enum list. | Correct the value. |
| TPL-E007 | A template takes a counter that no enclosing block declares. | Declare the counter in counters: of the block that uses the template. |
| TPL-E008 | Two instances get the same browse path or the same node id after expansion. | Use a counter, an index or a param in the browseName and in the nodeId. |
| TPL-E009 | A $Name anchor names a browseName that the expansion gave to more than one instance. | Start the path at a unique name and go down from there: $Station/P1/ASD01. |
| TPL-E010 | jsonata cannot read or evaluate an expression, or the expression uses $now, $millis, $random or $eval. | Correct the expression. An expansion must give the same result each time. |
| TPL-E011 | A record, or the with: of a layout entry, gives a value for a param that the template does not declare. | Correct the name of the param. |
| TPL-E012 | repeat: does not give a whole number of zero or more. | Give a whole number, or an expression that gives one. |
| TPL-E013 | A table has a column that no param matches, or has no column for a required param. | Correct the header line of the table. |
| TPL-E014 | A cell of a table cannot be read as the type of its param. | Correct the cell. For a decimal comma, declare decimalSeparator: "," and delimiter: ";". |
| TPL-E015 | The expander cannot read a table file. | Put the table in the folder of the configuration file, or below it, and give a relative path. |
| TPL-E016 | A template or a block does not have the correct shape. | Correct the definition. The schema of the configuration shows each key. |
| TPL-E017 | An override names a browse path or a node id that no instance has after expansion. | Write the path as dump-config prints it, <parent>/<browseName>, or the node id. Remove the override when its instance is gone. |
| TPL-W001 | A value has more digits than its format. The expander keeps the value whole. This is a warning. | Make the format wider. |
| TPL-W002 | A block that reads a table also uses index. A moved or added row changes every value after it. This is a warning. | Put the value in a column of the table. |