Traversal Pipeline Engine Anatomy
Deep architectural breakdown of the core modules comprising the
src/v9/ co-traversal engine.
src/v9/index.js
Public API Envelope
The external entry point. Converts positional arguments
(source, recipe) into the internal { inSource, inRecipe } configuration object and invokes the central dispatcher.
import traverse from "./traverse.js";
const transform = (source, recipe) => {
const localSource = source;
const localRecipe = recipe;
return traverse({
inSource: localSource,
inRecipe: localRecipe
});
};
export default transform;
src/v9/traverse.js
Central Dispatcher
The core router. It inspects the runtime type of
localSource:
- Arrays route to
traverseArray. - Objects route to
traverseObject. - Primitives (strings, numbers, booleans, null) pass through untouched.
const startFunc = ({ inSource, inRecipe }) => {
const localSource = inSource;
const localRecipe = inRecipe;
if (Array.isArray(localSource)) {
return traverseArray({ inItems: localSource, inRecipe: localRecipe });
}
if (typeof localSource === "object" && localSource !== null) {
return traverseObject({ inSource: localSource, inRecipe: localRecipe });
}
return localSource;
};
src/v9/traverseObject/index.js
The Secret Gatekeeper
The critical design decision: The engine inspects the Recipe, not the source. If
"transform" in localRecipe is true, it enters reshaping mode via ifTransformFound. If absent, child properties continue unhindered to prevent unintended data loss.
let newElement = localSource;
if (localRecipe && typeof localRecipe === "object" && "transform" in localRecipe) {
newElement = ifTransformFound({
inSource: localSource,
inTransform: localRecipe.transform
});
}
for (const [key, value] of Object.entries(newElement)) {
if (Array.isArray(value) && localRecipe && key in localRecipe) {
newElement[key] = traverseArray({ inItems: value, inRecipe: localRecipe[key] });
}
}
return newElement;
src/v9/ifTransformFound/index.js
Orchestrated Function Pipeline
Rather than a monolithic loop,
v9 decomposes property transformation into four pure, single-purpose functions. The orchestrator drives iteration from localSource, executing each stage in clean sequence:
for (const [key, value] of Object.entries(localSource)) {
if (!(key in localTransform)) continue;
const directive = localTransform[key];
const newKey = resolveKey({ inKey: key, inDirective: directive });
let processedValue = value;
processedValue = applyTransform({ inValue: processedValue, inDirective: directive });
processedValue = normalizeValueType({ inValue: processedValue, inDirective: directive });
processedValue = extractValueKey({ inValue: processedValue, inDirective: directive });
newElement[newKey] = processedValue;
}
Submodules in
src/v9/ifTransformFound/:
resolveKey/index.js— ResolvesalterKey || key.applyTransform/index.js— Recurses into child recipes viatraverse.normalizeValueType/index.js— Normalizes single objects to arrays whenvalueType === "array".extractValueKey/index.js— Unwraps XML metadata/text wrappers (valueKey).
src/v9/traverseArray/index.js
Collection Processor
Maps each array element recursively through
traverse, flattens deep sub-arrays with .flat(Infinity), and strips empty/falsy residues with .filter(Boolean).
const startFunc = ({ inItems, inRecipe }) => {
const localItems = inItems;
const localRecipe = inRecipe;
return localItems
.map((item) => traverse({ inSource: item, inRecipe: localRecipe }))
.flat(Infinity)
.filter(Boolean);
};