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.
- package/README.md +74 -0
- package/dist/compute/runner.d.ts +1 -22
- package/dist/compute/runner.d.ts.map +1 -1
- package/dist/compute/runner.js.map +1 -1
- package/dist/extensibility.d.ts +35 -0
- package/dist/extensibility.d.ts.map +1 -0
- package/dist/extensibility.js +49 -0
- package/dist/extensibility.js.map +1 -0
- package/dist/flowquery.min.js +1 -1
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +0 -80
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.d.ts +3 -3
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +0 -80
- package/dist/index.node.js.map +1 -1
- package/dist/parsing/functions/avg.d.ts.map +1 -1
- package/dist/parsing/functions/avg.js +20 -2
- package/dist/parsing/functions/avg.js.map +1 -1
- package/dist/parsing/functions/collect.d.ts.map +1 -1
- package/dist/parsing/functions/collect.js +20 -2
- package/dist/parsing/functions/collect.js.map +1 -1
- package/dist/parsing/functions/function_factory.d.ts +26 -80
- package/dist/parsing/functions/function_factory.d.ts.map +1 -1
- package/dist/parsing/functions/function_factory.js +46 -168
- package/dist/parsing/functions/function_factory.js.map +1 -1
- package/dist/parsing/functions/function_metadata.d.ts +81 -20
- package/dist/parsing/functions/function_metadata.d.ts.map +1 -1
- package/dist/parsing/functions/function_metadata.js +154 -152
- package/dist/parsing/functions/function_metadata.js.map +1 -1
- package/dist/parsing/functions/functions.d.ts.map +1 -1
- package/dist/parsing/functions/functions.js +37 -2
- package/dist/parsing/functions/functions.js.map +1 -1
- package/dist/parsing/functions/join.d.ts.map +1 -1
- 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 +1 -0
- package/dist/parsing/functions/predicate_function.d.ts.map +1 -1
- 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.map +1 -1
- 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.map +1 -1
- package/dist/parsing/functions/rand.js +18 -2
- package/dist/parsing/functions/rand.js.map +1 -1
- package/dist/parsing/functions/range.d.ts.map +1 -1
- package/dist/parsing/functions/range.js +21 -2
- package/dist/parsing/functions/range.js.map +1 -1
- package/dist/parsing/functions/replace.d.ts.map +1 -1
- package/dist/parsing/functions/replace.js +22 -2
- package/dist/parsing/functions/replace.js.map +1 -1
- package/dist/parsing/functions/round.d.ts.map +1 -1
- package/dist/parsing/functions/round.js +20 -2
- package/dist/parsing/functions/round.js.map +1 -1
- package/dist/parsing/functions/size.d.ts.map +1 -1
- package/dist/parsing/functions/size.js +20 -2
- package/dist/parsing/functions/size.js.map +1 -1
- package/dist/parsing/functions/split.d.ts.map +1 -1
- package/dist/parsing/functions/split.js +21 -2
- package/dist/parsing/functions/split.js.map +1 -1
- package/dist/parsing/functions/stringify.d.ts.map +1 -1
- package/dist/parsing/functions/stringify.js +20 -2
- package/dist/parsing/functions/stringify.js.map +1 -1
- package/dist/parsing/functions/sum.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/parsing/functions/to_json.js +20 -2
- package/dist/parsing/functions/to_json.js.map +1 -1
- package/dist/parsing/parser.d.ts.map +1 -1
- package/dist/parsing/parser.js +1 -2
- package/dist/parsing/parser.js.map +1 -1
- 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/README.md +139 -0
- package/misc/apps/RAG/src/plugins/index.ts +68 -0
- package/misc/apps/RAG/src/plugins/loaders/CatFacts.ts +75 -0
- package/misc/apps/RAG/src/plugins/loaders/FetchJson.ts +67 -0
- package/misc/apps/RAG/src/plugins/loaders/Llm.ts +437 -0
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +151 -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/compute/runner.ts +1 -26
- package/src/extensibility.ts +45 -0
- package/src/index.browser.ts +2 -88
- package/src/index.node.ts +3 -92
- package/src/parsing/functions/avg.ts +10 -0
- package/src/parsing/functions/collect.ts +10 -0
- package/src/parsing/functions/function_factory.ts +56 -194
- package/src/parsing/functions/function_metadata.ts +187 -168
- 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 +1 -2
- package/tests/extensibility.test.ts +563 -0
- package/tsconfig.json +1 -0
- package/dist/parsing/functions/predicate_function_factory.d.ts +0 -6
- package/dist/parsing/functions/predicate_function_factory.d.ts.map +0 -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/tests/parsing/function_plugins.test.ts +0 -369
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Category types for functions.
|
|
3
|
+
* Core categories: scalar, aggregate, predicate, async
|
|
4
|
+
* Additional categories for organization: string, math, data, etc.
|
|
5
|
+
*/
|
|
6
|
+
export type FunctionCategory = "scalar" | "aggregate" | "predicate" | "async" | string;
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
* Schema definition for function arguments and outputs.
|
|
3
10
|
* Compatible with JSON Schema for LLM consumption.
|
|
@@ -47,192 +54,204 @@ export interface FunctionMetadata {
|
|
|
47
54
|
name: string;
|
|
48
55
|
/** Human-readable description of what the function does */
|
|
49
56
|
description: string;
|
|
50
|
-
/** Category
|
|
51
|
-
category
|
|
57
|
+
/** Category that determines function type and behavior */
|
|
58
|
+
category: FunctionCategory;
|
|
52
59
|
/** Array of parameter schemas */
|
|
53
60
|
parameters: ParameterSchema[];
|
|
54
61
|
/** Output schema */
|
|
55
62
|
output: OutputSchema;
|
|
56
63
|
/** Example usage in FlowQuery syntax */
|
|
57
64
|
examples?: string[];
|
|
58
|
-
/** Whether this is an async data provider for LOAD operations */
|
|
59
|
-
isAsyncProvider?: boolean;
|
|
60
65
|
/** Additional notes or caveats */
|
|
61
66
|
notes?: string;
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
/**
|
|
65
|
-
*
|
|
70
|
+
* Registry for function metadata collected via decorators.
|
|
71
|
+
*/
|
|
72
|
+
const functionMetadataRegistry: Map<string, FunctionMetadata> = new Map();
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Registry for function factories collected via decorators.
|
|
76
|
+
* Allows @FunctionDef to automatically register functions for instantiation.
|
|
77
|
+
*/
|
|
78
|
+
const functionFactoryRegistry: Map<string, () => any> = new Map();
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Type for async data provider functions used in LOAD operations.
|
|
82
|
+
*/
|
|
83
|
+
export type AsyncDataProvider = (...args: any[]) => AsyncGenerator<any, void, unknown> | Promise<any>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Registry for async data providers collected via decorators.
|
|
87
|
+
*/
|
|
88
|
+
const asyncProviderRegistry: Map<string, AsyncDataProvider> = new Map();
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Decorator options - metadata without the name (derived from class).
|
|
92
|
+
*/
|
|
93
|
+
export type FunctionDefOptions = Omit<FunctionMetadata, 'name'>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Class decorator that registers function metadata.
|
|
97
|
+
* The function name is derived from the class's constructor call to super() for regular functions,
|
|
98
|
+
* or from the class name for async providers.
|
|
99
|
+
*
|
|
100
|
+
* For async providers (category: "async"), the class must have a `fetch` method that returns
|
|
101
|
+
* an AsyncGenerator. The function name is derived from the class name (removing 'Loader' suffix
|
|
102
|
+
* if present) and converted to camelCase.
|
|
103
|
+
*
|
|
104
|
+
* @param options - Function metadata (excluding name)
|
|
105
|
+
* @returns Class decorator
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // Regular function
|
|
110
|
+
* @FunctionDef({
|
|
111
|
+
* description: "Calculates the sum of numeric values",
|
|
112
|
+
* category: "aggregate",
|
|
113
|
+
* parameters: [{ name: "value", description: "Numeric value to sum", type: "number" }],
|
|
114
|
+
* output: { description: "Sum of all values", type: "number", example: 150 },
|
|
115
|
+
* examples: ["WITH [1, 2, 3] AS nums UNWIND nums AS n RETURN sum(n)"]
|
|
116
|
+
* })
|
|
117
|
+
* class Sum extends AggregateFunction { ... }
|
|
118
|
+
*
|
|
119
|
+
* // Async data provider
|
|
120
|
+
* @FunctionDef({
|
|
121
|
+
* description: "Fetches random cat facts from the Cat Facts API",
|
|
122
|
+
* category: "async",
|
|
123
|
+
* parameters: [{ name: "count", description: "Number of facts", type: "number", required: false, default: 1 }],
|
|
124
|
+
* output: { description: "Cat fact object", type: "object" },
|
|
125
|
+
* examples: ["LOAD JSON FROM catFacts(5) AS fact RETURN fact.text"]
|
|
126
|
+
* })
|
|
127
|
+
* class CatFactsLoader {
|
|
128
|
+
* async *fetch(count: number = 1): AsyncGenerator<any> { ... }
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function FunctionDef(options: FunctionDefOptions) {
|
|
133
|
+
return function <T extends new (...args: any[]) => any>(constructor: T): T {
|
|
134
|
+
// Handle async providers differently
|
|
135
|
+
if (options.category === 'async') {
|
|
136
|
+
// Derive the function name from the class name
|
|
137
|
+
// Remove 'Loader' suffix if present and convert to lowercase for registry
|
|
138
|
+
let baseName = constructor.name;
|
|
139
|
+
if (baseName.endsWith('Loader')) {
|
|
140
|
+
baseName = baseName.slice(0, -6);
|
|
141
|
+
}
|
|
142
|
+
// Keep display name in camelCase, but use lowercase for registry keys
|
|
143
|
+
const displayName = baseName.charAt(0).toLowerCase() + baseName.slice(1);
|
|
144
|
+
const registryKey = displayName.toLowerCase();
|
|
145
|
+
|
|
146
|
+
// Register metadata with display name
|
|
147
|
+
const metadata: FunctionMetadata = {
|
|
148
|
+
name: displayName,
|
|
149
|
+
...options
|
|
150
|
+
};
|
|
151
|
+
functionMetadataRegistry.set(registryKey, metadata);
|
|
152
|
+
|
|
153
|
+
// Register the async provider (wraps the class's fetch method)
|
|
154
|
+
asyncProviderRegistry.set(registryKey, (...args: any[]) => new constructor().fetch(...args));
|
|
155
|
+
|
|
156
|
+
return constructor;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Regular function handling
|
|
160
|
+
// Create an instance to get the function name from super() call
|
|
161
|
+
const instance = new constructor();
|
|
162
|
+
const baseName = instance.name?.toLowerCase() || constructor.name.toLowerCase();
|
|
163
|
+
|
|
164
|
+
// Use category-qualified key to avoid collisions (e.g., sum vs sum:predicate)
|
|
165
|
+
// but store the display name without the qualifier
|
|
166
|
+
const displayName = baseName.includes(':') ? baseName.split(':')[0] : baseName;
|
|
167
|
+
const registryKey = options.category ? `${displayName}:${options.category}` : displayName;
|
|
168
|
+
|
|
169
|
+
// Register metadata with display name but category-qualified key
|
|
170
|
+
const metadata: FunctionMetadata = {
|
|
171
|
+
name: displayName,
|
|
172
|
+
...options
|
|
173
|
+
};
|
|
174
|
+
functionMetadataRegistry.set(registryKey, metadata);
|
|
175
|
+
|
|
176
|
+
// Register factory function for automatic instantiation
|
|
177
|
+
// Only register to the simple name if no collision exists (predicate functions use qualified keys)
|
|
178
|
+
if (options.category !== 'predicate') {
|
|
179
|
+
functionFactoryRegistry.set(displayName, () => new constructor());
|
|
180
|
+
}
|
|
181
|
+
functionFactoryRegistry.set(registryKey, () => new constructor());
|
|
182
|
+
|
|
183
|
+
return constructor;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Gets all registered function metadata from decorators.
|
|
189
|
+
*
|
|
190
|
+
* @returns Array of function metadata
|
|
66
191
|
*/
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
factory: () => any;
|
|
70
|
-
/** Function metadata for documentation */
|
|
71
|
-
metadata: FunctionMetadata;
|
|
192
|
+
export function getRegisteredFunctionMetadata(): FunctionMetadata[] {
|
|
193
|
+
return Array.from(functionMetadataRegistry.values());
|
|
72
194
|
}
|
|
73
195
|
|
|
74
196
|
/**
|
|
75
|
-
*
|
|
197
|
+
* Gets a registered function factory by name.
|
|
198
|
+
* Used by FunctionFactory to instantiate decorator-registered functions.
|
|
199
|
+
*
|
|
200
|
+
* @param name - Function name (case-insensitive)
|
|
201
|
+
* @param category - Optional category to disambiguate (e.g., 'predicate')
|
|
202
|
+
* @returns Factory function or undefined
|
|
76
203
|
*/
|
|
77
|
-
export
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
204
|
+
export function getRegisteredFunctionFactory(name: string, category?: string): (() => any) | undefined {
|
|
205
|
+
const lowerName = name.toLowerCase();
|
|
206
|
+
|
|
207
|
+
// If category specified, look for exact match
|
|
208
|
+
if (category) {
|
|
209
|
+
return functionFactoryRegistry.get(`${lowerName}:${category}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Try direct match first
|
|
213
|
+
if (functionFactoryRegistry.has(lowerName)) {
|
|
214
|
+
return functionFactoryRegistry.get(lowerName);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return undefined;
|
|
82
218
|
}
|
|
83
219
|
|
|
84
220
|
/**
|
|
85
|
-
*
|
|
221
|
+
* Gets metadata for a specific function by name.
|
|
222
|
+
* If multiple functions share the same name (e.g., aggregate vs predicate),
|
|
223
|
+
* optionally specify the category to get the specific one.
|
|
224
|
+
*
|
|
225
|
+
* @param name - Function name (case-insensitive)
|
|
226
|
+
* @param category - Optional category to disambiguate
|
|
227
|
+
* @returns Function metadata or undefined
|
|
86
228
|
*/
|
|
87
|
-
export
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
{ name: "value", description: "Numeric value to sum", type: "number" }
|
|
94
|
-
],
|
|
95
|
-
output: { description: "Sum of all values", type: "number", example: 150 },
|
|
96
|
-
examples: ["WITH [1, 2, 3] AS nums UNWIND nums AS n RETURN sum(n)"]
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: "avg",
|
|
100
|
-
description: "Calculates the average of numeric values across grouped rows",
|
|
101
|
-
category: "aggregation",
|
|
102
|
-
parameters: [
|
|
103
|
-
{ name: "value", description: "Numeric value to average", type: "number" }
|
|
104
|
-
],
|
|
105
|
-
output: { description: "Average of all values", type: "number", example: 50 },
|
|
106
|
-
examples: ["WITH [10, 20, 30] AS nums UNWIND nums AS n RETURN avg(n)"]
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
name: "collect",
|
|
110
|
-
description: "Collects values into an array across grouped rows",
|
|
111
|
-
category: "aggregation",
|
|
112
|
-
parameters: [
|
|
113
|
-
{ name: "value", description: "Value to collect", type: "any" }
|
|
114
|
-
],
|
|
115
|
-
output: { description: "Array of collected values", type: "array", example: [1, 2, 3] },
|
|
116
|
-
examples: ["WITH [1, 2, 3] AS nums UNWIND nums AS n RETURN collect(n)"]
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: "range",
|
|
120
|
-
description: "Generates an array of sequential integers",
|
|
121
|
-
category: "generator",
|
|
122
|
-
parameters: [
|
|
123
|
-
{ name: "start", description: "Starting number (inclusive)", type: "number" },
|
|
124
|
-
{ name: "end", description: "Ending number (inclusive)", type: "number" }
|
|
125
|
-
],
|
|
126
|
-
output: { description: "Array of integers from start to end", type: "array", items: { type: "number" }, example: [1, 2, 3, 4, 5] },
|
|
127
|
-
examples: ["WITH range(1, 5) AS nums RETURN nums"]
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
name: "rand",
|
|
131
|
-
description: "Generates a random number between 0 and 1",
|
|
132
|
-
category: "generator",
|
|
133
|
-
parameters: [],
|
|
134
|
-
output: { description: "Random number between 0 and 1", type: "number", example: 0.7234 },
|
|
135
|
-
examples: ["WITH rand() AS r RETURN r"]
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: "round",
|
|
139
|
-
description: "Rounds a number to the nearest integer",
|
|
140
|
-
category: "math",
|
|
141
|
-
parameters: [
|
|
142
|
-
{ name: "value", description: "Number to round", type: "number" }
|
|
143
|
-
],
|
|
144
|
-
output: { description: "Rounded integer", type: "number", example: 4 },
|
|
145
|
-
examples: ["WITH 3.7 AS n RETURN round(n)"]
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
name: "split",
|
|
149
|
-
description: "Splits a string into an array by a delimiter",
|
|
150
|
-
category: "string",
|
|
151
|
-
parameters: [
|
|
152
|
-
{ name: "text", description: "String to split", type: "string" },
|
|
153
|
-
{ name: "delimiter", description: "Delimiter to split by", type: "string" }
|
|
154
|
-
],
|
|
155
|
-
output: { description: "Array of string parts", type: "array", items: { type: "string" }, example: ["a", "b", "c"] },
|
|
156
|
-
examples: ["WITH 'a,b,c' AS s RETURN split(s, ',')"]
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: "join",
|
|
160
|
-
description: "Joins an array of strings with a delimiter",
|
|
161
|
-
category: "string",
|
|
162
|
-
parameters: [
|
|
163
|
-
{ name: "array", description: "Array of values to join", type: "array" },
|
|
164
|
-
{ name: "delimiter", description: "Delimiter to join with", type: "string" }
|
|
165
|
-
],
|
|
166
|
-
output: { description: "Joined string", type: "string", example: "a,b,c" },
|
|
167
|
-
examples: ["WITH ['a', 'b', 'c'] AS arr RETURN join(arr, ',')"]
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
name: "replace",
|
|
171
|
-
description: "Replaces occurrences of a pattern in a string",
|
|
172
|
-
category: "string",
|
|
173
|
-
parameters: [
|
|
174
|
-
{ name: "text", description: "Source string", type: "string" },
|
|
175
|
-
{ name: "pattern", description: "Pattern to find", type: "string" },
|
|
176
|
-
{ name: "replacement", description: "Replacement string", type: "string" }
|
|
177
|
-
],
|
|
178
|
-
output: { description: "String with replacements", type: "string", example: "hello world" },
|
|
179
|
-
examples: ["WITH 'hello there' AS s RETURN replace(s, 'there', 'world')"]
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: "stringify",
|
|
183
|
-
description: "Converts a value to its JSON string representation",
|
|
184
|
-
category: "conversion",
|
|
185
|
-
parameters: [
|
|
186
|
-
{ name: "value", description: "Value to stringify", type: "any" }
|
|
187
|
-
],
|
|
188
|
-
output: { description: "JSON string", type: "string", example: "{\"a\":1}" },
|
|
189
|
-
examples: ["WITH {a: 1} AS obj RETURN stringify(obj)"]
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name: "tojson",
|
|
193
|
-
description: "Parses a JSON string into an object",
|
|
194
|
-
category: "conversion",
|
|
195
|
-
parameters: [
|
|
196
|
-
{ name: "text", description: "JSON string to parse", type: "string" }
|
|
197
|
-
],
|
|
198
|
-
output: { description: "Parsed object or array", type: "object", example: { a: 1 } },
|
|
199
|
-
examples: ["WITH '{\"a\": 1}' AS s RETURN tojson(s)"]
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
name: "size",
|
|
203
|
-
description: "Returns the length of an array or string",
|
|
204
|
-
category: "utility",
|
|
205
|
-
parameters: [
|
|
206
|
-
{ name: "value", description: "Array or string to measure", type: "array" }
|
|
207
|
-
],
|
|
208
|
-
output: { description: "Length of the input", type: "number", example: 3 },
|
|
209
|
-
examples: ["WITH [1, 2, 3] AS arr RETURN size(arr)"]
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
name: "functions",
|
|
213
|
-
description: "Lists all registered functions with their metadata. Useful for discovering available functions and their documentation. Results include name, description, parameters, output schema, and usage examples.",
|
|
214
|
-
category: "introspection",
|
|
215
|
-
parameters: [
|
|
216
|
-
{ name: "category", description: "Optional category to filter by (e.g., 'aggregation', 'string', 'math')", type: "string", required: false }
|
|
217
|
-
],
|
|
218
|
-
output: {
|
|
219
|
-
description: "Array of function metadata objects",
|
|
220
|
-
type: "array",
|
|
221
|
-
items: {
|
|
222
|
-
type: "object",
|
|
223
|
-
properties: {
|
|
224
|
-
name: { description: "Function name", type: "string" },
|
|
225
|
-
description: { description: "What the function does", type: "string" },
|
|
226
|
-
category: { description: "Function category", type: "string" },
|
|
227
|
-
parameters: { description: "Array of parameter definitions", type: "array" },
|
|
228
|
-
output: { description: "Output schema", type: "object" },
|
|
229
|
-
examples: { description: "Usage examples", type: "array" }
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
examples: [
|
|
234
|
-
"WITH functions() AS funcs RETURN funcs",
|
|
235
|
-
"WITH functions('aggregation') AS funcs UNWIND funcs AS f RETURN f.name, f.description"
|
|
236
|
-
]
|
|
229
|
+
export function getFunctionMetadata(name: string, category?: string): FunctionMetadata | undefined {
|
|
230
|
+
const lowerName = name.toLowerCase();
|
|
231
|
+
|
|
232
|
+
// If category specified, look for exact match
|
|
233
|
+
if (category) {
|
|
234
|
+
return functionMetadataRegistry.get(`${lowerName}:${category}`);
|
|
237
235
|
}
|
|
238
|
-
|
|
236
|
+
|
|
237
|
+
// Otherwise, first try direct match (for functions without category conflicts)
|
|
238
|
+
// Then search for any function with matching name
|
|
239
|
+
for (const [key, meta] of functionMetadataRegistry) {
|
|
240
|
+
if (meta.name === lowerName) {
|
|
241
|
+
return meta;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Gets a registered async data provider by name.
|
|
250
|
+
* Used by FunctionFactory to get decorator-registered async providers.
|
|
251
|
+
*
|
|
252
|
+
* @param name - Function name (case-insensitive)
|
|
253
|
+
* @returns Async data provider or undefined
|
|
254
|
+
*/
|
|
255
|
+
export function getRegisteredAsyncProvider(name: string): AsyncDataProvider | undefined {
|
|
256
|
+
return asyncProviderRegistry.get(name.toLowerCase());
|
|
257
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Function from "./function";
|
|
2
2
|
import FunctionFactory from "./function_factory";
|
|
3
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Built-in function that lists all registered functions with their metadata.
|
|
@@ -15,6 +16,32 @@ import FunctionFactory from "./function_factory";
|
|
|
15
16
|
* RETURN func.name, func.description
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
19
|
+
@FunctionDef({
|
|
20
|
+
description: "Lists all registered functions with their metadata. Useful for discovering available functions and their documentation. Results include name, description, parameters, output schema, and usage examples.",
|
|
21
|
+
category: "scalar",
|
|
22
|
+
parameters: [
|
|
23
|
+
{ name: "category", description: "Optional category to filter by (e.g., 'aggregation', 'string', 'math')", type: "string", required: false }
|
|
24
|
+
],
|
|
25
|
+
output: {
|
|
26
|
+
description: "Array of function metadata objects",
|
|
27
|
+
type: "array",
|
|
28
|
+
items: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
name: { description: "Function name", type: "string" },
|
|
32
|
+
description: { description: "What the function does", type: "string" },
|
|
33
|
+
category: { description: "Function category", type: "string" },
|
|
34
|
+
parameters: { description: "Array of parameter definitions", type: "array" },
|
|
35
|
+
output: { description: "Output schema", type: "object" },
|
|
36
|
+
examples: { description: "Usage examples", type: "array" }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
examples: [
|
|
41
|
+
"WITH functions() AS funcs RETURN funcs",
|
|
42
|
+
"WITH functions('aggregation') AS funcs UNWIND funcs AS f RETURN f.name, f.description"
|
|
43
|
+
]
|
|
44
|
+
})
|
|
18
45
|
class Functions extends Function {
|
|
19
46
|
constructor() {
|
|
20
47
|
super("functions");
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import ASTNode from "../ast_node";
|
|
2
2
|
import Function from "./function";
|
|
3
3
|
import String from "../expressions/string";
|
|
4
|
+
import { FunctionDef } from "./function_metadata";
|
|
4
5
|
|
|
6
|
+
@FunctionDef({
|
|
7
|
+
description: "Joins an array of strings with a delimiter",
|
|
8
|
+
category: "scalar",
|
|
9
|
+
parameters: [
|
|
10
|
+
{ name: "array", description: "Array of values to join", type: "array" },
|
|
11
|
+
{ name: "delimiter", description: "Delimiter to join with", type: "string" }
|
|
12
|
+
],
|
|
13
|
+
output: { description: "Joined string", type: "string", example: "a,b,c" },
|
|
14
|
+
examples: ["WITH ['a', 'b', 'c'] AS arr RETURN join(arr, ',')"]
|
|
15
|
+
})
|
|
5
16
|
class Join extends Function {
|
|
6
17
|
constructor() {
|
|
7
18
|
super("join");
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import PredicateFunction from "./predicate_function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
2
3
|
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Calculates the sum of values in an array with optional filtering. Uses list comprehension syntax: sum(variable IN array [WHERE condition] | expression)",
|
|
6
|
+
category: "predicate",
|
|
7
|
+
parameters: [
|
|
8
|
+
{ name: "variable", description: "Variable name to bind each element", type: "string" },
|
|
9
|
+
{ name: "array", description: "Array to iterate over", type: "array" },
|
|
10
|
+
{ name: "expression", description: "Expression to sum for each element", type: "any" },
|
|
11
|
+
{ name: "where", description: "Optional filter condition", type: "boolean", required: false }
|
|
12
|
+
],
|
|
13
|
+
output: { description: "Sum of the evaluated expressions", type: "number", example: 6 },
|
|
14
|
+
examples: ["WITH [1, 2, 3] AS nums RETURN sum(n IN nums | n)", "WITH [1, 2, 3, 4] AS nums RETURN sum(n IN nums WHERE n > 1 | n * 2)"]
|
|
15
|
+
})
|
|
3
16
|
class PredicateSum extends PredicateFunction {
|
|
4
17
|
constructor() {
|
|
5
18
|
super("sum");
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
2
3
|
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Generates a random number between 0 and 1",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [],
|
|
8
|
+
output: { description: "Random number between 0 and 1", type: "number", example: 0.7234 },
|
|
9
|
+
examples: ["WITH rand() AS r RETURN r"]
|
|
10
|
+
})
|
|
3
11
|
class Rand extends Function {
|
|
4
12
|
constructor() {
|
|
5
13
|
super("rand");
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
2
3
|
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Generates an array of sequential integers",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{ name: "start", description: "Starting number (inclusive)", type: "number" },
|
|
9
|
+
{ name: "end", description: "Ending number (inclusive)", type: "number" }
|
|
10
|
+
],
|
|
11
|
+
output: { description: "Array of integers from start to end", type: "array", items: { type: "number" }, example: [1, 2, 3, 4, 5] },
|
|
12
|
+
examples: ["WITH range(1, 5) AS nums RETURN nums"]
|
|
13
|
+
})
|
|
3
14
|
class Range extends Function {
|
|
4
15
|
constructor() {
|
|
5
16
|
super("range");
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
2
3
|
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Replaces occurrences of a pattern in a string",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{ name: "text", description: "Source string", type: "string" },
|
|
9
|
+
{ name: "pattern", description: "Pattern to find", type: "string" },
|
|
10
|
+
{ name: "replacement", description: "Replacement string", type: "string" }
|
|
11
|
+
],
|
|
12
|
+
output: { description: "String with replacements", type: "string", example: "hello world" },
|
|
13
|
+
examples: ["WITH 'hello there' AS s RETURN replace(s, 'there', 'world')"]
|
|
14
|
+
})
|
|
3
15
|
class Replace extends Function {
|
|
4
16
|
constructor() {
|
|
5
17
|
super("replace");
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
2
3
|
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Rounds a number to the nearest integer",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{ name: "value", description: "Number to round", type: "number" }
|
|
9
|
+
],
|
|
10
|
+
output: { description: "Rounded integer", type: "number", example: 4 },
|
|
11
|
+
examples: ["WITH 3.7 AS n RETURN round(n)"]
|
|
12
|
+
})
|
|
3
13
|
class Round extends Function {
|
|
4
14
|
constructor() {
|
|
5
15
|
super("round");
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
2
3
|
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Returns the length of an array or string",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{ name: "value", description: "Array or string to measure", type: "array" }
|
|
9
|
+
],
|
|
10
|
+
output: { description: "Length of the input", type: "number", example: 3 },
|
|
11
|
+
examples: ["WITH [1, 2, 3] AS arr RETURN size(arr)"]
|
|
12
|
+
})
|
|
3
13
|
class Size extends Function {
|
|
4
14
|
constructor() {
|
|
5
15
|
super("size");
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import ASTNode from "../ast_node";
|
|
2
2
|
import Function from "./function";
|
|
3
3
|
import String from "../expressions/string";
|
|
4
|
+
import { FunctionDef } from "./function_metadata";
|
|
4
5
|
|
|
6
|
+
@FunctionDef({
|
|
7
|
+
description: "Splits a string into an array by a delimiter",
|
|
8
|
+
category: "scalar",
|
|
9
|
+
parameters: [
|
|
10
|
+
{ name: "text", description: "String to split", type: "string" },
|
|
11
|
+
{ name: "delimiter", description: "Delimiter to split by", type: "string" }
|
|
12
|
+
],
|
|
13
|
+
output: { description: "Array of string parts", type: "array", items: { type: "string" }, example: ["a", "b", "c"] },
|
|
14
|
+
examples: ["WITH 'a,b,c' AS s RETURN split(s, ',')"]
|
|
15
|
+
})
|
|
5
16
|
class Split extends Function {
|
|
6
17
|
constructor() {
|
|
7
18
|
super("split");
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import ASTNode from "../ast_node";
|
|
2
2
|
import Function from "./function";
|
|
3
3
|
import Number from "../expressions/number";
|
|
4
|
+
import { FunctionDef } from "./function_metadata";
|
|
4
5
|
|
|
6
|
+
@FunctionDef({
|
|
7
|
+
description: "Converts a value to its JSON string representation",
|
|
8
|
+
category: "scalar",
|
|
9
|
+
parameters: [
|
|
10
|
+
{ name: "value", description: "Value to stringify", type: "any" }
|
|
11
|
+
],
|
|
12
|
+
output: { description: "JSON string", type: "string", example: "{\"a\":1}" },
|
|
13
|
+
examples: ["WITH {a: 1} AS obj RETURN stringify(obj)"]
|
|
14
|
+
})
|
|
5
15
|
class Stringify extends Function {
|
|
6
16
|
constructor() {
|
|
7
17
|
super("stringify");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import AggregateFunction from "./aggregate_function";
|
|
2
2
|
import ReducerElement from "./reducer_element";
|
|
3
|
+
import { FunctionDef } from "./function_metadata";
|
|
3
4
|
|
|
4
5
|
class SumReducerElement extends ReducerElement {
|
|
5
6
|
private _value: any = null;
|
|
@@ -15,6 +16,15 @@ class SumReducerElement extends ReducerElement {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
@FunctionDef({
|
|
20
|
+
description: "Calculates the sum of numeric values across grouped rows",
|
|
21
|
+
category: "aggregate",
|
|
22
|
+
parameters: [
|
|
23
|
+
{ name: "value", description: "Numeric value to sum", type: "number" }
|
|
24
|
+
],
|
|
25
|
+
output: { description: "Sum of all values", type: "number", example: 150 },
|
|
26
|
+
examples: ["WITH [1, 2, 3] AS nums UNWIND nums AS n RETURN sum(n)"]
|
|
27
|
+
})
|
|
18
28
|
class Sum extends AggregateFunction {
|
|
19
29
|
constructor() {
|
|
20
30
|
super("sum");
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import Function from "./function";
|
|
2
|
+
import { FunctionDef } from "./function_metadata";
|
|
2
3
|
|
|
4
|
+
@FunctionDef({
|
|
5
|
+
description: "Parses a JSON string into an object",
|
|
6
|
+
category: "scalar",
|
|
7
|
+
parameters: [
|
|
8
|
+
{ name: "text", description: "JSON string to parse", type: "string" }
|
|
9
|
+
],
|
|
10
|
+
output: { description: "Parsed object or array", type: "object", example: { a: 1 } },
|
|
11
|
+
examples: ["WITH '{\"a\": 1}' AS s RETURN tojson(s)"]
|
|
12
|
+
})
|
|
3
13
|
class ToJson extends Function {
|
|
4
14
|
constructor() {
|
|
5
15
|
super("tojson");
|
package/src/parsing/parser.ts
CHANGED
|
@@ -31,7 +31,6 @@ import AggregateFunction from "./functions/aggregate_function";
|
|
|
31
31
|
import ObjectUtils from "../utils/object_utils";
|
|
32
32
|
import PredicateFunction from "./functions/predicate_function";
|
|
33
33
|
import Token from "../tokenization/token";
|
|
34
|
-
import PredicateFunctionFactory from "./functions/predicate_function_factory";
|
|
35
34
|
import FString from "./expressions/f_string";
|
|
36
35
|
import String from "./expressions/string";
|
|
37
36
|
import AggregatedWith from "./operations/aggregated_with";
|
|
@@ -617,7 +616,7 @@ class Parser extends BaseParser {
|
|
|
617
616
|
if(this.token.value === null) {
|
|
618
617
|
throw new Error('Expected identifier');
|
|
619
618
|
}
|
|
620
|
-
const func =
|
|
619
|
+
const func = FunctionFactory.createPredicate(this.token.value);
|
|
621
620
|
this.setNextToken();
|
|
622
621
|
if(!this.token.isLeftParenthesis()) {
|
|
623
622
|
throw new Error('Expected left parenthesis');
|