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,143 +1,146 @@
1
- import Operation from "./operation";
2
1
  import CSV from "../components/csv";
3
- import {default as _JSON} from "../components/json";
4
- import Text from "../components/text";
5
- import Function from "../functions/function";
6
- import AsyncFunction from "../functions/async_function";
7
- import AssociativeArray from "../data_structures/associative_array";
8
- import Reference from "../expressions/reference";
9
- import Expression from "../expressions/expression";
2
+ import From from "../components/from";
10
3
  import Headers from "../components/headers";
4
+ import { default as _JSON } from "../components/json";
11
5
  import Post from "../components/post";
6
+ import Text from "../components/text";
7
+ import AssociativeArray from "../data_structures/associative_array";
12
8
  import Lookup from "../data_structures/lookup";
13
- import From from "../components/from";
9
+ import Expression from "../expressions/expression";
10
+ import Reference from "../expressions/reference";
11
+ import AsyncFunction from "../functions/async_function";
12
+ import Function from "../functions/function";
13
+ import Operation from "./operation";
14
14
 
15
15
  class Load extends Operation {
16
- private _value: any = null;
17
- constructor() {
18
- super()
19
- }
20
- public get type(): _JSON | CSV | Text {
21
- return this.children[0] as _JSON | CSV | Text;
22
- }
16
+ private _value: any = null;
17
+
18
+ constructor() {
19
+ super();
20
+ }
21
+ public get type(): _JSON | CSV | Text {
22
+ return this.children[0] as _JSON | CSV | Text;
23
+ }
23
24
 
24
- /**
25
- * Gets the From component which contains either a URL expression or an AsyncFunction.
26
- */
27
- public get fromComponent(): From {
28
- return this.children[1] as From;
29
- }
25
+ /**
26
+ * Gets the From component which contains either a URL expression or an AsyncFunction.
27
+ */
28
+ public get fromComponent(): From {
29
+ return this.children[1] as From;
30
+ }
30
31
 
31
- /**
32
- * Checks if the data source is an async function.
33
- */
34
- public get isAsyncFunction(): boolean {
35
- return this.fromComponent.firstChild() instanceof AsyncFunction;
36
- }
32
+ /**
33
+ * Checks if the data source is an async function.
34
+ */
35
+ public get isAsyncFunction(): boolean {
36
+ return this.fromComponent.firstChild() instanceof AsyncFunction;
37
+ }
37
38
 
38
- /**
39
- * Gets the async function if the source is a function, otherwise null.
40
- */
41
- public get asyncFunction(): AsyncFunction | null {
42
- const child = this.fromComponent.firstChild();
43
- return child instanceof AsyncFunction ? child : null;
44
- }
39
+ /**
40
+ * Gets the async function if the source is a function, otherwise null.
41
+ */
42
+ public get asyncFunction(): AsyncFunction | null {
43
+ const child = this.fromComponent.firstChild();
44
+ return child instanceof AsyncFunction ? child : null;
45
+ }
45
46
 
46
- public get from(): string {
47
- return this.children[1].value() as string;
48
- }
49
- public get headers(): { [key: string]: string } {
50
- if(this.childCount() > 2 && this.children[2] instanceof Headers) {
51
- return this.children[2].value() as { [key: string]: string } || {};
47
+ public get from(): string {
48
+ return this.children[1].value() as string;
52
49
  }
53
- return {};
54
- }
55
- public get payload(): Function | Reference | Expression | AssociativeArray | Lookup | null {
56
- let post: Post | null = null;
57
- if(this.childCount() > 2 && this.children[2] instanceof Post) {
58
- post = this.children[2] as Post;
59
- } else if(this.childCount() > 3 && this.children[3] instanceof Post) {
60
- post = this.children[3] as Post;
50
+ public get headers(): { [key: string]: string } {
51
+ if (this.childCount() > 2 && this.children[2] instanceof Headers) {
52
+ return (this.children[2].value() as { [key: string]: string }) || {};
53
+ }
54
+ return {};
61
55
  }
62
- return post !== null ? post.firstChild() as Function | Reference | Expression | AssociativeArray | Lookup : null;
63
- }
64
- private method(): "GET" | "POST" {
65
- if(this.payload === null) {
66
- return "GET";
67
- } else {
68
- return "POST";
56
+ public get payload(): Function | Reference | Expression | AssociativeArray | Lookup | null {
57
+ let post: Post | null = null;
58
+ if (this.childCount() > 2 && this.children[2] instanceof Post) {
59
+ post = this.children[2] as Post;
60
+ } else if (this.childCount() > 3 && this.children[3] instanceof Post) {
61
+ post = this.children[3] as Post;
62
+ }
63
+ return post !== null
64
+ ? (post.firstChild() as Function | Reference | Expression | AssociativeArray | Lookup)
65
+ : null;
69
66
  }
70
- }
71
- private options(): object {
72
- const headers = this.headers as { [key: string]: string };
73
- const payload = this.payload;
74
- const data = payload?.value();
75
- if(data !== null && typeof data === "object" && !(headers.hasOwnProperty("Content-Type"))) {
76
- headers["Content-Type"] = "application/json";
67
+ private method(): "GET" | "POST" {
68
+ if (this.payload === null) {
69
+ return "GET";
70
+ } else {
71
+ return "POST";
72
+ }
77
73
  }
78
- return {
79
- "method": this.method(),
80
- "headers": headers,
81
- ...(payload !== null ? {"body": JSON.stringify(payload.value())} : {})
82
- };
83
- }
84
-
85
- /**
86
- * Loads data from an async function source.
87
- * Arguments from the query (e.g., myFunc(arg1, arg2)) are passed to generate().
88
- */
89
- private async loadFromFunction(): Promise<void> {
90
- const asyncFunc = this.asyncFunction!;
91
- const args = asyncFunc.getArguments();
92
- for await (const item of asyncFunc.generate(...args)) {
93
- this._value = item;
94
- await this.next?.run();
74
+ private options(): object {
75
+ const headers = this.headers as { [key: string]: string };
76
+ const payload = this.payload;
77
+ const data = payload?.value();
78
+ if (data !== null && typeof data === "object" && !headers.hasOwnProperty("Content-Type")) {
79
+ headers["Content-Type"] = "application/json";
80
+ }
81
+ return {
82
+ method: this.method(),
83
+ headers: headers,
84
+ ...(payload !== null ? { body: JSON.stringify(payload.value()) } : {}),
85
+ };
95
86
  }
96
- }
97
87
 
98
- /**
99
- * Loads data from a URL source (original behavior).
100
- */
101
- private async loadFromUrl(): Promise<void> {
102
- const result = await fetch(this.from, this.options());
103
- let data: any = null;
104
- if(this.type instanceof _JSON) {
105
- data = await result.json();
106
- } else if(this.type instanceof Text) {
107
- data = await result.text();
88
+ /**
89
+ * Loads data from an async function source.
90
+ * Arguments from the query (e.g., myFunc(arg1, arg2)) are passed to generate().
91
+ */
92
+ private async loadFromFunction(): Promise<void> {
93
+ const asyncFunc = this.asyncFunction!;
94
+ const args = asyncFunc.getArguments();
95
+ for await (const item of asyncFunc.generate(...args)) {
96
+ this._value = item;
97
+ await this.next?.run();
98
+ }
108
99
  }
109
- if(Array.isArray(data)) {
110
- for(const item of data) {
111
- this._value = item;
112
- await this.next?.run();
113
- }
114
- } else if(typeof data === "object" && data !== null) {
115
- this._value = data;
116
- await this.next?.run();
117
- } else if(typeof data === "string") {
118
- this._value = data;
119
- await this.next?.run();
100
+
101
+ /**
102
+ * Loads data from a URL source (original behavior).
103
+ */
104
+ private async loadFromUrl(): Promise<void> {
105
+ const result = await fetch(this.from, this.options());
106
+ let data: any = null;
107
+ if (this.type instanceof _JSON) {
108
+ data = await result.json();
109
+ } else if (this.type instanceof Text) {
110
+ data = await result.text();
111
+ }
112
+ if (Array.isArray(data)) {
113
+ for (const item of data) {
114
+ this._value = item;
115
+ await this.next?.run();
116
+ }
117
+ } else if (typeof data === "object" && data !== null) {
118
+ this._value = data;
119
+ await this.next?.run();
120
+ } else if (typeof data === "string") {
121
+ this._value = data;
122
+ await this.next?.run();
123
+ }
120
124
  }
121
- }
122
125
 
123
- public async load(): Promise<any> {
124
- if (this.isAsyncFunction) {
125
- await this.loadFromFunction();
126
- } else {
127
- await this.loadFromUrl();
126
+ public async load(): Promise<any> {
127
+ if (this.isAsyncFunction) {
128
+ await this.loadFromFunction();
129
+ } else {
130
+ await this.loadFromUrl();
131
+ }
132
+ }
133
+ public async run(): Promise<void> {
134
+ try {
135
+ await this.load();
136
+ } catch (e) {
137
+ const source = this.isAsyncFunction ? this.asyncFunction?.name : this.from;
138
+ throw new Error(`Failed to load data from ${source}. Error: ${e}`);
139
+ }
128
140
  }
129
- }
130
- public async run(): Promise<void> {
131
- try {
132
- await this.load();
133
- } catch(e) {
134
- const source = this.isAsyncFunction ? this.asyncFunction?.name : this.from;
135
- throw new Error(`Failed to load data from ${source}. Error: ${e}`);
141
+ public value(): any {
142
+ return this._value;
136
143
  }
137
- }
138
- public value(): any {
139
- return this._value;
140
- }
141
144
  }
142
145
 
143
- export default Load;
146
+ export default Load;
@@ -2,16 +2,16 @@ import ASTNode from "../ast_node";
2
2
 
3
3
  /**
4
4
  * Base class for all FlowQuery operations.
5
- *
5
+ *
6
6
  * Operations represent the main statements in FlowQuery (WITH, UNWIND, RETURN, LOAD, WHERE).
7
7
  * They form a linked list structure and can be executed sequentially.
8
- *
8
+ *
9
9
  * @abstract
10
10
  */
11
11
  abstract class Operation extends ASTNode {
12
12
  private _previous: Operation | null = null;
13
13
  private _next: Operation | null = null;
14
-
14
+
15
15
  /**
16
16
  * Creates a new Operation instance.
17
17
  */
@@ -35,31 +35,32 @@ abstract class Operation extends ASTNode {
35
35
  operation.previous = this;
36
36
  this.next = operation;
37
37
  }
38
-
38
+ public get isLast(): boolean {
39
+ return this._next === null;
40
+ }
41
+
39
42
  /**
40
43
  * Executes this operation. Must be implemented by subclasses.
41
- *
44
+ *
42
45
  * @returns A promise that resolves when the operation completes
43
46
  * @throws {Error} If not implemented by subclass
44
47
  */
45
48
  public async run(): Promise<void> {
46
- throw new Error('Not implemented');
49
+ throw new Error("Not implemented");
47
50
  }
48
-
51
+
49
52
  /**
50
53
  * Finishes execution by calling finish on the next operation in the chain.
51
- *
54
+ *
52
55
  * @returns A promise that resolves when all operations finish
53
56
  */
54
57
  public async finish(): Promise<void> {
55
58
  await this.next?.finish();
56
59
  }
57
- public reset(): void {
58
- ;
59
- }
60
+ public reset(): void {}
60
61
  public get results(): Record<string, any>[] {
61
- throw new Error('Not implemented');
62
+ throw new Error("Not implemented");
62
63
  }
63
64
  }
64
65
 
65
- export default Operation;
66
+ export default Operation;
@@ -1,5 +1,5 @@
1
- import Operation from "./operation";
2
1
  import Expression from "../expressions/expression";
2
+ import Operation from "./operation";
3
3
 
4
4
  class Projection extends Operation {
5
5
  constructor(expressions: Expression[]) {
@@ -7,7 +7,7 @@ class Projection extends Operation {
7
7
  this.children = expressions;
8
8
  }
9
9
  protected *expressions(): Generator<[Expression, string]> {
10
- for(let i = 0; i < this.children.length; i++) {
10
+ for (let i = 0; i < this.children.length; i++) {
11
11
  const expression: Expression = this.children[i] as Expression;
12
12
  const alias = expression.alias || `expr${i}`;
13
13
  yield [expression, alias];
@@ -15,4 +15,4 @@ class Projection extends Operation {
15
15
  }
16
16
  }
17
17
 
18
- export default Projection;
18
+ export default Projection;