bpmn-elements 15.0.3 → 16.1.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.
Files changed (39) hide show
  1. package/README.md +1 -1
  2. package/dist/Environment.js +1 -1
  3. package/dist/Scripts.js +2 -2
  4. package/dist/activity/Activity.js +1 -1
  5. package/dist/condition.js +65 -0
  6. package/dist/eventDefinitions/ConditionalEventDefinition.js +101 -106
  7. package/dist/eventDefinitions/ErrorEventDefinition.js +2 -2
  8. package/dist/eventDefinitions/TimerEventDefinition.js +2 -0
  9. package/dist/eventDefinitions/index.js +76 -0
  10. package/dist/events/BoundaryEvent.js +3 -2
  11. package/dist/events/index.js +67 -55
  12. package/dist/flows/SequenceFlow.js +4 -37
  13. package/dist/flows/index.js +27 -0
  14. package/dist/gateways/index.js +54 -44
  15. package/dist/index.js +39 -64
  16. package/dist/process/Process.js +3 -2
  17. package/dist/tasks/index.js +101 -88
  18. package/eventDefinitions.d.ts +1 -0
  19. package/flows.d.ts +1 -0
  20. package/package.json +21 -6
  21. package/src/Environment.js +1 -1
  22. package/src/activity/Activity.js +1 -1
  23. package/src/condition.js +58 -0
  24. package/src/eventDefinitions/ConditionalEventDefinition.js +96 -106
  25. package/src/eventDefinitions/ErrorEventDefinition.js +2 -2
  26. package/src/eventDefinitions/TimerEventDefinition.js +2 -0
  27. package/src/eventDefinitions/index.js +23 -0
  28. package/src/events/BoundaryEvent.js +5 -2
  29. package/src/events/index.js +18 -5
  30. package/src/flows/SequenceFlow.js +3 -38
  31. package/src/flows/index.js +5 -0
  32. package/src/gateways/index.js +15 -4
  33. package/src/index.js +16 -30
  34. package/src/process/Process.js +3 -2
  35. package/src/tasks/index.js +26 -8
  36. package/types/index.d.ts +31 -25
  37. package/types/types.d.ts +52 -1
  38. package/dist/ExtensionsMapper.js +0 -41
  39. package/dist/iso-duration.js +0 -88
@@ -3,91 +3,104 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _CallActivity = require("./CallActivity.js");
7
- Object.keys(_CallActivity).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _CallActivity[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _CallActivity[key];
14
- }
15
- });
16
- });
17
- var _ReceiveTask = require("./ReceiveTask.js");
18
- Object.keys(_ReceiveTask).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _ReceiveTask[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _ReceiveTask[key];
25
- }
26
- });
27
- });
28
- var _ScriptTask = require("./ScriptTask.js");
29
- Object.keys(_ScriptTask).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _ScriptTask[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _ScriptTask[key];
36
- }
37
- });
38
- });
39
- var _ServiceTask = require("./ServiceTask.js");
40
- Object.keys(_ServiceTask).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _ServiceTask[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _ServiceTask[key];
47
- }
48
- });
49
- });
50
- var _SignalTask = require("./SignalTask.js");
51
- Object.keys(_SignalTask).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _SignalTask[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _SignalTask[key];
58
- }
59
- });
60
- });
61
- var _SubProcess = require("./SubProcess.js");
62
- Object.keys(_SubProcess).forEach(function (key) {
63
- if (key === "default" || key === "__esModule") return;
64
- if (key in exports && exports[key] === _SubProcess[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function () {
68
- return _SubProcess[key];
69
- }
70
- });
71
- });
72
- var _Task = require("./Task.js");
73
- Object.keys(_Task).forEach(function (key) {
74
- if (key === "default" || key === "__esModule") return;
75
- if (key in exports && exports[key] === _Task[key]) return;
76
- Object.defineProperty(exports, key, {
77
- enumerable: true,
78
- get: function () {
79
- return _Task[key];
80
- }
81
- });
82
- });
83
- var _Transaction = require("./Transaction.js");
84
- Object.keys(_Transaction).forEach(function (key) {
85
- if (key === "default" || key === "__esModule") return;
86
- if (key in exports && exports[key] === _Transaction[key]) return;
87
- Object.defineProperty(exports, key, {
88
- enumerable: true,
89
- get: function () {
90
- return _Transaction[key];
91
- }
92
- });
93
- });
6
+ Object.defineProperty(exports, "CallActivity", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _CallActivity.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "CallActivityBehaviour", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _CallActivity.CallActivityBehaviour;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "ReceiveTask", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _ReceiveTask.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "ReceiveTaskBehaviour", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _ReceiveTask.ReceiveTaskBehaviour;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "ScriptTask", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _ScriptTask.default;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "ScriptTaskBehaviour", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _ScriptTask.ScriptTaskBehaviour;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "ServiceTask", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _ServiceTask.default;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "ServiceTaskBehaviour", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _ServiceTask.ServiceTaskBehaviour;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "SignalTask", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _SignalTask.default;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "SignalTaskBehaviour", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _SignalTask.SignalTaskBehaviour;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "SubProcess", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _SubProcess.default;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "SubProcessBehaviour", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _SubProcess.SubProcessBehaviour;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "Task", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _Task.default;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "TaskBehaviour", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _Task.TaskBehaviour;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "Transaction", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _Transaction.default;
94
+ }
95
+ });
96
+ var _CallActivity = _interopRequireWildcard(require("./CallActivity.js"));
97
+ var _ReceiveTask = _interopRequireWildcard(require("./ReceiveTask.js"));
98
+ var _ScriptTask = _interopRequireWildcard(require("./ScriptTask.js"));
99
+ var _ServiceTask = _interopRequireWildcard(require("./ServiceTask.js"));
100
+ var _SignalTask = _interopRequireWildcard(require("./SignalTask.js"));
101
+ var _SubProcess = _interopRequireWildcard(require("./SubProcess.js"));
102
+ var _Task = _interopRequireWildcard(require("./Task.js"));
103
+ var _Transaction = _interopRequireDefault(require("./Transaction.js"));
104
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
105
+ 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); }
106
+ 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; }
@@ -0,0 +1 @@
1
+ import './types/index.js';
package/flows.d.ts ADDED
@@ -0,0 +1 @@
1
+ import './types/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-elements",
3
- "version": "15.0.3",
3
+ "version": "16.1.0",
4
4
  "description": "Executable workflow elements based on BPMN 2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,6 +18,16 @@
18
18
  "require": "./dist/events/index.js",
19
19
  "import": "./src/events/index.js"
20
20
  },
21
+ "./eventDefinitions": {
22
+ "types": "./types/index.d.ts",
23
+ "require": "./dist/eventDefinitions/index.js",
24
+ "import": "./src/eventDefinitions/index.js"
25
+ },
26
+ "./flows": {
27
+ "types": "./types/index.d.ts",
28
+ "require": "./dist/flows/index.js",
29
+ "import": "./src/flows/index.js"
30
+ },
21
31
  "./gateways": {
22
32
  "types": "./types/index.d.ts",
23
33
  "require": "./dist/gateways/index.js",
@@ -35,7 +45,7 @@
35
45
  "posttest": "npm run lint && npm run dist",
36
46
  "lint": "eslint . --cache && prettier . --check --cache",
37
47
  "prepack": "npm run dist",
38
- "test:md": "texample ./docs/Examples.md,./docs/StartEvent.md,./docs/Extension.md",
48
+ "test:md": "texample ./docs/Examples.md,./docs/StartEvent.md,./docs/Extension.md,./docs/ConditionalEventDefinition.md",
39
49
  "cov:html": "c8 -r html -r text mocha -R @bonniernews/hot-bev -p -t 3000",
40
50
  "test:lcov": "c8 -r lcov mocha && npm run lint",
41
51
  "dist": "babel src -d dist/"
@@ -59,10 +69,15 @@
59
69
  ],
60
70
  "files": [
61
71
  "dist",
62
- "types",
63
72
  "src",
73
+ "types",
64
74
  "*.d.ts"
65
75
  ],
76
+ "c8": {
77
+ "include": [
78
+ "src/**/*"
79
+ ]
80
+ },
66
81
  "devDependencies": {
67
82
  "@aircall/expression-parser": "^1.0.4",
68
83
  "@babel/cli": "^7.24.1",
@@ -82,13 +97,13 @@
82
97
  "got": "^14.2.1",
83
98
  "mocha": "^10.4.0",
84
99
  "mocha-cakes-2": "^3.3.0",
85
- "moddle-context-serializer": "^4.1.2",
100
+ "moddle-context-serializer": "^4.2.1",
86
101
  "nock": "^13.5.3",
87
102
  "prettier": "^3.2.5",
88
- "texample": "^0.0.5"
103
+ "texample": "^0.0.6"
89
104
  },
90
105
  "dependencies": {
91
- "@0dep/piso": "^2.0.0",
106
+ "@0dep/piso": "^2.0.2",
92
107
  "smqp": "^9.0.2"
93
108
  }
94
109
  }
@@ -88,7 +88,7 @@ Environment.prototype.assignVariables = function assignVariables(newVars) {
88
88
  };
89
89
  };
90
90
 
91
- Environment.prototype.assignSettings = function assignVariables(newSettings) {
91
+ Environment.prototype.assignSettings = function assignSettings(newSettings) {
92
92
  if (!newSettings || typeof newSettings !== 'object') return;
93
93
 
94
94
  this.settings = {
@@ -99,7 +99,7 @@ function Activity(Behaviour, activityDef, context) {
99
99
  onExecutionMessage: this._onExecutionMessage.bind(this),
100
100
  };
101
101
 
102
- this[kEventDefinitions] = eventDefinitions && eventDefinitions.map((ed) => new ed.Behaviour(this, ed, this.context));
102
+ this[kEventDefinitions] = eventDefinitions && eventDefinitions.map((ed, idx) => new ed.Behaviour(this, ed, context, idx));
103
103
  this[kExtensions] = context.loadExtensions(this);
104
104
  this[kConsuming] = false;
105
105
  this[kConsumingRunQ] = undefined;
@@ -0,0 +1,58 @@
1
+ import ExecutionScope from './activity/ExecutionScope.js';
2
+
3
+ /**
4
+ * Script condition
5
+ * @param {import('types').ElementBase} owner
6
+ * @param {any} script
7
+ * @param {string} language
8
+ */
9
+ export function ScriptCondition(owner, script, language) {
10
+ this.type = 'script';
11
+ this.language = language;
12
+ this._owner = owner;
13
+ this._script = script;
14
+ }
15
+
16
+ /**
17
+ * Execute
18
+ * @param {any} message
19
+ * @param {CallableFunction} callback
20
+ */
21
+ ScriptCondition.prototype.execute = function execute(message, callback) {
22
+ const owner = this._owner;
23
+ try {
24
+ return this._script.execute(ExecutionScope(owner, message), callback);
25
+ } catch (err) {
26
+ if (!callback) throw err;
27
+ owner.logger.error(`<${owner.id}>`, err);
28
+ callback(err);
29
+ }
30
+ };
31
+
32
+ /**
33
+ * Expression condition
34
+ * @param {import('types').ElementBase} owner
35
+ * @param {string} expression
36
+ */
37
+ export function ExpressionCondition(owner, expression) {
38
+ this.type = 'expression';
39
+ this.expression = expression;
40
+ this._owner = owner;
41
+ }
42
+
43
+ /**
44
+ * Execute
45
+ * @param {any} message
46
+ * @param {CallableFunction} callback
47
+ */
48
+ ExpressionCondition.prototype.execute = function execute(message, callback) {
49
+ const owner = this._owner;
50
+ try {
51
+ const result = owner.environment.resolveExpression(this.expression, message);
52
+ if (callback) return callback(null, result);
53
+ return result;
54
+ } catch (err) {
55
+ if (callback) return callback(err);
56
+ throw err;
57
+ }
58
+ };
@@ -1,21 +1,21 @@
1
1
  import { cloneContent, shiftParent } from '../messageHelper.js';
2
2
  import { ActivityError } from '../error/Errors.js';
3
+ import { ScriptCondition, ExpressionCondition } from '../condition.js';
3
4
 
4
5
  const kExecuteMessage = Symbol.for('executeMessage');
5
6
 
6
- export default function ConditionalEventDefinition(activity, eventDefinition) {
7
- const { id, broker, environment, attachedTo } = activity;
7
+ export default function ConditionalEventDefinition(activity, eventDefinition, _context, index) {
8
+ const { id, broker, environment } = activity;
8
9
 
9
10
  const { type = 'ConditionalEventDefinition', behaviour = {} } = eventDefinition;
10
-
11
11
  this.id = id;
12
12
  this.type = type;
13
- this.isWaiting = !attachedTo;
14
- this.condition = behaviour.expression;
13
+ this.behaviour = behaviour;
15
14
  this.activity = activity;
16
15
  this.environment = environment;
17
16
  this.broker = broker;
18
17
  this.logger = environment.Logger(type.toLowerCase());
18
+ this.condition = this.getCondition(index);
19
19
  }
20
20
 
21
21
  Object.defineProperty(ConditionalEventDefinition.prototype, 'executionId', {
@@ -27,90 +27,72 @@ Object.defineProperty(ConditionalEventDefinition.prototype, 'executionId', {
27
27
 
28
28
  ConditionalEventDefinition.prototype.execute = function execute(executeMessage) {
29
29
  this[kExecuteMessage] = executeMessage;
30
- return this.isWaiting ? this.executeWait(executeMessage) : this.executeCatch(executeMessage);
30
+
31
+ if (!this.condition) return this._setup(executeMessage);
32
+
33
+ this.evaluate(executeMessage, (err, result) => {
34
+ this.evaluateCallback(err, result);
35
+ if (!err && !result) {
36
+ this._setup(executeMessage);
37
+ }
38
+ });
31
39
  };
32
40
 
33
- ConditionalEventDefinition.prototype.executeWait = function executeWait(executeMessage) {
41
+ ConditionalEventDefinition.prototype._setup = function setup(executeMessage) {
42
+ const broker = this.broker;
34
43
  const executeContent = executeMessage.content;
35
44
  const { executionId, parent } = executeContent;
36
45
  const parentExecutionId = parent.executionId;
37
46
 
38
- if (this._evaluateWait(executeMessage)) return;
39
-
40
- const broker = this.broker;
41
- const onApiMessage = this._onWaitApiMessage.bind(this);
47
+ const onApiMessage = this._onApiMessage.bind(this);
42
48
  broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
43
49
  noAck: true,
44
50
  consumerTag: `_api-${executionId}`,
45
51
  });
46
- broker.subscribeTmp('api', `activity.signal.${parentExecutionId}`, onApiMessage, {
52
+ broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
47
53
  noAck: true,
48
54
  consumerTag: `_parent-signal-${executionId}`,
49
55
  });
50
-
51
- const waitContent = cloneContent(executeContent, {
52
- executionId: parentExecutionId,
53
- condition: this.condition,
54
- });
55
- waitContent.parent = shiftParent(parent);
56
-
57
- broker.publish('event', 'activity.wait', waitContent);
58
- };
59
-
60
- ConditionalEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
61
- const executeContent = executeMessage.content;
62
- const { executionId, index, parent } = executeContent;
63
- const parentExecutionId = parent.executionId;
64
-
65
- const broker = this.broker;
66
- broker.subscribeTmp('api', `activity.#.${executionId}`, this._onCatchApiMessage.bind(this), {
56
+ broker.subscribeTmp('api', '#.signal.*', this._onDelegateApiMessage.bind(this), {
67
57
  noAck: true,
68
- consumerTag: `_api-${executionId}_${index}`,
69
- });
70
-
71
- const { id: attachedToId, broker: attachedToBroker } = this.activity.attachedTo;
72
-
73
- this._debug(`listen for execute completed from <${attachedToId}>`);
74
-
75
- attachedToBroker.subscribeOnce('execution', 'execute.completed', this._onAttachedCompleted.bind(this), {
76
- priority: 300,
77
- consumerTag: `_onend-${executionId}_${index}`,
58
+ consumerTag: `_api-delegated-${executionId}`,
78
59
  });
79
60
 
80
61
  const waitContent = cloneContent(executeContent, {
81
62
  executionId: parentExecutionId,
82
- condition: this.condition,
63
+ ...(this.condition && { condition: this.condition.type }),
83
64
  });
84
65
  waitContent.parent = shiftParent(parent);
85
66
 
86
67
  broker.publish('event', 'activity.wait', waitContent);
87
68
  };
88
69
 
89
- ConditionalEventDefinition.prototype._onWaitApiMessage = function onWaitApiMessage(routingKey, message) {
90
- const messageType = message.properties.type;
91
-
92
- switch (messageType) {
93
- case 'signal': {
94
- return this._evaluateWait(message);
95
- }
96
- case 'discard': {
97
- this._stopWait();
98
- return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content, { state: 'discard' }));
99
- }
100
- case 'stop': {
101
- return this._stopWait();
102
- }
70
+ /**
71
+ * Evaluate condition
72
+ * @param {import('types').ElementBrokerMessage} message
73
+ * @param {CallableFunction} callback
74
+ */
75
+ ConditionalEventDefinition.prototype.evaluate = function evaluate(message, callback) {
76
+ const condition = this.condition;
77
+ if (!condition) {
78
+ this._debug(`condition is empty <${condition}>`);
79
+ return callback();
103
80
  }
81
+
82
+ condition.execute(message, callback);
104
83
  };
105
84
 
106
- ConditionalEventDefinition.prototype._evaluateWait = function evaluate(message) {
85
+ /**
86
+ * Handle evaluate result or error
87
+ * @param {Error|null} err Condition evaluation error
88
+ * @param {any} result Result from evaluated condition, completes execution if truthy
89
+ */
90
+ ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallback(err, result) {
91
+ const broker = this.broker;
107
92
  const executeMessage = this[kExecuteMessage];
108
- const broker = this.broker,
109
- executeContent = executeMessage.content;
93
+ const executeContent = executeMessage.content;
110
94
 
111
- try {
112
- var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
113
- } catch (err) {
95
+ if (err) {
114
96
  return broker.publish(
115
97
  'execution',
116
98
  'execute.error',
@@ -118,78 +100,86 @@ ConditionalEventDefinition.prototype._evaluateWait = function evaluate(message)
118
100
  );
119
101
  }
120
102
 
121
- this._debug(`condition evaluated to ${!!output}`);
103
+ this._debug(`condition evaluated to ${!!result}`);
122
104
 
123
- broker.publish(
105
+ this.broker.publish(
124
106
  'event',
125
107
  'activity.condition',
126
- cloneContent(executeContent, {
127
- conditionResult: output,
108
+ cloneContent(this[kExecuteMessage].content, {
109
+ conditionResult: result,
128
110
  }),
129
111
  );
130
112
 
131
- if (!output) return;
132
- this._stopWait();
133
- return broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output }));
134
- };
113
+ if (!result) return;
135
114
 
136
- ConditionalEventDefinition.prototype._stopWait = function stopWait() {
137
- const broker = this.broker,
138
- executionId = this.executionId;
139
- broker.cancel(`_api-${executionId}`);
140
- broker.cancel(`_parent-signal-${executionId}`);
115
+ this._stop();
116
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output: result }));
141
117
  };
142
118
 
143
- ConditionalEventDefinition.prototype._onAttachedCompleted = function onAttachedCompleted(routingKey, message) {
144
- this._stopCatch();
145
-
146
- const executeMessage = this[kExecuteMessage];
147
- const broker = this.broker,
148
- executeContent = executeMessage.content;
149
- try {
150
- var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
151
- } catch (err) {
152
- return broker.publish(
153
- 'execution',
154
- 'execute.error',
155
- cloneContent(executeContent, { error: new ActivityError(err.message, executeMessage, err) }, { mandatory: true }),
156
- );
119
+ /**
120
+ * Get condition
121
+ * @param {number} index Eventdefinition sequence number, used to name registered script
122
+ * @returns {ExpressionCondition|ScriptCondition|null}
123
+ */
124
+ ConditionalEventDefinition.prototype.getCondition = function getCondition(index) {
125
+ const behaviour = this.behaviour;
126
+
127
+ if (behaviour.script) {
128
+ const { language, body, resource } = behaviour.script;
129
+
130
+ const scriptId = `${this.id}/${index}`;
131
+
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 && { script: body }),
139
+ ...(resource && { resource }),
140
+ },
141
+ });
142
+
143
+ if (script) {
144
+ return new ScriptCondition(this, script, language);
145
+ }
146
+ } else if (behaviour.expression) {
147
+ return new ExpressionCondition(this, behaviour.expression);
157
148
  }
149
+ };
158
150
 
159
- this._debug(`condition from <${message.content.executionId}> evaluated to ${!!output}`);
160
-
161
- broker.publish(
162
- 'event',
163
- 'activity.condition',
164
- cloneContent(executeContent, {
165
- conditionResult: output,
166
- }),
167
- );
168
-
169
- if (output) {
170
- broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output }));
151
+ ConditionalEventDefinition.prototype._onDelegateApiMessage = function onDelegateApiMessage(routingKey, message) {
152
+ if (message.content.message && message.content.message.id === this.id) {
153
+ this._onApiMessage(routingKey, message);
171
154
  }
172
155
  };
173
156
 
174
- ConditionalEventDefinition.prototype._onCatchApiMessage = function onCatchApiMessage(routingKey, message) {
157
+ ConditionalEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
175
158
  const messageType = message.properties.type;
159
+
176
160
  switch (messageType) {
161
+ case 'signal': {
162
+ if (!this.condition) break;
163
+ return this.evaluate(message, (err, result) => this.evaluateCallback(err, result));
164
+ }
177
165
  case 'discard': {
178
- this._stopCatch();
166
+ this._stop();
179
167
  this._debug('discarded');
180
168
  return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content, { state: 'discard' }));
181
169
  }
182
170
  case 'stop': {
183
- this._stopCatch();
171
+ this._stop();
184
172
  return this._debug('stopped');
185
173
  }
186
174
  }
187
175
  };
188
176
 
189
- ConditionalEventDefinition.prototype._stopCatch = function stopCatch() {
190
- const { executionId, index } = this[kExecuteMessage].content;
191
- this.activity.attachedTo.broker.cancel(`_onend-${executionId}_${index}`);
192
- this.broker.cancel(`_api-${executionId}_${index}`);
177
+ ConditionalEventDefinition.prototype._stop = function stop() {
178
+ const executionId = this.executionId;
179
+ const broker = this.broker;
180
+ broker.cancel(`_api-${executionId}`);
181
+ broker.cancel(`_parent-signal-${executionId}`);
182
+ broker.cancel(`_api-delegated-${executionId}`);
193
183
  };
194
184
 
195
185
  ConditionalEventDefinition.prototype._debug = function debug(msg) {
@@ -200,8 +200,8 @@ ErrorEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
200
200
  };
201
201
 
202
202
  ErrorEventDefinition.prototype._stop = function stop() {
203
- const broker = this.broker,
204
- executionId = this.executionId;
203
+ const broker = this.broker;
204
+ const executionId = this.executionId;
205
205
  broker.cancel(`_onthrow-${executionId}`);
206
206
  broker.cancel(`_onerror-${executionId}`);
207
207
  broker.cancel(`_api-${executionId}`);
@@ -125,6 +125,8 @@ TimerEventDefinition.prototype._completed = function completed(completeContent,
125
125
  if (timerContent.repeat > 1) {
126
126
  const repeat = timerContent.repeat - 1;
127
127
  broker.publish('execution', 'execute.repeat', cloneContent(timerContent, { ...content, repeat }), options);
128
+ } else if (timerContent.repeat === -1) {
129
+ broker.publish('execution', 'execute.repeat', cloneContent(timerContent, content), options);
128
130
  }
129
131
 
130
132
  broker.publish('execution', 'execute.completed', cloneContent(timerContent, content), options);