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 +1 -1
- package/dist/activity/Activity.js +1 -1
- package/dist/condition.js +65 -0
- package/dist/eventDefinitions/ConditionalEventDefinition.js +101 -106
- package/dist/eventDefinitions/ErrorEventDefinition.js +2 -2
- package/dist/eventDefinitions/index.js +76 -0
- package/dist/events/index.js +67 -55
- package/dist/flows/SequenceFlow.js +4 -37
- package/dist/flows/index.js +27 -0
- package/dist/gateways/index.js +54 -44
- package/dist/index.js +39 -64
- package/dist/process/Process.js +3 -2
- package/dist/tasks/index.js +101 -88
- package/eventDefinitions.d.ts +1 -0
- package/flows.d.ts +1 -0
- package/package.json +21 -6
- package/src/activity/Activity.js +1 -1
- package/src/condition.js +58 -0
- package/src/eventDefinitions/ConditionalEventDefinition.js +96 -106
- package/src/eventDefinitions/ErrorEventDefinition.js +2 -2
- package/src/eventDefinitions/index.js +23 -0
- package/src/events/index.js +18 -5
- package/src/flows/SequenceFlow.js +3 -38
- package/src/flows/index.js +5 -0
- package/src/gateways/index.js +15 -4
- package/src/index.js +16 -30
- package/src/process/Process.js +3 -2
- package/src/tasks/index.js +26 -8
- package/types/index.d.ts +31 -25
- package/types/types.d.ts +53 -1
- package/dist/ExtensionsMapper.js +0 -41
- package/dist/iso-duration.js +0 -88
package/dist/tasks/index.js
CHANGED
|
@@ -3,91 +3,104 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
Object.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
Object.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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": "
|
|
3
|
+
"version": "16.0.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
|
|
100
|
+
"moddle-context-serializer": "^4.2.1",
|
|
86
101
|
"nock": "^13.5.3",
|
|
87
102
|
"prettier": "^3.2.5",
|
|
88
|
-
"texample": "^0.0.
|
|
103
|
+
"texample": "^0.0.6"
|
|
89
104
|
},
|
|
90
105
|
"dependencies": {
|
|
91
|
-
"@0dep/piso": "^
|
|
106
|
+
"@0dep/piso": "^2.0.0",
|
|
92
107
|
"smqp": "^9.0.2"
|
|
93
108
|
}
|
|
94
109
|
}
|
package/src/activity/Activity.js
CHANGED
|
@@ -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,
|
|
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;
|
package/src/condition.js
ADDED
|
@@ -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
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
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}
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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
|
|
109
|
-
executeContent = executeMessage.content;
|
|
93
|
+
const executeContent = executeMessage.content;
|
|
110
94
|
|
|
111
|
-
|
|
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 ${!!
|
|
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(
|
|
127
|
-
conditionResult:
|
|
108
|
+
cloneContent(this[kExecuteMessage].content, {
|
|
109
|
+
conditionResult: result,
|
|
128
110
|
}),
|
|
129
111
|
);
|
|
130
112
|
|
|
131
|
-
if (!
|
|
132
|
-
this._stopWait();
|
|
133
|
-
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output }));
|
|
134
|
-
};
|
|
113
|
+
if (!result) return;
|
|
135
114
|
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
171
|
+
this._stop();
|
|
184
172
|
return this._debug('stopped');
|
|
185
173
|
}
|
|
186
174
|
}
|
|
187
175
|
};
|
|
188
176
|
|
|
189
|
-
ConditionalEventDefinition.prototype.
|
|
190
|
-
const
|
|
191
|
-
this.
|
|
192
|
-
|
|
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
|
-
|
|
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}`);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import CancelEventDefinition from './CancelEventDefinition.js';
|
|
2
|
+
import CompensateEventDefinition from './CompensateEventDefinition.js';
|
|
3
|
+
import ConditionalEventDefinition from './ConditionalEventDefinition.js';
|
|
4
|
+
import ErrorEventDefinition from './ErrorEventDefinition.js';
|
|
5
|
+
import EscalationEventDefinition from './EscalationEventDefinition.js';
|
|
6
|
+
import LinkEventDefinition from './LinkEventDefinition.js';
|
|
7
|
+
import MessageEventDefinition from './MessageEventDefinition.js';
|
|
8
|
+
import SignalEventDefinition from './SignalEventDefinition.js';
|
|
9
|
+
import TerminateEventDefinition from './TerminateEventDefinition.js';
|
|
10
|
+
import TimerEventDefinition from './TimerEventDefinition.js';
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
CancelEventDefinition,
|
|
14
|
+
CompensateEventDefinition,
|
|
15
|
+
ConditionalEventDefinition,
|
|
16
|
+
ErrorEventDefinition,
|
|
17
|
+
EscalationEventDefinition,
|
|
18
|
+
LinkEventDefinition,
|
|
19
|
+
MessageEventDefinition,
|
|
20
|
+
SignalEventDefinition,
|
|
21
|
+
TerminateEventDefinition,
|
|
22
|
+
TimerEventDefinition,
|
|
23
|
+
};
|