in src/asl-utils/asl/asl.ts [197:238]
export function visitAllStatesInBranch<T extends StateDefinition>(
parent: Asl<T>,
partialPath: StateIdOrBranchIndex[],
fn: StateVisitor<T>,
): boolean {
if (isAslWithStates(parent)) {
for (const [id, state] of Object.entries(parent.States)) {
const path: StatePath = [...partialPath, id]
// returning false indicates halting the visit to the rest
const shouldContinueTheVisit = fn(id, state, parent, path)
if (!shouldContinueTheVisit) {
return false
}
if ('Iterator' in state && state.Iterator && state.Iterator.States) {
const shouldContinue = visitAllStatesInBranch(state.Iterator as T, path, fn)
if (!shouldContinue) {
return false
}
}
if ('ItemProcessor' in state && state.ItemProcessor && state.ItemProcessor.States) {
const shouldContinue = visitAllStatesInBranch(state.ItemProcessor as T, path, fn)
if (!shouldContinue) {
return false
}
}
if ('Branches' in state && state.Branches) {
for (let branchIndex = 0; branchIndex < state.Branches.length; branchIndex++) {
const branch = state.Branches[branchIndex]
const shouldContinue = visitAllStatesInBranch(branch as T, [...path, branchIndex], fn)
if (!shouldContinue) {
return false
}
}
}
}
}
// true means continue visiting other states
return true
}