bpmn-elements 6.0.0 → 8.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +335 -0
  2. package/README.md +3 -0
  3. package/dist/index.js +52 -44
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +176 -172
  6. package/dist/src/Environment.js +110 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/activity/Activity.js +1106 -916
  12. package/dist/src/activity/ActivityExecution.js +342 -297
  13. package/dist/src/activity/Dummy.js +3 -3
  14. package/dist/src/definition/Definition.js +498 -444
  15. package/dist/src/definition/DefinitionExecution.js +710 -408
  16. package/dist/src/error/Errors.js +17 -7
  17. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  18. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  19. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  20. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  21. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  22. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  23. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  24. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  25. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  26. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  27. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  28. package/dist/src/events/BoundaryEvent.js +180 -144
  29. package/dist/src/events/EndEvent.js +18 -23
  30. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  31. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  32. package/dist/src/events/StartEvent.js +109 -94
  33. package/dist/src/flows/Association.js +94 -100
  34. package/dist/src/flows/MessageFlow.js +86 -103
  35. package/dist/src/flows/SequenceFlow.js +173 -182
  36. package/dist/src/gateways/EventBasedGateway.js +88 -84
  37. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  38. package/dist/src/gateways/InclusiveGateway.js +11 -14
  39. package/dist/src/gateways/ParallelGateway.js +11 -14
  40. package/dist/src/getPropertyValue.js +34 -34
  41. package/dist/src/io/BpmnIO.js +17 -14
  42. package/dist/src/io/EnvironmentDataObject.js +33 -29
  43. package/dist/src/io/EnvironmentDataStore.js +33 -29
  44. package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
  45. package/dist/src/io/InputOutputSpecification.js +177 -168
  46. package/dist/src/io/Properties.js +117 -124
  47. package/dist/src/messageHelper.js +1 -1
  48. package/dist/src/process/Process.js +439 -362
  49. package/dist/src/process/ProcessExecution.js +748 -646
  50. package/dist/src/shared.js +2 -2
  51. package/dist/src/tasks/CallActivity.js +160 -0
  52. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  53. package/dist/src/tasks/ReceiveTask.js +233 -182
  54. package/dist/src/tasks/ScriptTask.js +35 -41
  55. package/dist/src/tasks/ServiceImplementation.js +13 -20
  56. package/dist/src/tasks/ServiceTask.js +82 -75
  57. package/dist/src/tasks/SignalTask.js +97 -93
  58. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  59. package/dist/src/tasks/SubProcess.js +193 -175
  60. package/dist/src/tasks/Task.js +17 -19
  61. package/index.js +2 -0
  62. package/package.json +15 -15
  63. package/src/Api.js +65 -59
  64. package/src/Context.js +145 -140
  65. package/src/Environment.js +116 -100
  66. package/src/EventBroker.js +67 -68
  67. package/src/ExtensionsMapper.js +2 -2
  68. package/src/MessageFormatter.js +132 -74
  69. package/src/activity/Activity.js +915 -775
  70. package/src/activity/ActivityExecution.js +293 -247
  71. package/src/activity/Dummy.js +2 -2
  72. package/src/definition/Definition.js +437 -401
  73. package/src/definition/DefinitionExecution.js +598 -340
  74. package/src/error/Errors.js +11 -6
  75. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  76. package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
  77. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  78. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  79. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  80. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  81. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  82. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  83. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  84. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  85. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  86. package/src/events/BoundaryEvent.js +156 -115
  87. package/src/events/EndEvent.js +15 -18
  88. package/src/events/IntermediateCatchEvent.js +40 -44
  89. package/src/events/IntermediateThrowEvent.js +15 -18
  90. package/src/events/StartEvent.js +84 -50
  91. package/src/flows/Association.js +98 -112
  92. package/src/flows/MessageFlow.js +81 -97
  93. package/src/flows/SequenceFlow.js +146 -160
  94. package/src/gateways/EventBasedGateway.js +75 -68
  95. package/src/gateways/ExclusiveGateway.js +8 -13
  96. package/src/gateways/InclusiveGateway.js +8 -13
  97. package/src/gateways/ParallelGateway.js +8 -13
  98. package/src/getPropertyValue.js +34 -33
  99. package/src/io/BpmnIO.js +20 -15
  100. package/src/io/EnvironmentDataObject.js +29 -18
  101. package/src/io/EnvironmentDataStore.js +29 -18
  102. package/src/io/EnvironmentDataStoreReference.js +31 -20
  103. package/src/io/InputOutputSpecification.js +154 -157
  104. package/src/io/Properties.js +95 -97
  105. package/src/process/Process.js +378 -333
  106. package/src/process/ProcessExecution.js +603 -553
  107. package/src/tasks/CallActivity.js +130 -0
  108. package/src/tasks/LoopCharacteristics.js +290 -289
  109. package/src/tasks/ReceiveTask.js +174 -107
  110. package/src/tasks/ScriptTask.js +27 -30
  111. package/src/tasks/ServiceImplementation.js +13 -18
  112. package/src/tasks/ServiceTask.js +67 -60
  113. package/src/tasks/SignalTask.js +77 -52
  114. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  115. package/src/tasks/SubProcess.js +184 -157
  116. package/src/tasks/Task.js +15 -19
@@ -7,6 +7,10 @@ exports.default = ConditionalEventDefinition;
7
7
 
8
8
  var _messageHelper = require("../messageHelper");
9
9
 
10
+ var _Errors = require("../error/Errors");
11
+
12
+ const kExecuteMessage = Symbol.for('executeMessage');
13
+
10
14
  function ConditionalEventDefinition(activity, eventDefinition) {
11
15
  const {
12
16
  id,
@@ -18,147 +22,205 @@ function ConditionalEventDefinition(activity, eventDefinition) {
18
22
  type = 'ConditionalEventDefinition',
19
23
  behaviour = {}
20
24
  } = eventDefinition;
21
- const {
22
- debug
23
- } = environment.Logger(type.toLowerCase());
24
- const condition = behaviour.expression;
25
- const isWaiting = !attachedTo;
26
- const source = {
27
- type,
28
- condition,
29
- execute
30
- };
31
- return source;
32
-
33
- function execute(executeMessage) {
34
- return isWaiting ? executeWait(executeMessage) : executeCatch(executeMessage);
25
+ this.id = id;
26
+ this.type = type;
27
+ this.isWaiting = !attachedTo;
28
+ this.condition = behaviour.expression;
29
+ this.activity = activity;
30
+ this.environment = environment;
31
+ this.broker = broker;
32
+ this.logger = environment.Logger(type.toLowerCase());
33
+ }
34
+
35
+ const proto = ConditionalEventDefinition.prototype;
36
+ Object.defineProperty(proto, 'executionId', {
37
+ get() {
38
+ const message = this[kExecuteMessage];
39
+ return message && message.content.executionId;
35
40
  }
36
41
 
37
- function executeCatch(executeMessage) {
38
- const attachedToBroker = attachedTo.broker;
39
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
40
- const {
41
- executionId,
42
- index
43
- } = messageContent;
44
- messageContent.condition = condition;
45
- const apiConsumerTag = `_api-${executionId}_${index}`;
46
- const endConsumerTag = `_onend-${executionId}_${index}`;
47
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
48
- noAck: true,
49
- consumerTag: apiConsumerTag
50
- });
51
- debug(`<${executionId} (${id})> listen for execute completed from <${attachedTo.id}>`);
52
- attachedToBroker.subscribeOnce('execution', 'execute.completed', onAttachedCompleted, {
53
- priority: 300,
54
- consumerTag: endConsumerTag
55
- });
56
-
57
- function onAttachedCompleted(routingKey, endMessage) {
58
- stop();
59
- const output = environment.resolveExpression(condition, endMessage);
60
- debug(`<${executionId} (${id})> condition from <${endMessage.content.executionId}> evaluated to`, !!output);
61
- broker.publish('event', 'activity.condition', { ...(0, _messageHelper.cloneContent)(messageContent),
62
- conditionResult: output
63
- });
64
-
65
- if (output) {
66
- broker.publish('execution', 'execute.completed', { ...messageContent,
67
- output
68
- });
42
+ });
43
+
44
+ proto.execute = function execute(executeMessage) {
45
+ this[kExecuteMessage] = executeMessage;
46
+ return this.isWaiting ? this.executeWait(executeMessage) : this.executeCatch(executeMessage);
47
+ };
48
+
49
+ proto.executeWait = function executeWait(executeMessage) {
50
+ const executeContent = executeMessage.content;
51
+ const {
52
+ executionId,
53
+ parent
54
+ } = executeContent;
55
+ const parentExecutionId = parent.executionId;
56
+ if (this._evaluateWait(executeMessage)) return;
57
+ const broker = this.broker;
58
+
59
+ const onApiMessage = this._onWaitApiMessage.bind(this);
60
+
61
+ broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
62
+ noAck: true,
63
+ consumerTag: `_api-${executionId}`
64
+ });
65
+ broker.subscribeTmp('api', `activity.signal.${parentExecutionId}`, onApiMessage, {
66
+ noAck: true,
67
+ consumerTag: `_parent-signal-${executionId}`
68
+ });
69
+ const waitContent = (0, _messageHelper.cloneContent)(executeContent, {
70
+ executionId: parentExecutionId,
71
+ condition: this.condition
72
+ });
73
+ waitContent.parent = (0, _messageHelper.shiftParent)(parent);
74
+ broker.publish('event', 'activity.wait', waitContent);
75
+ };
76
+
77
+ proto.executeCatch = function executeCatch(executeMessage) {
78
+ const executeContent = executeMessage.content;
79
+ const {
80
+ executionId,
81
+ index
82
+ } = executeContent;
83
+ this.broker.subscribeTmp('api', `activity.#.${executionId}`, this._onCatchApiMessage.bind(this), {
84
+ noAck: true,
85
+ consumerTag: `_api-${executionId}_${index}`
86
+ });
87
+ const {
88
+ id: attachedToId,
89
+ broker: attachedToBroker
90
+ } = this.activity.attachedTo;
91
+
92
+ this._debug(`listen for execute completed from <${attachedToId}>`);
93
+
94
+ attachedToBroker.subscribeOnce('execution', 'execute.completed', this._onAttachedCompleted.bind(this), {
95
+ priority: 300,
96
+ consumerTag: `_onend-${executionId}_${index}`
97
+ });
98
+ };
99
+
100
+ proto._onWaitApiMessage = function onWaitApiMessage(routingKey, message) {
101
+ const messageType = message.properties.type;
102
+
103
+ switch (messageType) {
104
+ case 'signal':
105
+ {
106
+ return this._evaluateWait(message);
69
107
  }
70
- }
71
-
72
- function onApiMessage(routingKey, message) {
73
- const messageType = message.properties.type;
74
-
75
- switch (messageType) {
76
- case 'discard':
77
- {
78
- stop();
79
- debug(`<${executionId} (${id})> discarded`);
80
- return broker.publish('execution', 'execute.discard', { ...messageContent,
81
- state: 'discard'
82
- });
83
- }
84
-
85
- case 'stop':
86
- {
87
- stop();
88
- return debug(`<${executionId} (${id})> stopped`);
89
- }
108
+
109
+ case 'discard':
110
+ {
111
+ this._stopWait();
112
+
113
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
114
+ state: 'discard'
115
+ }));
90
116
  }
91
- }
92
117
 
93
- function stop() {
94
- attachedToBroker.cancel(endConsumerTag);
95
- broker.cancel(apiConsumerTag);
96
- }
118
+ case 'stop':
119
+ {
120
+ return this._stopWait();
121
+ }
97
122
  }
123
+ };
124
+
125
+ proto._evaluateWait = function evaluate(message) {
126
+ const executeMessage = this[kExecuteMessage];
127
+ const broker = this.broker,
128
+ executeContent = executeMessage.content;
129
+
130
+ try {
131
+ var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
132
+ } catch (err) {
133
+ return broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeContent, {
134
+ error: new _Errors.ActivityError(err.message, executeMessage, err)
135
+ }, {
136
+ mandatory: true
137
+ }));
138
+ }
139
+
140
+ this._debug(`condition evaluated to ${!!output}`);
141
+
142
+ broker.publish('event', 'activity.condition', (0, _messageHelper.cloneContent)(executeContent, {
143
+ conditionResult: output
144
+ }));
145
+ if (!output) return;
146
+
147
+ this._stopWait();
148
+
149
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
150
+ output
151
+ }));
152
+ };
153
+
154
+ proto._stopWait = function stopWait() {
155
+ const broker = this.broker,
156
+ executionId = this.executionId;
157
+ broker.cancel(`_api-${executionId}`);
158
+ broker.cancel(`_parent-signal-${executionId}`);
159
+ };
160
+
161
+ proto._onAttachedCompleted = function onAttachedCompleted(routingKey, message) {
162
+ this._stopCatch();
163
+
164
+ const executeMessage = this[kExecuteMessage];
165
+ const broker = this.broker,
166
+ executeContent = executeMessage.content;
167
+
168
+ try {
169
+ var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
170
+ } catch (err) {
171
+ return broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeContent, {
172
+ error: new _Errors.ActivityError(err.message, executeMessage, err)
173
+ }, {
174
+ mandatory: true
175
+ }));
176
+ }
177
+
178
+ this._debug(`condition from <${message.content.executionId}> evaluated to ${!!output}`);
179
+
180
+ broker.publish('event', 'activity.condition', (0, _messageHelper.cloneContent)(executeContent, {
181
+ conditionResult: output
182
+ }));
183
+
184
+ if (output) {
185
+ broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
186
+ output
187
+ }));
188
+ }
189
+ };
190
+
191
+ proto._onCatchApiMessage = function onCatchApiMessage(routingKey, message) {
192
+ const messageType = message.properties.type;
98
193
 
99
- function executeWait(executeMessage) {
100
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
101
- messageContent.condition = condition;
102
- const {
103
- executionId,
104
- parent
105
- } = messageContent;
106
- const parentExecutionId = parent && parent.executionId;
107
- if (evaluate(executeMessage)) return;
108
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
109
- noAck: true,
110
- consumerTag: `_api-${executionId}`
111
- });
112
- broker.subscribeTmp('api', `activity.signal.${parentExecutionId}`, onApiMessage, {
113
- noAck: true,
114
- consumerTag: `_parent-signal-${executionId}`
115
- });
116
- broker.publish('event', 'activity.wait', { ...(0, _messageHelper.cloneContent)(messageContent),
117
- executionId: parentExecutionId,
118
- parent: (0, _messageHelper.shiftParent)(parent)
119
- });
120
-
121
- function onApiMessage(routingKey, message) {
122
- const messageType = message.properties.type;
123
-
124
- switch (messageType) {
125
- case 'signal':
126
- {
127
- return evaluate(message);
128
- }
129
-
130
- case 'discard':
131
- {
132
- stop();
133
- return broker.publish('execution', 'execute.discard', { ...messageContent,
134
- state: 'discard'
135
- });
136
- }
137
-
138
- case 'stop':
139
- {
140
- stop();
141
- break;
142
- }
194
+ switch (messageType) {
195
+ case 'discard':
196
+ {
197
+ this._stopCatch();
198
+
199
+ this._debug('discarded');
200
+
201
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
202
+ state: 'discard'
203
+ }));
204
+ }
205
+
206
+ case 'stop':
207
+ {
208
+ this._stopCatch();
209
+
210
+ return this._debug('stopped');
143
211
  }
144
- }
145
-
146
- function evaluate(message) {
147
- const output = environment.resolveExpression(condition, message);
148
- debug(`<${executionId} (${id})> condition evaluated to`, !!output);
149
- broker.publish('event', 'activity.condition', { ...(0, _messageHelper.cloneContent)(messageContent),
150
- conditionResult: output
151
- });
152
- if (!output) return;
153
- stop();
154
- return broker.publish('execution', 'execute.completed', { ...messageContent,
155
- output
156
- });
157
- }
158
-
159
- function stop() {
160
- broker.cancel(`_api-${executionId}`);
161
- broker.cancel(`_parent-signal-${executionId}`);
162
- }
163
212
  }
164
- }
213
+ };
214
+
215
+ proto._stopCatch = function stopCatch() {
216
+ const {
217
+ executionId,
218
+ index
219
+ } = this[kExecuteMessage].content;
220
+ this.activity.attachedTo.broker.cancel(`_onend-${executionId}_${index}`);
221
+ this.broker.cancel(`_api-${executionId}_${index}`);
222
+ };
223
+
224
+ proto._debug = function debug(msg) {
225
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
226
+ };