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

Method toString

packages/graph/src/Traversals.ts:260–294  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

258 }
259
260 public toString(): string {
261 const parent = this.#parent;
262 const value = this.#value;
263 const labels = this.#labels;
264 const formattedValue = value instanceof Element ? value.toString() : `#value`;
265 const segment =
266 labels.length === 0 ? formattedValue : `${formattedValue} as ${labels.join(", ")}`;
267
268 if (parent === undefined) {
269 return segment;
270 }
271
272 const parentValue = (parent as TraversalPath<any, any, any>).value;
273 if (parentValue === undefined) {
274 return segment;
275 }
276 if (parentValue instanceof Vertex && value instanceof Edge) {
277 // outV is source, inV is target
278 if (value.outV === parentValue) {
279 // Parent vertex is the source - edge comes from it
280 return `${parent} -> ${segment}`;
281 }
282 // Parent vertex is the target - edge points to it
283 return `${parent} <- ${segment}`;
284 } else if (parentValue instanceof Edge && value instanceof Vertex) {
285 // outV is source, inV is target
286 if (value === parentValue.inV) {
287 // Current vertex is the target - edge points to it
288 return `${parent} -> ${segment}`;
289 }
290 // Current vertex is the source - edge comes from it
291 return `${parent} <- ${segment}`;
292 }
293 return `${parent} - ${segment}`;
294 }
295
296 *[Symbol.iterator](): IterableIterator<TraversalPath<any, any, any>> {
297 const parent = this.#parent;

Callers 1

[customInspectSymbol]Method · 0.95

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected