UNPKG

@neo4j/cypher-builder

Version:

A programmatic API for building Cypher queries for Neo4j

55 lines (54 loc) 1.98 kB
"use strict"; /* * 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.PatternElement = void 0; const Environment_1 = require("../Environment"); const pad_block_1 = require("../utils/pad-block"); const pad_left_1 = require("../utils/pad-left"); const stringify_object_1 = require("../utils/stringify-object"); const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom"); class PatternElement { constructor(element) { this.variable = element; } serializeParameters(parameters, env) { if (Object.keys(parameters).length === 0) return ""; const paramValues = Object.entries(parameters).reduce((acc, [key, param]) => { acc[key] = param.getCypher(env); return acc; }, {}); return (0, pad_left_1.padLeft)((0, stringify_object_1.stringifyObject)(paramValues)); } /** Custom string for browsers and templating * @hidden */ toString() { const cypher = (0, pad_block_1.padBlock)(this.getCypher(new Environment_1.CypherEnvironment())); return `<${this.constructor.name}> """\n${cypher}\n"""`; } /** Custom log for console.log in Node * @hidden */ [customInspectSymbol]() { return this.toString(); } } exports.PatternElement = PatternElement;