flowquery 1.0.17 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowquery",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "A declarative query language for data processing pipelines.",
5
5
  "main": "dist/index.node.js",
6
6
  "types": "dist/index.node.d.ts",
@@ -10,11 +10,22 @@ class PatternExpression extends Pattern {
10
10
  throw new Error("Cannot set identifier on PatternExpression");
11
11
  }
12
12
  public addElement(element: Relationship | Node): void {
13
- if (this._chain.length == 0 && !(element instanceof NodeReference)) {
14
- throw new Error("PatternExpression must start with a NodeReference");
15
- }
16
13
  super.addElement(element);
17
14
  }
15
+ public verify(): void {
16
+ if (this._chain.length === 0) {
17
+ throw new Error("PatternExpression must contain at least one element");
18
+ }
19
+ const referenced = this._chain.some((element) => {
20
+ if (element instanceof NodeReference) {
21
+ return true;
22
+ }
23
+ return false;
24
+ });
25
+ if (!referenced) {
26
+ throw new Error("PatternExpression must contain at least one NodeReference");
27
+ }
28
+ }
18
29
  public async evaluate(): Promise<void> {
19
30
  this._evaluation = false;
20
31
  this.endNode.todoNext = async () => {
@@ -516,9 +516,6 @@ class Parser extends BaseParser {
516
516
  if (node === null) {
517
517
  throw new Error("Expected node definition");
518
518
  }
519
- if (!(node instanceof NodeReference)) {
520
- throw new Error("PatternExpression must start with a NodeReference");
521
- }
522
519
  pattern.addElement(node);
523
520
  let relationship: Relationship | null = null;
524
521
  while (true) {
@@ -536,6 +533,7 @@ class Parser extends BaseParser {
536
533
  }
537
534
  pattern.addElement(node);
538
535
  }
536
+ pattern.verify();
539
537
  return pattern;
540
538
  }
541
539
 
@@ -709,7 +707,12 @@ class Parser extends BaseParser {
709
707
  const lookup = this.parseLookup(func);
710
708
  expression.addNode(lookup);
711
709
  }
712
- } else if (this.token.isLeftParenthesis() && this.peek()?.isIdentifier()) {
710
+ } else if (
711
+ this.token.isLeftParenthesis() &&
712
+ (this.peek()?.isIdentifier() ||
713
+ this.peek()?.isColon() ||
714
+ this.peek()?.isRightParenthesis())
715
+ ) {
713
716
  // Possible graph pattern expression
714
717
  const pattern = this.parsePatternExpression();
715
718
  if (pattern !== null) {
@@ -752,3 +752,11 @@ test("Parse statement with graph pattern in where clause", () => {
752
752
  expect(relationship.type).toBe("KNOWS");
753
753
  expect(target.label).toBe("Person");
754
754
  });
755
+
756
+ test("Test check pattern expression without NodeReference", () => {
757
+ const parser = new Parser();
758
+ // Should throw an error because pattern does not start with NodeReference
759
+ expect(() => {
760
+ parser.parse("MATCH (a:Person) WHERE (:Person)-[:KNOWS]->(:Person) RETURN a");
761
+ }).toThrow("PatternExpression must contain at least one NodeReference");
762
+ });