bpmn-elements 17.2.2 → 18.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 +3 -1
- package/dist/Api.js +83 -0
- package/dist/Context.js +228 -22
- package/dist/Environment.js +111 -31
- package/dist/EventBroker.js +57 -1
- package/dist/Expressions.js +3 -4
- package/dist/MessageFormatter.js +29 -16
- package/dist/Timers.js +13 -9
- package/dist/Tracker.js +1 -0
- package/dist/activity/Activity.js +458 -254
- package/dist/activity/ActivityExecution.js +113 -40
- package/dist/activity/Dummy.js +6 -1
- package/dist/activity/Escalation.js +36 -24
- package/dist/activity/ExecutionScope.js +1 -1
- package/dist/activity/Message.js +36 -24
- package/dist/activity/Signal.js +36 -24
- package/dist/activity/outbound-evaluator.js +1 -1
- package/dist/condition.js +12 -6
- package/dist/constants.js +21 -0
- package/dist/definition/Definition.js +182 -64
- package/dist/definition/DefinitionExecution.js +195 -82
- package/dist/error/BpmnError.js +12 -1
- package/dist/error/Errors.js +50 -9
- package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
- package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
- package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
- package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
- package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
- package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
- package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
- package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
- package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
- package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
- package/dist/eventDefinitions/index.js +20 -21
- package/dist/events/BoundaryEvent.js +52 -40
- package/dist/events/EndEvent.js +22 -8
- package/dist/events/IntermediateCatchEvent.js +26 -8
- package/dist/events/IntermediateThrowEvent.js +24 -9
- package/dist/events/StartEvent.js +30 -14
- package/dist/events/index.js +10 -11
- package/dist/flows/Association.js +50 -7
- package/dist/flows/MessageFlow.js +49 -10
- package/dist/flows/SequenceFlow.js +93 -22
- package/dist/flows/index.js +6 -7
- package/dist/gateways/EventBasedGateway.js +29 -15
- package/dist/gateways/ExclusiveGateway.js +20 -5
- package/dist/gateways/InclusiveGateway.js +21 -5
- package/dist/gateways/ParallelGateway.js +253 -15
- package/dist/gateways/index.js +8 -9
- package/dist/getPropertyValue.js +2 -2
- package/dist/index.js +42 -43
- package/dist/io/BpmnIO.js +15 -1
- package/dist/io/EnvironmentDataObject.js +29 -1
- package/dist/io/EnvironmentDataStore.js +24 -1
- package/dist/io/EnvironmentDataStoreReference.js +24 -1
- package/dist/io/InputOutputSpecification.js +21 -11
- package/dist/io/Properties.js +28 -17
- package/dist/messageHelper.js +41 -4
- package/dist/process/Lane.js +15 -4
- package/dist/process/Process.js +174 -76
- package/dist/process/ProcessExecution.js +362 -177
- package/dist/shared.js +2 -0
- package/dist/tasks/CallActivity.js +19 -4
- package/dist/tasks/LoopCharacteristics.js +94 -9
- package/dist/tasks/ReceiveTask.js +36 -21
- package/dist/tasks/ScriptTask.js +22 -6
- package/dist/tasks/ServiceImplementation.js +7 -4
- package/dist/tasks/ServiceTask.js +19 -4
- package/dist/tasks/SignalTask.js +19 -4
- package/dist/tasks/StandardLoopCharacteristics.js +8 -4
- package/dist/tasks/SubProcess.js +44 -29
- package/dist/tasks/Task.js +19 -4
- package/dist/tasks/Transaction.js +8 -4
- package/dist/tasks/index.js +16 -18
- package/package.json +31 -13
- package/src/Api.js +70 -0
- package/src/Context.js +200 -19
- package/src/Environment.js +99 -30
- package/src/EventBroker.js +46 -1
- package/src/Expressions.js +2 -3
- package/src/MessageFormatter.js +24 -16
- package/src/Timers.js +12 -9
- package/src/Tracker.js +1 -0
- package/src/activity/Activity.js +388 -231
- package/src/activity/ActivityExecution.js +93 -42
- package/src/activity/Dummy.js +6 -1
- package/src/activity/Escalation.js +25 -18
- package/src/activity/ExecutionScope.js +1 -1
- package/src/activity/Message.js +25 -18
- package/src/activity/Signal.js +25 -18
- package/src/activity/outbound-evaluator.js +1 -1
- package/src/condition.js +11 -5
- package/src/constants.js +15 -0
- package/src/definition/Definition.js +157 -62
- package/src/definition/DefinitionExecution.js +161 -83
- package/src/error/BpmnError.js +11 -1
- package/src/error/Errors.js +44 -5
- package/src/eventDefinitions/CancelEventDefinition.js +27 -13
- package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
- package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
- package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
- package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
- package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
- package/src/eventDefinitions/LinkEventDefinition.js +34 -120
- package/src/eventDefinitions/MessageEventDefinition.js +42 -31
- package/src/eventDefinitions/SignalEventDefinition.js +43 -32
- package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
- package/src/eventDefinitions/TimerEventDefinition.js +53 -35
- package/src/eventDefinitions/index.js +10 -23
- package/src/events/BoundaryEvent.js +50 -39
- package/src/events/EndEvent.js +19 -7
- package/src/events/IntermediateCatchEvent.js +24 -8
- package/src/events/IntermediateThrowEvent.js +24 -8
- package/src/events/StartEvent.js +25 -14
- package/src/events/index.js +5 -18
- package/src/flows/Association.js +43 -9
- package/src/flows/MessageFlow.js +41 -10
- package/src/flows/SequenceFlow.js +82 -19
- package/src/flows/index.js +3 -4
- package/src/gateways/EventBasedGateway.js +27 -15
- package/src/gateways/ExclusiveGateway.js +16 -3
- package/src/gateways/InclusiveGateway.js +16 -3
- package/src/gateways/ParallelGateway.js +301 -10
- package/src/gateways/index.js +4 -4
- package/src/getPropertyValue.js +2 -2
- package/src/index.js +19 -19
- package/src/io/BpmnIO.js +13 -1
- package/src/io/EnvironmentDataObject.js +26 -1
- package/src/io/EnvironmentDataStore.js +22 -1
- package/src/io/EnvironmentDataStoreReference.js +22 -1
- package/src/io/InputOutputSpecification.js +17 -8
- package/src/io/Properties.js +23 -13
- package/src/messageHelper.js +36 -4
- package/src/process/Lane.js +14 -4
- package/src/process/Process.js +154 -72
- package/src/process/ProcessExecution.js +326 -175
- package/src/shared.js +1 -0
- package/src/tasks/CallActivity.js +16 -2
- package/src/tasks/LoopCharacteristics.js +77 -11
- package/src/tasks/ReceiveTask.js +33 -22
- package/src/tasks/ScriptTask.js +17 -3
- package/src/tasks/ServiceImplementation.js +6 -3
- package/src/tasks/ServiceTask.js +16 -2
- package/src/tasks/SignalTask.js +16 -2
- package/src/tasks/StandardLoopCharacteristics.js +7 -3
- package/src/tasks/SubProcess.js +37 -23
- package/src/tasks/Task.js +16 -2
- package/src/tasks/Transaction.js +7 -3
- package/src/tasks/index.js +8 -9
- package/types/bundle-errors.d.ts +1 -0
- package/types/bundle.d.ts +97 -0
- package/types/index.d.ts +2614 -84
- package/types/interfaces.d.ts +636 -0
- package/types/types.d.ts +0 -765
package/dist/error/Errors.js
CHANGED
|
@@ -7,23 +7,41 @@ exports.RunError = exports.BpmnError = exports.ActivityError = void 0;
|
|
|
7
7
|
exports.makeErrorFromMessage = makeErrorFromMessage;
|
|
8
8
|
var _messageHelper = require("../messageHelper.js");
|
|
9
9
|
class ActivityError extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} description
|
|
12
|
+
* @param {import('#types').ElementBrokerMessage} [sourceMessage]
|
|
13
|
+
* @param {Error | { name?: string; code?: string | number }} [inner]
|
|
14
|
+
*/
|
|
10
15
|
constructor(description, sourceMessage, inner) {
|
|
11
16
|
super(description);
|
|
17
|
+
/** @type {string} */
|
|
12
18
|
this.type = 'ActivityError';
|
|
19
|
+
/** @type {string} */
|
|
13
20
|
this.name = this.constructor.name;
|
|
21
|
+
/** @type {string} */
|
|
14
22
|
this.description = description;
|
|
15
|
-
if (sourceMessage)
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
if (sourceMessage) {
|
|
24
|
+
/** @type {Pick<import('#types').ElementBrokerMessage, 'fields' | 'content' | 'properties'> | undefined} */
|
|
25
|
+
this.source = (0, _messageHelper.cloneMessage)(sourceMessage, sourceMessage.content?.error && {
|
|
26
|
+
error: undefined
|
|
27
|
+
});
|
|
28
|
+
}
|
|
18
29
|
if (inner) {
|
|
30
|
+
/** @type {Error | { name?: string; code?: string | number } | undefined} */
|
|
19
31
|
this.inner = inner;
|
|
20
32
|
if (inner.name) this.name = inner.name;
|
|
21
|
-
if (
|
|
33
|
+
if ('code' in inner && inner.code) {
|
|
34
|
+
/** @type {string | number | undefined} */
|
|
35
|
+
this.code = inner.code;
|
|
36
|
+
}
|
|
22
37
|
}
|
|
23
38
|
}
|
|
24
39
|
}
|
|
25
40
|
exports.ActivityError = ActivityError;
|
|
26
41
|
class RunError extends ActivityError {
|
|
42
|
+
/**
|
|
43
|
+
* @param {ConstructorParameters<typeof ActivityError>} args
|
|
44
|
+
*/
|
|
27
45
|
constructor(...args) {
|
|
28
46
|
super(...args);
|
|
29
47
|
this.type = 'RunError';
|
|
@@ -31,19 +49,37 @@ class RunError extends ActivityError {
|
|
|
31
49
|
}
|
|
32
50
|
exports.RunError = RunError;
|
|
33
51
|
class BpmnError extends Error {
|
|
34
|
-
|
|
52
|
+
/**
|
|
53
|
+
* @param {string} description
|
|
54
|
+
* @param {{ id?: string; name?: string; errorCode?: string | number; code?: string }} [behaviour]
|
|
55
|
+
* @param {import('#types').ElementBrokerMessage} [sourceMessage]
|
|
56
|
+
*/
|
|
57
|
+
constructor(description, behaviour, sourceMessage) {
|
|
35
58
|
super(description);
|
|
59
|
+
/** @type {string} */
|
|
36
60
|
this.type = 'BpmnError';
|
|
61
|
+
/** @type {string} */
|
|
37
62
|
this.name = behaviour?.name ?? this.constructor.name;
|
|
63
|
+
/** @type {string} */
|
|
38
64
|
this.description = description;
|
|
65
|
+
/** @type {string | undefined} */
|
|
39
66
|
this.code = behaviour?.errorCode?.toString() ?? behaviour?.code;
|
|
67
|
+
/** @type {string | undefined} */
|
|
40
68
|
this.id = behaviour?.id;
|
|
41
|
-
if (sourceMessage)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
69
|
+
if (sourceMessage) {
|
|
70
|
+
/** @type {Pick<import('#types').ElementBrokerMessage, 'fields' | 'content' | 'properties'> | undefined} */
|
|
71
|
+
this.source = (0, _messageHelper.cloneMessage)(sourceMessage, sourceMessage.content?.error && {
|
|
72
|
+
error: undefined
|
|
73
|
+
});
|
|
74
|
+
}
|
|
45
75
|
}
|
|
46
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get an Error from an error message.
|
|
80
|
+
* @param {import('#types').ElementBrokerMessage} errorMessage
|
|
81
|
+
* @returns {Error | ActivityError | RunError | BpmnError}
|
|
82
|
+
*/
|
|
47
83
|
exports.BpmnError = BpmnError;
|
|
48
84
|
function makeErrorFromMessage(errorMessage) {
|
|
49
85
|
const {
|
|
@@ -71,6 +107,11 @@ function makeErrorFromMessage(errorMessage) {
|
|
|
71
107
|
}
|
|
72
108
|
return error;
|
|
73
109
|
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {any} test
|
|
113
|
+
* @returns {Error | undefined}
|
|
114
|
+
*/
|
|
74
115
|
function isKnownError(test) {
|
|
75
116
|
if (test instanceof ActivityError) return test;
|
|
76
117
|
if (test instanceof BpmnError) return test;
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.CancelEventDefinition = CancelEventDefinition;
|
|
7
7
|
var _messageHelper = require("../messageHelper.js");
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var _constants = require("../constants.js");
|
|
9
|
+
/**
|
|
10
|
+
* Cancel event definition
|
|
11
|
+
* @param {import('#types').Activity} activity
|
|
12
|
+
* @param {import('moddle-context-serializer').EventDefinition} eventDefinition
|
|
13
|
+
*/
|
|
10
14
|
function CancelEventDefinition(activity, eventDefinition) {
|
|
11
15
|
const {
|
|
12
16
|
id,
|
|
@@ -17,6 +21,7 @@ function CancelEventDefinition(activity, eventDefinition) {
|
|
|
17
21
|
const type = eventDefinition.type;
|
|
18
22
|
this.id = id;
|
|
19
23
|
this.type = type;
|
|
24
|
+
/** @type {import('#types').EventReference} */
|
|
20
25
|
this.reference = {
|
|
21
26
|
referenceType: 'cancel'
|
|
22
27
|
};
|
|
@@ -27,16 +32,25 @@ function CancelEventDefinition(activity, eventDefinition) {
|
|
|
27
32
|
this.logger = environment.Logger(type.toLowerCase());
|
|
28
33
|
}
|
|
29
34
|
Object.defineProperty(CancelEventDefinition.prototype, 'executionId', {
|
|
35
|
+
/** @returns {string} */
|
|
30
36
|
get() {
|
|
31
|
-
return this[
|
|
37
|
+
return this[_constants.K_EXECUTE_MESSAGE]?.content.executionId;
|
|
32
38
|
}
|
|
33
39
|
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
43
|
+
*/
|
|
34
44
|
CancelEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
35
45
|
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
36
46
|
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
50
|
+
*/
|
|
37
51
|
CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
|
|
38
|
-
this[
|
|
39
|
-
this[
|
|
52
|
+
this[_constants.K_EXECUTE_MESSAGE] = executeMessage;
|
|
53
|
+
this[_constants.K_COMPLETED] = false;
|
|
40
54
|
const executeContent = executeMessage.content;
|
|
41
55
|
const {
|
|
42
56
|
executionId,
|
|
@@ -66,6 +80,10 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
|
|
|
66
80
|
waitContent.parent = (0, _messageHelper.shiftParent)(parent);
|
|
67
81
|
broker.publish('event', 'activity.wait', waitContent);
|
|
68
82
|
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
86
|
+
*/
|
|
69
87
|
CancelEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
70
88
|
const executeContent = executeMessage.content;
|
|
71
89
|
const {
|
|
@@ -82,7 +100,7 @@ CancelEventDefinition.prototype.executeThrow = function executeThrow(executeMess
|
|
|
82
100
|
broker.publish('event', 'activity.cancel', cancelContent, {
|
|
83
101
|
type: 'cancel'
|
|
84
102
|
});
|
|
85
|
-
|
|
103
|
+
broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent));
|
|
86
104
|
};
|
|
87
105
|
CancelEventDefinition.prototype._onCatchMessage = function onCatchMessage(_, message) {
|
|
88
106
|
const content = message.content;
|
|
@@ -90,10 +108,10 @@ CancelEventDefinition.prototype._onCatchMessage = function onCatchMessage(_, mes
|
|
|
90
108
|
return this._complete(content.message);
|
|
91
109
|
};
|
|
92
110
|
CancelEventDefinition.prototype._complete = function complete(output) {
|
|
93
|
-
this[
|
|
111
|
+
this[_constants.K_COMPLETED] = true;
|
|
94
112
|
this._stop();
|
|
95
113
|
this._debug('completed');
|
|
96
|
-
const content = (0, _messageHelper.cloneContent)(this[
|
|
114
|
+
const content = (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
|
|
97
115
|
output,
|
|
98
116
|
state: 'cancel'
|
|
99
117
|
});
|
|
@@ -103,9 +121,9 @@ CancelEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey
|
|
|
103
121
|
switch (message.properties.type) {
|
|
104
122
|
case 'discard':
|
|
105
123
|
{
|
|
106
|
-
this[
|
|
124
|
+
this[_constants.K_COMPLETED] = true;
|
|
107
125
|
this._stop();
|
|
108
|
-
const content = (0, _messageHelper.cloneContent)(this[
|
|
126
|
+
const content = (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content);
|
|
109
127
|
return this.broker.publish('execution', 'execute.discard', content);
|
|
110
128
|
}
|
|
111
129
|
case 'stop':
|
|
@@ -3,14 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.CompensateEventDefinition = CompensateEventDefinition;
|
|
7
7
|
var _shared = require("../shared.js");
|
|
8
8
|
var _messageHelper = require("../messageHelper.js");
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
var _constants = require("../constants.js");
|
|
10
|
+
const K_COMPENSATE_Q = Symbol.for('compensateQ');
|
|
11
|
+
const K_ASSOCIATIONS = Symbol.for('associations');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Compensate event definition
|
|
15
|
+
* @param {import('#types').Activity} activity
|
|
16
|
+
* @param {import('moddle-context-serializer').EventDefinition} eventDefinition
|
|
17
|
+
* @param {import('#types').ContextInstance} context
|
|
18
|
+
*/
|
|
14
19
|
function CompensateEventDefinition(activity, eventDefinition, context) {
|
|
15
20
|
const {
|
|
16
21
|
id,
|
|
@@ -20,45 +25,56 @@ function CompensateEventDefinition(activity, eventDefinition, context) {
|
|
|
20
25
|
} = activity;
|
|
21
26
|
this.id = id;
|
|
22
27
|
const type = this.type = eventDefinition.type;
|
|
23
|
-
const
|
|
24
|
-
|
|
28
|
+
const referenceType = 'compensate';
|
|
29
|
+
/** @type {import('#types').EventReference} */
|
|
30
|
+
this.reference = {
|
|
31
|
+
referenceType
|
|
25
32
|
};
|
|
26
33
|
this.isThrowing = isThrowing;
|
|
27
34
|
this.activity = activity;
|
|
28
35
|
this.broker = broker;
|
|
29
36
|
this.logger = environment.Logger(type.toLowerCase());
|
|
30
37
|
if (!isThrowing) {
|
|
31
|
-
this[
|
|
32
|
-
this[
|
|
33
|
-
const messageQueueName = `${
|
|
34
|
-
this[
|
|
38
|
+
this[_constants.K_COMPLETED] = false;
|
|
39
|
+
this[K_ASSOCIATIONS] = context.getOutboundAssociations(id);
|
|
40
|
+
const messageQueueName = `${referenceType}-${(0, _shared.brokerSafeId)(id)}-q`;
|
|
41
|
+
this[_constants.K_MESSAGE_Q] = broker.assertQueue(messageQueueName, {
|
|
35
42
|
autoDelete: false,
|
|
36
43
|
durable: true
|
|
37
44
|
});
|
|
38
|
-
this[
|
|
45
|
+
this[K_COMPENSATE_Q] = broker.assertQueue('compensate-q', {
|
|
39
46
|
autoDelete: false,
|
|
40
47
|
durable: true
|
|
41
48
|
});
|
|
42
|
-
broker.bindQueue(messageQueueName, 'api', `*.${
|
|
49
|
+
broker.bindQueue(messageQueueName, 'api', `*.${referenceType}.#`, {
|
|
43
50
|
durable: true,
|
|
44
51
|
priority: 400
|
|
45
52
|
});
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
55
|
Object.defineProperty(CompensateEventDefinition.prototype, 'executionId', {
|
|
56
|
+
/** @returns {string} */
|
|
49
57
|
get() {
|
|
50
|
-
return this[
|
|
58
|
+
return this[_constants.K_EXECUTE_MESSAGE]?.content.executionId;
|
|
51
59
|
}
|
|
52
60
|
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
64
|
+
*/
|
|
53
65
|
CompensateEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
54
66
|
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
55
67
|
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
71
|
+
*/
|
|
56
72
|
CompensateEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
|
|
57
|
-
this[
|
|
58
|
-
this[
|
|
73
|
+
this[_constants.K_EXECUTE_MESSAGE] = executeMessage;
|
|
74
|
+
this[_constants.K_COMPLETED] = false;
|
|
59
75
|
if (executeMessage.fields.routingKey === 'execute.compensating') {
|
|
60
76
|
this._debug('resumed at compensating');
|
|
61
|
-
this[
|
|
77
|
+
this[_constants.K_COMPLETED] = true;
|
|
62
78
|
return this._compensate();
|
|
63
79
|
}
|
|
64
80
|
const executeContent = executeMessage.content;
|
|
@@ -74,11 +90,11 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
|
|
|
74
90
|
noAck: true,
|
|
75
91
|
consumerTag: '_oncollect-messages'
|
|
76
92
|
});
|
|
77
|
-
this[
|
|
93
|
+
this[_constants.K_MESSAGE_Q].consume(this._onCompensateApiMessage.bind(this), {
|
|
78
94
|
noAck: true,
|
|
79
95
|
consumerTag: `_oncompensate-${executionId}`
|
|
80
96
|
});
|
|
81
|
-
if (this[
|
|
97
|
+
if (this[_constants.K_COMPLETED]) return;
|
|
82
98
|
broker.subscribeTmp('api', `activity.#.${parent.executionId}#`, this._onApiMessage.bind(this), {
|
|
83
99
|
noAck: true,
|
|
84
100
|
consumerTag: `_api-${executionId}`
|
|
@@ -89,6 +105,10 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
|
|
|
89
105
|
expect: 'compensate'
|
|
90
106
|
}));
|
|
91
107
|
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
111
|
+
*/
|
|
92
112
|
CompensateEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
93
113
|
const executeContent = executeMessage.content;
|
|
94
114
|
const {
|
|
@@ -113,15 +133,15 @@ CompensateEventDefinition.prototype._onCollect = function onCollect(routingKey,
|
|
|
113
133
|
case 'execute.error':
|
|
114
134
|
case 'execute.completed':
|
|
115
135
|
{
|
|
116
|
-
return this[
|
|
136
|
+
return this[K_COMPENSATE_Q].queueMessage(message.fields, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
117
137
|
}
|
|
118
138
|
}
|
|
119
139
|
};
|
|
120
140
|
CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompensateApiMessage(routingKey, message) {
|
|
121
|
-
this[
|
|
141
|
+
this[_constants.K_COMPLETED] = true;
|
|
122
142
|
const output = message.content.message;
|
|
123
143
|
const broker = this.broker;
|
|
124
|
-
const executeContent = this[
|
|
144
|
+
const executeContent = this[_constants.K_EXECUTE_MESSAGE].content;
|
|
125
145
|
this._stopCollect();
|
|
126
146
|
this._debug('caught compensate event');
|
|
127
147
|
const catchContent = (0, _messageHelper.cloneContent)(executeContent, {
|
|
@@ -131,7 +151,7 @@ CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompens
|
|
|
131
151
|
executionId: executeContent.parent.executionId
|
|
132
152
|
});
|
|
133
153
|
catchContent.parent = (0, _messageHelper.shiftParent)(catchContent.parent);
|
|
134
|
-
this[
|
|
154
|
+
this[K_COMPENSATE_Q].queueMessage({
|
|
135
155
|
routingKey: 'execute.compensated'
|
|
136
156
|
}, (0, _messageHelper.cloneContent)(executeContent));
|
|
137
157
|
broker.publish('execution', 'execute.compensating', (0, _messageHelper.cloneContent)(executeContent, {
|
|
@@ -145,7 +165,7 @@ CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompens
|
|
|
145
165
|
return this._compensate();
|
|
146
166
|
};
|
|
147
167
|
CompensateEventDefinition.prototype._compensate = function compensate() {
|
|
148
|
-
return this[
|
|
168
|
+
return this[K_COMPENSATE_Q].consume(this._onCollected.bind(this), {
|
|
149
169
|
noAck: true,
|
|
150
170
|
consumerTag: '_convey-messages'
|
|
151
171
|
});
|
|
@@ -158,14 +178,14 @@ CompensateEventDefinition.prototype._onCollected = function onCollected(routingK
|
|
|
158
178
|
cancelActivity: false
|
|
159
179
|
}));
|
|
160
180
|
}
|
|
161
|
-
for (const association of this[
|
|
181
|
+
for (const association of this[K_ASSOCIATIONS]) association.take((0, _messageHelper.cloneMessage)(message));
|
|
162
182
|
};
|
|
163
183
|
CompensateEventDefinition.prototype._onDiscardApiMessage = function onDiscardApiMessage(routingKey, message) {
|
|
164
|
-
this[
|
|
184
|
+
this[_constants.K_COMPLETED] = true;
|
|
165
185
|
this._stop();
|
|
166
|
-
this[
|
|
167
|
-
for (const association of this[
|
|
168
|
-
return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[
|
|
186
|
+
this[K_COMPENSATE_Q].purge();
|
|
187
|
+
for (const association of this[K_ASSOCIATIONS]) association.discard((0, _messageHelper.cloneMessage)(message));
|
|
188
|
+
return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content));
|
|
169
189
|
};
|
|
170
190
|
CompensateEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
171
191
|
const messageType = message.properties.type;
|
|
@@ -190,7 +210,7 @@ CompensateEventDefinition.prototype._stopCollect = function stopCollect() {
|
|
|
190
210
|
broker.cancel(`_api-${executionId}`);
|
|
191
211
|
broker.cancel(`_oncompensate-${executionId}`);
|
|
192
212
|
broker.cancel('_oncollect-messages');
|
|
193
|
-
this[
|
|
213
|
+
this[_constants.K_MESSAGE_Q].purge();
|
|
194
214
|
};
|
|
195
215
|
CompensateEventDefinition.prototype._stop = function stop() {
|
|
196
216
|
this._stopCollect();
|
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.ConditionalEventDefinition = ConditionalEventDefinition;
|
|
7
7
|
var _messageHelper = require("../messageHelper.js");
|
|
8
8
|
var _Errors = require("../error/Errors.js");
|
|
9
9
|
var _condition = require("../condition.js");
|
|
10
|
-
|
|
10
|
+
var _constants = require("../constants.js");
|
|
11
|
+
/**
|
|
12
|
+
* Conditional event definition
|
|
13
|
+
* @param {import('#types').Activity} activity
|
|
14
|
+
* @param {import('moddle-context-serializer').EventDefinition} eventDefinition
|
|
15
|
+
* @param {import('#types').ContextInstance} _context
|
|
16
|
+
* @param {number} index event definition index
|
|
17
|
+
*/
|
|
11
18
|
function ConditionalEventDefinition(activity, eventDefinition, _context, index) {
|
|
12
19
|
const {
|
|
13
20
|
id,
|
|
@@ -28,12 +35,17 @@ function ConditionalEventDefinition(activity, eventDefinition, _context, index)
|
|
|
28
35
|
this.condition = this.getCondition(index);
|
|
29
36
|
}
|
|
30
37
|
Object.defineProperty(ConditionalEventDefinition.prototype, 'executionId', {
|
|
38
|
+
/** @returns {string} */
|
|
31
39
|
get() {
|
|
32
|
-
return this[
|
|
40
|
+
return this[_constants.K_EXECUTE_MESSAGE]?.content.executionId;
|
|
33
41
|
}
|
|
34
42
|
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
46
|
+
*/
|
|
35
47
|
ConditionalEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
36
|
-
this[
|
|
48
|
+
this[_constants.K_EXECUTE_MESSAGE] = executeMessage;
|
|
37
49
|
if (!this.condition) return this._setup(executeMessage);
|
|
38
50
|
this.evaluate(executeMessage, (err, result) => {
|
|
39
51
|
this.evaluateCallback(err, result);
|
|
@@ -75,7 +87,7 @@ ConditionalEventDefinition.prototype._setup = function setup(executeMessage) {
|
|
|
75
87
|
|
|
76
88
|
/**
|
|
77
89
|
* Evaluate condition
|
|
78
|
-
* @param {import('types').ElementBrokerMessage} message
|
|
90
|
+
* @param {import('#types').ElementBrokerMessage} message
|
|
79
91
|
* @param {CallableFunction} callback
|
|
80
92
|
*/
|
|
81
93
|
ConditionalEventDefinition.prototype.evaluate = function evaluate(message, callback) {
|
|
@@ -94,7 +106,7 @@ ConditionalEventDefinition.prototype.evaluate = function evaluate(message, callb
|
|
|
94
106
|
*/
|
|
95
107
|
ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallback(err, result) {
|
|
96
108
|
const broker = this.broker;
|
|
97
|
-
const executeMessage = this[
|
|
109
|
+
const executeMessage = this[_constants.K_EXECUTE_MESSAGE];
|
|
98
110
|
const executeContent = executeMessage.content;
|
|
99
111
|
if (err) {
|
|
100
112
|
return broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeContent, {
|
|
@@ -104,7 +116,7 @@ ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallbac
|
|
|
104
116
|
}));
|
|
105
117
|
}
|
|
106
118
|
this._debug(`condition evaluated to ${!!result}`);
|
|
107
|
-
this.broker.publish('event', 'activity.condition', (0, _messageHelper.cloneContent)(this[
|
|
119
|
+
this.broker.publish('event', 'activity.condition', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
|
|
108
120
|
conditionResult: result
|
|
109
121
|
}));
|
|
110
122
|
if (!result) return;
|
|
@@ -117,7 +129,7 @@ ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallbac
|
|
|
117
129
|
/**
|
|
118
130
|
* Get condition
|
|
119
131
|
* @param {number} index Eventdefinition sequence number, used to name registered script
|
|
120
|
-
* @returns {
|
|
132
|
+
* @returns {import('#types').ICondition | null}
|
|
121
133
|
*/
|
|
122
134
|
ConditionalEventDefinition.prototype.getCondition = function getCondition(index) {
|
|
123
135
|
const behaviour = this.behaviour;
|
|
@@ -166,7 +178,7 @@ ConditionalEventDefinition.prototype._onApiMessage = function onApiMessage(routi
|
|
|
166
178
|
{
|
|
167
179
|
this._stop();
|
|
168
180
|
this._debug('discarded');
|
|
169
|
-
return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[
|
|
181
|
+
return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
|
|
170
182
|
state: 'discard'
|
|
171
183
|
}));
|
|
172
184
|
}
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.ErrorEventDefinition = ErrorEventDefinition;
|
|
7
7
|
var _shared = require("../shared.js");
|
|
8
8
|
var _messageHelper = require("../messageHelper.js");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
var _constants = require("../constants.js");
|
|
10
|
+
/**
|
|
11
|
+
* Error event definition
|
|
12
|
+
* @param {import('#types').Activity} activity
|
|
13
|
+
* @param {import('moddle-context-serializer').EventDefinition} eventDefinition
|
|
14
|
+
*/
|
|
14
15
|
function ErrorEventDefinition(activity, eventDefinition) {
|
|
15
16
|
const {
|
|
16
17
|
id,
|
|
@@ -24,7 +25,9 @@ function ErrorEventDefinition(activity, eventDefinition) {
|
|
|
24
25
|
} = eventDefinition;
|
|
25
26
|
this.id = id;
|
|
26
27
|
this.type = type;
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
/** @type {import('#types').EventReference} */
|
|
30
|
+
this.reference = {
|
|
28
31
|
name: 'anonymous',
|
|
29
32
|
...behaviour.errorRef,
|
|
30
33
|
referenceType: 'throw'
|
|
@@ -34,44 +37,53 @@ function ErrorEventDefinition(activity, eventDefinition) {
|
|
|
34
37
|
this.environment = environment;
|
|
35
38
|
this.broker = broker;
|
|
36
39
|
this.logger = environment.Logger(type.toLowerCase());
|
|
37
|
-
const referenceElement = this[
|
|
40
|
+
const referenceElement = this[_constants.K_REFERENCE_ELEMENT] = this.reference.id && activity.getActivityById(this.reference.id);
|
|
38
41
|
if (!isThrowing) {
|
|
39
|
-
this[
|
|
42
|
+
this[_constants.K_COMPLETED] = false;
|
|
40
43
|
const referenceId = referenceElement ? referenceElement.id : 'anonymous';
|
|
41
|
-
const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(referenceId)}-q`;
|
|
42
|
-
this[
|
|
44
|
+
const messageQueueName = `${this.reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(referenceId)}-q`;
|
|
45
|
+
this[_constants.K_MESSAGE_Q] = broker.assertQueue(messageQueueName, {
|
|
43
46
|
autoDelete: false,
|
|
44
47
|
durable: true
|
|
45
48
|
});
|
|
46
|
-
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {
|
|
49
|
+
broker.bindQueue(messageQueueName, 'api', `*.${this.reference.referenceType}.#`, {
|
|
47
50
|
durable: true,
|
|
48
51
|
priority: 300
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
Object.defineProperty(ErrorEventDefinition.prototype, 'executionId', {
|
|
56
|
+
/** @returns {string} */
|
|
53
57
|
get() {
|
|
54
|
-
return this[
|
|
58
|
+
return this[_constants.K_EXECUTE_MESSAGE]?.content.executionId;
|
|
55
59
|
}
|
|
56
60
|
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
64
|
+
*/
|
|
57
65
|
ErrorEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
58
66
|
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
59
67
|
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
71
|
+
*/
|
|
60
72
|
ErrorEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
|
|
61
|
-
this[
|
|
62
|
-
this[
|
|
73
|
+
this[_constants.K_EXECUTE_MESSAGE] = executeMessage;
|
|
74
|
+
this[_constants.K_COMPLETED] = false;
|
|
63
75
|
const executeContent = executeMessage.content;
|
|
64
76
|
const {
|
|
65
77
|
executionId,
|
|
66
78
|
parent
|
|
67
79
|
} = executeContent;
|
|
68
80
|
const parentExecutionId = parent?.executionId;
|
|
69
|
-
const info = this[
|
|
70
|
-
this[
|
|
81
|
+
const info = this[_constants.K_REFERENCE_INFO] = this._getReferenceInfo(executeMessage);
|
|
82
|
+
this[_constants.K_MESSAGE_Q].consume(this._onThrowApiMessage.bind(this), {
|
|
71
83
|
noAck: true,
|
|
72
84
|
consumerTag: `_onthrow-${executionId}`
|
|
73
85
|
});
|
|
74
|
-
if (this[
|
|
86
|
+
if (this[_constants.K_COMPLETED]) return;
|
|
75
87
|
this._debug(`expect ${info.description}`);
|
|
76
88
|
const broker = this.broker;
|
|
77
89
|
broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
|
|
@@ -92,7 +104,7 @@ ErrorEventDefinition.prototype.executeCatch = function executeCatch(executeMessa
|
|
|
92
104
|
...info.message
|
|
93
105
|
}
|
|
94
106
|
}));
|
|
95
|
-
if (this[
|
|
107
|
+
if (this[_constants.K_COMPLETED]) return this._stop();
|
|
96
108
|
}
|
|
97
109
|
const waitContent = (0, _messageHelper.cloneContent)(executeContent, {
|
|
98
110
|
executionId: parentExecutionId,
|
|
@@ -103,6 +115,10 @@ ErrorEventDefinition.prototype.executeCatch = function executeCatch(executeMessa
|
|
|
103
115
|
waitContent.parent = (0, _messageHelper.shiftParent)(parent);
|
|
104
116
|
broker.publish('event', 'activity.wait', waitContent);
|
|
105
117
|
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
121
|
+
*/
|
|
106
122
|
ErrorEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
107
123
|
const executeContent = executeMessage.content;
|
|
108
124
|
const {
|
|
@@ -132,24 +148,24 @@ ErrorEventDefinition.prototype.executeThrow = function executeThrow(executeMessa
|
|
|
132
148
|
};
|
|
133
149
|
ErrorEventDefinition.prototype._onErrorMessage = function onErrorMessage(routingKey, message) {
|
|
134
150
|
const error = message.content.error;
|
|
135
|
-
if (!this[
|
|
151
|
+
if (!this[_constants.K_REFERENCE_ELEMENT]) return this._catchError(routingKey, message, error);
|
|
136
152
|
if (!error) return;
|
|
137
|
-
const info = this[
|
|
153
|
+
const info = this[_constants.K_REFERENCE_INFO];
|
|
138
154
|
if ('' + error.code !== '' + info.message.code) return;
|
|
139
155
|
return this._catchError(routingKey, message, error);
|
|
140
156
|
};
|
|
141
157
|
ErrorEventDefinition.prototype._onThrowApiMessage = function onThrowApiMessage(routingKey, message) {
|
|
142
158
|
const error = message.content.message;
|
|
143
|
-
if (!this[
|
|
144
|
-
const info = this[
|
|
159
|
+
if (!this[_constants.K_REFERENCE_ELEMENT]) return this._catchError(routingKey, message, error);
|
|
160
|
+
const info = this[_constants.K_REFERENCE_INFO];
|
|
145
161
|
if (info.message.id !== error?.id) return;
|
|
146
162
|
return this._catchError(routingKey, message, error);
|
|
147
163
|
};
|
|
148
164
|
ErrorEventDefinition.prototype._catchError = function catchError(routingKey, message, error) {
|
|
149
|
-
this[
|
|
165
|
+
this[_constants.K_COMPLETED] = true;
|
|
150
166
|
this._stop();
|
|
151
|
-
this._debug(`caught ${this[
|
|
152
|
-
const executeContent = this[
|
|
167
|
+
this._debug(`caught ${this[_constants.K_REFERENCE_INFO].description}`);
|
|
168
|
+
const executeContent = this[_constants.K_EXECUTE_MESSAGE].content;
|
|
153
169
|
const parent = executeContent.parent;
|
|
154
170
|
const catchContent = (0, _messageHelper.cloneContent)(executeContent, {
|
|
155
171
|
source: {
|
|
@@ -176,9 +192,9 @@ ErrorEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
|
|
|
176
192
|
switch (messageType) {
|
|
177
193
|
case 'discard':
|
|
178
194
|
{
|
|
179
|
-
this[
|
|
195
|
+
this[_constants.K_COMPLETED] = true;
|
|
180
196
|
this._stop();
|
|
181
|
-
return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[
|
|
197
|
+
return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content));
|
|
182
198
|
}
|
|
183
199
|
case 'stop':
|
|
184
200
|
{
|
|
@@ -193,10 +209,10 @@ ErrorEventDefinition.prototype._stop = function stop() {
|
|
|
193
209
|
broker.cancel(`_onthrow-${executionId}`);
|
|
194
210
|
broker.cancel(`_onerror-${executionId}`);
|
|
195
211
|
broker.cancel(`_api-${executionId}`);
|
|
196
|
-
this[
|
|
212
|
+
this[_constants.K_MESSAGE_Q].purge();
|
|
197
213
|
};
|
|
198
214
|
ErrorEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(message) {
|
|
199
|
-
const referenceElement = this[
|
|
215
|
+
const referenceElement = this[_constants.K_REFERENCE_ELEMENT];
|
|
200
216
|
if (!referenceElement) {
|
|
201
217
|
return {
|
|
202
218
|
message: {
|