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.
- package/.editorconfig +21 -0
- package/.husky/pre-commit +1 -0
- package/.prettierrc +22 -0
- package/dist/flowquery.min.js +1 -1
- package/dist/parsing/expressions/expression_map.d.ts +9 -0
- package/dist/parsing/expressions/expression_map.d.ts.map +1 -0
- package/dist/parsing/expressions/expression_map.js +24 -0
- package/dist/parsing/expressions/expression_map.js.map +1 -0
- package/dist/parsing/operations/call.d.ts +17 -0
- package/dist/parsing/operations/call.d.ts.map +1 -0
- package/dist/parsing/operations/call.js +105 -0
- package/dist/parsing/operations/call.js.map +1 -0
- package/dist/parsing/operations/load.d.ts +6 -6
- package/dist/parsing/operations/load.d.ts.map +1 -1
- package/dist/parsing/operations/load.js +8 -6
- package/dist/parsing/operations/load.js.map +1 -1
- 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 -5
- package/dist/parsing/operations/operation.js.map +1 -1
- package/dist/parsing/operations/projection.d.ts +1 -1
- package/dist/parsing/operations/projection.d.ts.map +1 -1
- package/dist/parsing/operations/projection.js.map +1 -1
- package/dist/parsing/parser.d.ts +1 -0
- package/dist/parsing/parser.d.ts.map +1 -1
- package/dist/parsing/parser.js +148 -99
- package/dist/parsing/parser.js.map +1 -1
- package/dist/parsing/token_to_node.d.ts +2 -2
- package/dist/parsing/token_to_node.d.ts.map +1 -1
- package/dist/parsing/token_to_node.js +12 -12
- package/dist/parsing/token_to_node.js.map +1 -1
- package/dist/tokenization/token.d.ts +5 -1
- package/dist/tokenization/token.d.ts.map +1 -1
- package/dist/tokenization/token.js +17 -5
- package/dist/tokenization/token.js.map +1 -1
- package/docs/flowquery.min.js +1 -1
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/misc/apps/RAG/package.json +1 -1
- package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +21 -26
- package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +65 -0
- package/misc/apps/RAG/src/plugins/loaders/Form.ts +163 -147
- package/misc/apps/RAG/src/plugins/loaders/Llm.ts +106 -92
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +80 -58
- package/misc/apps/RAG/src/plugins/loaders/Table.ts +106 -103
- package/misc/apps/RAG/src/plugins/loaders/Weather.ts +50 -38
- package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +77 -78
- package/package.json +12 -2
- package/src/parsing/expressions/expression_map.ts +22 -0
- package/src/parsing/operations/call.ts +69 -0
- package/src/parsing/operations/load.ts +123 -120
- package/src/parsing/operations/operation.ts +14 -13
- package/src/parsing/operations/projection.ts +3 -3
- package/src/parsing/parser.ts +303 -239
- package/src/parsing/token_to_node.ts +67 -50
- package/src/tokenization/token.ts +29 -14
- package/tests/compute/runner.test.ts +277 -165
- package/tests/parsing/parser.test.ts +352 -303
- package/tests/tokenization/tokenizer.test.ts +17 -17
- 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
|
|
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
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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;
|