Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isDirectlyDependentOn(successfulGoal: SdmGoalKey, goal: SdmGoalEvent): boolean {
if (!goal) {
logger.warn("Internal error: Trying to work out if %j is dependent on null or undefined goal", successfulGoal);
return false;
}
if (!goal.preConditions || goal.preConditions.length === 0) {
return false; // no preconditions? not dependent
}
if (mapKeyToGoal(goal.preConditions)(successfulGoal)) {
logger.debug("%s depends on %s", goal.uniqueName, successfulGoal.uniqueName);
return true; // the failed goal is one of my preconditions? dependent
}
return false;
}
function isDirectlyDependentOn(successfulGoal: SdmGoalKey, goal: SdmGoalEvent): boolean {
if (!goal) {
return false;
}
if (!goal.preConditions || goal.preConditions.length === 0) {
return false; // no preconditions? not dependent
}
if (mapKeyToGoal(goal.preConditions)(successfulGoal)) {
logger.debug("%s depends on %s", goal.uniqueName, successfulGoal.uniqueName);
return true; // the failed goal is one of my preconditions? dependent
}
return false;
}
function isDependentOn(failedGoal: SdmGoalKey, goal: SdmGoalEvent, preconditionToGoal: (g: SdmGoalKey) => SdmGoalEvent): boolean {
if (!goal) {
return false;
}
if (!goal.preConditions || goal.preConditions.length === 0) {
return false; // no preconditions? not dependent
}
if (mapKeyToGoal(goal.preConditions)(failedGoal)) {
return true; // the failed goal is one of my preconditions? dependent
}
// otherwise, recurse on my preconditions
return !!goal.preConditions
.map(precondition => isDependentOn(failedGoal, preconditionToGoal(precondition), preconditionToGoal))
.find(a => a); // if one is true, return true
}
const goalsToSkip = goals.filter(g => isDependentOn(failedGoal, g, mapKeyToGoal(goals)))
.filter(g => g.state === "planned");