API/api.medcify.app/node_modules/@pm2/io/build/main/features/events.js
2022-09-26 11:41:44 +05:30

44 lines
3.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const serviceManager_1 = require("../serviceManager");
const Debug = require("debug");
class EventsFeature {
constructor() {
this.logger = Debug('axm:features:events');
}
init() {
this.transport = serviceManager_1.ServiceManager.get('transport');
this.logger('init');
}
emit(name, data) {
if (typeof name !== 'string') {
console.error('event name must be a string');
return console.trace();
}
if (typeof data !== 'object') {
console.error('event data must be an object');
return console.trace();
}
if (data instanceof Array) {
console.error(`event data cannot be an array`);
return console.trace();
}
let inflightObj = {};
try {
inflightObj = JSON.parse(JSON.stringify(data));
}
catch (err) {
return console.log('Failed to serialize the event data', err.message);
}
inflightObj.__name = name;
if (this.transport === undefined) {
return this.logger('Failed to send event as transporter isnt available');
}
this.transport.send('human:event', inflightObj);
}
destroy() {
this.logger('destroy');
}
}
exports.EventsFeature = EventsFeature;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2ZlYXR1cmVzL2V2ZW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHNEQUFrRDtBQUdsRCwrQkFBOEI7QUFFOUIsTUFBYSxhQUFhO0lBQTFCO1FBR1UsV0FBTSxHQUFhLEtBQUssQ0FBQyxxQkFBcUIsQ0FBQyxDQUFBO0lBc0N6RCxDQUFDO0lBcENDLElBQUk7UUFDRixJQUFJLENBQUMsU0FBUyxHQUFHLCtCQUFjLENBQUMsR0FBRyxDQUFDLFdBQVcsQ0FBQyxDQUFBO1FBQ2hELElBQUksQ0FBQyxNQUFNLENBQUMsTUFBTSxDQUFDLENBQUE7SUFDckIsQ0FBQztJQUVELElBQUksQ0FBRSxJQUFhLEVBQUUsSUFBVTtRQUM3QixJQUFJLE9BQU8sSUF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