"use strict"; import sysinfo from 'systeminformation'; import log from '../../lib/io/NamespacedLog.mjs'; const l = log("infobroker"); class InfoBroker { constructor() { this.allowed_tables = { // name → sysinfo name cpu: "cpu", }; } is_valid_table(name) { return Object.keys(this.allowed_tables).includes(name); } async fetch_table(name) { if(!(typeof name === "string")) throw new Exception(`Error: Expected name to be of type string, but received value of type ${typeof name} instead.`); if(!this.is_valid_table(name)) { l.warn(`Unrecognised table '${name}' requested, returning null`); return null; } return await sysinfo[this.allowed_tables[name]](); } } export default InfoBroker;