flowquery 1.0.5 → 1.0.6

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 (131) hide show
  1. package/README.md +182 -0
  2. package/dist/extensibility.d.ts +9 -0
  3. package/dist/extensibility.d.ts.map +1 -0
  4. package/dist/extensibility.js +25 -0
  5. package/dist/extensibility.js.map +1 -0
  6. package/dist/flowquery.min.js +1 -1
  7. package/dist/parsing/functions/avg.d.ts.map +1 -1
  8. package/dist/parsing/functions/avg.js +20 -2
  9. package/dist/parsing/functions/avg.js.map +1 -1
  10. package/dist/parsing/functions/collect.d.ts.map +1 -1
  11. package/dist/parsing/functions/collect.js +20 -2
  12. package/dist/parsing/functions/collect.js.map +1 -1
  13. package/dist/parsing/functions/extensibility/index.d.ts +37 -0
  14. package/dist/parsing/functions/extensibility/index.d.ts.map +1 -0
  15. package/dist/parsing/functions/extensibility/index.js +50 -0
  16. package/dist/parsing/functions/extensibility/index.js.map +1 -0
  17. package/dist/parsing/functions/function_factory.d.ts +23 -0
  18. package/dist/parsing/functions/function_factory.d.ts.map +1 -1
  19. package/dist/parsing/functions/function_factory.js +44 -47
  20. package/dist/parsing/functions/function_factory.js.map +1 -1
  21. package/dist/parsing/functions/function_metadata.d.ts +57 -6
  22. package/dist/parsing/functions/function_metadata.d.ts.map +1 -1
  23. package/dist/parsing/functions/function_metadata.js +103 -153
  24. package/dist/parsing/functions/function_metadata.js.map +1 -1
  25. package/dist/parsing/functions/functions.d.ts.map +1 -1
  26. package/dist/parsing/functions/functions.js +37 -2
  27. package/dist/parsing/functions/functions.js.map +1 -1
  28. package/dist/parsing/functions/join.d.ts.map +1 -1
  29. package/dist/parsing/functions/join.js +21 -2
  30. package/dist/parsing/functions/join.js.map +1 -1
  31. package/dist/parsing/functions/predicate_function.d.ts +1 -0
  32. package/dist/parsing/functions/predicate_function.d.ts.map +1 -1
  33. package/dist/parsing/functions/predicate_function.js +3 -0
  34. package/dist/parsing/functions/predicate_function.js.map +1 -1
  35. package/dist/parsing/functions/predicate_sum.d.ts.map +1 -1
  36. package/dist/parsing/functions/predicate_sum.js +23 -2
  37. package/dist/parsing/functions/predicate_sum.js.map +1 -1
  38. package/dist/parsing/functions/rand.d.ts.map +1 -1
  39. package/dist/parsing/functions/rand.js +18 -2
  40. package/dist/parsing/functions/rand.js.map +1 -1
  41. package/dist/parsing/functions/range.d.ts.map +1 -1
  42. package/dist/parsing/functions/range.js +21 -2
  43. package/dist/parsing/functions/range.js.map +1 -1
  44. package/dist/parsing/functions/replace.d.ts.map +1 -1
  45. package/dist/parsing/functions/replace.js +22 -2
  46. package/dist/parsing/functions/replace.js.map +1 -1
  47. package/dist/parsing/functions/round.d.ts.map +1 -1
  48. package/dist/parsing/functions/round.js +20 -2
  49. package/dist/parsing/functions/round.js.map +1 -1
  50. package/dist/parsing/functions/size.d.ts.map +1 -1
  51. package/dist/parsing/functions/size.js +20 -2
  52. package/dist/parsing/functions/size.js.map +1 -1
  53. package/dist/parsing/functions/split.d.ts.map +1 -1
  54. package/dist/parsing/functions/split.js +21 -2
  55. package/dist/parsing/functions/split.js.map +1 -1
  56. package/dist/parsing/functions/stringify.d.ts.map +1 -1
  57. package/dist/parsing/functions/stringify.js +20 -2
  58. package/dist/parsing/functions/stringify.js.map +1 -1
  59. package/dist/parsing/functions/sum.d.ts.map +1 -1
  60. package/dist/parsing/functions/sum.js +20 -2
  61. package/dist/parsing/functions/sum.js.map +1 -1
  62. package/dist/parsing/functions/to_json.d.ts.map +1 -1
  63. package/dist/parsing/functions/to_json.js +20 -2
  64. package/dist/parsing/functions/to_json.js.map +1 -1
  65. package/dist/parsing/parser.d.ts.map +1 -1
  66. package/dist/parsing/parser.js +1 -2
  67. package/dist/parsing/parser.js.map +1 -1
  68. package/docs/flowquery.min.js +1 -1
  69. package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
  70. package/misc/apps/RAG/.env.example +14 -0
  71. package/misc/apps/RAG/README.md +0 -7
  72. package/misc/apps/RAG/package.json +16 -7
  73. package/misc/apps/RAG/public/index.html +18 -0
  74. package/misc/apps/RAG/src/App.css +42 -0
  75. package/misc/apps/RAG/src/App.tsx +50 -0
  76. package/misc/apps/RAG/src/components/ApiKeySettings.tsx +245 -0
  77. package/misc/apps/RAG/src/components/ChatContainer.css +67 -0
  78. package/misc/apps/RAG/src/components/ChatContainer.tsx +239 -0
  79. package/misc/apps/RAG/src/components/ChatInput.css +23 -0
  80. package/misc/apps/RAG/src/components/ChatInput.tsx +62 -0
  81. package/misc/apps/RAG/src/components/ChatMessage.css +136 -0
  82. package/misc/apps/RAG/src/components/ChatMessage.tsx +152 -0
  83. package/misc/apps/RAG/src/components/FlowQueryAgent.ts +390 -0
  84. package/misc/apps/RAG/src/components/FlowQueryRunner.css +104 -0
  85. package/misc/apps/RAG/src/components/FlowQueryRunner.tsx +332 -0
  86. package/misc/apps/RAG/src/components/index.ts +15 -0
  87. package/misc/apps/RAG/src/index.tsx +17 -0
  88. package/misc/apps/RAG/src/plugins/PluginRegistry.ts +136 -0
  89. package/misc/apps/RAG/src/plugins/README.md +139 -0
  90. package/misc/apps/RAG/src/plugins/index.ts +72 -0
  91. package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +79 -0
  92. package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +71 -0
  93. package/misc/apps/RAG/src/plugins/loaders/Llm.ts +441 -0
  94. package/misc/apps/RAG/src/plugins/loaders/MockData.ts +161 -0
  95. package/misc/apps/RAG/src/plugins/types.ts +52 -0
  96. package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +385 -0
  97. package/misc/apps/RAG/src/prompts/index.ts +10 -0
  98. package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +131 -0
  99. package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +203 -0
  100. package/misc/apps/RAG/src/utils/index.ts +9 -0
  101. package/misc/apps/RAG/tsconfig.json +4 -2
  102. package/misc/apps/RAG/webpack.config.js +23 -12
  103. package/package.json +7 -1
  104. package/src/extensibility.ts +9 -0
  105. package/src/parsing/functions/avg.ts +10 -0
  106. package/src/parsing/functions/collect.ts +10 -0
  107. package/src/parsing/functions/extensibility/index.ts +54 -0
  108. package/src/parsing/functions/function_factory.ts +51 -48
  109. package/src/parsing/functions/function_metadata.ts +132 -156
  110. package/src/parsing/functions/functions.ts +27 -0
  111. package/src/parsing/functions/join.ts +11 -0
  112. package/src/parsing/functions/predicate_function.ts +4 -0
  113. package/src/parsing/functions/predicate_sum.ts +13 -0
  114. package/src/parsing/functions/rand.ts +8 -0
  115. package/src/parsing/functions/range.ts +11 -0
  116. package/src/parsing/functions/replace.ts +12 -0
  117. package/src/parsing/functions/round.ts +10 -0
  118. package/src/parsing/functions/size.ts +10 -0
  119. package/src/parsing/functions/split.ts +11 -0
  120. package/src/parsing/functions/stringify.ts +10 -0
  121. package/src/parsing/functions/sum.ts +10 -0
  122. package/src/parsing/functions/to_json.ts +10 -0
  123. package/src/parsing/parser.ts +1 -2
  124. package/tests/parsing/function_plugins.test.ts +11 -11
  125. package/tsconfig.json +1 -0
  126. package/dist/parsing/functions/predicate_function_factory.d.ts +0 -6
  127. package/dist/parsing/functions/predicate_function_factory.d.ts.map +0 -1
  128. package/dist/parsing/functions/predicate_function_factory.js +0 -19
  129. package/dist/parsing/functions/predicate_function_factory.js.map +0 -1
  130. package/misc/apps/RAG/src/index.ts +0 -20
  131. package/src/parsing/functions/predicate_function_factory.ts +0 -15
package/README.md CHANGED
@@ -143,6 +143,188 @@ post {
143
143
  return data
144
144
  ```
145
145
 
146
+ ## Extending FlowQuery with Custom Functions
147
+
148
+ FlowQuery provides a plugin system that allows you to register custom functions. You can create scalar functions for synchronous operations or async providers for data loading.
149
+
150
+ ### Creating a Custom Scalar Function
151
+
152
+ To create a custom function, extend the `Function` base class and register it with FlowQuery:
153
+
154
+ ```javascript
155
+ const FlowQuery = require('flowquery').default;
156
+ const { Function } = require('flowquery');
157
+
158
+ // Create a custom function class
159
+ class UpperCase extends Function {
160
+ constructor() {
161
+ super("uppercase"); // Function name used in queries
162
+ this._expectedParameterCount = 1; // Number of required parameters
163
+ }
164
+
165
+ // Implement the value() method to define the function's behavior
166
+ value() {
167
+ const input = this.getChildren()[0].value(); // Get first parameter
168
+ return String(input).toUpperCase();
169
+ }
170
+ }
171
+
172
+ // Register the function with FlowQuery
173
+ FlowQuery.registerFunction("uppercase", () => new UpperCase());
174
+
175
+ // Now use it in queries!
176
+ async function main() {
177
+ const query = new FlowQuery("WITH 'hello world' AS greeting RETURN uppercase(greeting)");
178
+ await query.run();
179
+ console.log(query.results); // [ { expr0: 'HELLO WORLD' } ]
180
+ }
181
+ ```
182
+
183
+ ### Registering Functions with Metadata
184
+
185
+ For better documentation and LLM integration, you can register functions with full metadata using the `@FunctionDef` decorator pattern:
186
+
187
+ ```javascript
188
+ FlowQuery.registerFunction("uppercase", {
189
+ factory: () => new UpperCase(),
190
+ metadata: {
191
+ name: "uppercase",
192
+ description: "Converts a string to uppercase",
193
+ category: "string",
194
+ parameters: [
195
+ { name: "text", description: "String to convert", type: "string" }
196
+ ],
197
+ output: {
198
+ description: "Uppercase string",
199
+ type: "string",
200
+ example: "HELLO WORLD"
201
+ },
202
+ examples: ["WITH 'hello' AS s RETURN uppercase(s)"]
203
+ }
204
+ });
205
+ ```
206
+
207
+ ### TypeScript: Using the @FunctionDef Decorator
208
+
209
+ In TypeScript projects, you can use the `@FunctionDef` decorator directly on your function class. Import from the extensibility module for a clean API:
210
+
211
+ ```typescript
212
+ import { Function, FunctionDef } from "flowquery/extensibility";
213
+
214
+ @FunctionDef({
215
+ description: "Converts a string to uppercase",
216
+ category: "string",
217
+ parameters: [
218
+ { name: "text", description: "String to convert", type: "string" }
219
+ ],
220
+ output: {
221
+ description: "Uppercase string",
222
+ type: "string",
223
+ example: "HELLO WORLD"
224
+ },
225
+ examples: ["WITH 'hello' AS s RETURN uppercase(s)"]
226
+ })
227
+ class UpperCase extends Function {
228
+ constructor() {
229
+ super("uppercase");
230
+ this._expectedParameterCount = 1;
231
+ }
232
+
233
+ public value(): string {
234
+ const input = this.getChildren()[0].value();
235
+ return String(input).toUpperCase();
236
+ }
237
+ }
238
+ ```
239
+
240
+ The decorator automatically registers the function with the FlowQuery function factory.
241
+
242
+ The extensibility module (`flowquery/extensibility`) exports:
243
+ - `Function` - Base class for scalar functions
244
+ - `AggregateFunction` - Base class for aggregate functions (like `sum`, `avg`, `collect`)
245
+ - `PredicateFunction` - Base class for predicate functions (like list comprehensions)
246
+ - `FunctionDef` - Decorator for registering functions with metadata
247
+ - `ReducerElement` - Helper class for aggregate function state
248
+ - `FunctionFactory` - Direct access to the function factory for advanced usage
249
+
250
+ ### Creating Async Data Providers
251
+
252
+ For functions that fetch data asynchronously (used with `LOAD ... FROM`), register an async provider:
253
+
254
+ ```javascript
255
+ FlowQuery.registerAsyncProvider("fetchUsers", {
256
+ provider: async function* (endpoint) {
257
+ const response = await fetch(endpoint);
258
+ const data = await response.json();
259
+ for (const user of data) {
260
+ yield user; // Yield each item individually
261
+ }
262
+ },
263
+ metadata: {
264
+ name: "fetchUsers",
265
+ description: "Fetches user data from an API endpoint",
266
+ category: "data",
267
+ parameters: [
268
+ { name: "endpoint", description: "API URL to fetch users from", type: "string" }
269
+ ],
270
+ output: {
271
+ description: "User object",
272
+ type: "object",
273
+ properties: {
274
+ id: { description: "User ID", type: "number" },
275
+ name: { description: "User name", type: "string" }
276
+ }
277
+ },
278
+ examples: ["LOAD JSON FROM fetchUsers('https://api.example.com/users') AS user"]
279
+ }
280
+ });
281
+
282
+ // Use in a query
283
+ const query = new FlowQuery(`
284
+ LOAD JSON FROM fetchUsers('https://api.example.com/users') AS user
285
+ RETURN user.name, user.id
286
+ `);
287
+ await query.run();
288
+ ```
289
+
290
+ ### Listing and Querying Functions
291
+
292
+ You can discover available functions programmatically:
293
+
294
+ ```javascript
295
+ // List all functions
296
+ const allFunctions = FlowQuery.listFunctions();
297
+
298
+ // Filter by category
299
+ const stringFunctions = FlowQuery.listFunctions({ category: "string" });
300
+ const asyncFunctions = FlowQuery.listFunctions({ asyncOnly: true });
301
+
302
+ // Get metadata for a specific function
303
+ const sumMetadata = FlowQuery.getFunctionMetadata("sum");
304
+ console.log(sumMetadata.description); // "Calculates the sum of numeric values..."
305
+ ```
306
+
307
+ You can also query functions from within FlowQuery itself:
308
+
309
+ ```cypher
310
+ // List all available functions
311
+ WITH functions() AS funcs
312
+ UNWIND funcs AS f
313
+ RETURN f.name, f.description, f.category
314
+ ```
315
+
316
+ ### Unregistering Functions
317
+
318
+ To remove a registered function:
319
+
320
+ ```javascript
321
+ // Unregister a sync function
322
+ FlowQuery.unregisterFunction("uppercase");
323
+
324
+ // Unregister an async provider
325
+ FlowQuery.unregisterAsyncProvider("fetchUsers");
326
+ ```
327
+
146
328
  ## Contributing
147
329
 
148
330
  This project welcomes contributions and suggestions. Most contributions require you to agree to a
@@ -0,0 +1,9 @@
1
+ /**
2
+ * FlowQuery Extensibility API
3
+ *
4
+ * This module re-exports the extensibility API from the parsing/functions/extensibility module.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export * from "./parsing/functions/extensibility";
9
+ //# sourceMappingURL=extensibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensibility.d.ts","sourceRoot":"","sources":["../src/extensibility.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,mCAAmC,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * FlowQuery Extensibility API
4
+ *
5
+ * This module re-exports the extensibility API from the parsing/functions/extensibility module.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ __exportStar(require("./parsing/functions/extensibility"), exports);
25
+ //# sourceMappingURL=extensibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensibility.js","sourceRoot":"","sources":["../src/extensibility.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;AAEH,oEAAkD"}