flowquery 1.0.14 → 1.0.16

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.
Files changed (59) hide show
  1. package/.editorconfig +21 -0
  2. package/.husky/pre-commit +1 -0
  3. package/.prettierrc +22 -0
  4. package/dist/flowquery.min.js +1 -1
  5. package/dist/parsing/expressions/expression_map.d.ts +9 -0
  6. package/dist/parsing/expressions/expression_map.d.ts.map +1 -0
  7. package/dist/parsing/expressions/expression_map.js +24 -0
  8. package/dist/parsing/expressions/expression_map.js.map +1 -0
  9. package/dist/parsing/operations/call.d.ts +17 -0
  10. package/dist/parsing/operations/call.d.ts.map +1 -0
  11. package/dist/parsing/operations/call.js +105 -0
  12. package/dist/parsing/operations/call.js.map +1 -0
  13. package/dist/parsing/operations/load.d.ts +6 -6
  14. package/dist/parsing/operations/load.d.ts.map +1 -1
  15. package/dist/parsing/operations/load.js +8 -6
  16. package/dist/parsing/operations/load.js.map +1 -1
  17. package/dist/parsing/operations/operation.d.ts +1 -0
  18. package/dist/parsing/operations/operation.d.ts.map +1 -1
  19. package/dist/parsing/operations/operation.js +6 -5
  20. package/dist/parsing/operations/operation.js.map +1 -1
  21. package/dist/parsing/operations/projection.d.ts +1 -1
  22. package/dist/parsing/operations/projection.d.ts.map +1 -1
  23. package/dist/parsing/operations/projection.js.map +1 -1
  24. package/dist/parsing/parser.d.ts +1 -0
  25. package/dist/parsing/parser.d.ts.map +1 -1
  26. package/dist/parsing/parser.js +148 -99
  27. package/dist/parsing/parser.js.map +1 -1
  28. package/dist/parsing/token_to_node.d.ts +2 -2
  29. package/dist/parsing/token_to_node.d.ts.map +1 -1
  30. package/dist/parsing/token_to_node.js +12 -12
  31. package/dist/parsing/token_to_node.js.map +1 -1
  32. package/dist/tokenization/token.d.ts +5 -1
  33. package/dist/tokenization/token.d.ts.map +1 -1
  34. package/dist/tokenization/token.js +17 -5
  35. package/dist/tokenization/token.js.map +1 -1
  36. package/docs/flowquery.min.js +1 -1
  37. package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
  38. package/misc/apps/RAG/package.json +1 -1
  39. package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +21 -26
  40. package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +65 -0
  41. package/misc/apps/RAG/src/plugins/loaders/Form.ts +163 -147
  42. package/misc/apps/RAG/src/plugins/loaders/Llm.ts +106 -92
  43. package/misc/apps/RAG/src/plugins/loaders/MockData.ts +80 -58
  44. package/misc/apps/RAG/src/plugins/loaders/Table.ts +106 -103
  45. package/misc/apps/RAG/src/plugins/loaders/Weather.ts +50 -38
  46. package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +77 -78
  47. package/package.json +12 -2
  48. package/src/parsing/expressions/expression_map.ts +22 -0
  49. package/src/parsing/operations/call.ts +69 -0
  50. package/src/parsing/operations/load.ts +123 -120
  51. package/src/parsing/operations/operation.ts +14 -13
  52. package/src/parsing/operations/projection.ts +3 -3
  53. package/src/parsing/parser.ts +303 -239
  54. package/src/parsing/token_to_node.ts +67 -50
  55. package/src/tokenization/token.ts +29 -14
  56. package/tests/compute/runner.test.ts +277 -165
  57. package/tests/parsing/parser.test.ts +352 -303
  58. package/tests/tokenization/tokenizer.test.ts +17 -17
  59. package/vscode-settings.json.recommended +16 -0
@@ -1,91 +1,108 @@
1
- import { Add, Subtract, Multiply, Divide, Modulo, Power, Equals, LessThan, GreaterThan, GreaterThanOrEqual, LessThanOrEqual, And, Or, Not, Is } from './expressions/operator';
2
- import String from './expressions/string';
3
- import Identifier from './expressions/identifier';
4
- import Number from './expressions/number';
5
- import Token from '../tokenization/token';
6
- import ASTNode from './ast_node';
7
- import JSON from './components/json';
8
- import CSV from './components/csv';
9
- import Text from './components/text';
10
- import When from './logic/when';
11
- import Then from './logic/then';
12
- import Else from './logic/else';
13
- import End from './logic/end';
14
- import Null from './components/null';
1
+ import Token from "../tokenization/token";
2
+ import ASTNode from "./ast_node";
3
+ import CSV from "./components/csv";
4
+ import JSON from "./components/json";
5
+ import Null from "./components/null";
6
+ import Text from "./components/text";
7
+ import Identifier from "./expressions/identifier";
8
+ import Number from "./expressions/number";
9
+ import {
10
+ Add,
11
+ And,
12
+ Divide,
13
+ Equals,
14
+ GreaterThan,
15
+ GreaterThanOrEqual,
16
+ Is,
17
+ LessThan,
18
+ LessThanOrEqual,
19
+ Modulo,
20
+ Multiply,
21
+ Not,
22
+ Or,
23
+ Power,
24
+ Subtract,
25
+ } from "./expressions/operator";
26
+ import String from "./expressions/string";
27
+ import Else from "./logic/else";
28
+ import End from "./logic/end";
29
+ import Then from "./logic/then";
30
+ import When from "./logic/when";
31
+
15
32
  class TokenToNode {
16
33
  public static convert(token: Token): ASTNode {
17
- if(token.isNumber()) {
18
- if(token.value === null) {
19
- throw new Error('Number token has no value');
34
+ if (token.isNumber()) {
35
+ if (token.value === null) {
36
+ throw new Error("Number token has no value");
20
37
  }
21
38
  return new Number(token.value);
22
- } else if(token.isString()) {
23
- if(token.value === null) {
24
- throw new Error('String token has no value');
39
+ } else if (token.isString()) {
40
+ if (token.value === null) {
41
+ throw new Error("String token has no value");
25
42
  }
26
43
  return new String(token.value);
27
- } else if(token.isIdentifier()) {
28
- if(token.value === null) {
29
- throw new Error('Identifier token has no value');
44
+ } else if (token.isIdentifier()) {
45
+ if (token.value === null) {
46
+ throw new Error("Identifier token has no value");
30
47
  }
31
48
  return new Identifier(token.value);
32
- } else if(token.isOperator()) {
33
- if(token.isAdd()) {
49
+ } else if (token.isOperator()) {
50
+ if (token.isAdd()) {
34
51
  return new Add();
35
- } else if(token.isSubtract()) {
52
+ } else if (token.isSubtract()) {
36
53
  return new Subtract();
37
- } else if(token.isMultiply()) {
54
+ } else if (token.isMultiply()) {
38
55
  return new Multiply();
39
- } else if(token.isDivide()) {
56
+ } else if (token.isDivide()) {
40
57
  return new Divide();
41
- } else if(token.isModulo()) {
58
+ } else if (token.isModulo()) {
42
59
  return new Modulo();
43
- } else if(token.isExponent()) {
60
+ } else if (token.isExponent()) {
44
61
  return new Power();
45
- } else if(token.isEquals()) {
62
+ } else if (token.isEquals()) {
46
63
  return new Equals();
47
- } else if(token.isLessThan()) {
64
+ } else if (token.isLessThan()) {
48
65
  return new LessThan();
49
- } else if(token.isGreaterThan()) {
66
+ } else if (token.isGreaterThan()) {
50
67
  return new GreaterThan();
51
- } else if(token.isGreaterThanOrEqual()) {
68
+ } else if (token.isGreaterThanOrEqual()) {
52
69
  return new GreaterThanOrEqual();
53
- } else if(token.isLessThanOrEqual()) {
70
+ } else if (token.isLessThanOrEqual()) {
54
71
  return new LessThanOrEqual();
55
- } else if(token.isAnd()) {
72
+ } else if (token.isAnd()) {
56
73
  return new And();
57
- } else if(token.isOr()) {
74
+ } else if (token.isOr()) {
58
75
  return new Or();
59
- } else if(token.isIs()) {
76
+ } else if (token.isIs()) {
60
77
  return new Is();
61
78
  }
62
- } else if(token.isUnaryOperator()) {
63
- if(token.isNot()) {
79
+ } else if (token.isUnaryOperator()) {
80
+ if (token.isNot()) {
64
81
  return new Not();
65
82
  }
66
83
  } else if (token.isKeyword()) {
67
- if(token.isJSON()) {
84
+ if (token.isJSON()) {
68
85
  return new JSON();
69
- } else if(token.isCSV()) {
86
+ } else if (token.isCSV()) {
70
87
  return new CSV();
71
- } else if(token.isText()) {
88
+ } else if (token.isText()) {
72
89
  return new Text();
73
- } else if(token.isWhen()) {
90
+ } else if (token.isWhen()) {
74
91
  return new When();
75
- } else if(token.isThen()) {
92
+ } else if (token.isThen()) {
76
93
  return new Then();
77
- } else if(token.isElse()) {
94
+ } else if (token.isElse()) {
78
95
  return new Else();
79
- } else if(token.isEnd()) {
96
+ } else if (token.isEnd()) {
80
97
  return new End();
81
- } else if(token.isNull()) {
98
+ } else if (token.isNull()) {
82
99
  return new Null();
83
100
  }
84
101
  } else {
85
- throw new Error('Unknown token');
102
+ throw new Error("Unknown token");
86
103
  }
87
104
  return new ASTNode();
88
105
  }
89
106
  }
90
107
 
91
- export default TokenToNode;
108
+ export default TokenToNode;
@@ -1,18 +1,18 @@
1
- import TokenType from "./token_type";
2
- import Keyword from "./keyword";
3
- import Symbol from "./symbol";
4
- import Operator from "./operator";
5
- import TokenToNode from "../parsing/token_to_node";
6
1
  import ASTNode from "../parsing/ast_node";
2
+ import TokenToNode from "../parsing/token_to_node";
7
3
  import StringUtils from "../utils/string_utils";
4
+ import Keyword from "./keyword";
5
+ import Operator from "./operator";
6
+ import Symbol from "./symbol";
7
+ import TokenType from "./token_type";
8
8
 
9
9
  /**
10
10
  * Represents a single token in the FlowQuery language.
11
- *
11
+ *
12
12
  * Tokens are the atomic units of lexical analysis, produced by the tokenizer
13
13
  * and consumed by the parser. Each token has a type (keyword, operator, identifier, etc.)
14
14
  * and an optional value.
15
- *
15
+ *
16
16
  * @example
17
17
  * ```typescript
18
18
  * const withToken = Token.WITH;
@@ -29,24 +29,24 @@ class Token {
29
29
 
30
30
  /**
31
31
  * Creates a new Token instance.
32
- *
32
+ *
33
33
  * @param type - The type of the token
34
34
  * @param value - The optional value associated with the token
35
35
  */
36
36
  constructor(type: TokenType, value: string | null = null) {
37
37
  this._type = type;
38
38
  this._value = value;
39
- this._can_be_identifier = StringUtils.can_be_identifier(value || '');
39
+ this._can_be_identifier = StringUtils.can_be_identifier(value || "");
40
40
  }
41
41
 
42
42
  /**
43
43
  * Checks if this token equals another token.
44
- *
44
+ *
45
45
  * @param other - The token to compare against
46
46
  * @returns True if tokens are equal, false otherwise
47
47
  */
48
48
  public equals(other: Token): boolean {
49
- if(this._type === TokenType.IDENTIFIER && other.type === TokenType.IDENTIFIER) {
49
+ if (this._type === TokenType.IDENTIFIER && other.type === TokenType.IDENTIFIER) {
50
50
  return true; // Identifier values are not compared
51
51
  }
52
52
  return this._type === other.type && this._value === other.value;
@@ -399,6 +399,22 @@ class Token {
399
399
  return this._type === TokenType.KEYWORD && this._value === Keyword.LOAD;
400
400
  }
401
401
 
402
+ public static get CALL(): Token {
403
+ return new Token(TokenType.KEYWORD, Keyword.CALL);
404
+ }
405
+
406
+ public isCall(): boolean {
407
+ return this._type === TokenType.KEYWORD && this._value === Keyword.CALL;
408
+ }
409
+
410
+ public static get YIELD(): Token {
411
+ return new Token(TokenType.KEYWORD, Keyword.YIELD);
412
+ }
413
+
414
+ public isYield(): boolean {
415
+ return this._type === TokenType.KEYWORD && this._value === Keyword.YIELD;
416
+ }
417
+
402
418
  public static get JSON(): Token {
403
419
  return new Token(TokenType.KEYWORD, Keyword.JSON);
404
420
  }
@@ -478,7 +494,7 @@ class Token {
478
494
  public isWhere(): boolean {
479
495
  return this._type === TokenType.KEYWORD && this._value === Keyword.WHERE;
480
496
  }
481
-
497
+
482
498
  public static get MERGE(): Token {
483
499
  return new Token(TokenType.KEYWORD, Keyword.MERGE);
484
500
  }
@@ -599,7 +615,6 @@ class Token {
599
615
  return this._type === TokenType.KEYWORD && this._value === Keyword.LIMIT;
600
616
  }
601
617
 
602
-
603
618
  // End of file token
604
619
 
605
620
  public static get EOF(): Token {
@@ -630,4 +645,4 @@ class Token {
630
645
  }
631
646
  }
632
647
 
633
- export default Token;
648
+ export default Token;