bpmn-elements 15.0.2 → 16.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@ The following elements are tested and supported.
18
18
  - BoundaryEvent
19
19
  - [CallActivity](/docs/CallActivity.md)
20
20
  - CancelEventDefinition
21
- - ConditionalEventDefinition
21
+ - [ConditionalEventDefinition](/docs/ConditionalEventDefinition.md)
22
22
  - CompensateEventDefinition
23
23
  - compensate by outbound Association
24
24
  - [DataObject](/docs/BpmnIO.md)
@@ -112,7 +112,7 @@ function Activity(Behaviour, activityDef, context) {
112
112
  onApiMessage: this._onApiMessage.bind(this),
113
113
  onExecutionMessage: this._onExecutionMessage.bind(this)
114
114
  };
115
- this[kEventDefinitions] = eventDefinitions && eventDefinitions.map(ed => new ed.Behaviour(this, ed, this.context));
115
+ this[kEventDefinitions] = eventDefinitions && eventDefinitions.map((ed, idx) => new ed.Behaviour(this, ed, context, idx));
116
116
  this[kExtensions] = context.loadExtensions(this);
117
117
  this[kConsuming] = false;
118
118
  this[kConsumingRunQ] = undefined;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ExpressionCondition = ExpressionCondition;
7
+ exports.ScriptCondition = ScriptCondition;
8
+ var _ExecutionScope = _interopRequireDefault(require("./activity/ExecutionScope.js"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ /**
11
+ * Script condition
12
+ * @param {import('types').ElementBase} owner
13
+ * @param {any} script
14
+ * @param {string} language
15
+ */
16
+ function ScriptCondition(owner, script, language) {
17
+ this.type = 'script';
18
+ this.language = language;
19
+ this._owner = owner;
20
+ this._script = script;
21
+ }
22
+
23
+ /**
24
+ * Execute
25
+ * @param {any} message
26
+ * @param {CallableFunction} callback
27
+ */
28
+ ScriptCondition.prototype.execute = function execute(message, callback) {
29
+ const owner = this._owner;
30
+ try {
31
+ return this._script.execute((0, _ExecutionScope.default)(owner, message), callback);
32
+ } catch (err) {
33
+ if (!callback) throw err;
34
+ owner.logger.error(`<${owner.id}>`, err);
35
+ callback(err);
36
+ }
37
+ };
38
+
39
+ /**
40
+ * Expression condition
41
+ * @param {import('types').ElementBase} owner
42
+ * @param {string} expression
43
+ */
44
+ function ExpressionCondition(owner, expression) {
45
+ this.type = 'expression';
46
+ this.expression = expression;
47
+ this._owner = owner;
48
+ }
49
+
50
+ /**
51
+ * Execute
52
+ * @param {any} message
53
+ * @param {CallableFunction} callback
54
+ */
55
+ ExpressionCondition.prototype.execute = function execute(message, callback) {
56
+ const owner = this._owner;
57
+ try {
58
+ const result = owner.environment.resolveExpression(this.expression, message);
59
+ if (callback) return callback(null, result);
60
+ return result;
61
+ } catch (err) {
62
+ if (callback) return callback(err);
63
+ throw err;
64
+ }
65
+ };
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = ConditionalEventDefinition;
7
7
  var _messageHelper = require("../messageHelper.js");
8
8
  var _Errors = require("../error/Errors.js");
9
+ var _condition = require("../condition.js");
9
10
  const kExecuteMessage = Symbol.for('executeMessage');
10
- function ConditionalEventDefinition(activity, eventDefinition) {
11
+ function ConditionalEventDefinition(activity, eventDefinition, _context, index) {
11
12
  const {
12
13
  id,
13
14
  broker,
14
- environment,
15
- attachedTo
15
+ environment
16
16
  } = activity;
17
17
  const {
18
18
  type = 'ConditionalEventDefinition',
@@ -20,12 +20,12 @@ function ConditionalEventDefinition(activity, eventDefinition) {
20
20
  } = eventDefinition;
21
21
  this.id = id;
22
22
  this.type = type;
23
- this.isWaiting = !attachedTo;
24
- this.condition = behaviour.expression;
23
+ this.behaviour = behaviour;
25
24
  this.activity = activity;
26
25
  this.environment = environment;
27
26
  this.broker = broker;
28
27
  this.logger = environment.Logger(type.toLowerCase());
28
+ this.condition = this.getCondition(index);
29
29
  }
30
30
  Object.defineProperty(ConditionalEventDefinition.prototype, 'executionId', {
31
31
  get() {
@@ -35,141 +35,137 @@ Object.defineProperty(ConditionalEventDefinition.prototype, 'executionId', {
35
35
  });
36
36
  ConditionalEventDefinition.prototype.execute = function execute(executeMessage) {
37
37
  this[kExecuteMessage] = executeMessage;
38
- return this.isWaiting ? this.executeWait(executeMessage) : this.executeCatch(executeMessage);
38
+ if (!this.condition) return this._setup(executeMessage);
39
+ this.evaluate(executeMessage, (err, result) => {
40
+ this.evaluateCallback(err, result);
41
+ if (!err && !result) {
42
+ this._setup(executeMessage);
43
+ }
44
+ });
39
45
  };
40
- ConditionalEventDefinition.prototype.executeWait = function executeWait(executeMessage) {
46
+ ConditionalEventDefinition.prototype._setup = function setup(executeMessage) {
47
+ const broker = this.broker;
41
48
  const executeContent = executeMessage.content;
42
49
  const {
43
50
  executionId,
44
51
  parent
45
52
  } = executeContent;
46
53
  const parentExecutionId = parent.executionId;
47
- if (this._evaluateWait(executeMessage)) return;
48
- const broker = this.broker;
49
- const onApiMessage = this._onWaitApiMessage.bind(this);
54
+ const onApiMessage = this._onApiMessage.bind(this);
50
55
  broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
51
56
  noAck: true,
52
57
  consumerTag: `_api-${executionId}`
53
58
  });
54
- broker.subscribeTmp('api', `activity.signal.${parentExecutionId}`, onApiMessage, {
59
+ broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
55
60
  noAck: true,
56
61
  consumerTag: `_parent-signal-${executionId}`
57
62
  });
58
- const waitContent = (0, _messageHelper.cloneContent)(executeContent, {
59
- executionId: parentExecutionId,
60
- condition: this.condition
61
- });
62
- waitContent.parent = (0, _messageHelper.shiftParent)(parent);
63
- broker.publish('event', 'activity.wait', waitContent);
64
- };
65
- ConditionalEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
66
- const executeContent = executeMessage.content;
67
- const {
68
- executionId,
69
- index,
70
- parent
71
- } = executeContent;
72
- const parentExecutionId = parent.executionId;
73
- const broker = this.broker;
74
- broker.subscribeTmp('api', `activity.#.${executionId}`, this._onCatchApiMessage.bind(this), {
63
+ broker.subscribeTmp('api', '#.signal.*', this._onDelegateApiMessage.bind(this), {
75
64
  noAck: true,
76
- consumerTag: `_api-${executionId}_${index}`
77
- });
78
- const {
79
- id: attachedToId,
80
- broker: attachedToBroker
81
- } = this.activity.attachedTo;
82
- this._debug(`listen for execute completed from <${attachedToId}>`);
83
- attachedToBroker.subscribeOnce('execution', 'execute.completed', this._onAttachedCompleted.bind(this), {
84
- priority: 300,
85
- consumerTag: `_onend-${executionId}_${index}`
65
+ consumerTag: `_api-delegated-${executionId}`
86
66
  });
87
67
  const waitContent = (0, _messageHelper.cloneContent)(executeContent, {
88
68
  executionId: parentExecutionId,
89
- condition: this.condition
69
+ ...(this.condition && {
70
+ condition: this.condition.type
71
+ })
90
72
  });
91
73
  waitContent.parent = (0, _messageHelper.shiftParent)(parent);
92
74
  broker.publish('event', 'activity.wait', waitContent);
93
75
  };
94
- ConditionalEventDefinition.prototype._onWaitApiMessage = function onWaitApiMessage(routingKey, message) {
95
- const messageType = message.properties.type;
96
- switch (messageType) {
97
- case 'signal':
98
- {
99
- return this._evaluateWait(message);
100
- }
101
- case 'discard':
102
- {
103
- this._stopWait();
104
- return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
105
- state: 'discard'
106
- }));
107
- }
108
- case 'stop':
109
- {
110
- return this._stopWait();
111
- }
76
+
77
+ /**
78
+ * Evaluate condition
79
+ * @param {import('types').ElementBrokerMessage} message
80
+ * @param {CallableFunction} callback
81
+ */
82
+ ConditionalEventDefinition.prototype.evaluate = function evaluate(message, callback) {
83
+ const condition = this.condition;
84
+ if (!condition) {
85
+ this._debug(`condition is empty <${condition}>`);
86
+ return callback();
112
87
  }
88
+ condition.execute(message, callback);
113
89
  };
114
- ConditionalEventDefinition.prototype._evaluateWait = function evaluate(message) {
90
+
91
+ /**
92
+ * Handle evaluate result or error
93
+ * @param {Error|null} err Condition evaluation error
94
+ * @param {any} result Result from evaluated condition, completes execution if truthy
95
+ */
96
+ ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallback(err, result) {
97
+ const broker = this.broker;
115
98
  const executeMessage = this[kExecuteMessage];
116
- const broker = this.broker,
117
- executeContent = executeMessage.content;
118
- try {
119
- var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
120
- } catch (err) {
99
+ const executeContent = executeMessage.content;
100
+ if (err) {
121
101
  return broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeContent, {
122
102
  error: new _Errors.ActivityError(err.message, executeMessage, err)
123
103
  }, {
124
104
  mandatory: true
125
105
  }));
126
106
  }
127
- this._debug(`condition evaluated to ${!!output}`);
128
- broker.publish('event', 'activity.condition', (0, _messageHelper.cloneContent)(executeContent, {
129
- conditionResult: output
107
+ this._debug(`condition evaluated to ${!!result}`);
108
+ this.broker.publish('event', 'activity.condition', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
109
+ conditionResult: result
130
110
  }));
131
- if (!output) return;
132
- this._stopWait();
111
+ if (!result) return;
112
+ this._stop();
133
113
  return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
134
- output
114
+ output: result
135
115
  }));
136
116
  };
137
- ConditionalEventDefinition.prototype._stopWait = function stopWait() {
138
- const broker = this.broker,
139
- executionId = this.executionId;
140
- broker.cancel(`_api-${executionId}`);
141
- broker.cancel(`_parent-signal-${executionId}`);
142
- };
143
- ConditionalEventDefinition.prototype._onAttachedCompleted = function onAttachedCompleted(routingKey, message) {
144
- this._stopCatch();
145
- const executeMessage = this[kExecuteMessage];
146
- const broker = this.broker,
147
- executeContent = executeMessage.content;
148
- try {
149
- var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
150
- } catch (err) {
151
- return broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeContent, {
152
- error: new _Errors.ActivityError(err.message, executeMessage, err)
153
- }, {
154
- mandatory: true
155
- }));
117
+
118
+ /**
119
+ * Get condition
120
+ * @param {number} index Eventdefinition sequence number, used to name registered script
121
+ * @returns {ExpressionCondition|ScriptCondition|null}
122
+ */
123
+ ConditionalEventDefinition.prototype.getCondition = function getCondition(index) {
124
+ const behaviour = this.behaviour;
125
+ if (behaviour.script) {
126
+ const {
127
+ language,
128
+ body,
129
+ resource
130
+ } = behaviour.script;
131
+ const scriptId = `${this.id}/${index}`;
132
+ const script = this.environment.scripts.register({
133
+ id: scriptId,
134
+ type: this.type,
135
+ environment: this.environment,
136
+ behaviour: {
137
+ scriptFormat: language,
138
+ ...(body && {
139
+ script: body
140
+ }),
141
+ ...(resource && {
142
+ resource
143
+ })
144
+ }
145
+ });
146
+ if (script) {
147
+ return new _condition.ScriptCondition(this, script, language);
148
+ }
149
+ } else if (behaviour.expression) {
150
+ return new _condition.ExpressionCondition(this, behaviour.expression);
156
151
  }
157
- this._debug(`condition from <${message.content.executionId}> evaluated to ${!!output}`);
158
- broker.publish('event', 'activity.condition', (0, _messageHelper.cloneContent)(executeContent, {
159
- conditionResult: output
160
- }));
161
- if (output) {
162
- broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
163
- output
164
- }));
152
+ };
153
+ ConditionalEventDefinition.prototype._onDelegateApiMessage = function onDelegateApiMessage(routingKey, message) {
154
+ if (message.content.message && message.content.message.id === this.id) {
155
+ this._onApiMessage(routingKey, message);
165
156
  }
166
157
  };
167
- ConditionalEventDefinition.prototype._onCatchApiMessage = function onCatchApiMessage(routingKey, message) {
158
+ ConditionalEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
168
159
  const messageType = message.properties.type;
169
160
  switch (messageType) {
161
+ case 'signal':
162
+ {
163
+ if (!this.condition) break;
164
+ return this.evaluate(message, (err, result) => this.evaluateCallback(err, result));
165
+ }
170
166
  case 'discard':
171
167
  {
172
- this._stopCatch();
168
+ this._stop();
173
169
  this._debug('discarded');
174
170
  return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
175
171
  state: 'discard'
@@ -177,18 +173,17 @@ ConditionalEventDefinition.prototype._onCatchApiMessage = function onCatchApiMes
177
173
  }
178
174
  case 'stop':
179
175
  {
180
- this._stopCatch();
176
+ this._stop();
181
177
  return this._debug('stopped');
182
178
  }
183
179
  }
184
180
  };
185
- ConditionalEventDefinition.prototype._stopCatch = function stopCatch() {
186
- const {
187
- executionId,
188
- index
189
- } = this[kExecuteMessage].content;
190
- this.activity.attachedTo.broker.cancel(`_onend-${executionId}_${index}`);
191
- this.broker.cancel(`_api-${executionId}_${index}`);
181
+ ConditionalEventDefinition.prototype._stop = function stop() {
182
+ const executionId = this.executionId;
183
+ const broker = this.broker;
184
+ broker.cancel(`_api-${executionId}`);
185
+ broker.cancel(`_parent-signal-${executionId}`);
186
+ broker.cancel(`_api-delegated-${executionId}`);
192
187
  };
193
188
  ConditionalEventDefinition.prototype._debug = function debug(msg) {
194
189
  this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
@@ -189,8 +189,8 @@ ErrorEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
189
189
  }
190
190
  };
191
191
  ErrorEventDefinition.prototype._stop = function stop() {
192
- const broker = this.broker,
193
- executionId = this.executionId;
192
+ const broker = this.broker;
193
+ const executionId = this.executionId;
194
194
  broker.cancel(`_onthrow-${executionId}`);
195
195
  broker.cancel(`_onerror-${executionId}`);
196
196
  broker.cancel(`_api-${executionId}`);
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "CancelEventDefinition", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _CancelEventDefinition.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "CompensateEventDefinition", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _CompensateEventDefinition.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "ConditionalEventDefinition", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _ConditionalEventDefinition.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "ErrorEventDefinition", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _ErrorEventDefinition.default;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "EscalationEventDefinition", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _EscalationEventDefinition.default;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "LinkEventDefinition", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _LinkEventDefinition.default;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "MessageEventDefinition", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _MessageEventDefinition.default;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "SignalEventDefinition", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _SignalEventDefinition.default;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "TerminateEventDefinition", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _TerminateEventDefinition.default;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "TimerEventDefinition", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _TimerEventDefinition.default;
64
+ }
65
+ });
66
+ var _CancelEventDefinition = _interopRequireDefault(require("./CancelEventDefinition.js"));
67
+ var _CompensateEventDefinition = _interopRequireDefault(require("./CompensateEventDefinition.js"));
68
+ var _ConditionalEventDefinition = _interopRequireDefault(require("./ConditionalEventDefinition.js"));
69
+ var _ErrorEventDefinition = _interopRequireDefault(require("./ErrorEventDefinition.js"));
70
+ var _EscalationEventDefinition = _interopRequireDefault(require("./EscalationEventDefinition.js"));
71
+ var _LinkEventDefinition = _interopRequireDefault(require("./LinkEventDefinition.js"));
72
+ var _MessageEventDefinition = _interopRequireDefault(require("./MessageEventDefinition.js"));
73
+ var _SignalEventDefinition = _interopRequireDefault(require("./SignalEventDefinition.js"));
74
+ var _TerminateEventDefinition = _interopRequireDefault(require("./TerminateEventDefinition.js"));
75
+ var _TimerEventDefinition = _interopRequireDefault(require("./TimerEventDefinition.js"));
76
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -3,58 +3,70 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _BoundaryEvent = require("./BoundaryEvent.js");
7
- Object.keys(_BoundaryEvent).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _BoundaryEvent[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _BoundaryEvent[key];
14
- }
15
- });
16
- });
17
- var _EndEvent = require("./EndEvent.js");
18
- Object.keys(_EndEvent).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _EndEvent[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _EndEvent[key];
25
- }
26
- });
27
- });
28
- var _IntermediateCatchEvent = require("./IntermediateCatchEvent.js");
29
- Object.keys(_IntermediateCatchEvent).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _IntermediateCatchEvent[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _IntermediateCatchEvent[key];
36
- }
37
- });
38
- });
39
- var _IntermediateThrowEvent = require("./IntermediateThrowEvent.js");
40
- Object.keys(_IntermediateThrowEvent).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _IntermediateThrowEvent[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _IntermediateThrowEvent[key];
47
- }
48
- });
49
- });
50
- var _StartEvent = require("./StartEvent.js");
51
- Object.keys(_StartEvent).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _StartEvent[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _StartEvent[key];
58
- }
59
- });
60
- });
6
+ Object.defineProperty(exports, "BoundaryEvent", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _BoundaryEvent.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "BoundaryEventBehaviour", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _BoundaryEvent.BoundaryEventBehaviour;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "EndEvent", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _EndEvent.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "EndEventBehaviour", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _EndEvent.EndEventBehaviour;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "IntermediateCatchEvent", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _IntermediateCatchEvent.default;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "IntermediateCatchEventBehaviour", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _IntermediateCatchEvent.IntermediateCatchEventBehaviour;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "IntermediateThrowEvent", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _IntermediateThrowEvent.default;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "IntermediateThrowEventBehaviour", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _IntermediateThrowEvent.IntermediateThrowEventBehaviour;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "StartEvent", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _StartEvent.default;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "StartEventBehaviour", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _StartEvent.StartEventBehaviour;
64
+ }
65
+ });
66
+ var _BoundaryEvent = _interopRequireWildcard(require("./BoundaryEvent.js"));
67
+ var _EndEvent = _interopRequireWildcard(require("./EndEvent.js"));
68
+ var _IntermediateCatchEvent = _interopRequireWildcard(require("./IntermediateCatchEvent.js"));
69
+ var _IntermediateThrowEvent = _interopRequireWildcard(require("./IntermediateThrowEvent.js"));
70
+ var _StartEvent = _interopRequireWildcard(require("./StartEvent.js"));
71
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
72
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -4,12 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _ExecutionScope = _interopRequireDefault(require("../activity/ExecutionScope.js"));
8
7
  var _messageHelper = require("../messageHelper.js");
9
8
  var _shared = require("../shared.js");
10
9
  var _EventBroker = require("../EventBroker.js");
11
10
  var _Api = require("../Api.js");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ var _condition = require("../condition.js");
13
12
  const kCounters = Symbol.for('counters');
14
13
  var _default = exports.default = SequenceFlow;
15
14
  function SequenceFlow(flowDef, {
@@ -41,7 +40,6 @@ function SequenceFlow(flowDef, {
41
40
  take: 0,
42
41
  discard: 0
43
42
  };
44
- environment.registerScript(this);
45
43
  const {
46
44
  broker,
47
45
  on,
@@ -58,6 +56,7 @@ function SequenceFlow(flowDef, {
58
56
  this.once = once;
59
57
  this.waitFor = waitFor;
60
58
  this.emitFatal = emitFatal;
59
+ environment.registerScript(this);
61
60
  logger.debug(`<${id}> init, <${sourceId}> -> <${targetId}>`);
62
61
  }
63
62
  Object.defineProperty(SequenceFlow.prototype, 'counters', {
@@ -145,13 +144,13 @@ SequenceFlow.prototype.getCondition = function getCondition() {
145
144
  } = conditionExpression;
146
145
  const script = this.environment.getScript(language, this);
147
146
  if (script) {
148
- return new ScriptCondition(this, script, language);
147
+ return new _condition.ScriptCondition(this, script, language);
149
148
  }
150
149
  if (!conditionExpression.body) {
151
150
  const msg = language ? `Condition expression script ${language} is unsupported or was not registered` : 'Condition expression without body is unsupported';
152
151
  return this.emitFatal(new Error(msg), this.createMessage());
153
152
  }
154
- return new ExpressionCondition(this, conditionExpression.body);
153
+ return new _condition.ExpressionCondition(this, conditionExpression.body);
155
154
  };
156
155
  SequenceFlow.prototype.createMessage = function createMessage(override) {
157
156
  return {
@@ -184,36 +183,4 @@ SequenceFlow.prototype._publishEvent = function publishEvent(action, content) {
184
183
  this.broker.publish('event', `flow.${action}`, eventContent, {
185
184
  type: action
186
185
  });
187
- };
188
- function ScriptCondition(owner, script, language) {
189
- this.type = 'script';
190
- this.language = language;
191
- this._owner = owner;
192
- this._script = script;
193
- }
194
- ScriptCondition.prototype.execute = function execute(message, callback) {
195
- const owner = this._owner;
196
- try {
197
- return this._script.execute((0, _ExecutionScope.default)(owner, message), callback);
198
- } catch (err) {
199
- if (!callback) throw err;
200
- owner.logger.error(`<${owner.id}>`, err);
201
- callback(err);
202
- }
203
- };
204
- function ExpressionCondition(owner, expression) {
205
- this.type = 'expression';
206
- this.expression = expression;
207
- this._owner = owner;
208
- }
209
- ExpressionCondition.prototype.execute = function execute(message, callback) {
210
- const owner = this._owner;
211
- try {
212
- const result = owner.environment.resolveExpression(this.expression, owner.createMessage(message));
213
- if (callback) return callback(null, result);
214
- return result;
215
- } catch (err) {
216
- if (callback) return callback(err);
217
- throw err;
218
- }
219
186
  };