flowquery 1.0.3 → 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.
- package/README.md +182 -0
- package/dist/compute/runner.d.ts +81 -0
- package/dist/compute/runner.d.ts.map +1 -0
- package/dist/extensibility.d.ts +9 -0
- package/dist/extensibility.d.ts.map +1 -0
- package/dist/extensibility.js +25 -0
- package/dist/extensibility.js.map +1 -0
- package/dist/flowquery.min.js +1 -1
- package/dist/index.browser.d.ts +10 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.d.ts +14 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/io/command_line.d.ts +28 -0
- package/dist/io/command_line.d.ts.map +1 -0
- package/dist/parsing/alias.d.ts +10 -0
- package/dist/parsing/alias.d.ts.map +1 -0
- package/dist/parsing/alias_option.d.ts +6 -0
- package/dist/parsing/alias_option.d.ts.map +1 -0
- package/dist/parsing/ast_node.d.ts +100 -0
- package/dist/parsing/ast_node.d.ts.map +1 -0
- package/dist/parsing/base_parser.d.ts +49 -0
- package/dist/parsing/base_parser.d.ts.map +1 -0
- package/dist/parsing/components/csv.d.ts +6 -0
- package/dist/parsing/components/csv.d.ts.map +1 -0
- package/dist/parsing/components/from.d.ts +7 -0
- package/dist/parsing/components/from.d.ts.map +1 -0
- package/dist/parsing/components/headers.d.ts +7 -0
- package/dist/parsing/components/headers.d.ts.map +1 -0
- package/dist/parsing/components/json.d.ts +6 -0
- package/dist/parsing/components/json.d.ts.map +1 -0
- package/dist/parsing/components/null.d.ts +6 -0
- package/dist/parsing/components/null.d.ts.map +1 -0
- package/dist/parsing/components/post.d.ts +6 -0
- package/dist/parsing/components/post.d.ts.map +1 -0
- package/dist/parsing/components/text.d.ts +6 -0
- package/dist/parsing/components/text.d.ts.map +1 -0
- package/dist/parsing/context.d.ts +38 -0
- package/dist/parsing/context.d.ts.map +1 -0
- package/dist/parsing/data_structures/associative_array.d.ts +28 -0
- package/dist/parsing/data_structures/associative_array.d.ts.map +1 -0
- package/dist/parsing/data_structures/json_array.d.ts +26 -0
- package/dist/parsing/data_structures/json_array.d.ts.map +1 -0
- package/dist/parsing/data_structures/key_value_pair.d.ts +25 -0
- package/dist/parsing/data_structures/key_value_pair.d.ts.map +1 -0
- package/dist/parsing/data_structures/lookup.d.ts +25 -0
- package/dist/parsing/data_structures/lookup.d.ts.map +1 -0
- package/dist/parsing/data_structures/range_lookup.d.ts +14 -0
- package/dist/parsing/data_structures/range_lookup.d.ts.map +1 -0
- package/dist/parsing/expressions/expression.d.ts +53 -0
- package/dist/parsing/expressions/expression.d.ts.map +1 -0
- package/dist/parsing/expressions/f_string.d.ts +21 -0
- package/dist/parsing/expressions/f_string.d.ts.map +1 -0
- package/dist/parsing/expressions/identifier.d.ts +17 -0
- package/dist/parsing/expressions/identifier.d.ts.map +1 -0
- package/dist/parsing/expressions/number.d.ts +25 -0
- package/dist/parsing/expressions/number.d.ts.map +1 -0
- package/dist/parsing/expressions/operator.d.ts +79 -0
- package/dist/parsing/expressions/operator.d.ts.map +1 -0
- package/dist/parsing/expressions/reference.d.ts +29 -0
- package/dist/parsing/expressions/reference.d.ts.map +1 -0
- package/dist/parsing/expressions/string.d.ts +23 -0
- package/dist/parsing/expressions/string.d.ts.map +1 -0
- package/dist/parsing/functions/aggregate_function.d.ts +42 -0
- package/dist/parsing/functions/aggregate_function.d.ts.map +1 -0
- package/dist/parsing/functions/async_function.d.ts +52 -0
- package/dist/parsing/functions/async_function.d.ts.map +1 -0
- package/dist/parsing/functions/avg.d.ts +15 -0
- package/dist/parsing/functions/avg.d.ts.map +1 -0
- package/dist/parsing/functions/avg.js +20 -2
- package/dist/parsing/functions/avg.js.map +1 -1
- package/dist/parsing/functions/collect.d.ts +21 -0
- package/dist/parsing/functions/collect.d.ts.map +1 -0
- package/dist/parsing/functions/collect.js +20 -2
- package/dist/parsing/functions/collect.js.map +1 -1
- package/dist/parsing/functions/extensibility/index.d.ts +37 -0
- package/dist/parsing/functions/extensibility/index.d.ts.map +1 -0
- package/dist/parsing/functions/extensibility/index.js +50 -0
- package/dist/parsing/functions/extensibility/index.js.map +1 -0
- package/dist/parsing/functions/function.d.ts +36 -0
- package/dist/parsing/functions/function.d.ts.map +1 -0
- package/dist/parsing/functions/function_factory.d.ts +174 -0
- package/dist/parsing/functions/function_factory.d.ts.map +1 -0
- package/dist/parsing/functions/function_factory.js +44 -47
- package/dist/parsing/functions/function_factory.js.map +1 -1
- package/dist/parsing/functions/function_metadata.d.ts +134 -0
- package/dist/parsing/functions/function_metadata.d.ts.map +1 -0
- package/dist/parsing/functions/function_metadata.js +103 -153
- package/dist/parsing/functions/function_metadata.js.map +1 -1
- package/dist/parsing/functions/functions.d.ts +21 -0
- package/dist/parsing/functions/functions.d.ts.map +1 -0
- package/dist/parsing/functions/functions.js +37 -2
- package/dist/parsing/functions/functions.js.map +1 -1
- package/dist/parsing/functions/join.d.ts +9 -0
- package/dist/parsing/functions/join.d.ts.map +1 -0
- package/dist/parsing/functions/join.js +21 -2
- package/dist/parsing/functions/join.js.map +1 -1
- package/dist/parsing/functions/predicate_function.d.ts +19 -0
- package/dist/parsing/functions/predicate_function.d.ts.map +1 -0
- package/dist/parsing/functions/predicate_function.js +3 -0
- package/dist/parsing/functions/predicate_function.js.map +1 -1
- package/dist/parsing/functions/predicate_sum.d.ts +7 -0
- package/dist/parsing/functions/predicate_sum.d.ts.map +1 -0
- package/dist/parsing/functions/predicate_sum.js +23 -2
- package/dist/parsing/functions/predicate_sum.js.map +1 -1
- package/dist/parsing/functions/rand.d.ts +7 -0
- package/dist/parsing/functions/rand.d.ts.map +1 -0
- package/dist/parsing/functions/rand.js +18 -2
- package/dist/parsing/functions/rand.js.map +1 -1
- package/dist/parsing/functions/range.d.ts +7 -0
- package/dist/parsing/functions/range.d.ts.map +1 -0
- package/dist/parsing/functions/range.js +21 -2
- package/dist/parsing/functions/range.js.map +1 -1
- package/dist/parsing/functions/reducer_element.d.ts +6 -0
- package/dist/parsing/functions/reducer_element.d.ts.map +1 -0
- package/dist/parsing/functions/replace.d.ts +7 -0
- package/dist/parsing/functions/replace.d.ts.map +1 -0
- package/dist/parsing/functions/replace.js +22 -2
- package/dist/parsing/functions/replace.js.map +1 -1
- package/dist/parsing/functions/round.d.ts +7 -0
- package/dist/parsing/functions/round.d.ts.map +1 -0
- package/dist/parsing/functions/round.js +20 -2
- package/dist/parsing/functions/round.js.map +1 -1
- package/dist/parsing/functions/size.d.ts +7 -0
- package/dist/parsing/functions/size.d.ts.map +1 -0
- package/dist/parsing/functions/size.js +20 -2
- package/dist/parsing/functions/size.js.map +1 -1
- package/dist/parsing/functions/split.d.ts +9 -0
- package/dist/parsing/functions/split.d.ts.map +1 -0
- package/dist/parsing/functions/split.js +21 -2
- package/dist/parsing/functions/split.js.map +1 -1
- package/dist/parsing/functions/stringify.d.ts +9 -0
- package/dist/parsing/functions/stringify.d.ts.map +1 -0
- package/dist/parsing/functions/stringify.js +20 -2
- package/dist/parsing/functions/stringify.js.map +1 -1
- package/dist/parsing/functions/sum.d.ts +14 -0
- package/dist/parsing/functions/sum.d.ts.map +1 -0
- package/dist/parsing/functions/sum.js +20 -2
- package/dist/parsing/functions/sum.js.map +1 -1
- package/dist/parsing/functions/to_json.d.ts +7 -0
- package/dist/parsing/functions/to_json.d.ts.map +1 -0
- package/dist/parsing/functions/to_json.js +20 -2
- package/dist/parsing/functions/to_json.js.map +1 -1
- package/dist/parsing/functions/value_holder.d.ts +8 -0
- package/dist/parsing/functions/value_holder.d.ts.map +1 -0
- package/dist/parsing/logic/case.d.ts +7 -0
- package/dist/parsing/logic/case.d.ts.map +1 -0
- package/dist/parsing/logic/else.d.ts +7 -0
- package/dist/parsing/logic/else.d.ts.map +1 -0
- package/dist/parsing/logic/end.d.ts +6 -0
- package/dist/parsing/logic/end.d.ts.map +1 -0
- package/dist/parsing/logic/then.d.ts +7 -0
- package/dist/parsing/logic/then.d.ts.map +1 -0
- package/dist/parsing/logic/when.d.ts +7 -0
- package/dist/parsing/logic/when.d.ts.map +1 -0
- package/dist/parsing/operations/aggregated_return.d.ts +8 -0
- package/dist/parsing/operations/aggregated_return.d.ts.map +1 -0
- package/dist/parsing/operations/aggregated_with.d.ts +8 -0
- package/dist/parsing/operations/aggregated_with.d.ts.map +1 -0
- package/dist/parsing/operations/group_by.d.ts +35 -0
- package/dist/parsing/operations/group_by.d.ts.map +1 -0
- package/dist/parsing/operations/limit.d.ts +10 -0
- package/dist/parsing/operations/limit.d.ts.map +1 -0
- package/dist/parsing/operations/load.d.ts +48 -0
- package/dist/parsing/operations/load.d.ts.map +1 -0
- package/dist/parsing/operations/operation.d.ts +39 -0
- package/dist/parsing/operations/operation.d.ts.map +1 -0
- package/dist/parsing/operations/projection.d.ts +8 -0
- package/dist/parsing/operations/projection.d.ts.map +1 -0
- package/dist/parsing/operations/return.d.ts +23 -0
- package/dist/parsing/operations/return.d.ts.map +1 -0
- package/dist/parsing/operations/unwind.d.ts +12 -0
- package/dist/parsing/operations/unwind.d.ts.map +1 -0
- package/dist/parsing/operations/where.d.ts +26 -0
- package/dist/parsing/operations/where.d.ts.map +1 -0
- package/dist/parsing/operations/with.d.ts +17 -0
- package/dist/parsing/operations/with.d.ts.map +1 -0
- package/dist/parsing/parser.d.ts +66 -0
- package/dist/parsing/parser.d.ts.map +1 -0
- package/dist/parsing/parser.js +2 -3
- package/dist/parsing/parser.js.map +1 -1
- package/dist/parsing/token_to_node.d.ts +7 -0
- package/dist/parsing/token_to_node.d.ts.map +1 -0
- package/dist/tokenization/keyword.d.ts +43 -0
- package/dist/tokenization/keyword.d.ts.map +1 -0
- package/dist/tokenization/operator.d.ts +22 -0
- package/dist/tokenization/operator.d.ts.map +1 -0
- package/dist/tokenization/string_walker.d.ts +55 -0
- package/dist/tokenization/string_walker.d.ts.map +1 -0
- package/dist/tokenization/symbol.d.ts +15 -0
- package/dist/tokenization/symbol.d.ts.map +1 -0
- package/dist/tokenization/token.d.ts +176 -0
- package/dist/tokenization/token.d.ts.map +1 -0
- package/dist/tokenization/token_mapper.d.ts +40 -0
- package/dist/tokenization/token_mapper.d.ts.map +1 -0
- package/dist/tokenization/token_type.d.ts +16 -0
- package/dist/tokenization/token_type.d.ts.map +1 -0
- package/dist/tokenization/tokenizer.d.ts +45 -0
- package/dist/tokenization/tokenizer.d.ts.map +1 -0
- package/dist/tokenization/trie.d.ts +41 -0
- package/dist/tokenization/trie.d.ts.map +1 -0
- package/dist/utils/object_utils.d.ts +15 -0
- package/dist/utils/object_utils.d.ts.map +1 -0
- package/dist/utils/string_utils.d.ts +51 -0
- package/dist/utils/string_utils.d.ts.map +1 -0
- package/docs/flowquery.min.js +1 -1
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/misc/apps/RAG/.env.example +14 -0
- package/misc/apps/RAG/README.md +0 -7
- package/misc/apps/RAG/package.json +16 -7
- package/misc/apps/RAG/public/index.html +18 -0
- package/misc/apps/RAG/src/App.css +42 -0
- package/misc/apps/RAG/src/App.tsx +50 -0
- package/misc/apps/RAG/src/components/ApiKeySettings.tsx +245 -0
- package/misc/apps/RAG/src/components/ChatContainer.css +67 -0
- package/misc/apps/RAG/src/components/ChatContainer.tsx +239 -0
- package/misc/apps/RAG/src/components/ChatInput.css +23 -0
- package/misc/apps/RAG/src/components/ChatInput.tsx +62 -0
- package/misc/apps/RAG/src/components/ChatMessage.css +136 -0
- package/misc/apps/RAG/src/components/ChatMessage.tsx +152 -0
- package/misc/apps/RAG/src/components/FlowQueryAgent.ts +390 -0
- package/misc/apps/RAG/src/components/FlowQueryRunner.css +104 -0
- package/misc/apps/RAG/src/components/FlowQueryRunner.tsx +332 -0
- package/misc/apps/RAG/src/components/index.ts +15 -0
- package/misc/apps/RAG/src/index.tsx +17 -0
- package/misc/apps/RAG/src/plugins/PluginRegistry.ts +136 -0
- package/misc/apps/RAG/src/plugins/README.md +139 -0
- package/misc/apps/RAG/src/plugins/index.ts +72 -0
- package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +79 -0
- package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +71 -0
- package/misc/apps/RAG/src/plugins/loaders/Llm.ts +441 -0
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +161 -0
- package/misc/apps/RAG/src/plugins/types.ts +52 -0
- package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +385 -0
- package/misc/apps/RAG/src/prompts/index.ts +10 -0
- package/misc/apps/RAG/src/utils/FlowQueryExecutor.ts +131 -0
- package/misc/apps/RAG/src/utils/FlowQueryExtractor.ts +203 -0
- package/misc/apps/RAG/src/utils/index.ts +9 -0
- package/misc/apps/RAG/tsconfig.json +4 -2
- package/misc/apps/RAG/webpack.config.js +23 -12
- package/package.json +7 -1
- package/src/extensibility.ts +9 -0
- package/src/parsing/functions/avg.ts +10 -0
- package/src/parsing/functions/collect.ts +10 -0
- package/src/parsing/functions/extensibility/index.ts +54 -0
- package/src/parsing/functions/function_factory.ts +51 -48
- package/src/parsing/functions/function_metadata.ts +132 -156
- package/src/parsing/functions/functions.ts +27 -0
- package/src/parsing/functions/join.ts +11 -0
- package/src/parsing/functions/predicate_function.ts +4 -0
- package/src/parsing/functions/predicate_sum.ts +13 -0
- package/src/parsing/functions/rand.ts +8 -0
- package/src/parsing/functions/range.ts +11 -0
- package/src/parsing/functions/replace.ts +12 -0
- package/src/parsing/functions/round.ts +10 -0
- package/src/parsing/functions/size.ts +10 -0
- package/src/parsing/functions/split.ts +11 -0
- package/src/parsing/functions/stringify.ts +10 -0
- package/src/parsing/functions/sum.ts +10 -0
- package/src/parsing/functions/to_json.ts +10 -0
- package/src/parsing/parser.ts +2 -3
- package/tests/parsing/function_plugins.test.ts +11 -11
- package/tsconfig.json +4 -1
- package/dist/parsing/functions/predicate_function_factory.js +0 -19
- package/dist/parsing/functions/predicate_function_factory.js.map +0 -1
- package/misc/apps/RAG/src/index.ts +0 -20
- 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,81 @@
|
|
|
1
|
+
import { FunctionCreator, AsyncDataProvider } from "../parsing/functions/function_factory";
|
|
2
|
+
import { FunctionMetadata, RegisterFunctionOptions, RegisterAsyncProviderOptions } from "../parsing/functions/function_metadata";
|
|
3
|
+
import Function from "../parsing/functions/function";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a FlowQuery statement and retrieves the results.
|
|
6
|
+
*
|
|
7
|
+
* The Runner class parses a FlowQuery statement into an AST and executes it,
|
|
8
|
+
* managing the execution flow from the first operation to the final return statement.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const runner = new Runner("WITH 1 as x RETURN x");
|
|
13
|
+
* await runner.run();
|
|
14
|
+
* console.log(runner.results); // [{ x: 1 }]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare class Runner {
|
|
18
|
+
private first;
|
|
19
|
+
private last;
|
|
20
|
+
/**
|
|
21
|
+
* Register a synchronous plugin function.
|
|
22
|
+
* Added dynamically in index.browser.ts / index.node.ts
|
|
23
|
+
*/
|
|
24
|
+
static registerFunction: (name: string, factoryOrOptions: FunctionCreator | RegisterFunctionOptions) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Unregister a synchronous plugin function.
|
|
27
|
+
* Added dynamically in index.browser.ts / index.node.ts
|
|
28
|
+
*/
|
|
29
|
+
static unregisterFunction: (name: string) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Register an async data provider function for use in LOAD operations.
|
|
32
|
+
* Added dynamically in index.browser.ts / index.node.ts
|
|
33
|
+
*/
|
|
34
|
+
static registerAsyncProvider: (name: string, providerOrOptions: AsyncDataProvider | RegisterAsyncProviderOptions) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Unregister an async data provider function.
|
|
37
|
+
* Added dynamically in index.browser.ts / index.node.ts
|
|
38
|
+
*/
|
|
39
|
+
static unregisterAsyncProvider: (name: string) => void;
|
|
40
|
+
/**
|
|
41
|
+
* List all registered functions with their metadata.
|
|
42
|
+
* Added dynamically in index.browser.ts / index.node.ts
|
|
43
|
+
*/
|
|
44
|
+
static listFunctions: (options?: {
|
|
45
|
+
category?: string;
|
|
46
|
+
asyncOnly?: boolean;
|
|
47
|
+
syncOnly?: boolean;
|
|
48
|
+
}) => FunctionMetadata[];
|
|
49
|
+
/**
|
|
50
|
+
* Get metadata for a specific function.
|
|
51
|
+
* Added dynamically in index.browser.ts / index.node.ts
|
|
52
|
+
*/
|
|
53
|
+
static getFunctionMetadata: (name: string) => FunctionMetadata | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Base Function class for creating custom plugin functions.
|
|
56
|
+
* Added dynamically in index.browser.ts / index.node.ts
|
|
57
|
+
*/
|
|
58
|
+
static Function: typeof Function;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new Runner instance and parses the FlowQuery statement.
|
|
61
|
+
*
|
|
62
|
+
* @param statement - The FlowQuery statement to execute
|
|
63
|
+
* @throws {Error} If the statement is null, empty, or contains syntax errors
|
|
64
|
+
*/
|
|
65
|
+
constructor(statement?: string | null);
|
|
66
|
+
/**
|
|
67
|
+
* Executes the parsed FlowQuery statement.
|
|
68
|
+
*
|
|
69
|
+
* @returns A promise that resolves when execution completes
|
|
70
|
+
* @throws {Error} If an error occurs during execution
|
|
71
|
+
*/
|
|
72
|
+
run(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the results from the executed statement.
|
|
75
|
+
*
|
|
76
|
+
* @returns The results from the last operation (typically a RETURN statement)
|
|
77
|
+
*/
|
|
78
|
+
get results(): any;
|
|
79
|
+
}
|
|
80
|
+
export default Runner;
|
|
81
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/compute/runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AACjI,OAAO,QAAQ,MAAM,+BAA+B,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,cAAM,MAAM;IACR,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,IAAI,CAAY;IAExB;;;OAGG;IACH,MAAM,CAAC,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,eAAe,GAAG,uBAAuB,KAAK,IAAI,CAAC;IAE7G;;;OAGG;IACH,MAAM,CAAC,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAElD;;;OAGG;IACH,MAAM,CAAC,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,4BAA4B,KAAK,IAAI,CAAC;IAE1H;;;OAGG;IACH,MAAM,CAAC,uBAAuB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAEvD;;;OAGG;IACH,MAAM,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,gBAAgB,EAAE,CAAC;IAEvH;;;OAGG;IACH,MAAM,CAAC,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,GAAG,SAAS,CAAC;IAE3E;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,OAAO,QAAQ,CAAC;IAEjC;;;;;OAKG;gBACS,SAAS,GAAE,MAAM,GAAG,IAAW;IAU3C;;;;;OAKG;IACU,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAYjC;;;;OAIG;IACH,IAAW,OAAO,IAAI,GAAG,CAExB;CACJ;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -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"}
|