flowquery 1.0.5 → 1.0.7

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 (138) hide show
  1. package/README.md +74 -0
  2. package/dist/compute/runner.d.ts +1 -22
  3. package/dist/compute/runner.d.ts.map +1 -1
  4. package/dist/compute/runner.js.map +1 -1
  5. package/dist/extensibility.d.ts +35 -0
  6. package/dist/extensibility.d.ts.map +1 -0
  7. package/dist/extensibility.js +49 -0
  8. package/dist/extensibility.js.map +1 -0
  9. package/dist/flowquery.min.js +1 -1
  10. package/dist/index.browser.d.ts.map +1 -1
  11. package/dist/index.browser.js +0 -80
  12. package/dist/index.browser.js.map +1 -1
  13. package/dist/index.node.d.ts +3 -3
  14. package/dist/index.node.d.ts.map +1 -1
  15. package/dist/index.node.js +0 -80
  16. package/dist/index.node.js.map +1 -1
  17. package/dist/parsing/functions/avg.d.ts.map +1 -1
  18. package/dist/parsing/functions/avg.js +20 -2
  19. package/dist/parsing/functions/avg.js.map +1 -1
  20. package/dist/parsing/functions/collect.d.ts.map +1 -1
  21. package/dist/parsing/functions/collect.js +20 -2
  22. package/dist/parsing/functions/collect.js.map +1 -1
  23. package/dist/parsing/functions/function_factory.d.ts +26 -80
  24. package/dist/parsing/functions/function_factory.d.ts.map +1 -1
  25. package/dist/parsing/functions/function_factory.js +46 -168
  26. package/dist/parsing/functions/function_factory.js.map +1 -1
  27. package/dist/parsing/functions/function_metadata.d.ts +81 -20
  28. package/dist/parsing/functions/function_metadata.d.ts.map +1 -1
  29. package/dist/parsing/functions/function_metadata.js +154 -152
  30. package/dist/parsing/functions/function_metadata.js.map +1 -1
  31. package/dist/parsing/functions/functions.d.ts.map +1 -1
  32. package/dist/parsing/functions/functions.js +37 -2
  33. package/dist/parsing/functions/functions.js.map +1 -1
  34. package/dist/parsing/functions/join.d.ts.map +1 -1
  35. package/dist/parsing/functions/join.js +21 -2
  36. package/dist/parsing/functions/join.js.map +1 -1
  37. package/dist/parsing/functions/predicate_function.d.ts +1 -0
  38. package/dist/parsing/functions/predicate_function.d.ts.map +1 -1
  39. package/dist/parsing/functions/predicate_function.js +3 -0
  40. package/dist/parsing/functions/predicate_function.js.map +1 -1
  41. package/dist/parsing/functions/predicate_sum.d.ts.map +1 -1
  42. package/dist/parsing/functions/predicate_sum.js +23 -2
  43. package/dist/parsing/functions/predicate_sum.js.map +1 -1
  44. package/dist/parsing/functions/rand.d.ts.map +1 -1
  45. package/dist/parsing/functions/rand.js +18 -2
  46. package/dist/parsing/functions/rand.js.map +1 -1
  47. package/dist/parsing/functions/range.d.ts.map +1 -1
  48. package/dist/parsing/functions/range.js +21 -2
  49. package/dist/parsing/functions/range.js.map +1 -1
  50. package/dist/parsing/functions/replace.d.ts.map +1 -1
  51. package/dist/parsing/functions/replace.js +22 -2
  52. package/dist/parsing/functions/replace.js.map +1 -1
  53. package/dist/parsing/functions/round.d.ts.map +1 -1
  54. package/dist/parsing/functions/round.js +20 -2
  55. package/dist/parsing/functions/round.js.map +1 -1
  56. package/dist/parsing/functions/size.d.ts.map +1 -1
  57. package/dist/parsing/functions/size.js +20 -2
  58. package/dist/parsing/functions/size.js.map +1 -1
  59. package/dist/parsing/functions/split.d.ts.map +1 -1
  60. package/dist/parsing/functions/split.js +21 -2
  61. package/dist/parsing/functions/split.js.map +1 -1
  62. package/dist/parsing/functions/stringify.d.ts.map +1 -1
  63. package/dist/parsing/functions/stringify.js +20 -2
  64. package/dist/parsing/functions/stringify.js.map +1 -1
  65. package/dist/parsing/functions/sum.d.ts.map +1 -1
  66. package/dist/parsing/functions/sum.js +20 -2
  67. package/dist/parsing/functions/sum.js.map +1 -1
  68. package/dist/parsing/functions/to_json.d.ts.map +1 -1
  69. package/dist/parsing/functions/to_json.js +20 -2
  70. package/dist/parsing/functions/to_json.js.map +1 -1
  71. package/dist/parsing/parser.d.ts.map +1 -1
  72. package/dist/parsing/parser.js +1 -2
  73. package/dist/parsing/parser.js.map +1 -1
  74. package/docs/flowquery.min.js +1 -1
  75. package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
  76. package/misc/apps/RAG/.env.example +14 -0
  77. package/misc/apps/RAG/README.md +0 -7
  78. package/misc/apps/RAG/package.json +16 -7
  79. package/misc/apps/RAG/public/index.html +18 -0
  80. package/misc/apps/RAG/src/App.css +42 -0
  81. package/misc/apps/RAG/src/App.tsx +50 -0
  82. package/misc/apps/RAG/src/components/ApiKeySettings.tsx +245 -0
  83. package/misc/apps/RAG/src/components/ChatContainer.css +67 -0
  84. package/misc/apps/RAG/src/components/ChatContainer.tsx +239 -0
  85. package/misc/apps/RAG/src/components/ChatInput.css +23 -0
  86. package/misc/apps/RAG/src/components/ChatInput.tsx +62 -0
  87. package/misc/apps/RAG/src/components/ChatMessage.css +136 -0
  88. package/misc/apps/RAG/src/components/ChatMessage.tsx +152 -0
  89. package/misc/apps/RAG/src/components/FlowQueryAgent.ts +390 -0
  90. package/misc/apps/RAG/src/components/FlowQueryRunner.css +104 -0
  91. package/misc/apps/RAG/src/components/FlowQueryRunner.tsx +332 -0
  92. package/misc/apps/RAG/src/components/index.ts +15 -0
  93. package/misc/apps/RAG/src/index.tsx +17 -0
  94. package/misc/apps/RAG/src/plugins/README.md +139 -0
  95. package/misc/apps/RAG/src/plugins/index.ts +68 -0
  96. package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +75 -0
  97. package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +67 -0
  98. package/misc/apps/RAG/src/plugins/loaders/Llm.ts +437 -0
  99. package/misc/apps/RAG/src/plugins/loaders/MockData.ts +151 -0
  100. package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +385 -0
  101. package/misc/apps/RAG/src/prompts/index.ts +10 -0
  102. package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +131 -0
  103. package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +203 -0
  104. package/misc/apps/RAG/src/utils/index.ts +9 -0
  105. package/misc/apps/RAG/tsconfig.json +4 -2
  106. package/misc/apps/RAG/webpack.config.js +23 -12
  107. package/package.json +7 -1
  108. package/src/compute/runner.ts +1 -26
  109. package/src/extensibility.ts +45 -0
  110. package/src/index.browser.ts +2 -88
  111. package/src/index.node.ts +3 -92
  112. package/src/parsing/functions/avg.ts +10 -0
  113. package/src/parsing/functions/collect.ts +10 -0
  114. package/src/parsing/functions/function_factory.ts +56 -194
  115. package/src/parsing/functions/function_metadata.ts +187 -168
  116. package/src/parsing/functions/functions.ts +27 -0
  117. package/src/parsing/functions/join.ts +11 -0
  118. package/src/parsing/functions/predicate_function.ts +4 -0
  119. package/src/parsing/functions/predicate_sum.ts +13 -0
  120. package/src/parsing/functions/rand.ts +8 -0
  121. package/src/parsing/functions/range.ts +11 -0
  122. package/src/parsing/functions/replace.ts +12 -0
  123. package/src/parsing/functions/round.ts +10 -0
  124. package/src/parsing/functions/size.ts +10 -0
  125. package/src/parsing/functions/split.ts +11 -0
  126. package/src/parsing/functions/stringify.ts +10 -0
  127. package/src/parsing/functions/sum.ts +10 -0
  128. package/src/parsing/functions/to_json.ts +10 -0
  129. package/src/parsing/parser.ts +1 -2
  130. package/tests/extensibility.test.ts +563 -0
  131. package/tsconfig.json +1 -0
  132. package/dist/parsing/functions/predicate_function_factory.d.ts +0 -6
  133. package/dist/parsing/functions/predicate_function_factory.d.ts.map +0 -1
  134. package/dist/parsing/functions/predicate_function_factory.js +0 -19
  135. package/dist/parsing/functions/predicate_function_factory.js.map +0 -1
  136. package/misc/apps/RAG/src/index.ts +0 -20
  137. package/src/parsing/functions/predicate_function_factory.ts +0 -15
  138. package/tests/parsing/function_plugins.test.ts +0 -369
@@ -1,38 +1,36 @@
1
- import Sum from "./sum";
2
- import Collect from "./collect";
3
- import Avg from "./avg";
4
- import Range from "./range";
5
- import Rand from "./rand";
6
- import Round from "./round";
7
- import Split from "./split";
8
- import Join from "./join";
9
- import ToJson from "./to_json";
10
- import Replace from "./replace";
11
- import Stringify from "./stringify";
12
- import Size from "./size";
13
- import Functions from "./functions";
14
1
  import Function from "./function";
2
+ import PredicateFunction from "./predicate_function";
3
+ // Import built-in functions to ensure their @FunctionDef decorators run
4
+ import "./sum";
5
+ import "./collect";
6
+ import "./avg";
7
+ import "./range";
8
+ import "./rand";
9
+ import "./round";
10
+ import "./split";
11
+ import "./join";
12
+ import "./to_json";
13
+ import "./replace";
14
+ import "./stringify";
15
+ import "./size";
16
+ import "./functions";
17
+ import "./predicate_sum";
15
18
  import {
16
19
  FunctionMetadata,
17
- RegisterFunctionOptions,
18
- RegisterAsyncProviderOptions,
19
- BUILTIN_FUNCTION_METADATA
20
+ getRegisteredFunctionMetadata,
21
+ getFunctionMetadata,
22
+ getRegisteredFunctionFactory,
23
+ getRegisteredAsyncProvider,
24
+ AsyncDataProvider
20
25
  } from "./function_metadata";
21
26
 
22
- /**
23
- * Type for synchronous function factories.
24
- */
25
- export type FunctionCreator = () => Function;
26
-
27
- /**
28
- * Type for async data provider functions used in LOAD operations.
29
- * These functions can yield data asynchronously.
30
- */
31
- export type AsyncDataProvider = (...args: any[]) => AsyncGenerator<any, void, unknown> | Promise<any>;
27
+ // Re-export AsyncDataProvider for backwards compatibility
28
+ export { AsyncDataProvider };
32
29
 
33
30
  /**
34
31
  * Factory for creating function instances by name.
35
32
  *
33
+ * All functions are registered via the @FunctionDef decorator.
36
34
  * Maps function names (case-insensitive) to their corresponding implementation classes.
37
35
  * Supports built-in functions like sum, avg, collect, range, split, join, etc.
38
36
  *
@@ -43,113 +41,6 @@ export type AsyncDataProvider = (...args: any[]) => AsyncGenerator<any, void, un
43
41
  * ```
44
42
  */
45
43
  class FunctionFactory {
46
- /**
47
- * Registry for plugin functions (synchronous).
48
- */
49
- private static plugins: Map<string, FunctionCreator> = new Map();
50
-
51
- /**
52
- * Registry for async data provider functions used in LOAD operations.
53
- */
54
- private static asyncProviders: Map<string, AsyncDataProvider> = new Map();
55
-
56
- /**
57
- * Registry for function metadata (both sync and async).
58
- */
59
- private static metadata: Map<string, FunctionMetadata> = new Map();
60
-
61
- /**
62
- * Registers a synchronous plugin function.
63
- *
64
- * @param name - The function name (will be lowercased)
65
- * @param factoryOrOptions - Factory function or options object with metadata
66
- */
67
- public static register(name: string, factoryOrOptions: FunctionCreator | RegisterFunctionOptions): void {
68
- const lowerName = name.toLowerCase();
69
- if (typeof factoryOrOptions === 'function') {
70
- FunctionFactory.plugins.set(lowerName, factoryOrOptions);
71
- } else {
72
- FunctionFactory.plugins.set(lowerName, factoryOrOptions.factory);
73
- FunctionFactory.metadata.set(lowerName, {
74
- ...factoryOrOptions.metadata,
75
- name: lowerName,
76
- isAsyncProvider: false
77
- });
78
- }
79
- }
80
-
81
- /**
82
- * Unregisters a synchronous plugin function.
83
- *
84
- * @param name - The function name to unregister
85
- */
86
- public static unregister(name: string): void {
87
- const lowerName = name.toLowerCase();
88
- FunctionFactory.plugins.delete(lowerName);
89
- FunctionFactory.metadata.delete(lowerName);
90
- }
91
-
92
- /**
93
- * Registers an async data provider function for use in LOAD operations.
94
- *
95
- * @param name - The function name (will be lowercased)
96
- * @param providerOrOptions - Async provider or options object with metadata
97
- *
98
- * @example
99
- * ```typescript
100
- * // Register with metadata for LLM consumption
101
- * FunctionFactory.registerAsyncProvider("fetchUsers", {
102
- * provider: async function* (endpoint: string) {
103
- * const response = await fetch(endpoint);
104
- * const data = await response.json();
105
- * for (const item of data) {
106
- * yield item;
107
- * }
108
- * },
109
- * metadata: {
110
- * name: "fetchUsers",
111
- * description: "Fetches user data from an API endpoint",
112
- * parameters: [
113
- * { name: "endpoint", description: "API endpoint URL", type: "string" }
114
- * ],
115
- * output: {
116
- * description: "User objects",
117
- * type: "object",
118
- * properties: {
119
- * id: { description: "User ID", type: "number" },
120
- * name: { description: "User name", type: "string" }
121
- * }
122
- * },
123
- * examples: ["LOAD JSON FROM fetchUsers('https://api.example.com/users') AS user"]
124
- * }
125
- * });
126
- * ```
127
- */
128
- public static registerAsyncProvider(name: string, providerOrOptions: AsyncDataProvider | RegisterAsyncProviderOptions): void {
129
- const lowerName = name.toLowerCase();
130
- if (typeof providerOrOptions === 'function') {
131
- FunctionFactory.asyncProviders.set(lowerName, providerOrOptions);
132
- } else {
133
- FunctionFactory.asyncProviders.set(lowerName, providerOrOptions.provider);
134
- FunctionFactory.metadata.set(lowerName, {
135
- ...providerOrOptions.metadata,
136
- name: lowerName,
137
- isAsyncProvider: true
138
- });
139
- }
140
- }
141
-
142
- /**
143
- * Unregisters an async data provider function.
144
- *
145
- * @param name - The function name to unregister
146
- */
147
- public static unregisterAsyncProvider(name: string): void {
148
- const lowerName = name.toLowerCase();
149
- FunctionFactory.asyncProviders.delete(lowerName);
150
- FunctionFactory.metadata.delete(lowerName);
151
- }
152
-
153
44
  /**
154
45
  * Gets an async data provider by name.
155
46
  *
@@ -157,7 +48,7 @@ class FunctionFactory {
157
48
  * @returns The async data provider, or undefined if not found
158
49
  */
159
50
  public static getAsyncProvider(name: string): AsyncDataProvider | undefined {
160
- return FunctionFactory.asyncProviders.get(name.toLowerCase());
51
+ return getRegisteredAsyncProvider(name.toLowerCase());
161
52
  }
162
53
 
163
54
  /**
@@ -167,7 +58,7 @@ class FunctionFactory {
167
58
  * @returns True if the function is an async data provider
168
59
  */
169
60
  public static isAsyncProvider(name: string): boolean {
170
- return FunctionFactory.asyncProviders.has(name.toLowerCase());
61
+ return getRegisteredAsyncProvider(name.toLowerCase()) !== undefined;
171
62
  }
172
63
 
173
64
  /**
@@ -177,45 +68,26 @@ class FunctionFactory {
177
68
  * @returns The function metadata, or undefined if not found
178
69
  */
179
70
  public static getMetadata(name: string): FunctionMetadata | undefined {
180
- const lowerName = name.toLowerCase();
181
- // Check plugin metadata first
182
- if (FunctionFactory.metadata.has(lowerName)) {
183
- return FunctionFactory.metadata.get(lowerName);
184
- }
185
- // Fall back to built-in metadata
186
- return BUILTIN_FUNCTION_METADATA.find(m => m.name === lowerName);
71
+ return getFunctionMetadata(name.toLowerCase());
187
72
  }
188
73
 
189
74
  /**
190
75
  * Lists all registered functions with their metadata.
191
- * Includes both built-in and plugin functions.
192
76
  *
193
77
  * @param options - Optional filter options
194
78
  * @returns Array of function metadata
195
79
  */
196
80
  public static listFunctions(options?: {
197
81
  category?: string;
198
- includeBuiltins?: boolean;
199
82
  asyncOnly?: boolean;
200
83
  syncOnly?: boolean;
201
84
  }): FunctionMetadata[] {
202
85
  const result: FunctionMetadata[] = [];
203
- const includeBuiltins = options?.includeBuiltins !== false;
204
-
205
- // Add built-in functions
206
- if (includeBuiltins) {
207
- for (const meta of BUILTIN_FUNCTION_METADATA) {
208
- if (options?.category && meta.category !== options.category) continue;
209
- if (options?.asyncOnly) continue; // Built-ins are sync
210
- result.push(meta);
211
- }
212
- }
213
86
 
214
- // Add plugin functions
215
- for (const [name, meta] of FunctionFactory.metadata) {
87
+ for (const meta of getRegisteredFunctionMetadata()) {
216
88
  if (options?.category && meta.category !== options.category) continue;
217
- if (options?.asyncOnly && !meta.isAsyncProvider) continue;
218
- if (options?.syncOnly && meta.isAsyncProvider) continue;
89
+ if (options?.asyncOnly && meta.category !== 'async') continue;
90
+ if (options?.syncOnly && meta.category === 'async') continue;
219
91
  result.push(meta);
220
92
  }
221
93
 
@@ -228,10 +100,7 @@ class FunctionFactory {
228
100
  * @returns Array of function names
229
101
  */
230
102
  public static listFunctionNames(): string[] {
231
- const builtinNames = BUILTIN_FUNCTION_METADATA.map(m => m.name);
232
- const pluginNames = Array.from(FunctionFactory.plugins.keys());
233
- const asyncNames = Array.from(FunctionFactory.asyncProviders.keys());
234
- return [...new Set([...builtinNames, ...pluginNames, ...asyncNames])];
103
+ return getRegisteredFunctionMetadata().map(m => m.name);
235
104
  }
236
105
 
237
106
  /**
@@ -254,41 +123,34 @@ class FunctionFactory {
254
123
  public static create(name: string): Function {
255
124
  const lowerName = name.toLowerCase();
256
125
 
257
- // Check plugin registry first (allows overriding built-ins)
258
- if (FunctionFactory.plugins.has(lowerName)) {
259
- return FunctionFactory.plugins.get(lowerName)!();
126
+ // Check decorator-registered functions (built-ins use @FunctionDef)
127
+ const decoratorFactory = getRegisteredFunctionFactory(lowerName);
128
+ if (decoratorFactory) {
129
+ return decoratorFactory();
260
130
  }
261
131
 
262
- switch (lowerName) {
263
- case "sum":
264
- return new Sum();
265
- case "collect":
266
- return new Collect();
267
- case "avg":
268
- return new Avg();
269
- case "range":
270
- return new Range();
271
- case "rand":
272
- return new Rand();
273
- case "round":
274
- return new Round();
275
- case "split":
276
- return new Split();
277
- case "join":
278
- return new Join();
279
- case "tojson":
280
- return new ToJson();
281
- case "replace":
282
- return new Replace();
283
- case "stringify":
284
- return new Stringify();
285
- case "size":
286
- return new Size();
287
- case "functions":
288
- return new Functions();
289
- default:
290
- return new Function(name);
132
+ // Unknown function - return generic Function instance
133
+ return new Function(name);
134
+ }
135
+
136
+ /**
137
+ * Creates a predicate function instance by name.
138
+ * Predicate functions are used in WHERE clauses with quantifiers (e.g., ANY, ALL).
139
+ *
140
+ * @param name - The function name (case-insensitive)
141
+ * @returns A PredicateFunction instance of the appropriate type
142
+ */
143
+ public static createPredicate(name: string): PredicateFunction {
144
+ const lowerName = name.toLowerCase();
145
+
146
+ // Check decorator-registered predicate functions
147
+ const decoratorFactory = getRegisteredFunctionFactory(lowerName, 'predicate');
148
+ if (decoratorFactory) {
149
+ return decoratorFactory();
291
150
  }
151
+
152
+ // Unknown predicate function - return generic PredicateFunction instance
153
+ return new PredicateFunction(name);
292
154
  }
293
155
  }
294
156