graph-ecs/tests/utils.js

17 lines
996 B
JavaScript

import { KeyValuePair, Name, Label, Identifier, Literal, Edge, Node, DirectedEdge, Relationship } from '../src/query/types.js'
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(
name && new Name(new Identifier(name)),
new Label(new Identifier(label)),
props.map(keyValuePair)
)
export const makeNode = graphObject
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)
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)
export const makeRelationship = (from, edge, to) => new Relationship(from, edge, to)