feat: add getNetworksByType api call
This commit is contained in:
parent
8bac2e4aab
commit
75c25d7cab
21
src/index.ts
21
src/index.ts
|
@ -6,6 +6,7 @@ const networks: Map<string, Set<string>> = new Map<string, Set<string>>();
|
||||||
addHandler("registerType", handleRegisterType);
|
addHandler("registerType", handleRegisterType);
|
||||||
addHandler("getTypes", handleGetTypes);
|
addHandler("getTypes", handleGetTypes);
|
||||||
addHandler("getNetworkTypes", handleGetNetworkTypes);
|
addHandler("getNetworkTypes", handleGetNetworkTypes);
|
||||||
|
addHandler("getNetworksByType", handleGetNetworksByType);
|
||||||
addHandler("registerNetwork", handleRegisterNetwork);
|
addHandler("registerNetwork", handleRegisterNetwork);
|
||||||
|
|
||||||
function handleRegisterType(aq: ActiveQuery) {
|
function handleRegisterType(aq: ActiveQuery) {
|
||||||
|
@ -55,3 +56,23 @@ function handleGetNetworkTypes(aq: ActiveQuery) {
|
||||||
...(networks.get(aq.callerInput.module) as Set<string>).values(),
|
...(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]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue