From b399bb09be3734129d05166b0df159ef03ba5ff4 Mon Sep 17 00:00:00 2001 From: angrykoala Date: Thu, 17 Jul 2025 17:19:07 +0100 Subject: [PATCH] Remove method children from concat --- .changeset/floppy-llamas-teach.md | 10 +++ src/clauses/utils/concat.ts | 5 -- tests/deprecated/concat.test.ts | 127 ------------------------------ 3 files changed, 10 insertions(+), 132 deletions(-) create mode 100644 .changeset/floppy-llamas-teach.md delete mode 100644 tests/deprecated/concat.test.ts diff --git a/.changeset/floppy-llamas-teach.md b/.changeset/floppy-llamas-teach.md new file mode 100644 index 00000000..6c8b0d05 --- /dev/null +++ b/.changeset/floppy-llamas-teach.md @@ -0,0 +1,10 @@ +--- +"@neo4j/cypher-builder": major +--- + +Remove method `.children` from concat clauses: + +```js +const query = Cypher.utils.concat(clause1, clause2); +query.children; // No longer supported +``` diff --git a/src/clauses/utils/concat.ts b/src/clauses/utils/concat.ts index fe2b471e..9a553491 100644 --- a/src/clauses/utils/concat.ts +++ b/src/clauses/utils/concat.ts @@ -52,11 +52,6 @@ export class CompositeClause extends Clause { return this._children.length === 0; } - /** @deprecated Children from a composite clause should not be accessed as this will lead to unexpected behaviour */ - public get children(): Array { - return this._children; - } - /** @internal */ public getCypher(env: CypherEnvironment, importWithCypher?: string): string { // NOTE: importWithCypher used to pass down import WITH to UNION clauses diff --git a/tests/deprecated/concat.test.ts b/tests/deprecated/concat.test.ts deleted file mode 100644 index ce35cdfe..00000000 --- a/tests/deprecated/concat.test.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -import Cypher from "../../src"; - -describe("CypherBuilder utils.concat", () => { - test("concatenates Match and Return", () => { - const node = new Cypher.Node(); - - const clause = new Cypher.Match(new Cypher.Pattern(node, { labels: ["Movie"] })).where( - Cypher.eq(new Cypher.Param("aa"), new Cypher.Param("bb")) - ); - const returnClause = new Cypher.Return([node.property("title"), "movie"]); - - const query = Cypher.utils.concat(clause, returnClause); - - const queryResult = query.build(); - expect(queryResult.cypher).toMatchInlineSnapshot(` - "MATCH (this0:Movie) - WHERE $param0 = $param1 - RETURN this0.title AS movie" - `); - - expect(queryResult.params).toMatchInlineSnapshot(` - { - "param0": "aa", - "param1": "bb", - } - `); - expect(query.children).toHaveLength(2); - }); - - test("Empty composite clause", () => { - const compositeClause = Cypher.utils.concat(undefined); - expect(compositeClause.empty).toBeTrue(); - expect(compositeClause.children).toHaveLength(0); - - const queryResult = compositeClause.build(); - - expect(queryResult.cypher).toMatchInlineSnapshot(`""`); - }); - - test("Empty nested composite clause", () => { - const compositeClause = Cypher.utils.concat(Cypher.utils.concat()); - expect(compositeClause.empty).toBeTrue(); - expect(compositeClause.children).toHaveLength(0); - - const queryResult = compositeClause.build(); - - expect(queryResult.cypher).toMatchInlineSnapshot(`""`); - }); - - test("Nested composite clause with multiple elements", () => { - const compositeClause = Cypher.utils.concat( - Cypher.utils.concat( - new Cypher.Match(new Cypher.Pattern(new Cypher.Node())), - new Cypher.Match(new Cypher.Pattern(new Cypher.Node())) - ) - ); - expect(compositeClause.empty).toBeFalse(); - expect(compositeClause.children).toHaveLength(1); - - const queryResult = compositeClause.build(); - - expect(queryResult.cypher).toMatchInlineSnapshot(` - "MATCH (this0) - MATCH (this1)" - `); - }); - - test("Non-Empty composite clause", () => { - const node = new Cypher.Node(); - - const clause = new Cypher.Match(new Cypher.Pattern(node, { labels: ["Movie"] })).where( - Cypher.eq(new Cypher.Param("aa"), new Cypher.Param("bb")) - ); - const compositeClause = Cypher.utils.concat(clause); - expect(compositeClause.empty).toBeFalse(); - expect(compositeClause.children).toHaveLength(1); - }); - - test("Nested concatenation flattens the tree if composite clause has 1 element", () => { - const node = new Cypher.Node(); - - const clause = new Cypher.Match(new Cypher.Pattern(node, { labels: ["Movie"] })).where( - Cypher.eq(new Cypher.Param("aa"), new Cypher.Param("bb")) - ); - const returnClause = new Cypher.Return([node.property("title"), "movie"]); - - const nestedConcat = Cypher.utils.concat(clause); - - const topLevelConcat = Cypher.utils.concat(nestedConcat, returnClause); - - const queryResult = topLevelConcat.build(); - expect(queryResult.cypher).toMatchInlineSnapshot(` - "MATCH (this0:Movie) - WHERE $param0 = $param1 - RETURN this0.title AS movie" - `); - - expect(queryResult.params).toMatchInlineSnapshot(` - { - "param0": "aa", - "param1": "bb", - } - `); - - // Three children as nested concat was flattened - expect(topLevelConcat.children).toHaveLength(2); - }); -});