MCPcopy Create free account
hub / github.com/dataform-co/dataform / checkCircularity

Method checkCircularity

core/session.ts:714–743  ·  view source on GitHub ↗
(actions: ActionProto[])

Source from the content-addressed store, hash-verified

712 }
713
714 private checkCircularity(actions: ActionProto[]) {
715 const allActionsByStringifiedTarget = new Map<string, ActionProto>(
716 actions.map(action => [targetStringifier.stringify(action.target), action])
717 );
718
719 // Type exports for tarjan-graph are unfortunately wrong, so we have to do this minor hack.
720 const tarjanGraph: TarjanGraph = new (TarjanGraphConstructor as any)();
721 actions.forEach(action => {
722 // Declarations cannot have dependencies.
723 const cleanedDependencies = (action instanceof dataform.Declaration ||
724 !action.dependencyTargets
725 ? []
726 : action.dependencyTargets
727 ).filter(
728 dependency => !!allActionsByStringifiedTarget.get(targetStringifier.stringify(dependency))
729 );
730 tarjanGraph.add(
731 targetStringifier.stringify(action.target),
732 cleanedDependencies.map(target => targetStringifier.stringify(target))
733 );
734 });
735 const cycles = tarjanGraph.getCycles();
736 cycles.forEach(cycle => {
737 const firstActionInCycle = allActionsByStringifiedTarget.get(cycle[0].name);
738 const message = `Circular dependency detected in chain: [${cycle
739 .map(vertex => vertex.name)
740 .join(" > ")} > ${targetAsReadableString(firstActionInCycle.target)}]`;
741 this.compileError(new Error(message), firstActionInCycle.fileName, firstActionInCycle.target);
742 });
743 }
744
745 private addTestsToCompiledGraph(actions: Action[]) {
746 actions

Callers 1

compileMethod · 0.95

Calls 5

compileErrorMethod · 0.95
targetAsReadableStringFunction · 0.90
stringifyMethod · 0.80
getMethod · 0.80
addMethod · 0.80

Tested by

no test coverage detected