1. The 4-Line Core Engine: executeStep
In `v4`, the core step execution function has been reduced to four clean, expressive lines with zero defensive boilerplate:
export const executeStep = (key, state, showLog = false) => {
const instruction = instructions[key];
const result = types[instruction.type](instruction, state);
writeResult(state, instruction.destinationPath, result, showLog);
return result;
};
Fetches the declarative instruction blueprint directly from declarative-instructions using its unique string identifier (e.g., "buildColgroup").
Maps instruction.type (single, rowOnColumn, or columnOnRow) to the appropriate mathematical transformer without touching DOM nodes.
writeResult locates the destination mount point inside the target canvas specification and commits the computed node AST.
Returns the transformed subtree result for optional intermediate validation or chaining.
2. The Dimension Dispatcher Table
The types registry routes instructions based on their geometric dimensionality:
const types = {
single: (instruction, state) => {
const template = spec[instruction.templateKey];
const source = resolveSource(instruction.sourcePath, state);
const fn = instruction.func === "fromCollection" ? fromCollection : applyTemplate;
return fn(source, template);
},
rowOnColumn: (instruction, { data }) => {
return rowOnColumn({
columns: data?.columns,
data,
columnSpec: spec[instruction.templateKey.columnKey],
rowSpec: spec[instruction.templateKey.rowKey]
});
},
columnOnRow: (instruction, { data }) => {
return columnOnRow({
columns: data?.columns,
data,
columnSpec: spec[instruction.templateKey.columnKey],
rowSpec: spec[instruction.templateKey.rowKey]
});
}
};
3. Path Navigation Helpers (helpers.js)
Two companion helper functions handle input data resolution and output canvas insertion:
A. resolveSource(sourcePath, state)
Extracts the required data subset from the state object. Supports dual navigation modes:
- JSONPath Mode (
sourcePath.jsonPath): Usesjsonpathlyto perform fast, expressive queries (e.g."$.data[*]"or"$.columns"). - Path Array Mode (
sourcePath.filePath): Traverses nested object keys sequentially for direct access.
B. writeResult(state, destinationPath, result, showLog)
Applies the generated spec directly into the canvas. Uses json-write-path to find target branches. Includes safe-skipping so missing optional containers won't crash execution.
4. The Canvas Pattern: Expect base, NEVER baseKey
json-renderers-run-instructions-steps is designed to accept an initialized base canvas object, mutate it sequentially in-place, and return that base. It must never accept or expect baseKey.
baseKey
Forces the steps runner to perform catalog resolution, introduces heavy dependencies on declarative-spec, isolates canvas state, and breaks composability with parent orchestrators.
// FORBIDDEN BLUNDER
runInstructions({ instructions, baseKey, data })
base
The runner receives the in-memory canvas AST (base), runs instructions against state = { base, data }, and returns the populated base to the pipeline.
// THE ARCHITECTURAL STANDARD
runInstructions({ instructions, base, data })
Why This Architecture Is Non-Negotiable:
-
Pipelining in
json-renderers-run-instructions: The master orchestrator resolves the definition, clones the base template once viaconst base = structuredClone(spec[definition.baseFromSpec]), passesbaseinto Task 1 (Steps) to populate core tables/forms, and then passes the exact same canvas to Task 2 (Options) to inject search bars, buttons, and pagination. IfstepsrequiredbaseKey, the shared canvas pipeline would break completely. -
Symmetry of Return Value: The runner returns
base. It receivesbase, mutates its sub-trees, and returns the modifiedbase. ReceivingbaseKeywhile returningbaseviolates interface predictability. -
Zero Catalog Coupling & Pollution: Expecting
basefrees the runner from needingdeclarative-specas an internal dependency. It also prevents catastrophic in-memory catalog mutation where multiple runs would poison a shared static spec.
5. Ecosystem Dependencies & Integration
Each package in the stack has a single, strictly bounded responsibility:
| Package | Role in Pipeline |
|---|---|
declarative-instructions |
Provides instruction metadata, template keys, and destination paths. |
spec-repo |
Central catalog for raw element specifications (tags, attributes, shells). |
json-transformer-funcs-primitive |
0D primitive template interpolator. |
json-transformer-funcs-one-dimension |
1D linear collection array mapper (fromCollection). |
json-transformer-funcs-two-dimensions |
2D Cartesian matrix engine (rowOnColumn, columnOnRow). |
jsonpathly |
High-speed JSONPath query engine for input data resolution. |
json-write-path |
In-place AST tree mutator for target specification insertion. |