feat: add getNetworksByType api call

This commit is contained in:
Derrick Hammer 2023-07-19 13:14:16 -04:00
parent 8bac2e4aab
commit 75c25d7cab
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 21 additions and 0 deletions

View File

@ -6,6 +6,7 @@ const networks: Map<string, Set<string>> = new Map<string, Set<string>>();
addHandler("registerType", handleRegisterType);
addHandler("getTypes", handleGetTypes);
addHandler("getNetworkTypes", handleGetNetworkTypes);
addHandler("getNetworksByType", handleGetNetworksByType);
addHandler("registerNetwork", handleRegisterNetwork);
function handleRegisterType(aq: ActiveQuery) {
@ -55,3 +56,23 @@ function handleGetNetworkTypes(aq: ActiveQuery) {
...(networks.get(aq.callerInput.module) as Set<string>).values(),
]);
}
function handleGetNetworksByType(aq: ActiveQuery) {
if (!("type" in aq.callerInput)) {
aq.reject("type missing");
return;
}
if (!types.has(aq.callerInput)) {
aq.reject("type not registered");
return;
}
aq.respond(
[...networks.entries()]
.filter((item) => {
return item[1].has(aq.callerInput);
})
.map((item) => item[0]),
);
}