bpmn-elements 5.1.3 → 7.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 (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -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/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. 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 executeMessageSymbol = 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[executeMessageSymbol];
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[executeMessageSymbol] = 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[executeMessageSymbol].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[executeMessageSymbol];
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[executeMessageSymbol];
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[executeMessageSymbol].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[executeMessageSymbol].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
+ };