graph-ecs/tests/utils.js

20 lines
1 KiB
JavaScript
Raw Normal View History

2024-11-26 22:38:27 +01:00
import { KeyValuePair, Name, Label, Identifier, Literal, Edge, Node, DirectedEdge, Relationship, Component } from '../src/query-parser/types.js'
2024-11-13 20:24:29 +01:00
export const keyValuePair = ([k, v]) => new KeyValuePair(new Name(new Identifier(k)), new Literal(v))
export const graphObject = (name, label, props = [], Type = Node) => new Type(
2024-11-26 22:38:27 +01:00
[new Component(
name && new Name(new Identifier(name)),
new Label(new Identifier(label)),
props.map(keyValuePair)
)]
2024-11-13 20:24:29 +01:00
)
export const makeNode = graphObject
2024-11-15 07:36:19 +01:00
export const makeEdge = (name, label, props = []) => graphObject(name, label, props, Edge)
export const makeDirectedEdge = (name, label, direction, props = []) => DirectedEdge.fromEdge(makeEdge(name, label, props), direction)
2024-11-19 02:10:29 +01:00
export const makeLeftEdge = (name, label, props = []) => DirectedEdge.fromEdge(makeEdge(name, label, props), 0)
export const makeRightEdge = (name, label, props = []) => DirectedEdge.fromEdge(makeEdge(name, label, props), 1)
2024-11-18 23:06:58 +01:00
export const makeRelationship = (from, edge, to) => new Relationship(from, edge, to)
2024-11-13 20:24:29 +01:00