@integromat/proto
Version:
Integromat Proto-Classes
252 lines • 10.6 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IMTBase = exports.moduleTypeNames = exports.ModuleType = void 0;
var util = __importStar(require("util"));
var warning_1 = require("./warning");
var events_1 = require("events");
var ModuleType;
(function (ModuleType) {
ModuleType[ModuleType["NONE"] = 0] = "NONE";
ModuleType[ModuleType["TRIGGER"] = 1] = "TRIGGER";
ModuleType[ModuleType["TRANSFORMER"] = 2] = "TRANSFORMER";
ModuleType[ModuleType["ROUTER"] = 3] = "ROUTER";
ModuleType[ModuleType["ACTION"] = 4] = "ACTION";
ModuleType[ModuleType["LISTENER"] = 5] = "LISTENER";
ModuleType[ModuleType["FEEDER"] = 6] = "FEEDER";
ModuleType[ModuleType["AGGREGATOR"] = 7] = "AGGREGATOR";
ModuleType[ModuleType["DIRECTIVE"] = 8] = "DIRECTIVE";
ModuleType[ModuleType["SEARCH"] = 9] = "SEARCH";
ModuleType[ModuleType["CONVERGER"] = 10] = "CONVERGER";
ModuleType[ModuleType["HITL"] = 11] = "HITL";
ModuleType[ModuleType["RETURNER"] = 12] = "RETURNER";
ModuleType[ModuleType["PAUSER"] = 13] = "PAUSER";
ModuleType[ModuleType["STARTER"] = 14] = "STARTER";
ModuleType[ModuleType["AGENT"] = 15] = "AGENT";
ModuleType[ModuleType["CONDITIONAL"] = 16] = "CONDITIONAL";
})(ModuleType || (exports.ModuleType = ModuleType = {}));
exports.moduleTypeNames = (_a = {},
_a[ModuleType.TRIGGER] = { singular: 'trigger', plural: 'triggers' },
_a[ModuleType.TRANSFORMER] = { singular: 'transformer', plural: 'transformers' },
_a[ModuleType.ROUTER] = { singular: 'router', plural: 'routers' },
_a[ModuleType.ACTION] = { singular: 'action', plural: 'actions' },
_a[ModuleType.LISTENER] = { singular: 'listener', plural: 'listeners' },
_a[ModuleType.FEEDER] = { singular: 'feeder', plural: 'feeders' },
_a[ModuleType.AGGREGATOR] = { singular: 'aggregator', plural: 'aggregators' },
_a[ModuleType.DIRECTIVE] = { singular: 'directive', plural: 'directives' },
_a[ModuleType.SEARCH] = { singular: 'search', plural: 'searches' },
_a[ModuleType.CONVERGER] = { singular: 'converger', plural: 'convergers' },
_a[ModuleType.HITL] = { singular: 'hitl', plural: 'hitls' },
_a[ModuleType.RETURNER] = { singular: 'returner', plural: 'returners' },
_a[ModuleType.PAUSER] = { singular: 'pauser', plural: 'pausers' },
_a[ModuleType.STARTER] = { singular: 'starter', plural: 'starters' },
_a[ModuleType.AGENT] = { singular: 'agent', plural: 'agents' },
_a[ModuleType.CONDITIONAL] = { singular: 'conditional', plural: 'conditionals' },
_a);
/**
* Base class for all Modules.
*
* @property scenario - Collection of scenario parameters. Read only.
* @property common - Collection of common parameters. Read only.
* @property data - Collection of data specific to one concrete occurance of this module in Scenario.
* @property parameters - Collection of config parameters. Read only.
* @property environment - Collection of environment variables. Read only.
* @property type - Module type. Read only.
*
* @event log - Dispatched when message is about to be printed to info log.
* @event warn - Dispatched when message is about to be printed to warning log.
*/
var IMTBase = /** @class */ (function (_super) {
__extends(IMTBase, _super);
function IMTBase() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = ModuleType.NONE;
_this.common = null;
_this.data = null;
_this.parameters = null;
_this.scenario = null;
_this.environment = null;
_this.internal = null;
return _this;
}
/**
* Initializes the module. Function that overrides should always call super.
*
* @callback done Callback to call when module is initialized.
* @param {Error} err Error on error, otherwise null.
*/
IMTBase.prototype.initialize = function (done) {
if ('function' === typeof done)
done();
};
/**
* Finalizes the module. Function that overrides should always call super.
*
* @callback done Callback to call when module is finalized.
* @param {Error} err Error on error, otherwise null.
*/
IMTBase.prototype.finalize = function (done) {
this.removeAllListeners();
if ('function' === typeof done)
done();
};
/**
* Adds module to a shared transaction.
*
* @param {Number} [id] Transaction ID. If omited, new transaction ID is generated.
* @return {Number} Transaction ID.
*/
IMTBase.prototype.addSharedTransaction = function (id) {
void id;
throw new Error("Must override a superclass method 'addSharedTransaction'.");
};
/**
* Emit audit message to Engine log. The arguments provided are intended to be shown in the Audit Trail for Module Execution Logs
*
* @param {object} payload Payload to be added to the Module Execution Log
*/
IMTBase.prototype.audit = function (payload) {
this.emit('audit', payload);
};
/**
* Commit all operations.
*
* @callback done Callback to call when operations are done.
* @param {Error} err Error on error, otherwise null.
* @param {Array} report Commit report (see docs).
*/
IMTBase.prototype.commit = function (done) {
if ('function' === typeof done)
done(null, null);
};
/**
* Print debug message to Scenario info log. Debug messages are only visible to system administrators.
*
* @param {...*} message Message to be printed to Scenario info log.
*/
IMTBase.prototype.debug = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.emit('debug', Array.prototype.slice.call(args));
};
/**
* Print message to Scenario info log.
*
* @param {...String|Warning|Error} message Message to be printed to Scenario info log.
*/
IMTBase.prototype.log = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof warning_1.Warning || args[0] instanceof Error) {
this.emit('log', args[0]);
}
else {
this.emit('log', util.format.apply(util, args));
}
};
/**
* Reset the module so it can be reused again.
*/
IMTBase.prototype.reset = function () {
return;
};
/**
* Rollback all operations.
*
* @callback done Callback to call when operations are done.
* @param {Error} err Error on error, otherwise null.
* @param {Array} report Rollback report (see docs).
*/
IMTBase.prototype.rollback = function (done) {
if ('function' === typeof done)
done(null, null);
};
/**
* Print message to Scenario warning log.
*
* @param {...String} message Message to be printed to Scenario warning log.
*/
IMTBase.prototype.warn = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof warning_1.Warning || args[0] instanceof Error) {
this.emit('warn', args[0]);
}
else {
this.emit('warn', util.format.apply(util, args));
}
};
IMTBase.MODULETYPE_NONE = ModuleType.NONE;
IMTBase.MODULETYPE_TRIGGER = ModuleType.TRIGGER;
IMTBase.MODULETYPE_TRANSFORMER = ModuleType.TRANSFORMER;
IMTBase.MODULETYPE_ROUTER = ModuleType.ROUTER;
IMTBase.MODULETYPE_ACTION = ModuleType.ACTION;
IMTBase.MODULETYPE_LISTENER = ModuleType.LISTENER;
IMTBase.MODULETYPE_FEEDER = ModuleType.FEEDER;
IMTBase.MODULETYPE_AGGREGATOR = ModuleType.AGGREGATOR;
IMTBase.MODULETYPE_DIRECTIVE = ModuleType.DIRECTIVE;
IMTBase.MODULETYPE_CONVERGER = ModuleType.CONVERGER;
IMTBase.MODULETYPE_HITL = ModuleType.HITL;
IMTBase.MODULETYPE_PAUSER = ModuleType.PAUSER;
IMTBase.MODULETYPE_RETURNER = ModuleType.RETURNER;
IMTBase.MODULETYPE_STARTER = ModuleType.STARTER;
IMTBase.MODULETYPE_AGENT = ModuleType.AGENT;
IMTBase.MODULETYPE_CONDITIONAL = ModuleType.CONDITIONAL;
return IMTBase;
}(events_1.EventEmitter));
exports.IMTBase = IMTBase;
//# sourceMappingURL=base.js.map