UNPKG

liveperson-functions-cli

Version:
72 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetricsView = void 0; const printer_1 = require("./printer"); const constants_1 = require("../shared/constants"); const utils_1 = require("../shared/utils"); class MetricsView { constructor({ log = new printer_1.LogMessage(), error = new printer_1.ErrorMessage(), cliUx = printer_1.cliUX, } = {}) { this.log = log; this.error = error; this.cliUx = cliUx; } /** * Prints the console logs from the invoked function * @param {*} message - message * @returns {void} * @memberof MetricsView */ printMetricsTable(metrics) { this.log.print(''); this.cliUx.table(metrics, { from: { header: 'From', get: (row) => (0, utils_1.formatDate)(row.from), }, to: { header: 'To', get: (row) => (0, utils_1.formatDate)(row.to), }, SUCCEEDED: { header: constants_1.INVOCATION_STATE_LABELS.SUCCEEDED, }, UNKOWN: { header: constants_1.INVOCATION_STATE_LABELS.UNKOWN, }, CODING_FAILURE: { header: constants_1.INVOCATION_STATE_LABELS.CODING_FAILURE, }, PLATFORM_FAILURE: { header: constants_1.INVOCATION_STATE_LABELS.PLATFORM_FAILURE, }, TIMEOUT: { header: constants_1.INVOCATION_STATE_LABELS.TIMEOUT, }, }); this.log.print(''); } printMetricsTableAsCSV(metrics) { this.log.print((0, utils_1.transformToCSV)(metrics, { from: 'From', to: 'To', ...constants_1.INVOCATION_STATE_LABELS, })); } printMetricsTableAsJSON(metrics) { this.log.print(MetricsView.transformMetricData(metrics)); } static transformMetricData(metrics) { const transformedMetrics = metrics.map((metric) => { return Object.entries(metric).reduce((entries, entry) => { const newLabel = constants_1.INVOCATION_STATE_LABELS[entry[0]] || entry[0]; return { ...entries, [newLabel]: entry[1], }; }, {}); }); return transformedMetrics; } } exports.MetricsView = MetricsView; //# sourceMappingURL=metrics.view.js.map