Skip to main content

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 of over: (a list of maps, or { file: <csv> }).
  • In a block, use: <template> or layout: [<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's with:. A param with inherit: true takes the enclosing call's value; then default; 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…) or index: { name, start, step, format, in } gives each iteration a value.
  • when: ${expr} on an entry keeps it only when the expression is true.
  • reverse: true on 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 $Name anchor on a non-unique browseName is an error.

Keys​

KeyInTypeMeaning
paramstemplateobjectThe params of the template, by name. A template sees only its params and parent.
countertemplateobject{ 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.
repeattemplateobjectRepeat the body of the template. { count, index }.
instancestemplatearrayThe instances that each use adds. An - expand: entry here is a nested block.
mappingtemplatearrayThe mapping entries that each use adds, at the end of mapping:.
initializerstemplatearrayThe initializers that each use adds, at the end of initializers:.
expandtemplateExpandBlockA block that runs after the entries of the template. Use it to make children.
parentexpand blockstringThe parent of the entries. Templates read it as ${parent}. Without it, the block uses the parent of the enclosing block.
withexpand blockobjectValues that are the same for all iterations. The block gives them to each template that declares a param with that name.
countersexpand blockobjectThe counters of the block, by name. A counter lives in this block and in the blocks in it.
useexpand blockstringThe template that each iteration uses.
layoutexpand blockarrayThe templates that each iteration uses, in order. An entry is a name, { use, repeat, with } or { expand }.
repeatexpand blocknumber or stringThe number of iterations. An expression can give it.
indexexpand blockTemplateIndexThe value of each iteration. n gives 0, 1, 2. A map gives a counter with a name: { name: n, start: 1, format: "000" }.
overexpand blockarray or objectOne iteration for each record. A list of maps, or a CSV table { file }.
reverseexpand blockboolean or stringThe counters of the block give their values from the other end. The order of the entries does not change.
instancesexpand blockarrayInstances that each iteration adds, without a template.
mappingexpand blockarrayMapping entries that each iteration adds, without a template.
initializersexpand blockarrayInitializers that each iteration adds, without a template.
startcounternumberThe first value. The default is 0.
stepcounternumberThe increase between two values. The default is 1.
formatcounterstringA run of "0". The value becomes text, with zeros on the left to this width: "00" gives 01, 02.
incounterarrayThe values, in order. Do not use it with start or step.
typeparam"string", "number", "boolean"The type of the value. A value of another type is an error.
defaultparamanyThe value when the block gives no value. Without a default, the param is required.
enumparamarrayThe only values that the param accepts.
inheritparambooleanWhen the block gives no value, take the value of the same name from the enclosing template call.
filetable (over:)stringThe CSV table, relative to the configuration file. Its first line names the columns.
delimitertable (over:)",", ";"The separator of the cells. Without it, the expander finds it from the first line.
decimalSeparatortable (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 shows repeat: and index:.
  • 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 shows over: with a list of records.
  • golden/07-csv-table: This sample shows over: with a CSV table.
  • golden/08-optional-equipment: This sample shows when:.
  • golden/09-mapping-and-initializers: This sample shows a template that adds mapping: and initializers: 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 shows overrides:.

Diagnostic codes​

CodeMeaningFix
TPL-E001use: names a template that templates: does not define.Correct the name, or add the template.
TPL-E002An 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-E003A param without a default gets no value.Give the value in with: or in the record, or give the param a default.
TPL-E004The same name comes from the with: of the block and from a record.Give the value one time only.
TPL-E005A template uses itself, directly or through other templates.Remove the loop.
TPL-E006A value does not have the type of its param, or is not in its enum list.Correct the value.
TPL-E007A template takes a counter that no enclosing block declares.Declare the counter in counters: of the block that uses the template.
TPL-E008Two 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-E009A $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-E010jsonata 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-E011A 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-E012repeat: does not give a whole number of zero or more.Give a whole number, or an expression that gives one.
TPL-E013A table has a column that no param matches, or has no column for a required param.Correct the header line of the table.
TPL-E014A 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-E015The 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-E016A template or a block does not have the correct shape.Correct the definition. The schema of the configuration shows each key.
TPL-E017An 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-W001A value has more digits than its format. The expander keeps the value whole. This is a warning.Make the format wider.
TPL-W002A 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.