MCPcopy Create free account
hub / github.com/codemix/graph / traverse

Method traverse

packages/graph/src/Steps.ts:4116–4152  ·  view source on GitHub ↗
(
    source: GraphSource<any>,
    input: Iterable<unknown>,
    _context?: QueryContext,
  )

Source from the content-addressed store, hash-verified

4114 }
4115
4116 public *traverse(
4117 source: GraphSource<any>,
4118 input: Iterable<unknown>,
4119 _context?: QueryContext,
4120 ): IterableIterator<unknown> {
4121 // Collect input into array for reuse across branches
4122 const inputArray = Array.from(input);
4123
4124 if (this.config.all) {
4125 // UNION ALL: yield all results from all branches
4126 for (const traverser of this.traversers) {
4127 for (const path of traverser.traverse(source, inputArray)) {
4128 this.traversed++;
4129 this.emitted++;
4130 yield path;
4131 }
4132 }
4133 } else {
4134 // UNION: yield unique results (deduplicated)
4135 // For row-based results, we stringify to compare
4136 const seen = new Set<string>();
4137
4138 for (const traverser of this.traversers) {
4139 for (const path of traverser.traverse(source, inputArray)) {
4140 this.traversed++;
4141
4142 // Create a key for deduplication
4143 const key = this.getDeduplicationKey(path);
4144 if (!seen.has(key)) {
4145 seen.add(key);
4146 this.emitted++;
4147 yield path;
4148 }
4149 }
4150 }
4151 }
4152 }
4153
4154 /**
4155 * Generate a key for deduplication.

Callers

nothing calls this directly

Calls 4

getDeduplicationKeyMethod · 0.95
addMethod · 0.65
traverseMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected