flowquery 1.0.16 → 1.0.17
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/.github/workflows/python-publish.yml +97 -0
- package/dist/compute/runner.d.ts +3 -2
- package/dist/compute/runner.d.ts.map +1 -1
- package/dist/compute/runner.js +7 -7
- package/dist/compute/runner.js.map +1 -1
- package/dist/flowquery.min.js +1 -1
- package/dist/graph/data.d.ts +31 -0
- package/dist/graph/data.d.ts.map +1 -0
- package/dist/graph/data.js +110 -0
- package/dist/graph/data.js.map +1 -0
- package/dist/graph/database.d.ts +20 -0
- package/dist/graph/database.d.ts.map +1 -0
- package/dist/graph/database.js +77 -0
- package/dist/graph/database.js.map +1 -0
- package/dist/graph/hops.d.ts +11 -0
- package/dist/graph/hops.d.ts.map +1 -0
- package/dist/graph/hops.js +25 -0
- package/dist/graph/hops.js.map +1 -0
- package/dist/graph/node.d.ts +35 -0
- package/dist/graph/node.d.ts.map +1 -0
- package/dist/graph/node.js +113 -0
- package/dist/graph/node.js.map +1 -0
- package/dist/graph/node_data.d.ts +11 -0
- package/dist/graph/node_data.d.ts.map +1 -0
- package/dist/graph/node_data.js +20 -0
- package/dist/graph/node_data.js.map +1 -0
- package/dist/graph/node_reference.d.ts +10 -0
- package/dist/graph/node_reference.d.ts.map +1 -0
- package/dist/graph/node_reference.js +52 -0
- package/dist/graph/node_reference.js.map +1 -0
- package/dist/graph/pattern.d.ts +18 -0
- package/dist/graph/pattern.d.ts.map +1 -0
- package/dist/graph/pattern.js +114 -0
- package/dist/graph/pattern.js.map +1 -0
- package/dist/graph/pattern_expression.d.ts +14 -0
- package/dist/graph/pattern_expression.d.ts.map +1 -0
- package/dist/graph/pattern_expression.js +58 -0
- package/dist/graph/pattern_expression.js.map +1 -0
- package/dist/graph/patterns.d.ts +11 -0
- package/dist/graph/patterns.d.ts.map +1 -0
- package/dist/graph/patterns.js +49 -0
- package/dist/graph/patterns.js.map +1 -0
- package/dist/graph/physical_node.d.ts +10 -0
- package/dist/graph/physical_node.d.ts.map +1 -0
- package/dist/graph/physical_node.js +40 -0
- package/dist/graph/physical_node.js.map +1 -0
- package/dist/graph/physical_relationship.d.ts +10 -0
- package/dist/graph/physical_relationship.d.ts.map +1 -0
- package/dist/graph/physical_relationship.js +40 -0
- package/dist/graph/physical_relationship.js.map +1 -0
- package/dist/graph/relationship.d.ts +40 -0
- package/dist/graph/relationship.d.ts.map +1 -0
- package/dist/graph/relationship.js +124 -0
- package/dist/graph/relationship.js.map +1 -0
- package/dist/graph/relationship_data.d.ts +12 -0
- package/dist/graph/relationship_data.d.ts.map +1 -0
- package/dist/graph/relationship_data.js +40 -0
- package/dist/graph/relationship_data.js.map +1 -0
- package/dist/graph/relationship_match_collector.d.ts +19 -0
- package/dist/graph/relationship_match_collector.d.ts.map +1 -0
- package/dist/graph/relationship_match_collector.js +55 -0
- package/dist/graph/relationship_match_collector.js.map +1 -0
- package/dist/graph/relationship_reference.d.ts +8 -0
- package/dist/graph/relationship_reference.d.ts.map +1 -0
- package/dist/graph/relationship_reference.js +37 -0
- package/dist/graph/relationship_reference.js.map +1 -0
- package/dist/parsing/base_parser.d.ts +1 -0
- package/dist/parsing/base_parser.d.ts.map +1 -1
- package/dist/parsing/base_parser.js +4 -1
- package/dist/parsing/base_parser.js.map +1 -1
- package/dist/parsing/context.d.ts +2 -2
- package/dist/parsing/context.js +5 -5
- package/dist/parsing/expressions/boolean.d.ts +8 -0
- package/dist/parsing/expressions/boolean.d.ts.map +1 -0
- package/dist/parsing/expressions/boolean.js +26 -0
- package/dist/parsing/expressions/boolean.js.map +1 -0
- package/dist/parsing/expressions/expression.d.ts +4 -1
- package/dist/parsing/expressions/expression.d.ts.map +1 -1
- package/dist/parsing/expressions/expression.js +15 -8
- package/dist/parsing/expressions/expression.js.map +1 -1
- package/dist/parsing/expressions/operator.d.ts +1 -1
- package/dist/parsing/expressions/operator.d.ts.map +1 -1
- package/dist/parsing/expressions/operator.js.map +1 -1
- package/dist/parsing/functions/function_factory.d.ts +13 -13
- package/dist/parsing/functions/function_factory.d.ts.map +1 -1
- package/dist/parsing/functions/function_factory.js +20 -18
- package/dist/parsing/functions/function_factory.js.map +1 -1
- package/dist/parsing/operations/create_node.d.ts +14 -0
- package/dist/parsing/operations/create_node.d.ts.map +1 -0
- package/dist/parsing/operations/create_node.js +51 -0
- package/dist/parsing/operations/create_node.js.map +1 -0
- package/dist/parsing/operations/create_relationship.d.ts +14 -0
- package/dist/parsing/operations/create_relationship.d.ts.map +1 -0
- package/dist/parsing/operations/create_relationship.js +51 -0
- package/dist/parsing/operations/create_relationship.js.map +1 -0
- package/dist/parsing/operations/match.d.ts +15 -0
- package/dist/parsing/operations/match.d.ts.map +1 -0
- package/dist/parsing/operations/match.js +45 -0
- package/dist/parsing/operations/match.js.map +1 -0
- package/dist/parsing/operations/operation.d.ts +1 -0
- package/dist/parsing/operations/operation.d.ts.map +1 -1
- package/dist/parsing/operations/operation.js +6 -0
- package/dist/parsing/operations/operation.js.map +1 -1
- package/dist/parsing/operations/return.d.ts +1 -0
- package/dist/parsing/operations/return.d.ts.map +1 -1
- package/dist/parsing/operations/return.js +7 -1
- package/dist/parsing/operations/return.js.map +1 -1
- package/dist/parsing/operations/where.d.ts +1 -1
- package/dist/parsing/operations/where.d.ts.map +1 -1
- package/dist/parsing/operations/where.js +4 -0
- package/dist/parsing/operations/where.js.map +1 -1
- package/dist/parsing/parser.d.ts +10 -0
- package/dist/parsing/parser.d.ts.map +1 -1
- package/dist/parsing/parser.js +344 -5
- package/dist/parsing/parser.js.map +1 -1
- package/dist/parsing/token_to_node.d.ts.map +1 -1
- package/dist/parsing/token_to_node.js +7 -0
- package/dist/parsing/token_to_node.js.map +1 -1
- package/dist/tokenization/keyword.d.ts +1 -0
- package/dist/tokenization/keyword.d.ts.map +1 -1
- package/dist/tokenization/keyword.js +1 -0
- package/dist/tokenization/keyword.js.map +1 -1
- package/dist/tokenization/token.d.ts +4 -0
- package/dist/tokenization/token.d.ts.map +1 -1
- package/dist/tokenization/token.js +14 -1
- package/dist/tokenization/token.js.map +1 -1
- package/dist/tokenization/token_type.d.ts +1 -0
- package/dist/tokenization/token_type.d.ts.map +1 -1
- package/dist/tokenization/token_type.js +1 -0
- package/dist/tokenization/token_type.js.map +1 -1
- package/dist/tokenization/tokenizer.d.ts +2 -1
- package/dist/tokenization/tokenizer.d.ts.map +1 -1
- package/dist/tokenization/tokenizer.js +25 -12
- package/dist/tokenization/tokenizer.js.map +1 -1
- package/docs/flowquery.min.js +1 -1
- package/flowquery-py/README.md +166 -0
- package/flowquery-py/pyproject.toml +75 -0
- package/flowquery-py/setup_env.ps1 +92 -0
- package/flowquery-py/setup_env.sh +87 -0
- package/flowquery-py/src/__init__.py +34 -0
- package/flowquery-py/src/__main__.py +10 -0
- package/flowquery-py/src/compute/__init__.py +5 -0
- package/flowquery-py/src/compute/runner.py +60 -0
- package/flowquery-py/src/extensibility.py +52 -0
- package/flowquery-py/src/graph/__init__.py +31 -0
- package/flowquery-py/src/graph/data.py +118 -0
- package/flowquery-py/src/graph/database.py +82 -0
- package/flowquery-py/src/graph/hops.py +43 -0
- package/flowquery-py/src/graph/node.py +112 -0
- package/flowquery-py/src/graph/node_data.py +26 -0
- package/flowquery-py/src/graph/node_reference.py +49 -0
- package/flowquery-py/src/graph/pattern.py +125 -0
- package/flowquery-py/src/graph/pattern_expression.py +62 -0
- package/flowquery-py/src/graph/patterns.py +42 -0
- package/flowquery-py/src/graph/physical_node.py +40 -0
- package/flowquery-py/src/graph/physical_relationship.py +36 -0
- package/flowquery-py/src/graph/relationship.py +135 -0
- package/flowquery-py/src/graph/relationship_data.py +33 -0
- package/flowquery-py/src/graph/relationship_match_collector.py +77 -0
- package/flowquery-py/src/graph/relationship_reference.py +21 -0
- package/flowquery-py/src/io/__init__.py +5 -0
- package/flowquery-py/src/io/command_line.py +67 -0
- package/flowquery-py/src/parsing/__init__.py +17 -0
- package/flowquery-py/src/parsing/alias.py +20 -0
- package/flowquery-py/src/parsing/alias_option.py +11 -0
- package/flowquery-py/src/parsing/ast_node.py +146 -0
- package/flowquery-py/src/parsing/base_parser.py +84 -0
- package/flowquery-py/src/parsing/components/__init__.py +19 -0
- package/flowquery-py/src/parsing/components/csv.py +8 -0
- package/flowquery-py/src/parsing/components/from_.py +10 -0
- package/flowquery-py/src/parsing/components/headers.py +12 -0
- package/flowquery-py/src/parsing/components/json.py +8 -0
- package/flowquery-py/src/parsing/components/null.py +10 -0
- package/flowquery-py/src/parsing/components/post.py +8 -0
- package/flowquery-py/src/parsing/components/text.py +8 -0
- package/flowquery-py/src/parsing/context.py +50 -0
- package/flowquery-py/src/parsing/data_structures/__init__.py +15 -0
- package/flowquery-py/src/parsing/data_structures/associative_array.py +41 -0
- package/flowquery-py/src/parsing/data_structures/json_array.py +30 -0
- package/flowquery-py/src/parsing/data_structures/key_value_pair.py +38 -0
- package/flowquery-py/src/parsing/data_structures/lookup.py +49 -0
- package/flowquery-py/src/parsing/data_structures/range_lookup.py +42 -0
- package/flowquery-py/src/parsing/expressions/__init__.py +57 -0
- package/flowquery-py/src/parsing/expressions/boolean.py +20 -0
- package/flowquery-py/src/parsing/expressions/expression.py +138 -0
- package/flowquery-py/src/parsing/expressions/expression_map.py +26 -0
- package/flowquery-py/src/parsing/expressions/f_string.py +27 -0
- package/flowquery-py/src/parsing/expressions/identifier.py +20 -0
- package/flowquery-py/src/parsing/expressions/number.py +32 -0
- package/flowquery-py/src/parsing/expressions/operator.py +169 -0
- package/flowquery-py/src/parsing/expressions/reference.py +47 -0
- package/flowquery-py/src/parsing/expressions/string.py +27 -0
- package/flowquery-py/src/parsing/functions/__init__.py +75 -0
- package/flowquery-py/src/parsing/functions/aggregate_function.py +60 -0
- package/flowquery-py/src/parsing/functions/async_function.py +62 -0
- package/flowquery-py/src/parsing/functions/avg.py +55 -0
- package/flowquery-py/src/parsing/functions/collect.py +75 -0
- package/flowquery-py/src/parsing/functions/function.py +68 -0
- package/flowquery-py/src/parsing/functions/function_factory.py +173 -0
- package/flowquery-py/src/parsing/functions/function_metadata.py +149 -0
- package/flowquery-py/src/parsing/functions/functions.py +59 -0
- package/flowquery-py/src/parsing/functions/join.py +47 -0
- package/flowquery-py/src/parsing/functions/keys.py +34 -0
- package/flowquery-py/src/parsing/functions/predicate_function.py +46 -0
- package/flowquery-py/src/parsing/functions/predicate_sum.py +47 -0
- package/flowquery-py/src/parsing/functions/rand.py +28 -0
- package/flowquery-py/src/parsing/functions/range_.py +34 -0
- package/flowquery-py/src/parsing/functions/reducer_element.py +15 -0
- package/flowquery-py/src/parsing/functions/replace.py +37 -0
- package/flowquery-py/src/parsing/functions/round_.py +32 -0
- package/flowquery-py/src/parsing/functions/size.py +32 -0
- package/flowquery-py/src/parsing/functions/split.py +47 -0
- package/flowquery-py/src/parsing/functions/stringify.py +47 -0
- package/flowquery-py/src/parsing/functions/sum.py +51 -0
- package/flowquery-py/src/parsing/functions/to_json.py +33 -0
- package/flowquery-py/src/parsing/functions/type_.py +47 -0
- package/flowquery-py/src/parsing/functions/value_holder.py +24 -0
- package/flowquery-py/src/parsing/logic/__init__.py +15 -0
- package/flowquery-py/src/parsing/logic/case.py +29 -0
- package/flowquery-py/src/parsing/logic/else_.py +12 -0
- package/flowquery-py/src/parsing/logic/end.py +8 -0
- package/flowquery-py/src/parsing/logic/then.py +12 -0
- package/flowquery-py/src/parsing/logic/when.py +10 -0
- package/flowquery-py/src/parsing/operations/__init__.py +35 -0
- package/flowquery-py/src/parsing/operations/aggregated_return.py +24 -0
- package/flowquery-py/src/parsing/operations/aggregated_with.py +22 -0
- package/flowquery-py/src/parsing/operations/call.py +74 -0
- package/flowquery-py/src/parsing/operations/create_node.py +34 -0
- package/flowquery-py/src/parsing/operations/create_relationship.py +34 -0
- package/flowquery-py/src/parsing/operations/group_by.py +130 -0
- package/flowquery-py/src/parsing/operations/limit.py +22 -0
- package/flowquery-py/src/parsing/operations/load.py +140 -0
- package/flowquery-py/src/parsing/operations/match.py +29 -0
- package/flowquery-py/src/parsing/operations/operation.py +69 -0
- package/flowquery-py/src/parsing/operations/projection.py +21 -0
- package/flowquery-py/src/parsing/operations/return_op.py +50 -0
- package/flowquery-py/src/parsing/operations/unwind.py +37 -0
- package/flowquery-py/src/parsing/operations/where.py +41 -0
- package/flowquery-py/src/parsing/operations/with_op.py +18 -0
- package/flowquery-py/src/parsing/parser.py +1011 -0
- package/flowquery-py/src/parsing/token_to_node.py +109 -0
- package/flowquery-py/src/tokenization/__init__.py +23 -0
- package/flowquery-py/src/tokenization/keyword.py +48 -0
- package/flowquery-py/src/tokenization/operator.py +29 -0
- package/flowquery-py/src/tokenization/string_walker.py +158 -0
- package/flowquery-py/src/tokenization/symbol.py +19 -0
- package/flowquery-py/src/tokenization/token.py +659 -0
- package/flowquery-py/src/tokenization/token_mapper.py +52 -0
- package/flowquery-py/src/tokenization/token_type.py +21 -0
- package/flowquery-py/src/tokenization/tokenizer.py +214 -0
- package/flowquery-py/src/tokenization/trie.py +124 -0
- package/flowquery-py/src/utils/__init__.py +6 -0
- package/flowquery-py/src/utils/object_utils.py +20 -0
- package/flowquery-py/src/utils/string_utils.py +113 -0
- package/flowquery-py/tests/__init__.py +1 -0
- package/flowquery-py/tests/compute/__init__.py +1 -0
- package/flowquery-py/tests/compute/test_runner.py +1335 -0
- package/flowquery-py/tests/graph/__init__.py +1 -0
- package/flowquery-py/tests/graph/test_create.py +56 -0
- package/flowquery-py/tests/graph/test_data.py +73 -0
- package/flowquery-py/tests/graph/test_match.py +40 -0
- package/flowquery-py/tests/parsing/__init__.py +1 -0
- package/flowquery-py/tests/parsing/test_context.py +34 -0
- package/flowquery-py/tests/parsing/test_expression.py +49 -0
- package/flowquery-py/tests/parsing/test_parser.py +674 -0
- package/flowquery-py/tests/test_extensibility.py +611 -0
- package/flowquery-py/tests/tokenization/__init__.py +1 -0
- package/flowquery-py/tests/tokenization/test_token_mapper.py +60 -0
- package/flowquery-py/tests/tokenization/test_tokenizer.py +164 -0
- package/flowquery-py/tests/tokenization/test_trie.py +30 -0
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/misc/apps/RAG/package.json +1 -1
- package/misc/apps/RAG/src/components/AdaptiveCardRenderer.tsx +76 -8
- package/misc/apps/RAG/src/components/index.ts +19 -10
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +70 -140
- package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +12 -0
- package/package.json +1 -1
- package/src/compute/runner.ts +24 -19
- package/src/graph/data.ts +112 -0
- package/src/graph/database.ts +63 -0
- package/src/graph/hops.ts +22 -0
- package/src/graph/node.ts +99 -0
- package/src/graph/node_data.ts +18 -0
- package/src/graph/node_reference.ts +33 -0
- package/src/graph/pattern.ts +101 -0
- package/src/graph/pattern_expression.ts +37 -0
- package/src/graph/patterns.ts +36 -0
- package/src/graph/physical_node.ts +23 -0
- package/src/graph/physical_relationship.ts +23 -0
- package/src/graph/relationship.ts +116 -0
- package/src/graph/relationship_data.ts +27 -0
- package/src/graph/relationship_match_collector.ts +58 -0
- package/src/graph/relationship_reference.ts +24 -0
- package/src/parsing/base_parser.ts +20 -14
- package/src/parsing/context.ts +14 -14
- package/src/parsing/expressions/boolean.ts +21 -0
- package/src/parsing/expressions/expression.ts +34 -26
- package/src/parsing/expressions/operator.ts +19 -1
- package/src/parsing/functions/function_factory.ts +45 -45
- package/src/parsing/operations/create_node.ts +39 -0
- package/src/parsing/operations/create_relationship.ts +38 -0
- package/src/parsing/operations/match.ts +31 -0
- package/src/parsing/operations/operation.ts +3 -0
- package/src/parsing/operations/return.ts +11 -7
- package/src/parsing/operations/where.ts +10 -6
- package/src/parsing/parser.ts +346 -8
- package/src/parsing/token_to_node.ts +6 -0
- package/src/tokenization/keyword.ts +41 -40
- package/src/tokenization/token.ts +21 -1
- package/src/tokenization/token_type.ts +2 -1
- package/src/tokenization/tokenizer.ts +52 -31
- package/tests/compute/runner.test.ts +654 -0
- package/tests/extensibility.test.ts +97 -93
- package/tests/graph/create.test.ts +36 -0
- package/tests/graph/data.test.ts +58 -0
- package/tests/graph/match.test.ts +29 -0
- package/tests/parsing/parser.test.ts +273 -2
- package/tests/tokenization/tokenizer.test.ts +90 -0
|
@@ -3,7 +3,7 @@ import Tokenizer from "../tokenization/tokenizer";
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Base class for parsers providing common token manipulation functionality.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* This class handles tokenization and provides utility methods for navigating
|
|
8
8
|
* through tokens, peeking ahead, and checking token sequences.
|
|
9
9
|
*/
|
|
@@ -11,9 +11,15 @@ class BaseParser {
|
|
|
11
11
|
private tokens: Token[] = <Token[]>[];
|
|
12
12
|
private tokenIndex: number = 0;
|
|
13
13
|
|
|
14
|
+
constructor(tokens: Token[] | null = null) {
|
|
15
|
+
if (tokens !== null) {
|
|
16
|
+
this.tokens = tokens;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
/**
|
|
15
21
|
* Tokenizes a statement and initializes the token array.
|
|
16
|
-
*
|
|
22
|
+
*
|
|
17
23
|
* @param statement - The input statement to tokenize
|
|
18
24
|
*/
|
|
19
25
|
protected tokenize(statement: string): void {
|
|
@@ -30,11 +36,11 @@ class BaseParser {
|
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
38
|
* Peeks at the next token without advancing the current position.
|
|
33
|
-
*
|
|
39
|
+
*
|
|
34
40
|
* @returns The next token, or null if at the end of the token stream
|
|
35
41
|
*/
|
|
36
42
|
protected peek(): Token | null {
|
|
37
|
-
if(this.tokenIndex + 1 >= this.tokens.length) {
|
|
43
|
+
if (this.tokenIndex + 1 >= this.tokens.length) {
|
|
38
44
|
return null;
|
|
39
45
|
}
|
|
40
46
|
return this.tokens[this.tokenIndex + 1];
|
|
@@ -42,22 +48,22 @@ class BaseParser {
|
|
|
42
48
|
|
|
43
49
|
/**
|
|
44
50
|
* Checks if a sequence of tokens appears ahead in the token stream.
|
|
45
|
-
*
|
|
51
|
+
*
|
|
46
52
|
* @param tokens - The sequence of tokens to look for
|
|
47
53
|
* @param skipWhitespaceAndComments - Whether to skip whitespace and comments when matching
|
|
48
54
|
* @returns True if the token sequence is found ahead, false otherwise
|
|
49
55
|
*/
|
|
50
56
|
protected ahead(tokens: Token[], skipWhitespaceAndComments: boolean = true): boolean {
|
|
51
57
|
let j = 0;
|
|
52
|
-
for(let i=this.tokenIndex; i<this.tokens.length; i++) {
|
|
53
|
-
if(skipWhitespaceAndComments && this.tokens[i].isWhitespaceOrComment()) {
|
|
58
|
+
for (let i = this.tokenIndex; i < this.tokens.length; i++) {
|
|
59
|
+
if (skipWhitespaceAndComments && this.tokens[i].isWhitespaceOrComment()) {
|
|
54
60
|
continue;
|
|
55
61
|
}
|
|
56
|
-
if(!this.tokens[i].equals(tokens[j])) {
|
|
62
|
+
if (!this.tokens[i].equals(tokens[j])) {
|
|
57
63
|
return false;
|
|
58
64
|
}
|
|
59
65
|
j++;
|
|
60
|
-
if(j === tokens.length) {
|
|
66
|
+
if (j === tokens.length) {
|
|
61
67
|
break;
|
|
62
68
|
}
|
|
63
69
|
}
|
|
@@ -66,11 +72,11 @@ class BaseParser {
|
|
|
66
72
|
|
|
67
73
|
/**
|
|
68
74
|
* Gets the current token.
|
|
69
|
-
*
|
|
75
|
+
*
|
|
70
76
|
* @returns The current token, or EOF if at the end
|
|
71
77
|
*/
|
|
72
78
|
protected get token(): Token {
|
|
73
|
-
if(this.tokenIndex >= this.tokens.length) {
|
|
79
|
+
if (this.tokenIndex >= this.tokens.length) {
|
|
74
80
|
return Token.EOF;
|
|
75
81
|
}
|
|
76
82
|
return this.tokens[this.tokenIndex];
|
|
@@ -78,15 +84,15 @@ class BaseParser {
|
|
|
78
84
|
|
|
79
85
|
/**
|
|
80
86
|
* Gets the previous token.
|
|
81
|
-
*
|
|
87
|
+
*
|
|
82
88
|
* @returns The previous token, or EOF if at the beginning
|
|
83
89
|
*/
|
|
84
90
|
protected get previousToken(): Token {
|
|
85
|
-
if(this.tokenIndex - 1 < 0) {
|
|
91
|
+
if (this.tokenIndex - 1 < 0) {
|
|
86
92
|
return Token.EOF;
|
|
87
93
|
}
|
|
88
94
|
return this.tokens[this.tokenIndex - 1];
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
export default BaseParser;
|
|
98
|
+
export default BaseParser;
|
package/src/parsing/context.ts
CHANGED
|
@@ -2,10 +2,10 @@ import ASTNode from "./ast_node";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Maintains a stack of AST nodes to track parsing context.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Used during parsing to maintain the current context and check for specific node types
|
|
7
7
|
* in the parsing hierarchy, which helps with context-sensitive parsing decisions.
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
11
|
* const context = new Context();
|
|
@@ -14,35 +14,35 @@ import ASTNode from "./ast_node";
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
class Context {
|
|
17
|
-
private
|
|
18
|
-
|
|
17
|
+
private nodes: ASTNode[] = [];
|
|
18
|
+
|
|
19
19
|
/**
|
|
20
20
|
* Pushes a node onto the context stack.
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
22
|
* @param node - The AST node to push
|
|
23
23
|
*/
|
|
24
24
|
public push(node: ASTNode): void {
|
|
25
|
-
this.
|
|
25
|
+
this.nodes.push(node);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
/**
|
|
29
29
|
* Pops the top node from the context stack.
|
|
30
|
-
*
|
|
30
|
+
*
|
|
31
31
|
* @returns The popped node, or undefined if the stack is empty
|
|
32
32
|
*/
|
|
33
33
|
public pop(): ASTNode | undefined {
|
|
34
|
-
return this.
|
|
34
|
+
return this.nodes.pop();
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
/**
|
|
38
|
-
* Checks if the stack contains a node of the specified type.
|
|
39
|
-
*
|
|
38
|
+
* Checks if the nodes stack contains a node of the specified type.
|
|
39
|
+
*
|
|
40
40
|
* @param type - The constructor of the node type to search for
|
|
41
41
|
* @returns True if a node of the specified type is found in the stack, false otherwise
|
|
42
42
|
*/
|
|
43
43
|
public containsType(type: new (...args: any[]) => ASTNode): boolean {
|
|
44
|
-
return this.
|
|
44
|
+
return this.nodes.some((v) => v instanceof type);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export default Context;
|
|
48
|
+
export default Context;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ASTNode from "../ast_node";
|
|
2
|
+
|
|
3
|
+
class Boolean extends ASTNode {
|
|
4
|
+
private _value: boolean;
|
|
5
|
+
constructor(value: string) {
|
|
6
|
+
super();
|
|
7
|
+
const _value = value.toUpperCase();
|
|
8
|
+
if (_value === "TRUE") {
|
|
9
|
+
this._value = true;
|
|
10
|
+
} else if (_value === "FALSE") {
|
|
11
|
+
this._value = false;
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error(`Invalid boolean value: ${value}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
public value(): boolean {
|
|
17
|
+
return this._value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default Boolean;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import PatternExpression from "../../graph/pattern_expression";
|
|
1
2
|
import ASTNode from "../ast_node";
|
|
2
3
|
import AggregateFunction from "../functions/aggregate_function";
|
|
3
4
|
import Reference from "./reference";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Represents an expression in the FlowQuery AST.
|
|
7
|
-
*
|
|
8
|
+
*
|
|
8
9
|
* Expressions are built using the Shunting Yard algorithm to handle operator
|
|
9
10
|
* precedence and associativity. They can contain operands (numbers, strings, identifiers)
|
|
10
11
|
* and operators (arithmetic, logical, comparison).
|
|
11
|
-
*
|
|
12
|
+
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```typescript
|
|
14
15
|
* const expr = new Expression();
|
|
@@ -24,23 +25,24 @@ class Expression extends ASTNode {
|
|
|
24
25
|
private _alias: string | null = null;
|
|
25
26
|
private _overridden: any | null = null;
|
|
26
27
|
private _reducers: AggregateFunction[] | null = null;
|
|
28
|
+
private _patterns: PatternExpression[] | null = null;
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* Adds a node (operand or operator) to the expression.
|
|
30
|
-
*
|
|
32
|
+
*
|
|
31
33
|
* Uses the Shunting Yard algorithm to maintain correct operator precedence.
|
|
32
|
-
*
|
|
34
|
+
*
|
|
33
35
|
* @param node - The AST node to add (operand or operator)
|
|
34
36
|
*/
|
|
35
37
|
public addNode(node: ASTNode): void {
|
|
36
38
|
/* Implements the Shunting Yard algorithm */
|
|
37
|
-
if(node.isOperand()) {
|
|
39
|
+
if (node.isOperand()) {
|
|
38
40
|
this.output.push(node);
|
|
39
|
-
} else if(node.isOperator()) {
|
|
41
|
+
} else if (node.isOperator()) {
|
|
40
42
|
const operator1: ASTNode = node;
|
|
41
|
-
while(this.operators.length > 0) {
|
|
43
|
+
while (this.operators.length > 0) {
|
|
42
44
|
let operator2 = this.operators[this.operators.length - 1];
|
|
43
|
-
if(
|
|
45
|
+
if (
|
|
44
46
|
operator2.precedence > operator1.precedence ||
|
|
45
47
|
(operator2.precedence === operator1.precedence && operator1.leftAssociative)
|
|
46
48
|
) {
|
|
@@ -56,25 +58,25 @@ class Expression extends ASTNode {
|
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* Finalizes the expression by converting it to a tree structure.
|
|
59
|
-
*
|
|
61
|
+
*
|
|
60
62
|
* Should be called after all nodes have been added.
|
|
61
63
|
*/
|
|
62
64
|
public finish(): void {
|
|
63
65
|
let last: ASTNode | undefined;
|
|
64
|
-
while(last = this.operators.pop()) {
|
|
66
|
+
while ((last = this.operators.pop())) {
|
|
65
67
|
this.output.push(last);
|
|
66
|
-
}
|
|
68
|
+
}
|
|
67
69
|
this.addChild(this.toTree());
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
private toTree(): ASTNode {
|
|
71
73
|
const node = this.output.pop() || new ASTNode();
|
|
72
|
-
if(node.isOperator()) {
|
|
74
|
+
if (node.isOperator()) {
|
|
73
75
|
const rhs = this.toTree();
|
|
74
76
|
const lhs = this.toTree();
|
|
75
77
|
node.addChild(lhs);
|
|
76
78
|
node.addChild(rhs);
|
|
77
|
-
}
|
|
79
|
+
}
|
|
78
80
|
return node;
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -83,11 +85,11 @@ class Expression extends ASTNode {
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
public value(): any {
|
|
86
|
-
if(this._overridden !== null) {
|
|
88
|
+
if (this._overridden !== null) {
|
|
87
89
|
return this._overridden;
|
|
88
90
|
}
|
|
89
|
-
if(this.childCount() !== 1) {
|
|
90
|
-
throw new Error(
|
|
91
|
+
if (this.childCount() !== 1) {
|
|
92
|
+
throw new Error("Expected one child");
|
|
91
93
|
}
|
|
92
94
|
return this.children[0].value();
|
|
93
95
|
}
|
|
@@ -101,31 +103,37 @@ class Expression extends ASTNode {
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
public get alias(): string | null {
|
|
104
|
-
if(this.firstChild() instanceof Reference && this._alias === null) {
|
|
106
|
+
if (this.firstChild() instanceof Reference && this._alias === null) {
|
|
105
107
|
return (<Reference>this.firstChild()).identifier;
|
|
106
108
|
}
|
|
107
109
|
return this._alias;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
public toString(): string {
|
|
111
|
-
if(this._alias !== null) {
|
|
113
|
+
if (this._alias !== null) {
|
|
112
114
|
return `Expression (${this._alias})`;
|
|
113
115
|
} else {
|
|
114
|
-
return
|
|
116
|
+
return "Expression";
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
public reducers(): AggregateFunction[] {
|
|
118
|
-
if(this._reducers === null) {
|
|
119
|
-
this._reducers = [...this.
|
|
120
|
+
if (this._reducers === null) {
|
|
121
|
+
this._reducers = [...this._extract(this, AggregateFunction)];
|
|
120
122
|
}
|
|
121
123
|
return this._reducers;
|
|
122
124
|
}
|
|
123
|
-
|
|
124
|
-
if(
|
|
125
|
+
public patterns(): PatternExpression[] {
|
|
126
|
+
if (this._patterns === null) {
|
|
127
|
+
this._patterns = [...this._extract(this, PatternExpression)];
|
|
128
|
+
}
|
|
129
|
+
return this._patterns;
|
|
130
|
+
}
|
|
131
|
+
private *_extract(node: ASTNode = this, of_type: any): Generator<any> {
|
|
132
|
+
if (node instanceof of_type) {
|
|
125
133
|
yield node;
|
|
126
134
|
}
|
|
127
|
-
for(const child of node.getChildren()) {
|
|
128
|
-
yield* this.
|
|
135
|
+
for (const child of node.getChildren()) {
|
|
136
|
+
yield* this._extract(child, of_type);
|
|
129
137
|
}
|
|
130
138
|
}
|
|
131
139
|
public mappable(): boolean {
|
|
@@ -139,4 +147,4 @@ class Expression extends ASTNode {
|
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
149
|
|
|
142
|
-
export default Expression;
|
|
150
|
+
export default Expression;
|
|
@@ -176,4 +176,22 @@ class Is extends Operator {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
export {
|
|
179
|
+
export {
|
|
180
|
+
Operator,
|
|
181
|
+
Add,
|
|
182
|
+
Subtract,
|
|
183
|
+
Multiply,
|
|
184
|
+
Divide,
|
|
185
|
+
Modulo,
|
|
186
|
+
Power,
|
|
187
|
+
Equals,
|
|
188
|
+
NotEquals,
|
|
189
|
+
GreaterThan,
|
|
190
|
+
LessThan,
|
|
191
|
+
GreaterThanOrEqual,
|
|
192
|
+
LessThanOrEqual,
|
|
193
|
+
And,
|
|
194
|
+
Or,
|
|
195
|
+
Not,
|
|
196
|
+
Is,
|
|
197
|
+
};
|
|
@@ -1,42 +1,41 @@
|
|
|
1
|
+
import AsyncFunction from "./async_function";
|
|
2
|
+
import "./avg";
|
|
3
|
+
import "./collect";
|
|
1
4
|
import Function from "./function";
|
|
5
|
+
import {
|
|
6
|
+
AsyncDataProvider,
|
|
7
|
+
FunctionMetadata,
|
|
8
|
+
getFunctionMetadata,
|
|
9
|
+
getRegisteredFunctionFactory,
|
|
10
|
+
getRegisteredFunctionMetadata,
|
|
11
|
+
} from "./function_metadata";
|
|
12
|
+
import "./functions";
|
|
13
|
+
import "./join";
|
|
14
|
+
import "./keys";
|
|
2
15
|
import PredicateFunction from "./predicate_function";
|
|
3
|
-
|
|
4
|
-
import "./sum";
|
|
5
|
-
import "./collect";
|
|
6
|
-
import "./avg";
|
|
7
|
-
import "./range";
|
|
16
|
+
import "./predicate_sum";
|
|
8
17
|
import "./rand";
|
|
18
|
+
import "./range";
|
|
19
|
+
import "./replace";
|
|
9
20
|
import "./round";
|
|
21
|
+
import "./size";
|
|
10
22
|
import "./split";
|
|
11
|
-
import "./join";
|
|
12
|
-
import "./keys";
|
|
13
|
-
import "./to_json";
|
|
14
|
-
import "./replace";
|
|
15
23
|
import "./stringify";
|
|
16
|
-
|
|
17
|
-
import "./
|
|
18
|
-
import "./
|
|
24
|
+
// Import built-in functions to ensure their @FunctionDef decorators run
|
|
25
|
+
import "./sum";
|
|
26
|
+
import "./to_json";
|
|
19
27
|
import "./type";
|
|
20
|
-
import {
|
|
21
|
-
FunctionMetadata,
|
|
22
|
-
getRegisteredFunctionMetadata,
|
|
23
|
-
getFunctionMetadata,
|
|
24
|
-
getRegisteredFunctionFactory,
|
|
25
|
-
AsyncDataProvider
|
|
26
|
-
} from "./function_metadata";
|
|
27
|
-
import AsyncFunction from "./async_function";
|
|
28
|
-
import { get } from "node:http";
|
|
29
28
|
|
|
30
29
|
// Re-export AsyncDataProvider for backwards compatibility
|
|
31
30
|
export { AsyncDataProvider };
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Factory for creating function instances by name.
|
|
35
|
-
*
|
|
34
|
+
*
|
|
36
35
|
* All functions are registered via the @FunctionDef decorator.
|
|
37
36
|
* Maps function names (case-insensitive) to their corresponding implementation classes.
|
|
38
37
|
* Supports built-in functions like sum, avg, collect, range, split, join, etc.
|
|
39
|
-
*
|
|
38
|
+
*
|
|
40
39
|
* @example
|
|
41
40
|
* ```typescript
|
|
42
41
|
* const sumFunc = FunctionFactory.create("sum");
|
|
@@ -46,7 +45,7 @@ export { AsyncDataProvider };
|
|
|
46
45
|
class FunctionFactory {
|
|
47
46
|
/**
|
|
48
47
|
* Gets an async data provider by name.
|
|
49
|
-
*
|
|
48
|
+
*
|
|
50
49
|
* @param name - The function name (case-insensitive)
|
|
51
50
|
* @returns The async data provider, or undefined if not found
|
|
52
51
|
*/
|
|
@@ -56,7 +55,7 @@ class FunctionFactory {
|
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
57
|
* Checks if a function name is registered as an async data provider.
|
|
59
|
-
*
|
|
58
|
+
*
|
|
60
59
|
* @param name - The function name (case-insensitive)
|
|
61
60
|
* @returns True if the function is an async data provider
|
|
62
61
|
*/
|
|
@@ -66,7 +65,7 @@ class FunctionFactory {
|
|
|
66
65
|
|
|
67
66
|
/**
|
|
68
67
|
* Gets metadata for a specific function.
|
|
69
|
-
*
|
|
68
|
+
*
|
|
70
69
|
* @param name - The function name (case-insensitive)
|
|
71
70
|
* @returns The function metadata, or undefined if not found
|
|
72
71
|
*/
|
|
@@ -76,56 +75,58 @@ class FunctionFactory {
|
|
|
76
75
|
|
|
77
76
|
/**
|
|
78
77
|
* Lists all registered functions with their metadata.
|
|
79
|
-
*
|
|
78
|
+
*
|
|
80
79
|
* @param options - Optional filter options
|
|
81
80
|
* @returns Array of function metadata
|
|
82
81
|
*/
|
|
83
|
-
public static listFunctions(options?: {
|
|
84
|
-
category?: string;
|
|
82
|
+
public static listFunctions(options?: {
|
|
83
|
+
category?: string;
|
|
85
84
|
asyncOnly?: boolean;
|
|
86
85
|
syncOnly?: boolean;
|
|
87
86
|
}): FunctionMetadata[] {
|
|
88
87
|
const result: FunctionMetadata[] = [];
|
|
89
|
-
|
|
88
|
+
|
|
90
89
|
for (const meta of getRegisteredFunctionMetadata()) {
|
|
91
90
|
if (options?.category && meta.category !== options.category) continue;
|
|
92
|
-
if (options?.asyncOnly && meta.category !==
|
|
93
|
-
if (options?.syncOnly && meta.category ===
|
|
91
|
+
if (options?.asyncOnly && meta.category !== "async") continue;
|
|
92
|
+
if (options?.syncOnly && meta.category === "async") continue;
|
|
94
93
|
result.push(meta);
|
|
95
94
|
}
|
|
96
|
-
|
|
95
|
+
|
|
97
96
|
return result;
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
/**
|
|
101
100
|
* Lists all registered function names.
|
|
102
|
-
*
|
|
101
|
+
*
|
|
103
102
|
* @returns Array of function names
|
|
104
103
|
*/
|
|
105
104
|
public static listFunctionNames(): string[] {
|
|
106
|
-
return getRegisteredFunctionMetadata().map(m => m.name);
|
|
105
|
+
return getRegisteredFunctionMetadata().map((m) => m.name);
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
/**
|
|
110
109
|
* Gets all function metadata as a JSON-serializable object for LLM consumption.
|
|
111
|
-
*
|
|
110
|
+
*
|
|
112
111
|
* @returns Object with functions grouped by category
|
|
113
112
|
*/
|
|
114
113
|
public static toJSON(): { functions: FunctionMetadata[]; categories: string[] } {
|
|
115
114
|
const functions = FunctionFactory.listFunctions();
|
|
116
|
-
const categories = [
|
|
115
|
+
const categories = [
|
|
116
|
+
...new Set(functions.map((f) => f.category).filter(Boolean)),
|
|
117
|
+
] as string[];
|
|
117
118
|
return { functions, categories };
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
/**
|
|
121
122
|
* Creates a function instance by name.
|
|
122
|
-
*
|
|
123
|
+
*
|
|
123
124
|
* @param name - The function name (case-insensitive)
|
|
124
125
|
* @returns A Function instance of the appropriate type
|
|
125
126
|
*/
|
|
126
127
|
public static create(name: string): Function {
|
|
127
128
|
const lowerName: string = name.toLowerCase();
|
|
128
|
-
|
|
129
|
+
|
|
129
130
|
// Check decorator-registered functions (built-ins use @FunctionDef)
|
|
130
131
|
const decoratorFactory = getRegisteredFunctionFactory(lowerName);
|
|
131
132
|
if (decoratorFactory) {
|
|
@@ -138,15 +139,15 @@ class FunctionFactory {
|
|
|
138
139
|
/**
|
|
139
140
|
* Creates a predicate function instance by name.
|
|
140
141
|
* Predicate functions are used in WHERE clauses with quantifiers (e.g., ANY, ALL).
|
|
141
|
-
*
|
|
142
|
+
*
|
|
142
143
|
* @param name - The function name (case-insensitive)
|
|
143
144
|
* @returns A PredicateFunction instance of the appropriate type
|
|
144
145
|
*/
|
|
145
146
|
public static createPredicate(name: string): PredicateFunction {
|
|
146
147
|
const lowerName: string = name.toLowerCase();
|
|
147
|
-
|
|
148
|
+
|
|
148
149
|
// Check decorator-registered predicate functions
|
|
149
|
-
const decoratorFactory = getRegisteredFunctionFactory(lowerName,
|
|
150
|
+
const decoratorFactory = getRegisteredFunctionFactory(lowerName, "predicate");
|
|
150
151
|
if (decoratorFactory) {
|
|
151
152
|
return decoratorFactory();
|
|
152
153
|
}
|
|
@@ -156,13 +157,12 @@ class FunctionFactory {
|
|
|
156
157
|
|
|
157
158
|
public static createAsync(name: string): AsyncFunction {
|
|
158
159
|
const lowerName: string = name.toLowerCase();
|
|
159
|
-
const decoratorFactory = getRegisteredFunctionFactory(lowerName,
|
|
160
|
+
const decoratorFactory = getRegisteredFunctionFactory(lowerName, "async");
|
|
160
161
|
if (decoratorFactory) {
|
|
161
162
|
return decoratorFactory() as AsyncFunction;
|
|
162
163
|
}
|
|
163
164
|
throw new Error(`Unknown async function: ${name}`);
|
|
164
165
|
}
|
|
165
|
-
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
export default FunctionFactory;
|
|
168
|
+
export default FunctionFactory;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Database from "../../graph/database";
|
|
2
|
+
import Node from "../../graph/node";
|
|
3
|
+
import ASTNode from "../ast_node";
|
|
4
|
+
import Operation from "./operation";
|
|
5
|
+
|
|
6
|
+
class CreateNode extends Operation {
|
|
7
|
+
private _node: Node | null = null;
|
|
8
|
+
private _statement: ASTNode | null = null;
|
|
9
|
+
constructor(node: Node, statement: ASTNode) {
|
|
10
|
+
super();
|
|
11
|
+
this._node = node;
|
|
12
|
+
this._statement = statement;
|
|
13
|
+
}
|
|
14
|
+
public get node(): Node | null {
|
|
15
|
+
return this._node;
|
|
16
|
+
}
|
|
17
|
+
public get statement(): ASTNode | null {
|
|
18
|
+
return this._statement;
|
|
19
|
+
}
|
|
20
|
+
public run(): Promise<void> {
|
|
21
|
+
return new Promise(async (resolve, reject) => {
|
|
22
|
+
try {
|
|
23
|
+
if (this._node === null) {
|
|
24
|
+
throw new Error("Node is null");
|
|
25
|
+
}
|
|
26
|
+
const db: Database = Database.getInstance();
|
|
27
|
+
db.addNode(this._node, this._statement!);
|
|
28
|
+
resolve();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
reject(error);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
public get results(): Record<string, any>[] {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default CreateNode;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Database from "../../graph/database";
|
|
2
|
+
import Relationship from "../../graph/relationship";
|
|
3
|
+
import ASTNode from "../ast_node";
|
|
4
|
+
import Operation from "./operation";
|
|
5
|
+
|
|
6
|
+
class CreateRelationship extends Operation {
|
|
7
|
+
private _relationship: Relationship | null = null;
|
|
8
|
+
private _statement: ASTNode | null = null;
|
|
9
|
+
constructor(relationship: Relationship, statement: ASTNode) {
|
|
10
|
+
super();
|
|
11
|
+
this._relationship = relationship;
|
|
12
|
+
this._statement = statement;
|
|
13
|
+
}
|
|
14
|
+
public get relationship(): Relationship | null {
|
|
15
|
+
return this._relationship;
|
|
16
|
+
}
|
|
17
|
+
public get statement(): ASTNode | null {
|
|
18
|
+
return this._statement;
|
|
19
|
+
}
|
|
20
|
+
public run(): Promise<void> {
|
|
21
|
+
return new Promise(async (resolve, reject) => {
|
|
22
|
+
try {
|
|
23
|
+
if (this._relationship === null) {
|
|
24
|
+
throw new Error("Relationship is null");
|
|
25
|
+
}
|
|
26
|
+
const db = Database.getInstance();
|
|
27
|
+
db.addRelationship(this._relationship, this._statement!);
|
|
28
|
+
resolve();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
reject(error);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
public get results(): Record<string, any>[] {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export default CreateRelationship;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Pattern from "../../graph/pattern";
|
|
2
|
+
import Patterns from "../../graph/patterns";
|
|
3
|
+
import Operation from "./operation";
|
|
4
|
+
|
|
5
|
+
class Match extends Operation {
|
|
6
|
+
private _patterns: Patterns | null = null;
|
|
7
|
+
|
|
8
|
+
constructor(patterns: Pattern[] = []) {
|
|
9
|
+
super();
|
|
10
|
+
this._patterns = new Patterns(patterns);
|
|
11
|
+
}
|
|
12
|
+
public get patterns(): Pattern[] {
|
|
13
|
+
return this._patterns ? this._patterns.patterns : [];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Executes the match operation by chaining the patterns together.
|
|
17
|
+
* After each pattern match, it continues to the next operation in the chain.
|
|
18
|
+
* @return Promise<void>
|
|
19
|
+
*/
|
|
20
|
+
public async run(): Promise<void> {
|
|
21
|
+
await this._patterns!.initialize();
|
|
22
|
+
this._patterns!.toDoNext = async () => {
|
|
23
|
+
// Continue to the next operation after all patterns are matched
|
|
24
|
+
await this.next?.run();
|
|
25
|
+
};
|
|
26
|
+
// Kick off the graph pattern traversal
|
|
27
|
+
await this._patterns!.traverse();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default Match;
|
|
@@ -57,6 +57,9 @@ abstract class Operation extends ASTNode {
|
|
|
57
57
|
public async finish(): Promise<void> {
|
|
58
58
|
await this.next?.finish();
|
|
59
59
|
}
|
|
60
|
+
public async initialize(): Promise<void> {
|
|
61
|
+
await this.next?.initialize();
|
|
62
|
+
}
|
|
60
63
|
public reset(): void {}
|
|
61
64
|
public get results(): Record<string, any>[] {
|
|
62
65
|
throw new Error("Not implemented");
|