UNPKG

1.94 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _GenericError = require("../error/GenericError");
8
9var _GenericError2 = _interopRequireDefault(_GenericError);
10
11var _Execution = require("./Execution");
12
13var _Execution2 = _interopRequireDefault(_Execution);
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17const CLASS_REGEX = /^\s*class\b/;
18/**
19 * Basic implementation of the {@link Execution} interface. Provides the basic
20 * functionality for appending and validating jobs.
21 *
22 * @abstract
23 * @extends Execution
24 */
25
26class AbstractExecution extends _Execution2.default {
27 constructor(jobs = []) {
28 super();
29 this._jobs = jobs.filter(this._validateJob);
30 }
31 /**
32 * @inheritDoc
33 */
34
35
36 append(jobs) {
37 if (!Array.isArray(jobs)) {
38 jobs = [jobs];
39 }
40
41 this._jobs = this._jobs.concat(jobs.filter(this._validateJob));
42 }
43 /**
44 * @inheritDoc
45 */
46
47
48 execute() {
49 throw new _GenericError2.default('The ima.execution.AbstractExecution.execute method is abstract ' + 'and must be overridden');
50 }
51 /**
52 * Return {@code true} if the given job can be executed
53 *
54 * @protected
55 * @param {function(): Promise} job
56 * @returns {boolean}
57 */
58
59
60 _validateJob(job) {
61 if (typeof job === 'function') {
62 if (!CLASS_REGEX.test(job.toString())) {
63 return true;
64 }
65 }
66
67 if ($Debug) {
68 console.warn('ima.execution.AbstractExecution: Given job is not a callable ' + 'function therefore it will be excluded from execution.', {
69 job
70 });
71 }
72
73 return false;
74 }
75
76}
77
78exports.default = AbstractExecution;
79
80typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/execution/AbstractExecution', [], function (_export, _context) {
81 'use strict';
82 return {
83 setters: [],
84 execute: function () {
85 _export('default', exports.default);
86 }
87 };
88});