@neo4j/cypher-builder
Version:
A programmatic API for building Cypher queries for Neo4j
33 lines (32 loc) • 1.23 kB
JavaScript
;
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeExpr = normalizeExpr;
exports.normalizeMap = normalizeMap;
exports.normalizeList = normalizeList;
const ListExpr_1 = require("../expressions/list/ListExpr");
const MapExpr_1 = require("../expressions/map/MapExpr");
const Literal_1 = require("../references/Literal");
const is_cypher_compilable_1 = require("./is-cypher-compilable");
function normalizeExpr(value) {
if (!value)
return undefined;
if ((0, is_cypher_compilable_1.isCypherCompilable)(value))
return value;
return new Literal_1.Literal(value);
}
/** Applies {@link normalizeExpr} to the properties of a map. Returns a {@link MapExpr} */
function normalizeMap(map) {
return Object.entries(map).reduce((mapExpr, [key, value]) => {
mapExpr.set(key, normalizeExpr(value));
return mapExpr;
}, new MapExpr_1.MapExpr());
}
/** Applies {@link normalizeExpr} to the elements of a list. Returns a {@link ListExpr} */
function normalizeList(list) {
const expressions = list.map((v) => normalizeExpr(v));
return new ListExpr_1.ListExpr(expressions);
}