@neo4j/cypher-builder
Version:
A programmatic API for building Cypher queries for Neo4j
50 lines (49 loc) • 1.86 kB
JavaScript
;
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeVariable = normalizeVariable;
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 normalizeVariable(value) {
if ((0, is_cypher_compilable_1.isCypherCompilable)(value))
return value;
return new Literal_1.Literal(value);
}
// Same as normalizeVariable, just typings are different
function normalizeExpr(value) {
if ((0, is_cypher_compilable_1.isCypherCompilable)(value))
return value;
return new Literal_1.Literal(value);
}
function normalizeMap(map) {
return Object.entries(map).reduce((mapExpr, [key, value]) => {
mapExpr.set(key, normalizeVariable(value));
return mapExpr;
}, new MapExpr_1.MapExpr());
}
function normalizeList(list) {
const expressions = list.map((v) => normalizeExpr(v));
return new ListExpr_1.ListExpr(expressions);
}