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

Method traverse

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

Source from the content-addressed store, hash-verified

4627 }
4628
4629 public *traverse(
4630 source: GraphSource<any>,
4631 input: Iterable<unknown>,
4632 _context?: QueryContext,
4633 ): IterableIterator<unknown> {
4634 const { items } = this.config;
4635 for (const row of input) {
4636 this.traversed++;
4637 if (!Array.isArray(row)) continue;
4638
4639 const result: unknown[] = [];
4640 for (let i = 0; i < items.length; i++) {
4641 const item = items[i]!;
4642 const pathOrValue = row[i];
4643
4644 // Extract the underlying value
4645 const value = this.#extractValue(pathOrValue);
4646
4647 // If property is specified, extract just that property
4648 if (item.property !== undefined) {
4649 const propValue = this.#extractProperty(value, item.property);
4650 result.push(propValue);
4651 } else {
4652 result.push(value);
4653 }
4654 }
4655
4656 this.emitted++;
4657 // Return single value directly, or array for multiple items
4658 yield result.length === 1 ? result[0] : result;
4659 }
4660 }
4661
4662 #extractValue(pathOrValue: unknown): unknown {
4663 if (pathOrValue instanceof TraversalPath) {

Callers

nothing calls this directly

Calls 3

#extractValueMethod · 0.95
#extractPropertyMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected