UNPKG

iobroker.js-controller

Version:

Updated by reinstall.js on 2018-06-11T15:19:56.688Z

77 lines (76 loc) 2.62 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var states_exports = {}; __export(states_exports, { calcProjects: () => calcProjects }); module.exports = __toCommonJS(states_exports); var import_visUtils = require("./visUtils.js"); async function calcProject(options) { const { visAdapter, instance, objects, projects } = options; const result = []; if (!projects?.length) { return result; } for (const project of projects) { if (!project?.isDir) { continue; } if (!await objects.fileExists(`${visAdapter}.${instance}`, `/${project.file}/vis-views.json`)) { continue; } const data = await objects.readFile(`${visAdapter}.${instance}`, `/${project.file}/vis-views.json`); let json; try { json = JSON.parse(data.file); } catch { console.error(`Cannot parse "/${project.file}/vis-views.json`); continue; } const dps = (0, import_visUtils.getUsedObjectIDs)(json, false); if (dps?.IDs) { result.push({ id: `${visAdapter}.${instance}.datapoints.${project.file.replace(/[.\\s]/g, "_")}`, val: dps.IDs.length }); } } return result; } async function calcProjects(options) { const { visAdapter, instance, objects } = options; const projects = await objects.readDirAsync(`${visAdapter}.${instance}`, "/"); if (!projects?.length) { return [{ id: `${visAdapter}.${instance}.datapoints.total`, val: 0 }]; } const result = await calcProject({ objects, projects, instance, visAdapter }); if (result?.length) { let total = 0; for (const entry of result) { total += entry.val; } result.push({ id: `${visAdapter}.${instance}.datapoints.total`, val: total }); } return result; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { calcProjects }); //# sourceMappingURL=states.js.map