2023-03-28 14:33:29 +00:00
|
|
|
import { error } from "loglevel";
|
|
|
|
|
|
|
|
|
|
export default class WidgetQueryGeneratorRegistry {
|
|
|
|
|
private static queryGeneratorMap = new Map();
|
|
|
|
|
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-04-13 11:09:24 +00:00
|
|
|
static register(id: string, queryGenerator: any) {
|
|
|
|
|
if (WidgetQueryGeneratorRegistry.queryGeneratorMap.has(id)) {
|
|
|
|
|
error("There is already a widget query generator with the given id:", id);
|
2023-03-28 14:33:29 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 11:09:24 +00:00
|
|
|
WidgetQueryGeneratorRegistry.queryGeneratorMap.set(id, queryGenerator);
|
2023-03-28 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static clear() {
|
|
|
|
|
WidgetQueryGeneratorRegistry.queryGeneratorMap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 11:09:24 +00:00
|
|
|
static get(id: string) {
|
|
|
|
|
const queryAdaptor = WidgetQueryGeneratorRegistry.queryGeneratorMap.get(id);
|
2023-03-28 14:33:29 +00:00
|
|
|
|
|
|
|
|
if (!queryAdaptor) {
|
2023-04-13 11:09:24 +00:00
|
|
|
error("Couldn't find the query generator with the given id:", id);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2023-03-28 14:33:29 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return queryAdaptor;
|
|
|
|
|
}
|
2023-04-13 11:09:24 +00:00
|
|
|
|
|
|
|
|
static has(id: string) {
|
|
|
|
|
return WidgetQueryGeneratorRegistry.queryGeneratorMap.has(id);
|
|
|
|
|
}
|
2023-03-28 14:33:29 +00:00
|
|
|
}
|