flowquery 1.0.7 → 1.0.8
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/dist/flowquery.min.js +1 -1
- package/dist/parsing/functions/function_metadata.d.ts +0 -17
- package/dist/parsing/functions/function_metadata.d.ts.map +1 -1
- package/dist/parsing/functions/function_metadata.js +61 -86
- package/dist/parsing/functions/function_metadata.js.map +1 -1
- package/docs/flowquery.min.js +1 -1
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/package.json +1 -1
- package/src/parsing/functions/function_metadata.ts +67 -108
- package/tests/extensibility.test.ts +38 -0
|
@@ -6,18 +6,61 @@ exports.getRegisteredFunctionFactory = getRegisteredFunctionFactory;
|
|
|
6
6
|
exports.getFunctionMetadata = getFunctionMetadata;
|
|
7
7
|
exports.getRegisteredAsyncProvider = getRegisteredAsyncProvider;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Centralized registry for function metadata, factories, and async providers.
|
|
10
|
+
* Encapsulates all registration logic for the @FunctionDef decorator.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
12
|
+
class FunctionRegistry {
|
|
13
|
+
/** Derives a camelCase display name from a class name, removing 'Loader' suffix. */
|
|
14
|
+
static deriveDisplayName(className) {
|
|
15
|
+
const baseName = className.endsWith('Loader') ? className.slice(0, -6) : className;
|
|
16
|
+
return baseName.charAt(0).toLowerCase() + baseName.slice(1);
|
|
17
|
+
}
|
|
18
|
+
/** Registers an async data provider class. */
|
|
19
|
+
static registerAsync(constructor, options) {
|
|
20
|
+
const displayName = this.deriveDisplayName(constructor.name);
|
|
21
|
+
const registryKey = displayName.toLowerCase();
|
|
22
|
+
this.metadata.set(registryKey, Object.assign({ name: displayName }, options));
|
|
23
|
+
this.asyncProviders.set(registryKey, (...args) => new constructor().fetch(...args));
|
|
24
|
+
}
|
|
25
|
+
/** Registers a regular function class. */
|
|
26
|
+
static registerFunction(constructor, options) {
|
|
27
|
+
var _a;
|
|
28
|
+
const instance = new constructor();
|
|
29
|
+
const baseName = (((_a = instance.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || constructor.name.toLowerCase());
|
|
30
|
+
const displayName = baseName.includes(':') ? baseName.split(':')[0] : baseName;
|
|
31
|
+
const registryKey = options.category ? `${displayName}:${options.category}` : displayName;
|
|
32
|
+
this.metadata.set(registryKey, Object.assign({ name: displayName }, options));
|
|
33
|
+
if (options.category !== 'predicate') {
|
|
34
|
+
this.factories.set(displayName, () => new constructor());
|
|
35
|
+
}
|
|
36
|
+
this.factories.set(registryKey, () => new constructor());
|
|
37
|
+
}
|
|
38
|
+
static getAllMetadata() {
|
|
39
|
+
return Array.from(this.metadata.values());
|
|
40
|
+
}
|
|
41
|
+
static getMetadata(name, category) {
|
|
42
|
+
const lowerName = name.toLowerCase();
|
|
43
|
+
if (category)
|
|
44
|
+
return this.metadata.get(`${lowerName}:${category}`);
|
|
45
|
+
for (const meta of this.metadata.values()) {
|
|
46
|
+
if (meta.name === lowerName)
|
|
47
|
+
return meta;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
static getFactory(name, category) {
|
|
52
|
+
const lowerName = name.toLowerCase();
|
|
53
|
+
if (category)
|
|
54
|
+
return this.factories.get(`${lowerName}:${category}`);
|
|
55
|
+
return this.factories.get(lowerName);
|
|
56
|
+
}
|
|
57
|
+
static getAsyncProvider(name) {
|
|
58
|
+
return this.asyncProviders.get(name.toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
FunctionRegistry.metadata = new Map();
|
|
62
|
+
FunctionRegistry.factories = new Map();
|
|
63
|
+
FunctionRegistry.asyncProviders = new Map();
|
|
21
64
|
/**
|
|
22
65
|
* Class decorator that registers function metadata.
|
|
23
66
|
* The function name is derived from the class's constructor call to super() for regular functions,
|
|
@@ -57,105 +100,37 @@ const asyncProviderRegistry = new Map();
|
|
|
57
100
|
*/
|
|
58
101
|
function FunctionDef(options) {
|
|
59
102
|
return function (constructor) {
|
|
60
|
-
var _a;
|
|
61
|
-
// Handle async providers differently
|
|
62
103
|
if (options.category === 'async') {
|
|
63
|
-
|
|
64
|
-
// Remove 'Loader' suffix if present and convert to lowercase for registry
|
|
65
|
-
let baseName = constructor.name;
|
|
66
|
-
if (baseName.endsWith('Loader')) {
|
|
67
|
-
baseName = baseName.slice(0, -6);
|
|
68
|
-
}
|
|
69
|
-
// Keep display name in camelCase, but use lowercase for registry keys
|
|
70
|
-
const displayName = baseName.charAt(0).toLowerCase() + baseName.slice(1);
|
|
71
|
-
const registryKey = displayName.toLowerCase();
|
|
72
|
-
// Register metadata with display name
|
|
73
|
-
const metadata = Object.assign({ name: displayName }, options);
|
|
74
|
-
functionMetadataRegistry.set(registryKey, metadata);
|
|
75
|
-
// Register the async provider (wraps the class's fetch method)
|
|
76
|
-
asyncProviderRegistry.set(registryKey, (...args) => new constructor().fetch(...args));
|
|
77
|
-
return constructor;
|
|
104
|
+
FunctionRegistry.registerAsync(constructor, options);
|
|
78
105
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const instance = new constructor();
|
|
82
|
-
const baseName = ((_a = instance.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || constructor.name.toLowerCase();
|
|
83
|
-
// Use category-qualified key to avoid collisions (e.g., sum vs sum:predicate)
|
|
84
|
-
// but store the display name without the qualifier
|
|
85
|
-
const displayName = baseName.includes(':') ? baseName.split(':')[0] : baseName;
|
|
86
|
-
const registryKey = options.category ? `${displayName}:${options.category}` : displayName;
|
|
87
|
-
// Register metadata with display name but category-qualified key
|
|
88
|
-
const metadata = Object.assign({ name: displayName }, options);
|
|
89
|
-
functionMetadataRegistry.set(registryKey, metadata);
|
|
90
|
-
// Register factory function for automatic instantiation
|
|
91
|
-
// Only register to the simple name if no collision exists (predicate functions use qualified keys)
|
|
92
|
-
if (options.category !== 'predicate') {
|
|
93
|
-
functionFactoryRegistry.set(displayName, () => new constructor());
|
|
106
|
+
else {
|
|
107
|
+
FunctionRegistry.registerFunction(constructor, options);
|
|
94
108
|
}
|
|
95
|
-
functionFactoryRegistry.set(registryKey, () => new constructor());
|
|
96
109
|
return constructor;
|
|
97
110
|
};
|
|
98
111
|
}
|
|
99
112
|
/**
|
|
100
113
|
* Gets all registered function metadata from decorators.
|
|
101
|
-
*
|
|
102
|
-
* @returns Array of function metadata
|
|
103
114
|
*/
|
|
104
115
|
function getRegisteredFunctionMetadata() {
|
|
105
|
-
return
|
|
116
|
+
return FunctionRegistry.getAllMetadata();
|
|
106
117
|
}
|
|
107
118
|
/**
|
|
108
119
|
* Gets a registered function factory by name.
|
|
109
|
-
* Used by FunctionFactory to instantiate decorator-registered functions.
|
|
110
|
-
*
|
|
111
|
-
* @param name - Function name (case-insensitive)
|
|
112
|
-
* @param category - Optional category to disambiguate (e.g., 'predicate')
|
|
113
|
-
* @returns Factory function or undefined
|
|
114
120
|
*/
|
|
115
121
|
function getRegisteredFunctionFactory(name, category) {
|
|
116
|
-
|
|
117
|
-
// If category specified, look for exact match
|
|
118
|
-
if (category) {
|
|
119
|
-
return functionFactoryRegistry.get(`${lowerName}:${category}`);
|
|
120
|
-
}
|
|
121
|
-
// Try direct match first
|
|
122
|
-
if (functionFactoryRegistry.has(lowerName)) {
|
|
123
|
-
return functionFactoryRegistry.get(lowerName);
|
|
124
|
-
}
|
|
125
|
-
return undefined;
|
|
122
|
+
return FunctionRegistry.getFactory(name, category);
|
|
126
123
|
}
|
|
127
124
|
/**
|
|
128
125
|
* Gets metadata for a specific function by name.
|
|
129
|
-
* If multiple functions share the same name (e.g., aggregate vs predicate),
|
|
130
|
-
* optionally specify the category to get the specific one.
|
|
131
|
-
*
|
|
132
|
-
* @param name - Function name (case-insensitive)
|
|
133
|
-
* @param category - Optional category to disambiguate
|
|
134
|
-
* @returns Function metadata or undefined
|
|
135
126
|
*/
|
|
136
127
|
function getFunctionMetadata(name, category) {
|
|
137
|
-
|
|
138
|
-
// If category specified, look for exact match
|
|
139
|
-
if (category) {
|
|
140
|
-
return functionMetadataRegistry.get(`${lowerName}:${category}`);
|
|
141
|
-
}
|
|
142
|
-
// Otherwise, first try direct match (for functions without category conflicts)
|
|
143
|
-
// Then search for any function with matching name
|
|
144
|
-
for (const [key, meta] of functionMetadataRegistry) {
|
|
145
|
-
if (meta.name === lowerName) {
|
|
146
|
-
return meta;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return undefined;
|
|
128
|
+
return FunctionRegistry.getMetadata(name, category);
|
|
150
129
|
}
|
|
151
130
|
/**
|
|
152
131
|
* Gets a registered async data provider by name.
|
|
153
|
-
* Used by FunctionFactory to get decorator-registered async providers.
|
|
154
|
-
*
|
|
155
|
-
* @param name - Function name (case-insensitive)
|
|
156
|
-
* @returns Async data provider or undefined
|
|
157
132
|
*/
|
|
158
133
|
function getRegisteredAsyncProvider(name) {
|
|
159
|
-
return
|
|
134
|
+
return FunctionRegistry.getAsyncProvider(name);
|
|
160
135
|
}
|
|
161
136
|
//# sourceMappingURL=function_metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function_metadata.js","sourceRoot":"","sources":["../../../src/parsing/functions/function_metadata.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"function_metadata.js","sourceRoot":"","sources":["../../../src/parsing/functions/function_metadata.ts"],"names":[],"mappings":";;AAkLA,kCASC;AAKD,sEAEC;AAKD,oEAEC;AAKD,kDAEC;AAKD,gEAEC;AA9ID;;;GAGG;AACH,MAAM,gBAAgB;IAKlB,oFAAoF;IAC5E,MAAM,CAAC,iBAAiB,CAAC,SAAiB;QAC9C,MAAM,QAAQ,GAAW,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,C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